❑ The calling convention is a convention used in the function call process. There are three kinds of this.
❑ CDECL : It is the abbreviation of C language DECLaration.
* C language uses CDECL.
Standard | Characteristic |
Parameter transfer method | Using stack frame |
Parameter transfer sequence | Right to left |
Return method | 4 Bytes↓ : EAX, 4~8 Bytes : EDX(High 4 bytes), EAX(Low 4 bytes) |
Stack frame cleanup | The caller cleans up the stack frame of the callee
* How to call sub(a, b).
PUSH b PUSH a CALL sub() ADD ESP, 8 |
* Caller : The function of the calling role.
* Callee : The function of the role being called.
❑ STDCALL : It is the abbreviation of the STanDard CALL.
* Win32 API uses STDCALL. It improves compatibility with languages other than C language.
Standard | Characteristic |
Parameter transfer method | Using stack frame |
Parameter transfer sequence | Right to left |
Return method | 4 Bytes↓ : EAX, 4~8 Bytes : EDX(High 4 bytes), EAX(Low 4 bytes) |
Stack frame cleanup | The callee cleans up the stack frame by itself
* How to call sub(a, b).
PUSH b PUSH a CALL sub() |
❑ FASTCALL : It means that it is faster to use registers than to use memory.
Standard | Characteristic |
Parameter transfer method | Using register and stack frame
* ECX and EDX are used when the number of parameters is 2.
* Stack frame is used when parameters exceed 2.
|
Parameter transfer sequence | Right to left |
Return method | 4 Bytes↓ : EAX, 4~8 Bytes : EDX(High 4 bytes), EAX(Low 4 bytes) |
Stack frame cleanup | The callee cleans up the stack frame by itself
* How to call sub(a, b).
MOV EDX, b MOV ECX, a CALL sub()
* How to call sub(a, b, c, d).
PUSH d PUSH c MOV EDX, b MOV ECX, a CALL sub() |