Basic format:
Extended inline assembly
- output:
"constraints-and-modifiers" (expr), ...
- input:
"constraints-and-modifiers" (expr), ...
- same thing as output, but expr can be any expression (not necessarily a lvalue)
- constraints
r
: use any register for this operand (refer to it using%n
, where n is the operand’s zero-based index in the entire output & input list)g
: TODO<n>
: use a zero-based index to refer to a previous operand<r>
: specify a register to use, a = eax, b = ebx, …, S = esi, D = edi
- constraint modifier
=<...>
: output registers should use a ”=” constraint modifier+<...>
: both an input and output register
- clobber list: list any registers that are changed and are not part of the output list
cc
: if condition codes are modified
Registers can also be named, so instead of %%ecx
or %0
, we can use [var_name]
. The corresponding name must appear in the operand list, e.g., asm( ... : [sum] "+r" (sum_var) : ... : ...)
.