Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Main:
- addi sp, zero, 1600 # make room in stack
- ecall t0, zero, 5 # store input in t0
- add a0, t0, zero # move input to a0
- jal ra, RecLin # call function
- ecall zero, a0, 0 # print result via a0
- beq zero, zero, Done
- RecLin:
- addi sp, sp, -16 # push stack for 2 items
- sd ra, 8(sp) # store return address
- sd a0, 0(sp) # store n on stack
- addi t1, zero, 6
- bge a0, t1, Else # goto Else if a0 >= 6
- addi a0, zero, 5 # base case: return 5
- addi sp, sp, 16 # pop stack; values not returned
- jalr zero, 0(ra)
- Else:
- addi a0, a0, -5 # n -= 5
- jal ra, RecLin # call RecLin(n - 5)
- add t2, a0, zero # t2 = RecLin(n - 5)
- ld a0, 0(sp) # restore caller's n value
- ld ra, 8(sp) # restore return address
- addi sp, sp, 16 # pop stack
- addi t3, zero, 4 # t3 = 4
- mul a0, t3, t2 # a0 = 4 * RecLin(n - 5)
- add a0, a0, t0 # a0 += n
- jalr zero, 0(ra)
- Done:
Add Comment
Please, Sign In to add comment