| ||
This section concentrates on another type of callthe fast call, or the register call. According to Table 20.1, this type of call assumes that the first three parameters will be passed in registers ( EAX, EDX , and ECX ) and that the remaining parameters will be passed through the stack, as was in case with the stdcall calling convention. At the same time, if the stack was used, the responsibility for releasing it is delegated to the called procedure. This approach has another nuance. If the fast calling convention is used, the C translator adds the @ prefix to the names , which must be taken into account in the module written in Assembly language.
// The ADDC.CPP file #include <windows.h> #include <stdio.h> // Declare the external function for adding four integers extern "C" __fastcall ADDD(DWORD, DWORD, DWORD, DWORD); void main() { DWORD a, b, c, d; a=1; b=2; c=3; d=4; printf("%lu\n", (DWORD *)ADDD(a, b, c, d) ) ; ExitProcess(0); } ; The ADD.ASM file .586P .MODEL FLAT, stdcall PUBLIC @ADDD ; Flat memory model _TEXT SEGMENT ; This procedure returns the sum of four parameters ; Parameters are passed through the registers ; The first three parameters are passed in the EAX, EDX, and ECX registers ; The fourth parameter is passed through the stack (e.g., [EPB+08H]) @ADDD PROC PUSH EBP MOV EBP, ESP ADD EAX, ECX ADD EAX, EDX ADD EAX, DWORD PTR [EBP+08H] POP EBP RET 4 @ADDD ENDP _TEXT ENDS END
To translate the modules presented in Listing 20.4, issue the following command:
tasm32 /ml add.asm
Then, include the ADD.OBJ file in the ADDC project (Borland C++ 5.0)
| ||