8085 program to find the factorial of a number

MicrocontrollerMicroprocessor8085

In this program we will see how to find the factorial of a number.

Problem Statement

Write 8085 Assembly language program to find the factorial of an 8-bit number.

Discussion

In 8085, there is no direct instruction to perform multiplication. We need to perform repetitive addition to get the result of the multiplication. In each step we are decreasing the value of B and multiply with the previous value of B. We are repeating these steps until B reaches 1. and B – 1 to 0. Thus the factorial is generated.

Input

Address
Data
8000
05

Flow Diagram

 

Program

Address
HEX Codes
Labels
Mnemonics
Comments
F000
21, 00, 80
 
LXI H, 8000H
Load the number
F003
46
 
MOV B,M
Take number from memory to B
F004
16, 01
 
MVI D, 01H
Set D to 01H
F006
CD, 10, F0
FACT
CALL MUL
Call multiplication
F009
05
 
DCR B
Decrease B by 1
F00A
C2, 06, F0
 
JNZ FACT
If Z = 0, jump to Fact
F00D
23
 
INX H
Point to next location
F00E
72
 
MOV M,D
Store result in memory
F00F
76
 
HLT
Terminate the program
F010
58
MUL
MOV E,B
Load B to E
F011
AF
 
XRA A
Clear accumulator to store result
F012
82
ML
ADD D
Add D to A
F013
1D
 
DCR E
Decrement E
F014
C2, 12, F0
 
JNZ ML
If Z = 0, jump to ML
F017
57
 
MOV D,A
Transfer contents of A to D
F018
C9
 
RET
Return result

Output

Address
Data
8001
78
raja
Published on 11-Mar-2019 11:40:28
Advertisements