Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- constants: addi x31, x0, 4 # conditional immediate that if i >= 4 go to true part
- addi x30, x0, 2 # the 2' in 2'*rec_func(i-2)+1
- addi x2, x0, 1600 // initialize the stack to 1600, x2= stackpointer
- ecall x5, x0, 5 // read the input to x5, the 5 signalling its an integer input
- jal x1, rec_func // main thread jump point (head to rec_func block)
- ecall x0, x10, 2 // print the result
- beq x0, x0, exit
- rec_func:
- addi x2, x2, -8 // make room in stack
- sd x1, 0(x2) // store pointer and result in stack
- bge x5, x31, true // if i > 3, then go to true branch
- ld x1, 0(x2)
- addi x10, x0, 1 // if i <= 3, then return 1
- addi x2, x2, 8 // reset stack point
- jalr x0, 0(x1) // link back to register x1 (main jump point)
- true:
- addi x5, x5, -2 // compute i-2
- jal x1, rec_func // call recursive func for i-2
- ld x1, 0(x2) // load the return address
- addi x2, x2, 8 // reset stack point
- mul x10, x10, x30 // multiply by 2
- addi x10, x10, 1 // add 1
- jalr x0, 0(x1) // return
- exit:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement