sebastian wrote:
>> mov edx, [esp+4]
I thought that when using 'call', the return address is pushed onto the stack, so that upon function entry esp+4 would contain the return address and the parameter I passed would be at esp+8?
It is on the stack, but the stack pointer points to the last thing you put on it. So, [esp] would be the return address, and [esp+4] is the address of the first variable. When you push something on in your routine (say, the old base pointer) [esp] would be the base pointer, [esp+4] would be the return address and [esp+8] would be the first argument.
For completeness (if you're using 32-bit linux systems, you can ignore it):
In windows parameters are passed by __stdcall. IIRC, that meant that the LAST parameter is [esp+8] after pushing the base pointer.
On any non-32-bit system the parameters are not 4 bytes. On any system they're [?sp + n] where ?sp is the name of the current stack pointer (sp, esp, rsp) and n is the number of bytes that hold those amounts of bits (2, 4,
.
64-bit arguments on a 32-bit system (and so on for the 16-bit systems etc.) are passed in 2 arguments rather than one. Count those doubles too. They're passed in little-endian order, so the first n-byte word is the smaller half, and the last one is the larger half.
>> are you sure you want to ret? there's nothing to catch you, probably...
What do you mean? I thought you always has to ret (from 'main', to the OS, and from frunctions, to the caller)?
Sorry, wrong forum. Thought you were doing osdev (barely any ASM programming otherwise) and if you were, there's no OS below you. That's why I said that.