Reputation: 11
I am currently working on using some ASM in C/C++
I have the following
__declspec(naked) unsigned long
someFunction( unsigned long inputDWord )
{
__asm
{
}
}
how, in asm, would I return the unsigned long?
Do I need to push something onto the stack and then call ret? I haven't used Asm in a long time, and never inside C++ before.
Thanks!
Upvotes: 0
Views: 310
Reputation: 12943
EDIT: Thanks to @Matteo Italia, I've corrected the usage of ret
.
Put the retval in eax
register, this is according to __cdecl
and __stdcall
conventions.
Then, depending on the calling convention, you should use the appropriate variant of ret
instruction:
__cdecl
convention (or similar) - use ret
. On machine level this means pop
-ing the return address from the stack and jmp
to it. The caller is responsible for removing all the function parameters from the stack.__stdcall
convention (or similar) - use ret X
, whereas X
is the size of all the function arguments.Upvotes: 2