I am struggling with a problem in MIPS programming. I have the following recursive function:
F(n) = 14F(n - 1) + 2F(n - 2) - 5n
I implemented it using a recursive function, it prints me the right answer.
My problem is: I want to print in console the sequence from F(0) and F(1), both are 1, to my F(n). I tried printing the register $v0
, in which I store the final value, in each iteration of my function, but it prints out (for 5
for example): 6 71 6 986 6 71 13921
.
This is the code i inserted in my function for printing:
sw $a0,var_curr
sw $v0,print_curr
lw $a0,print_curr
li $v0,1
syscall
li $v0,4
la $a0,space
syscall
lw $a0,var_curr
lw $v0,print_curr
Where var_curr
is the curent iteration; print_curr
is the current value for printing, and space
is the space between numbers.