High-Level Language Interface
There are three methods of connecting C/C++ programs to assembly language programs:
- Inline assembly code in C/C++,
- Separate assembly language modules linked to C/C++ programs, and
- Calling C/C++ functions from an assembly language program.
Inline Assembly Code
Inline assembly code is assembly language source code that is inserted directly into high-level language programs.
The __asm
Directive
In Visual C++, the __asm
directive can be placed at the beginning of a single statement, or it can mark the beginning of a block of assembly language statements (called an asm block).
The syntax is
__asm statement
__asm {
statement-1
statement-2
...
statement-n
}
(There are two underline characters before “asm.”)
Comments
Comments can be placed after any statements in the asm block, using either assembly language syntax or C/C++ syntax.
Here are examples of permissible comments:
mov esi, buf ; initialize index register
mov esi, buf // initialize index register
mov esi, buf /* initialize index register */