Commit e390c7d3 authored by Alan Marchiori's avatar Alan Marchiori
Browse files


parent b809aa4a
li $a0, 10
jal fact
move $s0, $v0
li $v0, 10
syscall # exit
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
li $t0, 1 # setup a register with 1
sw $t0, 8($sp) # store 1 into our local variable
# fall through to the 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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment