Basic Asm
1 | asm asm-qualifiers ( AssemblerInstructions ) |
The asm keyword is a GNU extension. When writing code that can be compiled with -ansi and the various -std options, use asm instead of asm
Qualifiers
volatile
The optional volatile qualifier has no effect. All basic asm blocks are implicitly volatile.
inline
If you use the inline qualifier, then for inlining purposes the size of the asm statement is taken as the smallest size possible (see Size of an asm).
Parameters
AssemblerInstructions
This is a literal string that specifies the assembler code. The string can contain any instructions recognized by the assembler, including directives. GCC does not parse the assembler instructions themselves and does not know what they mean or even whether they are valid assembler input.
You may place multiple assembler instructions together in a single asm string, separated by the characters normally used in assembly code for the system. A combination that works in most places is a newline to break the line, plus a tab character (written as ‘\n\t’). Some assemblers allow semicolons as a line separator. However, note that some assembler dialects use semicolons to start a comment.
Remarks
Using extended asm typically produces smaller, safer, and more efficient code, and in most cases it is a better solution than basic asm. However, there are two situations where only basic asm can be used:
- Extended asm statements have to be inside a C function, so to write inline assembly language at file scope (“top-level”), outside of C functions, you must use basic asm. You can use this technique to emit assembler directives, define assembly language macros that can be invoked elsewhere in the file, or write entire functions in assembly language. Basic asm statements outside of functions may not use any qualifiers.
- Functions declared with the naked attribute also require basic asm (see Function Attributes).
https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Basic-Asm.html#Basic-Asm
Extended Asm
1 | asm asm-qualifiers ( AssemblerTemplate |
asm statements that have no output operands, including asm goto statements, are implicitly volatile.