C Language and Libraries Help (clang.hlp) (
Table of Contents;
Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
Using C Symbols with the Inline Assembler
◄Up► ◄Contents► ◄Index► ◄Back►
─────C/C++ Language─────────────────────────────────────────────────────────
An __asm block can refer to any C symbol in the scope where the
block appears. This includes arguments, functions, and local,
static local, and global variables. Each assembly-language
statement can contain only one C symbol (except in LENGTH, TYPE,
and SIZE expressions). Functions referenced in an __asm block must
be declared (prototyped) earlier in the program.
If a structure or union member has a unique name, an __asm
block can refer to it by using only the member name
(mov ax, [bx].unique). If the member name is not unique, you must
place a variable or typedef name before the period operator
(mov ax, [bx]var.copy).
You can define functions in C and implement them with the inline
assembler, as shown below:
int power2( int num, int power )
{
__asm
{
mov ax, num ; Get first argument
mov cx, power ; Get second argument
shl ax, cl ; AX = AX * ( 2 to the power of CL )
}
} // Return with result in AX
This assumes the __cdecl or __pascal calling convention. To avoid
register conflicts, you should not use the __fastcall calling
convention for functions with __asm blocks.
-♦-