gpt4 book ai didi

assembly - 为什么在使用堆栈框架操作时 ebx、esi 和 edi 不可用?

转载 作者:行者123 更新时间:2023-12-03 06:39:27 28 4
gpt4 key购买 nike

在汇编中创建函数时,我在使用如此少量的寄存器进行操作时遇到问题 - 这些寄存器中的什么内容阻止了我使用它们?我可以在编码时将其内容复制到参数中,并在退出函数之前重置它,以免破坏其目的吗?

最佳答案

Why are ebx, esi and edi unusable

这完全取决于 ABI 和 calling conventions不过,大多数编译器都遵循这样的模式:寄存器 eax、ecx 和 edx 被认为是 volatile 的。函数调用,与其他寄存器不同。

Can I copy their contents into a parameter while coding and reset it before exiting the function to not break its purpose?

是的,事实上,在 x86 代码中恢复应该在函数调用中保留的寄存器是一个非常常见的习惯用法,如下所示:

my_fn:
push ebx
push esi


; code ...

pop esi
pop ebx
ret

假设; code ... 部分没有使堆栈不平衡,esiebx 在离开函数之前恢复为旧值。

关于assembly - 为什么在使用堆栈框架操作时 ebx、esi 和 edi 不可用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55820518/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com