八个保存寄存器的功能(MIPS)
我在我的《计算机组织与设计》(Patterson & Hennessy)一书中看到了这样的说法:
$s0-$s7:必须在过程调用中保留的八个已保存寄存器(如果使用,被调用者将保存并恢复它们)
我不明白“在过程调用上保留”是什么意思。
I came across this statement in my Computer Organization and Design (Patterson & Hennessy) book:
$s0-$s7: eight saved registers that must be preserved on a procedure call (if used, the callee saves and restores them)
I don't understand what that "preserved on a procedure call" means.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这意味着如果您正在实现子例程(例如被调用者),则需要保留这些寄存器的内容。
这意味着:您要么不在子例程中使用它们,要么如果使用,请先保存它们并在返回调用者之前恢复它们。
It means that if you're implementing a subroutine (e.g. the callee), you need to preserve the contents of those registers.
Which means: you either don't use them in your subroutine, or if you do, you save them first and restore them before you return to the caller.
通常我们将局部变量存储在这些寄存器上。假设您正在使用以下算法计算一个数字的阶乘:
在这种情况下,您会看到这里有局部变量
a
和t
。由于a
是一个参数,因此在此过程中它将存储在$a0-$a3
中。不过,您很可能会将这些参数存储在$s0-$s7
或$t0-$t7
中。该过程递归地调用自身,因此您应该将局部变量的值保存到堆栈中。 (阅读“激活记录”或“调用堆栈”)您应该将这些值推送到堆栈$sp
,然后在停止情况下返回时弹出它们。基本上,您可以在过程或主程序中将值保存在该堆栈上。这只是一个约定,您可以将值放入
$v
或$t
或$a
寄存器中,它们也可以工作,但是程序变得复杂后,事情可能会变得一团糟。如果您的过程使用
$s
寄存器,则在调用此过程之前,您必须将这些寄存器保存到堆栈中,以便在您的过程用完$t
寄存器时“保留”它们。如果你正在学习这方面的课程,现在不要担心,稍后你会学到更多。
Usually we store local variables on those registers. Let's say you are computing factorialof a number with the following algorithm:
In this case, you see there are local variables
a
andt
here. Sincea
is an argument, it will be stored in$a0-$a3
during this procedure. However most probably you will store those arguments in$s0-$s7
or$t0-$t7
. This procedure calls itself recursively therefore you should save values of local variables into a stack. (read about "activation record" or "call stack") You should push these values to the stack$sp
then pop them upon return on stop case.Basicly you save values on this stack in a procedure or a main program. This is just a convention, you can place your values into
$v
or$t
or$a
registers, they'll work too, but things may be messed up after complexity of the program.If your procedure is using
$s
registers , before calling this procedure you must save these registers to a stack to "preserve" them if your procedure runs out of$t
registers.If you are taking the couse about that, do not worry it about right now, you'll learn much more later.
寄存器 s0-s7(软寄存器)(又名 $16-$20 物理寄存器)是临时寄存器,使用 C/C++ 时会保留这些寄存器。
除非您正在编写汇编,否则您根本不必担心它,因为这是正常的 abi(应用程序二进制接口)
如果您需要阅读......或无法睡觉,我收集的一些书签可能会有所帮助: -)
[MIPS 上的 Wiki 条目][1]
[ABI 注释][2]
register s0-s7 (soft registers) (aka $16-$20 physical registers) are the temp register, these are preserved when using C/C++.
Unless you are writing assembly then you should'nt have to worry about it at all as this is normal abi (application binary interface)
Some bookmarks from my collection might help if you need to do some reading... or can't sleep :-)
[Wiki Entry on MIPS][1]
[ABI Notes][2]