什么是主被叫保存的寄存器? [英] What are callee and caller saved registers?

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

问题描述

我有一些麻烦了解主叫方和被叫方之间的差异保存的寄存器以及何时使用什么。

我使用的MSP430

步骤:

  MOV.W#0,R7
MOV.W#0,R6
ADD.W R6,R7
inc.w R6
CMP.W R12,R6
JL升$循环
MOV.W R7,R12
RET

以上code是一个被调用,并在教科书例如用于因此它遵循的惯例。 R6和R7被调用函数保存和R12是调用函数保存。我的理解是,被调用函数保存暂存器不在意义上的全局,在程序改变其值将不会影响它的过程外值。这就是为什么你必须保存一个新值在开始时被调用方章。

R12,保存来电者是全球性,由于缺乏更好的话。什么过程确实有通话后R12有持久的影响。

我的理解是否正确?我失去了其他的东西?


解决方案

  

调用者保存寄存器被用来保存临时量需要
  不被$ P $通过调用pserved。


由于这个原因,它是调用者的责任,如果它希望在过程调用后恢复该值对这些寄存器压入栈。


  

被调用函数保存寄存器用来存放长寿命值应
  被$ P $通过调用pserved。


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

希望它帮助。

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

I am using the MSP430 :

procedure:

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

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, 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 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 if it wants to restore this value after a procedure call.

callee-saved registers 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.

Hope it helps.

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

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