Skip to content

Instantly share code, notes, and snippets.

@dominiwe
Last active May 11, 2026 17:37
Show Gist options
  • Select an option

  • Save dominiwe/abbc8a8617066778b993c27ae61f10aa to your computer and use it in GitHub Desktop.

Select an option

Save dominiwe/abbc8a8617066778b993c27ae61f10aa to your computer and use it in GitHub Desktop.
Inline intel style assembly and syscalls in mojo.

Inline assembly and system calls in Mojo

See examples below (May 2026).

from std.sys._assembly import inlined_assembly
from std.sys import exit
# inline assembly write call
fn main():
var message = String("Hello World!\n").as_bytes().unsafe_ptr()
_ = inlined_assembly[
".intel_syntax noprefix\n\t"
"mov rax, 1\n\t"
"mov rdi, 1\n\t"
"mov rsi, r8\n\t"
"mov rdx, 13\n\t"
"syscall\n\t"
".att_syntax prefix",
Int64,
constraints="=r,{r8},~{rax},~{rdi},~{rsi},~{rdx},~{rcx},~{r11},~{memory}",
has_side_effect=True,
](message)
exit(0)
from std.sys import exit
from std.ffi import external_call
# ffi write call
fn main():
var message = String("Hello World!\n").as_bytes().unsafe_ptr()
_ = external_call["write", Int64](Int32(1), message, 13)
exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment