Reputation: 1025
What does the following code do...
0x080489b0 <+0>: push %ebp
0x080489b1 <+1>: mov %esp,%ebp
0x080489b3 <+3>: sub $0x14,%esp
0x080489b6 <+6>: push %ebx
To my knowledge this sets up the stack in the first two lines, and then pushes the %esp down 14 essentially increasing the stack on the third line, and finally pushes a %ebx onto the stack (even though it's empty), which also increases the stack, and pushes %esp down one more spot.
Am I wrong on any of these steps? Thanks for any help!
Upvotes: 0
Views: 723
Reputation: 14478
You are roughly correct. The third instruction (sub $0x14,%esp) actually means to grow the stack by 0x14 = 20 bytes, perhaps for alignment reasons. The fourth line means to push the 4-byte contents of %ebx onto the stack, subtracting 4 from %esp as a side effect. The reason for this is that %ebx is a callee-save register: if a function modifies the contents of %ebx, it is expected to push %ebx onto the stack, then modify %ebx, then pop %ebx back off the stack so that the caller never notices a change in %ebx. The other callee-save registers on x86 are %esi and %edi.
Upvotes: 1
Reputation:
Not quite. sub $0x14, %esp
subtracts hexadecimal 0x14 (decimal 20) from the stack pointer, which is equivalent to the space used by 5 dwords.
Upvotes: 1