You are on page 1of 1

.text .globl main factorial: bgtz $a0, doit li $v0, 1 # base case, 0!

= 1 jr $ra doit: sub $sp,8 # stack frame sw $s0,0($sp) # will use for argument n sw $ra,4($sp) # return address move sub jal mul lw lw add jr main: li sub sw jal move lw add jr $s0, $a0 $a0, 1 factorial $v0,$s0,$v0 $s0,($sp) $ra,4($sp) $sp,8 $ra $a0, 7 $sp, 4 $ra,0($sp) factorial $t1, $v0 $ra,0($sp) $sp,4 $ra # save argument # n-1 # v0 = (n-1)! # n*(n-1)! # restore registers from stack

# # # # # #

set the argument for the factorial function to 7 create the stack frame save the return address call factorial save the return value restore the orignal return address

You might also like