Reputation: 3197
I compiled this C code:
void foo() {
int i = 0;
i = 0;
i = 0;
}
and I got this:
push ebp
mov ebp,esp
push ecx
mov dword ptr ss:[ebp-4],0
mov dword ptr ss:[ebp-4],0
mov dword ptr ss:[ebp-4],0
mov esp,ebp
pop ebp
retn
My question is why is there push ecx
? and how come there is no sub esp,4
or something to make space on the stack? No compiler options used.
Upvotes: 0
Views: 237
Reputation: 62083
Either way will make 4 bytes of space available on the stack, and the push
saves a couple of bytes over the sub
. Maybe the compiler writer decided to optimize this case by pushing a register.
Upvotes: 4