Inline Assembler (v0.2.2)

Assembler functions and assembler values (unstable).

Latest

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.

LLVM Inline Assembler

The assembler strings follow the LLVM inline assembler format.

Example

asmfn invoke_exit_syscall() void {
    "mov $$60, %rax",
    "mov $$1, %rdi",
    "syscall"
} {
    "~{rax}~{rdi}"
}

fn main() s32 @public {
    invoke_exit_syscall();
    return 0;
}

Back to language reference