调用者和被调用者保存的寄存器有什么区别? [英] What's the difference between caller- and callee-saved registers?

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

问题描述

特别是,如何知道对调用者保存的寄存器中的一段代码中的变量执行的保存/恢复操作数量与被调用保存的寄存器的数量?

In particular, how can you know the number of save/restore operations executed for variables in a piece of code in a caller-saved register vs callee-saved register?

推荐答案

调用保存的寄存器,也称为易失性寄存器,是调用函数必须保存的任何CPU内核寄存器(通常是运行时栈),如果调用函数需要寄存器;即如果该值是活动。 Callee保存的寄存器,也称为非易失性寄存器,是任何CPU核心寄存器,包含函数必须承诺不会销毁的值。如果被调用者(被调用函数)需要使用这些寄存器,它必须首先将值保存在这些寄存器中(通常在运行时栈上),然后在返回调用者之前恢复它们。

Caller-saved registers, also known as volatile registers, are any CPU core registers that a calling function must save (generally to the runtime stack) if the calling function needs the value in the register; i.e. if the value is "live". Callee-saved registers, also known as nonvolatile registers, are any CPU core registers that contain values that a function must promise to not destroy. If the callee (called function) needs to use those registers, it must first save the values in those registers (generally on the runtime stack), and then restore them before returning back to the caller.

正如Carl Norum所提到的,哪个CPU核心寄存器是调用者保存&被调用者保存由调用约定(历史上记录不良,历史上特定于编译器)或由ABI(应用程序二进制接口)定义。

As Carl Norum mentions, which CPU core regs are caller-save & which are callee-save are defined by a calling convention (historically poorly documented, and historically compiler-specific), or defined by a ABI (Application Binary Interface).

虽然它的信息确定是x86特定的,但Agner Fog的以下文档确实描述了调用约定& caller-save / callee-save registers:

Although its information is decidedly x86-specific, the following document by Agner Fog does a really good job of describing calling conventions & caller-save/callee-save registers:

http://www.agner.org/optimize/calling_conventions.pdf

下面介绍PowerPC EABI,包括其调用约定。但在本文档中,分别搜索volatile和nonvolatile(caller-save和callee-save):

The following describes the PowerPC EABI, including its calling convention. But in this document, search for "volatile" and "nonvolatile" (caller-save and callee-save, respectively):

http://www.freescale.com/files/32bit/doc/app_note/PPCEABI.pdf

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

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