Inline Assembler (v0.2.2)
Assembler functions and assembler values (unstable).
Overview
Assembler functions are written entirely in inline assembler. They support Intel and AT&T x86_64 assembler.
This feature is unstable. It only works when the compiler runs in unstable mode, and it can change or disappear.
Primary source: syntax/assembler/asmfunctions.md
Syntax Signatures
asmfn add(a u32, b u32) u32 @public @asmSyntax("Intel") {
"mov %eax, $0"
} {
"=r"
}
Behavior and Use
An assembler function body has two blocks: the assembler lines and the constraints.
Assembler functions accept parameters, a return type, and attributes like normal functions.
The current asmfn parser expects assembler parameters as name Type without a colon. Assembler values (asm T { ... } { ... }) can carry attributes and typed arguments.
Related Attributes
Assembler constructs use these unstable attributes.
@asmSyntax("Intel" | "AT&T")- selects the inline assembler syntax.@asmAlignStack- aligns the stack for an assembler block.@asmThrow- lets assembler errors propagate.@asmEffects- tells the backend the assembler block has side effects.
LLVM Inline Assembler
The assembler strings follow the LLVM inline assembler format.
- See the LLVM language reference for the constraint and template syntax.
- Assembler values can take attributes after the type and arguments inside parentheses after the type.
Example
asmfn invoke_exit_syscall() void {
"mov $$60, %rax",
"mov $$1, %rdi",
"syscall"
} {
"~{rax}~{rdi}"
}
fn main() s32 @public {
invoke_exit_syscall();
return 0;
}