Slide 14.4: Inline assembly code (cont.)
Slide 14.6: Linking to C/C++ (Cont.)
Home

Linking to C/C++


Assembly language is still used widely to configure hardware devices and optimize both the speed and code size of programs. For external procedures in assembly language that can be called from C and C++ programs, such programs consist of at least two modules: Arguments
Arguments are passed by C/C++ programs from right to left, as they appear in the argument list.

External Names
In the assembly language source, specify the C calling convention in the .MODEL directive and create a prototype for each procedure called from an external C/C++ program. For example,
   .586
   .model  flat, C
   Encript PROTO, buf:PTR BYTE, count:DWORD, eChar:BYTE
Declaring the Function
In a C program, use the extern qualifier when declaring an external assembly language procedure. For example, this is how to declare Encript:
   extern void Encript( char* buf, long count, char eChar );
If the procedure will be called from a C++ program, add a ‘C’ qualifier to prevent C++ name decoration:
   extern "C" void Encript( char* buf, long count, char eChar );
Name decoration is a standard C++ compiler technique that involves modifying a function with extra characters that indicate the exact type of each function parameter.