【问题标题】:Local Variables offset from stack base pointer从堆栈基指针偏移的局部变量
【发布时间】:2013-01-26 08:37:03
【问题描述】:

我正在尝试了解有关堆栈和基指针的更多信息。以下示例汇编代码来自 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)指的是什么?

【问题讨论】:

    标签: c assembly x86


    【解决方案1】:

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

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

    see the following image:

    您也可以阅读calling convention

    【讨论】:

    • 所以你是说-0xc(%ebp),%eax 是我函数的参数?我认为 %ebp 周围的括号意味着这将是 (address contained in %ebp) - 0xc?
    猜你喜欢
    • 2013-01-14
    • 1970-01-01
    • 1970-01-01
    • 2021-09-17
    • 2020-01-03
    • 2016-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多