http://www.asmtrauma.com/Articles.htm
I suggest you read this and decide which one you like and has good compiler support (cdecl/stdcall/register, not pascal).
Note that while the articles linked to seems to explain well, they contain a good deal of errors that you need to be aware of if you program in assembly:
Cdecl:
- Bytes and words are returned in eax, not al and ax, however, the number is truncated to fit in al/ax. This sounds like the same, but it means that if you want to assign the result of a function returning a byte to a dword variable, you can do so without conversion. If the result was returned in only al/ax you'd end up with partial garbage if you didn't convert from byte/word to dword.
- Even if the result size is 4 or 8 bytes, it is returned in st0 if it is a floating point value.
Any parameter with any size is passed to the procedure using a 4-byte stack space whether it is 8-bits or 80-bits long.
If it's 80 bits it's passed in 8 bytes, not 4.
Keep the original state of the CPU registers in your procedure/function unless you need to return a value in one or two or some of them.
The registers eax, ecx, edx and st0-st7 are called scratch registers, and can be modified freely by any procedure. If you want them preserved them across a procedure call, you must do it yourself. All
other registers must be saved by the procedure.
Create a stack frame before trying to access local parameters.
Do not use the stack pointer explicitly neither to access local parameters nor to create local variables.
Stack frames are not necessary, nor fast nor particularly easy.
Register/Fastcall:
- Register and fastcall are different/not standardised. Which register to use for parameter is different from compiler to compiler.
- Gcc/VC++ passes the TWO first parameters in ecx then edx, the rest on the stack.
- Delphi passes the THREE first parameters in EAX, EDX then ECX, the rest on the stack.
The result of the function should be put inside one of these registers: AL, AX, EAX, EDX:EAX depending on the size of the result.
Same error as on cdecl: eax is used for byte and word returns.
Stdcall:
Same error about al/ax.