MIPS汇编语言 - 临时寄存器VS保存的寄存器 [英] MIPS assembly language - temporary register vs saved registers

查看:2030
本文介绍了MIPS汇编语言 - 临时寄存器VS保存的寄存器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我一直在使用寄存器$ S0- $ S9和方式寄存器$ $ T0- T9一样。有人告诉我,读无数的论坛帖子和段落这里和谷歌解释差异,但没有编码的例子。有人告诉我,我应该看到它涉及到使用程序区别,但我已经建立的涉及努力寻找VS临时寄存器保存的寄存器之间的差异手续的情况了不知多少,但我失败了。

So far I have been using registers $s0-$s9 and same way as registers $t0-$t9. I have been told and read countless forum posts and paragraphs here and on Google explaining the difference, but with no coding examples. I'm told I should see the difference it pertain to using procedures, but I have created a countless number of scenarios involving procedures in an effort to find the difference between saved registers vs temporary register but I have failed.

我会杀看到一个比较简单的例子,一个$ t0-9寄存器不会采取同样为$ s0-9寄存器,因此,产生不同的价值?

推荐答案

有在他们的工作暂时并保存变量之间没有什么区别。所不同的是在它们的使用,或者说,它们如何应该被使用。

There is no difference between the temporary and saved variables in how they work. The difference is in how they are used, or rather, how they ought to be used.

MIPS的调用约定指定了各种寄存器如何被使用 - $ V 寄存器用于函数返回时, $一个寄存器函数参数,在 $ T 变量是临时的调用函数保存的寄存器,而 $ S 寄存器的被调用函数保存

The MIPS calling convention specifies how the various registers are to be used -- the $v registers are for function returns, the $a registers are for function arguments, the $t variables are temporary caller saved registers, while the $s registers are callee saved.

保存主被叫之间的区别如下:调用函数时,会议保证了 $ S 寄存器是相同的回报后,而该公约没有这保证了 $ T 寄存器。当然,这意味着,如果你想使用 $ S 寄存器在例行,您必须保存和恢复它们的值。例如,如果函数A使用寄存器 $ T0 $ S0 ,然后调用一个函数B,它必须保存注册 $ T0 如果它想后函数B返回到使用它。功能B必须保存 $ S0 ,才可以开始使用它。

The difference between callee and caller saved is as follows: when calling a function, the convention guarantees that the $s registers are the same after return whereas the convention does not guarantee this for the $t registers. Of course this means that if you wish to use the $s registers in a routine, you must save and restore their values. For instance, if function A uses registers $t0 and $s0 and then calls a function B, it must save the register $t0 if it wants to use it after function B returns. Function B must save $s0 before it can begin using it.

一个例子:

main:

    li $s0 7
    li $t0 7

    jal myFunction

    #$s0 guaranteed to equal 7
    #$t0 value not guaranteed

<一个href=\"http://courses.cs.washington.edu/courses/cse410/09sp/examples/MIPSCallingConventionsSummary.pdf\">This链接看起来像一些像样的更深入的信息。

This link looks like some decent more in-depth information.

当然,这一切只是一个惯例,因此只有当你和其他程序保存和恢复 $ S 尊重约定注册使作品它们不是由一个函数调用覆盖。

Of course, all of this is only a convention, and therefore it only works if you and the other programs respect the convention by saving and restoring $s registers so that they are not overwritten by a function call.

这篇关于MIPS汇编语言 - 临时寄存器VS保存的寄存器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆