Tuesday 28 November 2017

8085 Program to find factorial of a number in 8085

Program to find factorial of a number in 8085

Here is a program to find factorial of a number in 8085

MVI B, 03H
MOV C, B
DCR C
LOOP1:
MOV E, C
SUB A
LOOP2:
ADD B
DCR E
JNZ LOOP2
MOV B, A
DCR C
JNZ LOOP1
STA 8000H
HLT

Advanced Code


MEMORY
LABEL
MNEMONIC
HEX CODE
COMMENT
4200
LXI H,4100
21

Load the number to the HL pair
4201
00
4202
41
4203
MVI C,M
4E
Copy the number to register C
4204
MVI E,M
5E
Copy memory content to E
4205
DCR E
1D
Decrement E
4206
LOOP1
INX H
23
Increment memory
4207
DCR C
0D
Decrement C
4208
MOV M,C
71
Copy content of C to memory
4209
JNZ LOOP1
C2

Jump on non-zero to label LOOP1
420A
06
420B
42
420C
LXI H,4100
21
Load the number whose factorial is to be found in HL pair
420D
00
420E
41
420F
LOOP2
MOV A,M
7E
Copy memory content to accumulator
4210
INX H
23
Increment memory
4211
MOV B,M
46
Copy memory content to B
4212
MOV C,A
4F
Copy accumulator content to C
4213
MVI A,00
3E
Initialize A with 0
4214
00
4215
GO
ADD B
80
[A] ß [A] + [B]
4216
DCR C
0D
Decrement C
4217
JNZ GO
C2

Jump on non-zero to label GO
4218
15
4219
42
421A
MOV M,A
77
Copy accumulator content to memory
421B
DCR E
1D
Decrement E
421C
JNZ LOOP2
C2

Jump on non-zero to label LOOP2
421D
0F
421E
42
421F
STA 4500
32
Store accumulator content to memory
4220
00
4221
45
4222
HLT
76
Program ends
 
;