Beginner learning assembly preserving esp after function calls
- by Daniel
I'm a beginner learning some assembly, when preserving the ESP register before a function call does it matter if you do it by adding or subtracting? hard to explain, consider the following
mov esi, esp
sub esp, 12 // on 32bit OS this would mean that there are 3 arguments to the function
// push, function call etc
cmp esi, esp // should be the same
or
mov esi, esp
// push, function call etc
add esp, 12
cmp esi, esp // should be the same
Also if for some reason the cmp fails, is it safe to do mov esp, esi to re-align the stack?
Thanks
EDIT: Also how come i need to do this for a call like sprintf, but MessageBox seems to fix ESP for me? How am i to know what function needs this and what doesn't?