Quote:
Originally Posted by resetreset
Anyone care to explain what all that stuff is before mov DWORD PTR?
|
Code:
0x08048344 <main+0>: push ebp
0x08048345 <main+1>: mov ebp,esp
...
0x0804835b <main+23>: leave
Those two instructions at the beginning balanced by that one instruction before the return, are the simple (not necessarily efficient) way to establish a basic stack frame for a function.
The old value of ebp is pushed on the stack, then ebp is set to point to where that old ebp was saved.
The leave instruction uses ebp to restore the prior value of both ebp and esp. So, prior to leave, it is not necessary to clean up any excess positions (nested function parameters, etc.) that might have been pushed by this function.
Code:
0x08048347 <main+3>: sub esp,0x8
Reserving 8 bytes of space at [ebp-8].
I think the stack was being kept 8-byte aligned. So the need to allocate 4 bytes for x caused it to allocate 8 bytes total.
Code:
0x0804834a <main+6>: and esp,0xfffffff0
16-byte aligning the stack. Some operations (none of which are in this function) need a 16-byte aligned stack. But the calling convention is not 16-byte aligned. So any function that thinks it needs 16-byte alignment must create that for itself.
Quote:
Why is it subtracting 0 from esp?
|
I guess it was reserving space for all of the variables that need 16 byte alignment. The total size of such variables in this function appears to be zero.
Non optimized code generation was following a general pattern of code for entry to a function, without caring that the steps were pointless in this trivial function.
Everything but the ret was pointless. x could be optimized away, so you don't need to allocate space for it nor set its value. The stack frame is optional. If you aren't calling nested functions nor need 16 byte alignment of the stack, there is no need for the overhead of using ebp.