• API
• FAQ
• Tools
• Archive
daily pastebin goal
25%
SHARE
TWEET

# Untitled

a guest Oct 22nd, 2018 60 Never
ENDING IN00days00hours00mins00secs
1. ########## Recursive Function ############
2. # f(t0) = ┌ x                 if  n <= y #
3. #         └ g[f(t0 - z), t0]  otherwise  #
4. ##########################################
5.
6. Main:
7.     addi    sp, zero, 1600      # make room in stack
8.     ecall   t0, zero, 5         # store input in t0
9.     add     a0, t0, zero        # move input to a0
10.
11.     jal     ra, RecLin          # call function
12.     ecall   zero, a0, 0         # print result via a0
13.     beq     zero, zero, Done
14.
15. RecLin:
16.     addi    sp, sp, -16         # push stack for 2 items
17.     sd      ra, 8(sp)           # store return address
18.     sd      a0, 0(sp)           # store n on stack
19.
20.     addi    t1, zero, [y + 1]
21.     bge     a0, t1, Else        # goto Else if a0 >= [y + 1]
22.     addi    a0, zero, x         # base case: return x
23.
24.     addi    sp, sp, 16          # pop stack; values not returned
25.     jalr    zero, 0(ra)
26.
27. Else:
28.     addi    a0, a0, -z          # n -= z
29.     jal     ra, RecLin          # call RecLin(n - z)
30.
31.     add     t2, a0, zero        # t2 = RecLin(n - z)
32.     ld      a0, 0(sp)           # restore caller's n value
33.     ld      ra, 8(sp)           # restore return address
34.     addi    sp, sp, 16          # pop stack
35.
36.     inst    a0, t2, imm         # a0 = RecLin(n - 5)
37.     inst    a0, a0, t0          # a0 += n
38.
39.     jalr    zero, 0(ra)
40.
41. Done:
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top