views:

247

answers:

2

MIPS registers have a convention - $s registers are to be preserved across subroutine calls, so if your subroutine modifies them, it should save them to the stack, while $t registers are not preserved.

Now, can a syscall potentially modify a $t register? In a simulator I have, it doesn't, but could a real machine have the $t registers change, potentially? I ask because I want to know whether it's safe to assume a $t register will remain the same across a syscall.

+2  A: 

It's not wise, unless documented, to rely on any call preserving specific registers.

If the doco for the syscall states that it only modifies certain registers, that's a contract with your code. If it breaks that contract, it's a bug (although probably easier for you to fix in your own code than wait for the developer). If it states nothing of the sort, don't depend on it, convention or otherwise.

Well-written calls will preserve all registers that aren't specifically used to return you information. But, if you're not sure, and you need that register preserved, do it yourself before calling the syscall.

paxdiablo
A: 

Now, can a syscall potentially modify a $t register?

Yes!

Of course, your operating system's syscall interface may preserve all these registers. But there's no technical reason why a syscall can't modify them. Check the documentation of your OS.

Artelius