Reputation: 753
When I program in visual studio 2019, I input the following code and I compile it in debug mode and do some disassembly. I discover that the variable "c" is located in address ebp-8(in myfunction). However, I read from books that "the first local variable should appear in address ebp-4". Is there something with visual studio or with debug mode?
int myfunction(int a, int b)
{
013017B0 55 push ebp
013017B1 8B EC mov ebp,esp
013017B3 81 EC D8 00 00 00 sub esp,0D8h
013017B9 53 push ebx
013017BA 56 push esi
013017BB 57 push edi
013017BC 8D BD 28 FF FF FF lea edi,[ebp+FFFFFF28h]
013017C2 B9 36 00 00 00 mov ecx,36h
013017C7 B8 CC CC CC CC mov eax,0CCCCCCCCh
013017CC F3 AB rep stos dword ptr es:[edi]
013017CE B9 08 C0 30 01 mov ecx,130C008h
013017D3 E8 3F FA FF FF call 01301217
//Nonsense above.
int c = a + b;
013017D8 8B 45 08 mov eax,dword ptr [ebp+8] //a
013017DB 03 45 0C add eax,dword ptr [ebp+0Ch] //b
013017DE 89 45 F8 mov dword ptr [ebp-8],eax //Why it is not [ebp-4]? }
Upvotes: 0
Views: 346
Reputation: 77
I've figured out that Visual Studio is leaving 8 bytes between local variables in debug mode, but in release mode it is working normal as expected.
Upvotes: 0