Beginner learning assembly preserving esp after function calls
Posted
by Daniel
on Stack Overflow
See other posts from Stack Overflow
or by Daniel
Published on 2010-03-12T00:28:03Z
Indexed on
2010/03/12
0:47 UTC
Read the original article
Hit count: 862
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?
© Stack Overflow or respective owner