Compiling a recursive procedure, showing nested procedure linking
Let's tackle a recursive procedure that calculates factorial: long long int fact (long long int n)
if (n < 1) return (1); else return (n * fact(n - 1));
If n = 3, analyze and evaluate the MIPS code line by line and fill in the stack behavior throughout the code
Fact:
addi $sp, $sp, -4
sw $ra, 0($sp)
sw $a0, 4($sp)
STACK
0xFFC
slti $t0, $a0, 1
beq $t0, $zero, L1
0xFF8
0xFF4
addi $v0, $zero, 1
addi $sp, $sp, -8
sub $a0, $a0, 1
0xFF0
0xFEC
0xFE8
L1:
addi $a0, $a0, -1
jal fact
lw $ra, 4($sp)
addi $sp, $sp, 8
mul $v0, $v0, $a0
jr $ra