8051 ASSEMBLY LEVEL CODE TO FIND THE FACTORIAL OF GIVEN NUMBER


CODE:

//GIVEN NUMBER STORED IN R1 REGISTER
//RESULT IS STORED IN R7 REGISTER
//RESULT IS IN HEXADECIMAL 
//FACTORIAL UP TO 5 CAN BE FOUND 

ORG 0000
MOV R1,#04
MOV R7,#01
LCALL FACT
MOV R7,A
FACT:
MOV A,R7
CJNE R1,#00,UP
SJMP UP1
UP:
MOV B,R1
MUL AB
DJNZ R1,UP
UP1:
RET
END

OUTPUT:



Comments

  1. mov b,r1
    djnz r1,up


    and i thnk no need of r2

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
    2. Ya you are correct. The modification further to be made is to check for zero condition. since factorial of 0 is 1. Sorry for the mistake! Actually that earlier program won't give you the factorial output at all.

      Delete
  2. program for number greater than 5

    ReplyDelete
  3. It's not working properly in kit

    ReplyDelete
  4. factorial hundred In the last few days, the “factorial of 100” is one of the top subjects and a lot of maths geeks compute it using voice assistants such as Alexa, Shiri, etc.
    factorial hundred In the last few days, the “factorial of 100” is one of the top subjects and a lot of maths geeks compute it using voice assistants such as Alexa, Shiri, etc.
    factorial hundred In the last few days, the “factorial of 100” is one of the top subjects and a lot of maths geeks compute it using voice assistants such as Alexa, Shiri, etc.

    ReplyDelete

Post a Comment