0

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.

Konrad Lindenbach
  • 4,911
  • 1
  • 26
  • 28
  • Use QtSpim's single-step functionality to find out where any of the registers first get an unexpected value. – Michael Apr 12 '16 at 10:30
  • did that for 4 hours, can't figure it out.. I tried changing the position of that code in a done label, wich returns a value from stack, same thing, but it changes some of those numbers with 0 – Razvan Calinescu Apr 12 '16 at 10:34
  • _"can't figure it out"_ What do you mean? Work out which values you should have on the stack and in the registers for each call for some input using pen and paper. Then single-step through your function and cross-check the actual register/memory values against the one you worked out earlier. – Michael Apr 12 '16 at 10:38
  • ps. for 3 it prints 6 71, wich is right, but for any other n greater than 3, it prints again 6 or 71 or 986, it depends on n – Razvan Calinescu Apr 12 '16 at 10:39
  • ok, i'll come with an update later on – Razvan Calinescu Apr 12 '16 at 10:40

0 Answers0