# Recursive factorial function coded by Lin Jensen for CSC116 # March 2012 .globl fact .text # calculate n! fact: movl 4(%esp), %eax #n - arg from stack cmp $1, %eax jg doit # if (n <= 1) mov $1, %eax ret # return 0! =1! =1 doit: sub $1, %eax # n-1 push %eax call fact # fact(n-1) add $4, %esp #omit n-1 from stack imul 4(%esp), %eax # return n*fact(n-1) ret