flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
asmrox 20 Jan 2008, 01:02
why returned value by retn is added to esp?
|
|||
![]() |
|
asmrox 20 Jan 2008, 01:28
okay, so instead add esp, 64 i use retn -64 ;]
and why its only 2byte long? stack can have more than 1626 argumernts |
|||
![]() |
|
LocoDelAssembly 20 Jan 2008, 01:47
But what function could push soooooo many arguments? Note that printf doesn't count since it can't be stdcall (unless you use some relatively complicated stack handling but if the fmt doesn't match the number of arguments you destroy the stack so is better to use cdecl calling convention where the caller must use the "add esp, xxx" rather than using stdcall convention that is meant just for no-vargars functions).
Quote:
The joke would be "add esp, 64"->"retn -60". I have not good sense of humor maybe but do you realize that are not the same at all no? ![]() I leave some examples Code: push 5 push 10 call stdcall_func ; EAX = 15; no need to adjust the stack push 3 push eax call cdecl_func ; EAX = 18; stack still holds the room for the two args so we must release them (or reuse the space for something else if seems appropiate but we have nothing else to do this time) add esp, 8 ; Now we can use RET since the stack is adjusted and hence ESP points to the return address instead of the first argument of cdecl_func (15 since the function doesn't write the args) ret ; Two args funcs stdcall_func: mov eax, [esp+4] add eax, [esp+8] ret 8 cdecl_func: mov eax, [esp+4] add eax, [esp+8] ret |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.