gpt4 book ai didi

c - 局部变量从堆栈基址指针偏移

转载 作者:太空狗 更新时间:2023-10-29 14:57:38 26 4
gpt4 key购买 nike

我正在尝试了解有关堆栈和基址指针的更多信息。以下示例汇编代码来自 gcc 在 IA32 上编译的二进制文件的 objdump。

08048e0b <func_3>:
8048e0b: 55 push %ebp
8048e0c: 89 e5 mov %esp,%ebp
8048e0e: 83 ec 28 sub $0x28,%esp
8048e11: 8d 45 f0 lea -0x10(%ebp),%eax
8048e14: 89 44 24 0c mov %eax,0xc(%esp)
8048e18: 8d 45 f4 lea -0xc(%ebp),%eax
8048e1b: 89 44 24 08 mov %eax,0x8(%esp)
8048e1f: c7 44 24 04 65 9b 04 movl $0x8049b65,0x4(%esp)

我知道基指针%ebp是用来引用函数参数和局部变量的。通常正偏移量是传递给函数的参数,负偏移量是局部变量?

8048e18: 8d 45 f4 lea -0xc(%ebp),%eax -0xc(%ebp) 指的是什么?

最佳答案

函数的参数基于 (%ebp) + (positive value) 在您的情况下您有 1 个参数。

(%ebp) - (positive value) 是局部变量,你有 2 个。

see the following image :

enter image description here

您可以阅读关于 calling convention 的内容

关于c - 局部变量从堆栈基址指针偏移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14535266/

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