I disassembled an object file (most likely generated using the Visual C++ compiler) using DumpBin
and saw the following piece of code:
... ...
mov dword ptr [ebp-4],eax // Why save EAX?
push dword ptr [ebp+14h]
push dword ptr [ebp+10h]
push dword ptr [ebp+0Ch]
push dword ptr [ebp+8]
mov eax,dword ptr [ebp-4] // Why restore EAX? Did it change at all?
call <function>
... ...
Could someone please explain why the EAX register is being saved and restored across these 4 push
instructions?
Also, maybe it's compiled in release mode, but that variable has been marked as volatile
, which tells the compiler that such variable may change without it knowing, so it is forced to continuously write/restore it on/from the stack
Was this built in debug mode? If so, the compiler stores every local variable on the stack so that the debugger can find them in a consistent way.
The elision of such unnecessary stores and reloads is one of the optimizations that constitutes "release" mode.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With