Saving Registers
At the start of the procedure, save everthing that must be preserved ... at the end, put it back
Since this factorial is not recursive ...
Start of Procedure
Fact: addi $sp, $sp,-24
sw $a0, 20($sp)
sw $a1, 16($sp)
sw $a2, 12($sp)
sw $ra, 8($sp)
sw $s0, 4($sp)
sw $s1, 0($sp)
End of Procedure
lw $a0, 20($sp)
lw $a1, 16($sp)
lw $a2, 12($sp)
lw $ra, 8($sp)
lw $s0, 4($sp)
lw $s1, 0($sp)
addi $sp, $sp,24
jr $ra
Previous slide
Back to first slide
View graphic version