Inline assembly, c inline assembly
Link: http://www.orlion.ga/776/
The program written in C may be less efficient than assembly, and some platform-related commands must be handwritten. For example, x86 is a port I/O, and C language does not have this concept, therefore, the in/out command must be compiled.
Gcc provides an extended way to try inline assembly in C code. The simplest format is _ asm _ ("assembly code ");, for example, the command _ asm _ ("nop"); nop allows the CPU to be idling for one cycle. If multiple commands need to be executed, separate each command with \ n \ t, for example:
__asm__("movl $1, %eax\n\t" "movl $4, %ebx\n\t" "int $0x80");
Generally, inline assembly in c code needs to be associated with the c variable, and the complete inline assembly style must be used:
__asm__(assembler template : output operands /* optional */ : input operands /* optional */ : list of clobbered registers /* optional */ );
This format is composed of four parts. The first part is the assembly instruction. Like the above example, the second part and the third part are constraints, the second part indicates that the computation result of the assembly instruction is to be output to those c operations, the c operation must be a left value expression, and the third part indicates that the assembly instruction needs to obtain the input from those c operations, the fourth part is the list of registers modified in the assembly instruction, which indicates which registers of the compiler will change when executing this _ asm _ statement. The last three parts are optional. If there is no value, enter the ":" number, for example: