I don't understand VC++ 2010 Express x64 assembly

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<div style="background-color:#ffffff; margin-bottom:2px; font-family:Verdana,Arial,Helvetica,sans-serif; color:#000000; font-weight:normal; font-size:11.5px; line-height:1.4; border-top-width:0px; border-right-width:0px; border-bottom-width:0px; border-left-width:0px; border-style:initial; border-color:initial
I installed the Windows SDK v7.1 to get 64 bit support for a simple test program so I could see what sort of code VS generates.

Heres my simple program:

int main(int argc, char ** argv){
<span style="white-space:pre int a;
<span style="white-space:pre a = atoi(argv[1]);
<span style="white-space:pre return a;
}

Heres the assembly:

int main(int argc, char ** argv){
000000013F1F1020 mov qword ptr [rsp+10h],rdx
000000013F1F1025 mov dword ptr [rsp+8],ecx
000000013F1F1029 sub rsp,38h
<span style="white-space:pre int a;
<span style="white-space:pre a = atoi(argv[1]);
000000013F1F102D mov rax,qword ptr [rsp+48h]
000000013F1F1032 mov rcx,qword ptr [rax+8]
000000013F1F1036 call qword ptr [3F1F2100h]
000000013F1F103C mov dword ptr [rsp+20h],eax
<span style="white-space:pre return a;
000000013F1F1040 mov eax,dword ptr [rsp+20h]
}
000000013F1F1044 add rsp,38h
000000013F1F1048 ret

Heres my core question: Why does this do "sub rsp,38h" instead of "sub rsp,28h"? It never touches 10h bytes of the stack space.

I know that after the subtract, esp+0, 8h, 10h, and 18h are the required space that must be allocated to back the rcx, rdx, r8, r9 paramters. And esp+20h is for my single local variable a. But esp+28h, and esp+30h are never used (as the assembly shows).
Whats the point of them? I have turned off everything I can find like buffer security check, optimizations, etc, but havent been able to get rid of the extra 16 bytes of wasted stack space.

Anybody have any idea whats going on?

Thanks

JB



View the full article
 
Back
Top