No. The value in $t0
might have been changed by somesub
,
since $t0
(according to convention)
is a register that a subroutine is free to use.
add $t0,$s5,$s3 # calculate an important sum jal somesub # call some subroutine nop # branch delay mul $s4,$t0,$v1 # multiply the sum by the result
Here is an example of a calling convention. This convention is very simple and is not suitable for any serious program. But it illustrates some ideas that will be used later on in more complex conventions. Let us call it the Simple Linkage convention. Most of the rules of this convention you have already seen:
jal
.jr $ra
.$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.
Since a subroutine may not call another subroutine,
programs will consist of a main
routine
that calls any number of subroutines.
But the subroutines do not call other subroutines and
always return directly to main
.