# fact0.mips # Calculate 4! (4 factorial). # # Register Usage: # $1 - Accumulates result # $2 - Counter of current value to multiply .globl main main: addi $2, $0, 4 # Place the number 4 in $2 addi $1, $0, 1 # Initialize result to 1 beq $0, $2, done # If none left, finish loop: mult $1, $2 # Multiply result by counter mflo $1 # Get product from Lo register addi $2, $2, -1 # Decrement counter bne $0, $2, loop # If more to do, loop done: add $4, $0, $1 # Copy result (24) to $4 trap 10 # Exit program