All internal assembly statements must follow this syntax:
[LocalLabel:] (instruction | directive) [operands];
Other rules for statements are:
- The assembly instructions are the standard Power Architecture instruction mnemonics.
- Each instruction must end with a newline character or a semicolon ( ;).
- Hexadecimal constants must be in C style: 0xABCDEF is a valid constant, but $ABCDEF is not.
- Assembler directives, instructions, and registers are not case-sensitive. To the inline assembler, these statements are the same:
move.l b, DO
MOVE.L b, d0
- To specify assembly-language interpretation for a block of code in your file, use the asm keyword.
Note: To make sure that the C/C++ compiler recognizes the asm keyword, you must clear the ANSI Keywords Only checkbox of the C/C++ Language panel.
The following listings are valid examples of inline assembly code:
Listing: Function-Level Sample
long int b;
struct mystruct {
long int a;
} ;
static asm long f(void) // Legal asm qualifier
{
move.l struct(mystruct.a)(A0),D0 // Accessing a struct.
add.l b,D0 // Using a global variable, put return value
// in D0.
rts // Return from the function:
// result = mystruct.a + b
}
Listing: Statement-Level Sample
long square(short a)
{
asm {
move.w a,d0 // fetch function argument `a'
mulu.w d0,d0 // multiply
return // return from function (result is in D0)
}
}
Note: Regardless of its settings, the compiler never optimizes assembly-language functions. However, to maintain integrity of all registers, the compiler notes which registers inline assembly uses.