Write an assembly language program for calculating the factorial of a number (between 0 and8) using an 8085 microprocessor. Assume that the number for which the factorial needs to becalculated is loaded in the memory location F000H. Results should be available in the F001H &F002H location. Use the subroutine or CALL instruction.
Question
Write an assembly language program for calculating the factorial of a number (between 0 and8) using an 8085 microprocessor. Assume that the number for which the factorial needs to becalculated is loaded in the memory location F000H. Results should be available in the F001H &F002H location. Use the subroutine or CALL instruction.
Solution
Here is a simple assembly language program for calculating the factorial of a number using an 8085 microprocessor:
MVI A,00H ; Initialize register A
STA F001H ; Store the result in memory location F001H
STA F002H ; Store the result in memory location F002H
LDA F000H ; Load the number from memory location F000H
MOV B,A ; Move the number to register B
MVI A,01H ; Initialize register A with 1
CALL FACT ; Call the subroutine FACT
HLT ; Halt the program
FACT: ; Subroutine to calculate factorial
CMP B ; Compare register A with register B
JZ STORE ; If A=B, jump to STORE
INR A ; Increment register A
CALL FACT ; Call the subroutine FACT again
RET ; Return from the subroutine
STORE: ; Subroutine to store the result
STA F001H ; Store the result in memory location F001H
INX H ; Increment register H
STA F002H ; Store the result in memory location F002H
RET ; Return from the subroutine
This program calculates the factorial of a number by repeatedly multiplying the number with decremented values of itself until it reaches 1. The result is then stored in the memory locations F001H and F002H.
Similar Questions
Write a C program, using functions where the function calculates the factorial of a given integer, and the main() program does I/O and calling of factorial function.
Write a program to calculate the factorial of N.
c++ program on factorial of a number in short
write an iterative code for factorial in c
00:47Write a program to find a factorial of a number
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.