什么是被调用者和调用者保存的寄存器? [英] What are callee and caller saved registers?

查看:78
本文介绍了什么是被调用者和调用者保存的寄存器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在理解调用者和被调用者保存的寄存器之间的区别以及何时使用什么时遇到了一些麻烦.

I'm having some trouble understanding the difference between caller and callee saved registers and when to use what.

我正在使用 MSP430:

I am using the MSP430 :

程序:

mov.w #0,R7 
mov.w #0,R6 
add.w R6,R7 
inc.w R6 
cmp.w R12,R6 
jl l$loop 
mov.w R7,R12
ret

上面的代码是一个被调用者,在教科书的例子中使用过,所以它遵循约定.R6 和 R7 是被调用者保存的,R12 是被调用者保存的.我的理解是,被调用者保存的 regs 不是全局"的,因为在过程中更改其值不会影响它在过程之外的值.这就是为什么你必须在开始时将一个新值保存到被调用者 reg 中.

the above code is a callee and was used in a textbook example so it follows the convention. R6 and R7 are callee saved and R12 is caller saved. My understanding is that the callee saved regs aren't "global" in the sense that changing its value in a procedure will not affect it's value outside the procedure. This is why you have to save a new value into the callee reg at the beginning.

R12,保存的调用者是全局的",因为缺乏更好的词.调用后,程序所做的事情对 R12 具有持久影响.

R12, the caller saved is "global", for lack of better words. What the procedure does has a lasting effect on R12 after the call.

我的理解正确吗?我还缺少其他东西吗?

Is my understanding correct? Am I missing other things?

推荐答案

调用者保存的寄存器(又名易失性寄存器,或调用破坏)用于保存需要的临时数量不会在调用之间保留.

Caller-saved registers (AKA volatile registers, or call-clobbered) are used to hold temporary quantities that need not be preserved across calls.

因此,调用者有责任将这些寄存器压入堆栈或将它们复制到其他位置如果它想在过程调用后恢复该值.

For that reason, it is the caller's responsibility to push these registers onto the stack or copy them somewhere else if it wants to restore this value after a procedure call.

不过,让 call 破坏这些寄存器中的临时值是正常的.

It's normal to let a call destroy temporary values in these registers, though.

被调用者保存的寄存器(又名非易失性寄存器,或调用保存)用于保存长期存在的值,这些值应该在调用之间保留.

Callee-saved registers (AKA non-volatile registers, or call-preserved) are used to hold long-lived values that should be preserved across calls.

当调用者进行过程调用时,可以预期这些寄存器在被调用者返回后将保持相同的值,这使得被调用者有责任在返回给调用者之前保存并恢复它们.或者不碰它们.

When the caller makes a procedure call, it can expect that those registers will hold the same value after the callee returns, making it the responsibility of the callee to save them and restore them before returning to the caller. Or to not touch them.

这篇关于什么是被调用者和调用者保存的寄存器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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