什么是函数尾声和序言?

发布于 2024-09-09 07:02:38 字数 90 浏览 2 评论 0原文

我读到了类似“尾声和序言”的内容

在阅读某些 CPU 架构中的一些调用约定时,当从另一个函数调用一个函数时,

。什么是函数序言或结尾?

While reading some calling convention in some CPU architecture I read something like

"epilogue and prologue", when a function is called from another function.

What is a function prologue or epilogue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时间海 2024-09-16 07:02:38

函数的尾声和序言只是一组指令,它们在调用函数时“设置”函数的上下文,并在函数返回时进行清理。

序言通常执行以下任务:

  • 保存函数可能使用的任何寄存器(平台标准要求在函数调用之间保留这些寄存器)
  • 在堆栈上分配函数可能需要的局部变量存储
  • 设置任何指针(或其他链接)到可能在堆栈上传递的

参数尾声通常只需要恢复任何保存寄存器并恢复堆栈指针,以便“释放”函数为自己使用而保留的任何内存。

序言/尾声中可能使用的确切机制取决于 CPU 体系结构、平台标准、函数的参数和返回值以及函数可能使用的特定调用约定。

The epilogue and prologue of a function are simply the set of instructions that 'set up' the context for the function when it's called and clean up when it returns.

The prologue typically performs such tasks as:

  • saves any registers that the function might use (that are required by the platform's standard to be preserved across function calls)
  • allocates storage on the stack that the function might require for local variables
  • sets up any pointer (or other linkage) to parameters that might be passed on the stack

The epilogue generally only needs to restore any save registers and restore the stack pointer such that any memory reserved by the function for its own use is 'freed'.

The exact mechanisms that might be used in a prologue/epilogue are Dependant on the CPU architecture, the platforms standard, the arguments and return values of the function, and the particular calling convention the function might be using.

粉红×色少女 2024-09-16 07:02:38

维基百科 FTW: https://en.wikipedia.org/wiki/Function_prologue

这似乎解释了在我看来,这相当不错。如果有任何不清楚的地方,请告诉我,我可以尝试解决问题。

Wikipedia FTW: https://en.wikipedia.org/wiki/Function_prologue

This seemed to explain it fairly well, in my opinion. If there is anything that is unclear, let me know and I can try and clear things up.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文