Initial training build preserving esp after function calls

I am starting to learn assembly by storing the ESP register before calling the function, does it matter if you do this by adding or subtracting? difficult 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 cmp fails, is it safe to use mov esp, esi to align the stack?

thank

EDIT: And how do I need to do this to call a sprintf type, but the MessageBox seems to fix the ESP for me? How do I know which function needs this and what not?

+3
source share
2 answers

, esp ( , , - , , ). , . , ( ), stac k. X86 ( ) . ... , .

, esp, , , , , - , , . esp esi ... esp esi, , , , esp , .

MessageBox - " ". (C), . sprintf cdecl, MessageBox - stdcall.

+4

sprintf, MessageBox, , ESP ?

, MessageBox() , . , .

sprintf() . , , .

+1

Source: https://habr.com/ru/post/1736582/


All Articles