The general format of the asm (or __asm__) construct:
assembler template
- Put assembler instructions here.
- Format: "assembler instruction(s)". Each instructions is followed by a semicolon or a newline (\n).
- %0 for the first operand, %1 for the second operand,…etc.
- List of operands in C expressions.
- Format: “constraint” (C expression). Each operand is separated by a comma.
- The output operands can be written to by instructions. The input operands can be read by the instructions.
- The gcc website maintains an exhaustive list of machine constraints. Just scroll down a few pages to the Blackfin family section.
- List of modified registers. This will prevent the compiler from using these registers for other purposes.
- Format: enclosed in double quotes (” ”). Each register is separated by a comma.
example:
int y;
asm(
"%0 = %1" /* y=x */
:"=r"(y) /* output operand (%0): write-only, register constrained variable y */
:"m"(x) ); /* input operand (%1): memory variable x */
asm volatile
The volatile construct should be used if the code must remain in a certain location or should not otherwise be optimized by the compiler.參考文獻
- Blackfin Linux Docs: Using In-line Assembly, Calling External Assembly from C
- For more information on asm construct see: GCC-Inline-Assembly-HOWTO.