flat assembler
Message board for the users of flat assembler.
Index
> Windows > restore stack after cdecl |
Author |
|
MazeGen 03 Aug 2005, 18:03
That's because the code, following the wsprintf call, doesn't depend on previous stack state. Even POP EBP is unnecessary - your program doesn't depend on its value.
I mean, if you comment that three pops, POP EBP will not match PUSH EBP, but PUSH ESI. Your program will still work, because you never use EBP after POP EBP. Try to put some important value to EBP (e.g. offset of _ok) just before PUSH EBP and your program will not work correctly, when you comment that three pops: Code: .code start: mov ebp,_ok push ebp ; save ebp mov ebp, esp ... mov esp, ebp ; restore stack pointer pop ebp invoke MessageBox, HWND_DESKTOP, ebp, NULL, MB_OK ... |
|||
03 Aug 2005, 18:03 |
|
f0dder 03 Aug 2005, 18:44
Btw, don't use pop to clean the stack - use "add esp, <whatever>".
|
|||
03 Aug 2005, 18:44 |
|
wisepenguin 03 Aug 2005, 21:55
f0dder: ok will do, i will remember that. is the microsoft code wrong then using pops ?
|
|||
03 Aug 2005, 21:55 |
|
f0dder 04 Aug 2005, 00:58
Doing pops (probably) isn't wrong, but it's less efficient (you can adjust by some amounts with less opcode bytes with pop, but the code is slower). Has MS coded like this? Eek!
|
|||
04 Aug 2005, 00:58 |
|
DC740 04 Aug 2005, 01:09
"Btw, don't use pop to clean the stack - use "add esp, <whatever>"."
i'm a newbie and i would like to know more about this topic, any suggestion? maybe some texts about this...(anyway i'm searching in google right now) thanx |
|||
04 Aug 2005, 01:09 |
|
comrade 04 Aug 2005, 03:52
If you use add esp, X then it takes always one instruction, no matter how many parameters the function call took. However, using pop requires a pop for each parameter of the function call.
So if you have a function that takes ten parameters, you can either do a single add esp, 40 or you can do ten pop's. Clearly it is faster and smaller to do a single add esp, x. |
|||
04 Aug 2005, 03:52 |
|
f0dder 04 Aug 2005, 11:21
Not to mention that "add esp, X" only modifies the register, while pop has to read memory, trashes a register, and has multiple modifications of ESP.
You might want to look at fasm's proc macros to automate the stack cleanup... |
|||
04 Aug 2005, 11:21 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.