# compute the factorial of 9 using the following algorithm # N = 5 # result = 1 # while (N != 0) { # result = result * N # N = N - 1 # } N: .word 5 # reserve and initialize a word result: .space 4 # reserve but don't initalize a word addi $t0, $0, 1 # $t0 will hold result, initially 1 lw $t1, N($gp) # $t1 will hold N, initially 9 top: beq $t1, $0, bottom mult $t0, $t0, $t1 # result = result * N addi $t1, $t1, -1 # decrement N j top # goto top bottom: sw $t0, result($gp) # we'd better save result halt # all done