Visual Studio 在引用堆栈变量时不使用 EBP



我有以下C++代码

int myFuncSum( int a, int b)
{
    int c;
    c = a + b;
    return c;
}
int main(int argc, char *argv[])
{
    int result;
    result = myFuncSum(100, 200);
    return 0;
}

当我在我的Win7 Pro机器上的Visual Studio 2008的反汇编窗口中执行此操作时,我会看到以下对myFuncSum()的调用:

int myFuncSum( int a, int b)
{
001C1000  push        ebp  
001C1001  mov         ebp,esp 
001C1003  push        ecx  
    int c;
    c = a + b;
001C1004  mov         eax,dword ptr [a] <--------------------
001C1007  add         eax,dword ptr [b] <--------------------
001C100A  mov         dword ptr [c],eax <--------------------
    return c;
001C100D  mov         eax,dword ptr [c] <--------------------
}

正如我所指出的,引用变量a、b和c的四行是指它们本身,而不是相对于EBP的偏移。

有人能建议我需要对Visual Studio做些什么吗?我已经在项目设置中禁用了C++优化;如果不这样做,我甚至不会调用我的函数。

反汇编程序只是想提供帮助,而不是向您发送太多无关细节的垃圾邮件。并非完全偶然,在带有__asm关键字的内联程序集中也允许使用此语法缩写。

可以来回切换,右键单击反汇编窗口,然后取消选中"显示符号名称"。现在您将看到真实的机器代码:

    c = a + b;
003613DE  mov         eax,dword ptr [ebp+8]  
003613E1  add         eax,dword ptr [ebp+0Ch]  
003613E4  mov         dword ptr [ebp-8],eax  
    return c;
003613E7  mov         eax,dword ptr [ebp-8]  

最新更新