Reputation: 5357
When I disassemble a gcc-compiled binary, I can see that the local variable is addressed using the EBP register. [EBP-0x10], [EBP-0x20] like this... However, sometimes I can see that local variables are address via ESP. like this.. [ESP+0x20], [ESP+0x3c]...
When does the gcc uses ESP? or EBP? to address local variable? and what is the difference between ESP based addressing and EBP based addressing??
Can I force GCC to use ESP or EBP to address local variables??
thank you in advance.
Upvotes: 1
Views: 469
Reputation: 126418
ebp
is used as the frame pointer register, and will be used for all frame accesses (local variables and parameters) if it is available.
You can control use of the frame pointer in gcc with -fomit-frame-pointer
, which is implicitly enabled by -O2
and higher. You can disable this (bringing back the frame pointer) with an explicit-fno-omit-frame-pointer
combined with a higher -O
level.
Upvotes: 1