Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # int fib(int n) {
- # if (n < 2)
- # return n;
- # else
- # return fib(n-1) + fib(n-2);
- # }
- .include "macrolib.s"
- .text
- main:
- read_int(a0)
- jal fib
- print_int(a0)
- li a7, 10
- ecall
- fib:
- addi sp, sp, -12
- sw s0, 0(sp)
- sw s1, 4(sp)
- sw ra, 8(sp)
- li t0, 2
- bge a0, t0, else
- j fib_end
- else:
- mv s0, a0
- addi a0, a0, -1
- jal fib
- mv s1, a0
- mv a0, s0
- addi a0, a0, -2
- jal fib
- add a0, a0, s1
- fib_end:
- lw s0, 0(sp)
- lw s1, 4(sp)
- lw ra, 8(sp)
- addi sp, sp, 12
- jr ra
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement