Recursive function for finding factorial in Assembly Language

 .type factorial [function]( "External link to")

 .globl factorial


 pushl %ebp # Push base pointer address on top of stack for return purpose

 movl %esp, %ebp # Now we will be using %ebp as a for all operations on stack

 1.  subl $4,%ebp # Make room for local varibales

 movl 8(%ebp), %eax # Take parameter in to the ebx

 cmpl $1, %eax

 je exit_factorial

 decl %eax

 pushl %eax

 call factorial;

 movl 8(%ebp), %ebx

 imull %ebx,%eax


 movl %ebp,%esp

 popl %ebp

Share on : Twitter, Facebook or Google+