This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: a0 = 3 ra= 4024 a0 = 2 ra = 4024 a0 = 1 ra = 1004 n=3 result Now test if n < 1 (i.e. n = 0). In that case return 0 to $v0. slti $t0, $a0, 1 # if n ! 1 then goto L1 beq $t0, $zero, L1 addi $v0, $zero, 1 # return 1 to $v0 addi $sp, $sp, 8 # pop 2 items from stack jr $ra # return L1: addi $a0, $a0, -1 # decrement n jal fact # call fact with (n – 1) Now, we need to compute n * fact (n-1) lw $a0, 0($sp) # restore argument n lw $ra, 4($sp) # restore return address addi $sp, $sp, 8 # pop 2 items mult $v0, $a0, $v0 # return n * fact(n-1) jr $ra # return to caller...
View Full Document
This note was uploaded on 02/18/2011 for the course 22C 060 taught by Professor Ghosh during the Spring '11 term at University of Iowa.
- Spring '11