Loading section01/Lec15/fact_localvar.s 0 → 100644 +39 −0 Original line number Diff line number Diff line .text main: li $a0, 10 jal fact move $s0, $v0 li $v0, 10 syscall # exit fact: addi $sp, $sp, -12 # allocate stack sw $ra, 4($sp) sw $a0, 0($sp) # setup stack, 8($sp) is un-initialized ble $a0, 1, L1 # if a0 <= 1, goto L1 # else recurse addi $a0, $a0, -1 jal fact # find fact (a0 - 1) lw $a0, 0($sp) # get our a0 back mul $t0, $v0, $a0 # t0 = a0 * fact (a0 - 1) sw $t0, 8($sp) # store t0 into our local variable on the stack j return L1: li $t0, 1 # setup a register with 1 sw $t0, 8($sp) # store 1 into our local variable # fall through to the return return: lw $v0, 8($sp) # load return value from the local variable lw $ra, 4($sp) # load the return address addi $sp, $sp, 12 # pop stack jr $ra # return No newline at end of file Loading
section01/Lec15/fact_localvar.s 0 → 100644 +39 −0 Original line number Diff line number Diff line .text main: li $a0, 10 jal fact move $s0, $v0 li $v0, 10 syscall # exit fact: addi $sp, $sp, -12 # allocate stack sw $ra, 4($sp) sw $a0, 0($sp) # setup stack, 8($sp) is un-initialized ble $a0, 1, L1 # if a0 <= 1, goto L1 # else recurse addi $a0, $a0, -1 jal fact # find fact (a0 - 1) lw $a0, 0($sp) # get our a0 back mul $t0, $v0, $a0 # t0 = a0 * fact (a0 - 1) sw $t0, 8($sp) # store t0 into our local variable on the stack j return L1: li $t0, 1 # setup a register with 1 sw $t0, 8($sp) # store 1 into our local variable # fall through to the return return: lw $v0, 8($sp) # load return value from the local variable lw $ra, 4($sp) # load the return address addi $sp, $sp, 12 # pop stack jr $ra # return No newline at end of file