Recursive function for finding factorial in Assembly Language

 .type factorial [function](http://function.tiddlyspace.com/ "External link to http://function.tiddlyspace.com")


 .globl factorial


 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


 exit_factorial:


 movl %ebp,%esp

 popl %ebp

 ret
Share on : Twitter, Facebook or Google+