Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 965
user3175173 Avatar asked Apr 22 '26 08:04

user3175173


1 Answers

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.)

like image 184
markgz Avatar answered Apr 26 '26 02:04

markgz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!