- Uncategorized

8051 Code to find factorial of N (AT89C51) | Assembly Code 8051

8051 Assembly Code or 8051 ALP to find the facorial of N.Finding factorial is nothing repetitive multiplication with decrement until 1 is encountered. Here in this Code the number whose factorial is to obtained is stored in the Register R0 and a 11 bit function call(ACALL) is used and the value of R0 is decremented and is compared with ‘1’ for this purpose the CJNE(Compare and jump if not equal) instruction is used.Execution will be stopped when R0=1.

; 8051 Assembly Code to 
; Find a Factorial of N
; Programmer Name:Abhay KAgalakar

ORG 0000H
MOV R0,#5 ;Number N
MOV A,R0
ACALL FACT ;11bit function call
fact:DEC R0
CJNE R0,#01,rel ;value of R0 is compared with 1
SJMP stop ;if R0=1, stop execution
rel:MOV B,R0
MUL AB
ACALL FACT ;calling back the same function
stop:END

If you are facing problem reading the code.Download this code.
Click on the link below to Download

Factorial of N ASM File

3 thoughts on “8051 Code to find factorial of N (AT89C51) | Assembly Code 8051

Leave a Reply to Yogeesh K NCancel reply