This is the simple factorial program.
.global main
main:
mov r0,#7 // insert here the number to calculate the factorial, e.g. 7
mov r1,r0 // it will be useful after
push {ip,lr} // save the lr
bl factorial // jump to factorial label
pop {ip,lr} // reset the lr so the program can return
bx lr
factorial:
cmp r1,#1 // if r1=1
moveq pc,lr // then return
sub r1,r1,#1 // else r1 = r1-1
mul r0,r1,r0 // and multiply r0*r1
b factorial // then do it again until moveq return to main
If I execute it I receive wrongs results (very lower):
$ ./a.out
$ echo $?
176
176 instead of 5040.. There must be some logic error, could you help me?