# This is the C start-up code crt0: lui $sp,0x7fff ori $sp,$sp,0xfffc jal main *done: beq $0,$0,done # int factorial(int x) { # if (x > 1) # return x*factorial(x-1); # else # return 1; # } factorial: la $v0,5040 jr $ra # main() # { # factorial(7); # } # main() is not a leaf, so it needs to # allocate space on the stack to store the return address # and the arguments of functions it calls main: addiu $sp,$sp,-32 # allocates 8 words sw $ra,20($sp) la $a0,7 jal factorial * la $v0,0 lw $ra,20($sp) addiu $sp,$sp,32 jr $ra