I don't know.
To answer the question, look at the
code for main
to determine which registers
contain information and
can not be altered.
Do this for
each call to sub
,
because registers are likely to hold
different information at different points.
This is tedious and error prone.
Worse, if main
is altered,
now you have to inspect the registers again,
and possibly re-code
sub
.
One of the goals of subroutines is to create a module that is independent of the rest of the code. We have not achieved that, yet.
Another issue is how data is passed into and out of the subroutine. Often data is in registers, and the results are in registers. Which registers?
By agreement between programmers (not by hardware) registers have been assigned different roles with subroutine linkage:
$t0 - $t9
— The subroutine is free to change these registers.$s0 - $s7
— The subroutine must not change these registers.$a0 - $a3
— These registers contain arguments for the subroutine.
The subroutine can change them.$v0 - $v1
— These registers contain values returned from the subroutine.