Assembly code for Apple Silicon M4 (arm64) tested on macOS 26 Tahoe (formerly macOS 14 Sonoma and macOS 15 Sequoia). You need the Command Line Tools for Xcode package.
FYI, I usually update this page at least once a year to make sure that newer versions of the compiler haven't introduced any errors or warnings. Last update: December 2025
Registers used in this routine:
x0, x1, x2: general-purpose registers, typically used to pass parameters to a function or to receive its return value
x16: (IP0) intra-procedure-call scratch register, used by supervisor calls
// hello.s
.global _main
.align 2
_main:
adr x1, str // address of str
mov x2, #13 // length of str, 13 bytes including the newline
mov x0, #1 // file descriptor 1 (stdout)
mov x16, #4 // 4 stands for "write"
svc #0 // supervisor call (system call)
mov x0, #0 // 0 is the return value
mov x16, #1 // 1 stands for "exit"
svc #0 // supervisor call (system call)
str:
.ascii "Hello world!\n"
[Deprecated:] Assemble with as and link with ld (through cc):
% as hello.s
% cc hello.o
% ./a.out
Hello world!
%
However, as is now deprecated, according to man as. Therefore, you just have to use clang:
% clang hello.s
% ./a.out
Hello world!
%
System info:
% clang -v
Apple clang version 17.0.0 (clang-1700.6.3.2)
Target: arm64-apple-darwin25.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
%