Basic structure of inline assembly

 one
two
three
four
 asm  asm -qualifiers ( AssemblerTemplate
: OutputOperands
[ : InputOperands
[ : Clobbers ] ])

AssemblerTemplate
OutputOperands
InputOperands
Clobbers

Sample code

 one
two
three
four
five
six
seven
 int src = one ;
int dst;
asm ( "mov %1, %0\n\t"
"add $1, %0"
: "=r" (dst)
: "r" (src));
printf ( "%d\n" , dst);

Copy this code src reach dst , and add 1 to dst

Multiple assembler instructions can be placed in one asm String, separated by characters commonly used in system assembly code. The combination that is valid in most places is a new line character, plus a tab character (written as " n t")

Constraint symbol

“=”:Means that this operand is written to by this instruction: the previous value is discarded and replaced by new data.

”r”:Means that this operand is both read and written by the instruction. Identifies both readable and writable operands

If '=' or '+' is specified in the constraint, it is placed in the first character of the constraint string.

"A": ax register, function returns

"R": any register

"M": memory

 image-20240412231300895

 image-20240412231241954