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

4 comments:

  1. THANK YOU FOR AN AMAZING CODE...IT WOULD BE HELPFUL IF YOU COULD EXTEND THIS FOR FINDING FACTORIAL OF NUMBERS GREATER THAN 05

    ReplyDelete
    Replies
    1. Surely we will get back to you.

      Keep visiting..

      Thank You

      Delete
    2. Thank you so much...but i would be greatful to you if i could get the code as soon as possible....

      Delete

Powered by Blogger.