Lab 3 8-Bit Multiplication and Division, Factorial: Siddhartha (SC13B119) February, 01,2015
Lab 3 8-Bit Multiplication and Division, Factorial: Siddhartha (SC13B119) February, 01,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
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
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
LDA
8500
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
INR
SUB
JNZ
C
B
LOOP
Increment by 1
subtract the B from A.
Jump if no zero to LOOP.
8013
32
STA
8600
8014
8015
8016
00
86
79
MOV
A,C
8017
32
STA
8601
8018
8019
801A
01
86
76
HLT
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
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
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
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