Search code examples
assemblymipsmips32

MIPS saved and temporary


Ive read some describing the difference between $S and $T I cant seem to comprehend what exactly the difference is. So for a beginner programmer who just started learning RISC.

What exactly is the difference in laymans terms? It seems they should do the same thing for addition, subtraction? Does the difference lay in arrays?

Thank you!


Solution

  • There is no difference in how the registers work. There is a difference in how the registers are conventionally used. According to the MIPS calling convention, the values of the $S registers $S0,..,$S7 are preserved across function calls, and the values of the $T0,...,$T9 registers may be changed by the called function.

    Consider the following code as a concrete example: (Note that a syscall is basically a function call.)

    li   $s3, 42
    li   $t0, 81
    move $a0, $t0         # the value in $a0 will be printed
    li   $v0, 1           # syscall 1 is print integer
    syscall
    

    After the syscall, $s3 is still guaranteed by the calling convention to have the value 42, and the other $sxx registers' values are unchanged. We do not know what the value in $T0 will be after the call, because the convention does not require its value to be preserved.

    (Edited to add an example.)