Skip to main content
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:
mov b,r1
ReplyDeletedjnz r1,up
and i thnk no need of r2
This comment has been removed by the author.
DeleteYa 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.
Deleteprogram for number greater than 5
ReplyDeleteIt's not working properly in kit
ReplyDeletefactorial 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.
ReplyDeletefactorial 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.