MIPS 系统调用和 $t 寄存器

发布于 2024-08-10 12:29:04 字数 179 浏览 2 评论 0原文

MIPS 寄存器有一个约定 - $s 寄存器将在子例程调用之间保留,因此如果您的子例程修改了它们,它应该将它们保存到堆栈中,而 $t 寄存器则不保留。

现在,系统调用是否可以修改 $t 寄存器?在我的模拟器中,它没有,但是真机可能会改变 $t 寄存器吗?我问是因为我想知道 是否可以安全地假设 $t 寄存器在系统调用中保持不变。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

网名女生简单气质 2024-08-17 12:29:04

除非有记录,否则依赖任何调用来保存特定寄存器是不明智的。

如果系统调用的 doco 声明它只修改某些寄存器,那么这就是与您的代码的合同。如果它违反了合同,那就是一个错误(尽管您在自己的代码中修复可能比等待开发人员更容易)。如果它没有说明任何此类内容,则不要依赖它、约定或其他方式。

编写良好的调用将保留所有不专门用于返回信息的寄存器。但是,如果您不确定,并且需要保留该寄存器,请在调用系统调用之前自行完成。

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.

墨小沫ゞ 2024-08-17 12:29:04

现在,系统调用可以修改 $t 寄存器吗?

是的!

当然,您的操作系统的系统调用接口可能会保留所有这些寄存器。但没有技术原因导致系统调用无法修改它们。检查您的操作系统的文档。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文