Winter 2001-2002 CS 232

int
main(int argc, char *argv)
{
printf("The factorial of 10 is %d\n",
fact(10));
}
int
fact(int n)
{
if (n<1) {
return(1);
}
else {
return(n*fact(n-1));
}
}

main:   subu $sp, $sp, 32
sw   $ra, 20($sp)
sw   $fp, 16($sp)
addu $fp, $sp, 28
li   $a0, 10
jal  fact
0x00400038      la   $a0, STRING
move $a1, $v0
jal  printf
lw   $ra, 20($sp)
lw   $fp, 16($sp)
addu $sp, $sp, 32
jr   $ra
fact:   subu $sp, $sp, 32
sw   $ra, 20($sp)
sw   $fp, 16($sp)
addu $fp, $sp, 28
sw   $a0, 0($fp)
lw   $v0, 0($fp)
bgtz $v0, L2
li   $v0, 1
j    L1
L2:     lw   $v1, 0($fp)
subu $v0, $v1, 1
move $a0, $v0
jal  fact
0x0040008C      lw   $v1, 0($fp)
mul  $v0, $v0, $v1
L1:     lw   $ra, 20($sp)
lw   $fp, 16($sp)
addu $sp, $sp, 32
j    $ra

0x7FFFEDC0

0x7FFFEDFC 0x0040008C 0x7FFFEDDC 9 0x7FFFEDE0

0x7FFFEE1C 0x00400038 0x7FFFEDFC 10 0x7FFFEE00

0x00000000 0x00400018 0x7FFFEE1C 0x7FFFEE20 14 August 2002 Page 1