Keep both the limit and current argument in callee-saved registers, so a call to foo preserves them. Under the same no-delay-slot convention, use
li   $s0, n
li   $s1, 1
slti $t0, $s0, 1
bne  $t0, $0, testEnd
testLoop:
move $a0, $s1
jal  foo
break 1
beq  $s1, $s0, testEnd
addi $s1, $s1, 1
b    testLoop
testEnd:
break 0
b    testEnd
At every break 1, $s1 is the tested value and $v0 is its result. Resuming after the breakpoint continues to the next value; after the program reaches its separate final stop. The initial guard handles with no calls. Testing equality before incrementing also avoids overflowing the loop variable after the final call when is the largest positive machine integer. As with the supplied procedures, evaluating all calls assumes enough stack space and representable arithmetic results.

Articles by others on the same topic (0)

There are currently no matching articles.