汇编中的堆栈指针移动超过所需的字节数以存储自动变量

时间:2017-01-03 04:21:49

标签: c assembly x86-64

引自here

  

对于许多编译器,标准函数入口序列是   下面的一段代码(X是所有的总大小,以字节为单位   函数中使用的自动变量:

push ebp
mov ebp, esp
sub esp, X

我在64位Intel处理器的Visual Studio 2015中。我正在通过反汇编检查一个非常简单的主函数,即使我只有两个自动变量,esp最终会分配比两个变量的空间多得多(216字节)。相关代码如下所示。

int main() {
00E61650  push        ebp  
00E61651  mov         ebp,esp  
00E61653  sub         esp,0D8h ; why is esp being decremented by 0D8h
                               ;which is decimal for 216 even though there
                               ;are only two auto variables, a and b?
00E61659  push        ebx  
00E6165A  push        esi  
00E6165B  push        edi  
00E6165C  lea         edi,[ebp-0D8h]  
00E61662  mov         ecx,36h  
00E61667  mov         eax,0CCCCCCCCh  
00E6166C  rep stos    dword ptr es:[edi]  
    int a = 5;
00E6166E  mov         dword ptr [a],5  
    int b = a + 6;
00E61675  mov         eax,dword ptr [a]  
00E61678  add         eax,6  
00E6167B  mov         dword ptr [b],eax  
    return 0;
00E6167E  xor         eax,eax  
}

main()中的自动变量是否需要比其他函数中的自动变量更多的内存?

0 个答案:

没有答案