0% found this document useful (0 votes)
46 views

Lab 3 8-Bit Multiplication and Division, Factorial: Siddhartha (SC13B119) February, 01,2015

This document contains an assembly language program written for the 8085 microprocessor to perform 8-bit multiplication, division, and factorial calculations. It includes the algorithms, program code, and results for each calculation. The multiplication program multiplies two 8-bit numbers by repeatedly adding the first number. The division program divides and finds the quotient and remainder by subtracting the second number from the first until it is smaller. The factorial program calculates the factorial of a given number by repeatedly multiplying it by descending integers and storing the result in the HL register pair.

Uploaded by

vetalap7
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

Lab 3 8-Bit Multiplication and Division, Factorial: Siddhartha (SC13B119) February, 01,2015

This document contains an assembly language program written for the 8085 microprocessor to perform 8-bit multiplication, division, and factorial calculations. It includes the algorithms, program code, and results for each calculation. The multiplication program multiplies two 8-bit numbers by repeatedly adding the first number. The division program divides and finds the quotient and remainder by subtracting the second number from the first until it is smaller. The factorial program calculates the factorial of a given number by repeatedly multiplying it by descending integers and storing the result in the HL register pair.

Uploaded by

vetalap7
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Lab 3

8-bit Multiplication and Division, Factorial


Siddhartha
(SC13B119)
February,01,2015
Sub: Microprocessor and Micro-controllers
Date of Submission: February 8, 2015

Department:B Tech(Avionics)

Question 1:
Write an assembly language program (ALP) in 8085 to multiply two 8 bit numbers.

Algorithm:
load the first number to A.
Move the number in B.
load the second number to A and store it in D.
Move the 1st number in A.
Decrement the second number stored in D by 1.
Add the first number with same number.
Jump if no carry.
Decrement the second number stored in D by 1 again.
Make a loop till the content of D not become 0.
Store the content of A to memory.

Program Code:

Label

Address
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009

GO

L1

800A
800B
800C
800D
800E
800F
8010
8011
8012
8013
8014
8015
8016
8017
8018

Table 1: Multiplication of two 8 bit numbers


Opcode
Mnemonics
Operands
Comments
0E
MVI
C,00
Move Immediate value to C
00
3A
LDA
8500
Load the accumulator
00
85
Copy content of accumulator to
47
MOV
B,A
B
3A
LDA
8501
Load the accumulator
01
85
Copy content of accumulator to
57
MOV
D,A
D.
78
MOV
A,B
Copy content of B to A.
15
DCR
D
Decrement the content of D by 1.
80
ADD
B
Add content of B to Accumulator
D2
JNC
L1
Jump if no carry to L1
11
80
0C
INR
C
Increment by 1
15
DCR
D
Decrement the content of D by 1
C2
JNZ
GO
Jump if no zero to GO.
0C
80
store the content of accumulator
32
STA
8504
to memory
00
86
76
HLT

Result
Contents of utilised memory locations and the registers after execution of the program are as follows:
Table 2: Memory contents
Memory Locations Content
8500
03
8501
04
8502
0C

Table 3: Register contents


Register Content
A
0C
B
03
C
00
D
00
E
00
H
00
L
00

Discussion
The program multiplies two bytes using basic technique that is addition of the first number second
number times.

Question 2:
Write an assembly language program (ALP) in 8085 to divide two immediate 8 bit numbers and take
care of the quotient and reminder generated during operation.

Algorithm:
load the first number to A.
Move the number in B.
load the second number to A and store it in D.
Move the 1st number in A.
Compare the two numbers.
If second number is greater than the first number then quotient is 0 and reminder is first number.
If second number is smaller than the first number then subtract the number till it become smaller.
Set a loop and increment the content of one register by 1 in each execution of loop that is our
quotient.
Final subtraction is reminder.
Return control to moniter.

Program Code:

LOOP

GO

8000
8001
8002
8003
8004

0E
00
3A
00
85

8005

Division of two Bytes


MVI
C,00

Move Immediate value to C

LDA

8500

Load the accumulator

47

MOV

B,A

8006
8007
8008

3A
01
85

LDA

8501

8009

57

MOV

D,A

800A
800B
800C
800D
800E
800F
8010
8011
8012

B8
DA
13
85
0C
90
C2
0A
80

CMP
JC

B
GO

Copy content of accumulator to


D.
copmpare a with B.
Jump if carry is set to GO.

INR
SUB
JNZ

C
B
LOOP

Increment by 1
subtract the B from A.
Jump if no zero to LOOP.

8013

32

STA

8600

REMINDERstore the content


of accumulator to memory

8014
8015
8016

00
86
79

MOV

A,C

8017

32

STA

8601

8018
8019
801A

01
86
76

HLT

Copy content of accumulator to


B
Load the accumulator

Copy content of C to A.
QUOTIENTstore the content
of accumulator to memory

Result
Contents of utilised memory locations and the registers after execution of the program are as follows:
Table 4: Memory contents
Memory Locations Content Memory Locations
8500
0A
8600
8502
03
8601

Table 5: Register contents


Register Content Register Content
A
03
B
03
C
03
D
0A
E
00
H
00
L
00

Content
01
03

Discussion
The program divide two bytes using SUB and CMP.

Question 3:
Write an assembly language program (ALP) in 8085 to find the factorial of a given number and store it
in HL pair.

Algorithm:
load the bytes into accumulator and Register B and L.
Store 00 in H register.
decrease the content of register B by 1.
move contents of HL pair to DE pair.
move contents of register B to C.
decrease the content of register C by 1.
add contents of DE pair to HL pair.
decrease the content of register C by 1.
jump if not zero.
move contents of L to accumulator.
store contents of HL pair to memory loaction 8501.
Return control to the monitor.

Program Code:

Label

Address
8000
8001
8002
8003
8004
8006
8007
8008

Opcode
3A
06
08
47
6F
26
00
05

8009

Table 6: Factorial of a number


Mnemonics
Operands
LDA
8600

Comments
load content in accumulator

MOV
MOV
MVI

B,A
L,A
H,00

move contents of A to B
move contents of A to L
store 00 to to register H

DCR

54

MOV

D,A

800A
800B
800C
800D
800E
800F
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
801A
801B
801C
801D
801E
801F

5D
48
0D
CA
18
80
19
0D
C2
10
80
CA
08
80
7D
32
01
86
7C
32
03
86

MOV
MOV
DCR
JZ

E,L
C,B
C
8018

decrement B
move contents of accumulator to
D
move contents of L to E
move contents of B to C
decrement C
jump if zero

DAD
DCR
JNZ

D
C
8010

add content of DE to HL
decrement C
jump if not zero

JZ

8008

jump if zero

MOV
STA

A,L
8601

move contents of L to A
store content of accumulator

MOV
STA

A,H
8602

move contents of H to A
store content of accumulator

8020

DF

RST3

Return controls to monitor program

Result
Contents of utilised memory locations and the registers after execution of the program are as follows:
Table 7: Register contents
Register Content Register Content
A
05
B
01
C
00
D
00
E
3C
H
00
L
78

Discussion
The program calculates the factorial using DAD

You might also like