Calling the Dist Procedure
The factorial can be written as
- {[N(N-1)](N-2)}(N-3) ...
- Dist(Dist(Dist(N,N,-1),N,-2),N,-3)
addi $v0,$0,1 # Initialize
add $v0,$a0,$0 # Move argument
add $s0,$a0,$0 # Save arg register
addi $s1,$0,1 # Get 1 constant
Loop: add $a0,$v0,$0 # Move running product
sub $a2,$0,$s1 # Negate and move
jal Dist # Go to subroutine
addi $s1,$s1,1 # Bump count
bne $s1,$a1,Loop# Continue until done
Done: add $a0,$s0,$0 # Put argument back