Commit bae076c1 authored by Alan Marchiori's avatar Alan Marchiori

add

parent 68c68fe4
.text
li $a0, 10
jal fact
move $s0, $v0
li $v0, 10
syscall
fact:
addi $sp, $sp, -12 #Allocate space for return, arg, result
sw $ra, 0($sp)
sw $a0, 4($sp)
li $t0, 1
bge $a0, $t0, ELSE #If arg >= 1
sw $t0, 8($sp)
j END
ELSE:
addi $a0, $a0, -1 #n-1
jal fact
lw $a0, 4($sp) #Load arg
mul $t0, $a0, $v0 # t0 = arg * returnValue
sw $t0, 8($sp) # result = t0
END:
lw $v0, 8($sp) #Set return register = return
lw $ra, 0($sp) #Load return address
addi $sp, $sp, 12 #Deallocate stack
jr $ra
\ 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