assembly - cdecl 调用约定

标签 assembly x86 stack-frame cdecl

在一篇关于 _cdecl 调用约定的文章中,作者提到:

Release local storage When the function allocates local, temporary space, it does so by decrementing from the stack point the amount of space needed, and this process must be reversed to reclaim that space. It's usually done by adding to the stack pointer the same amount which was subtracted previously, though a series of POP instructions could achieve the same thing.

我的问题是:我可以简单地将 ESP 设置为当前 EBP 值,而不是“向堆栈指针添加减去的相同数量”或“一系列 POP 指令”吗?

喜欢:

mov esp, ebp

对我来说似乎是一个更好的方法,因为如果我稍后更改此函数的局部变量的数量,我就不必再费心增加该值了。

最佳答案

从技术上讲,这将是对堆栈帧的滥用,堆栈帧用于捕获堆栈不平衡引起的错误,但这是完全合法的。

有一些事情需要注意,如果由于大型分配或嵌入式设备而导致堆栈空间非常有限,那么在每次调用后清理堆栈是值得的。它还使调试变得更加容易,因为这样您就知道某些东西使用了错误数量的参数。

此外,如果有人要维护您的代码,他们会发现它非常困惑。

关于assembly - cdecl 调用约定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9478317/

相关文章:

assembly - 我可以将返回地址保存在寄存器中并将其推回堆栈中 NASM x86_64 中的 `ret` 之前吗

assembly - 为什么此汇编代码无法打印到 VGA 文本模式显存?

linux - Linux 中的 VMX 测试中出现软锁定

c - 如果该函数没有真正提供一个函数调用的返回值是什么

c# - 如何通过辅助方法打印当前执行的方法名?

c - 编译器如何在堆栈上使用默认值为零来初始化本地数组?

assembly - 打印有符号整数优化

linux - 创建/写入文件 x86 Linux

c++ - 使用 intel pin 工具的堆栈分配大小

java-7 - 使用ASM api构造FrameNode