        .text
# $a0: value of N
# $a1: accumulator
# $v0: Result
#
# C code:
# int recFac(int n, int accum) {
#   if (n == 0) {
#     return accum
#   } else {
#     return recFac(n - 1, n * accum)
#   }
# }
        
recFac: 
        # test for base case
        beq $a0, $zero, base_case

        # if not, calculate one step
        # t0: n - 1
        # t1: n * accum
        addi $t0, $a0, -1
        mult $a0, $a1
        mflo $t1

        # setup the next call, and make it
        move $a0, $t0
        move $a1, $t1
        j recFac # NOT jal, just a normal jump!
base_case:
        move $v0, $a1
        jr $ra

main:
        # number to get factorial of, with initial accumulator of 1
        li $a0, 5
        li $a1, 1
        
        # make the call
        jal recFac

        # print out the result
        move $a0, $v0
        li $v0, 1
        syscall

        # exit
        li $v0, 10
        syscall
        
