Inline Assembly
C3 provides two ways to insert inline assembly: asm strings and asm blocks.
Asm strings
This form takes a single compile time string and passes it directly to the underlying backend without any changes.
Asm block
Asm blocks uses a common grammar for all types of processors. It assumes that all assembly statements can be reduced to the format:
Where an arg is:
- An identifier, e.g.
FOO
,x
. - A numeric constant
1
0xFF
etc. - A register name (always lower case with a ’$’ prefix) e.g.
$eax
$r7
. - The address of a variable e.g.
&x
. - An indirect address:
[addr]
or[addr + index * <const> + offset]
. - Any expression inside of ”()” (will be evaluated before entering the
asm
block).
An example:
The asm block will infer register clobbers and in/out parameters.
*Please note that the current state of inline asm is a work in progress, only a subset of x86, aarch64 and riscv instructions are available, other platforms have no support at all. It is likely that the grammar will be extended as more architectures are supported. More instructions can be added as they are needed, so please file issues when you encounter missing instructions you need.