= Solution
The missing <MIPS instructions>, in order, are
``
bne $t0, $0, fooRet1
subi $a0, $s0, 3
add $v0, $s1, $v0
``
The comparison `slti $t0, $s0, 3` makes `$t0` nonzero exactly when $y<3$, so the first instruction selects the base case. The second forms $y-3$ from the saved argument, rather than relying on `$a0` surviving the first call. After the second call, `$s1` holds `bar(y-2)` and `$v0` holds `bar(y-3)`; the final addition puts \b[their sum in `$v0`], as required by the <calling convention>.
Back to article page