Double recursion using MIPS
<p>I am trying to implement double recursion for the function <code>f(n) = 2f(n-1) + 3f(n-2) + 1</code>.  I was able to figure out singular recursion and implement the <code>2f(n-1) + 1</code> part of it, but I can't figure out how to implement the second part.  Here is my working code for the singular recursion:</p>

<pre><code>.data
prompt1: .asciiz "Enter the value for the recursive function f(n) = 2f(n-1)+3f(n-2)+1:  "
prompt2: .asciiz "Result: "
numberEntered: .word 0
answer: .word 0

.text

main:
#Ask for the value
li $v0 4
la $a0, prompt1
syscall

#enter value
li $v0, 5
syscall

sw $v0, numberEntered  #stores the number

# call the function
lw $a0, numberEntered
jal function
sw $v0, answer

#Print out the result
li $v0 4
la $a0, prompt2
syscall

lw $a0, answer
li $v0, 1
syscall

li $v0, 10
syscall

.globl function
function:
subu $sp, $sp, 8
sw $ra, ($sp)
sw $s0, 4($sp)

#base case
li $v0, 1
beq $a0, $zero, done

#calling f(n-1)
move $s0, $a0
sub $a0, $a0, 1
jal function

#calculations occur here
mul $v0, $v0, 2
addi $v0, $v0, 1

done:

lw $ra, ($sp)
lw $s0, 4($sp)
addi $sp, $sp, 8

jr $ra  #returns
</code></pre>

<p>I tried loading the address of the next part down the stack in the calculation part of it, but I couldn't figure out the implementation to get it to work.  Do I have to "wind up" the stack twice?  Once how it is currently and once in the calculation section?  I can't figure it out, and any help would be appreciated!</p>