Blog

It all starts here: Hello world in assembly on macOS for Apple Silicon

by Giuseppe Macario

Assembly code for Apple Silicon M4 (arm64) tested on macOS 26 Tahoe (formerly macOS 14 Sonoma and macOS 15 Sequoia)


.global _main
.align 2

_main:
mov x0, #1       // file descriptor 1 (stdout) in X0
adr x1, str      // address of str in X1 (don't replace adr with ldr)
mov x2, #13      // 13 (length of str) in X2
mov x16, #4      // 4 (macOS write) in X16
svc #0           // system call (supervisor call)

mov x0, #0       // 0 (program's return value) in X0
mov x16, #1      // 1 (macOS exit) in X16
svc #0

str:
.ascii "Hello world!\n"

Compile with as and link with ld (through cc):

% as hello.s -o hello.o
% cc hello.o -o hello
% ./hello
Hello world!
%


System info:

% as --version
Apple clang version 17.0.0 (clang-1700.4.4.1)
Target: arm64-apple-darwin25.1.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
% cc -v
Apple clang version 17.0.0 (clang-1700.4.4.1)
Target: arm64-apple-darwin25.1.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
% ld -v
@(#)PROGRAM:ld PROJECT:ld-1230.1
BUILD 16:18:08 Oct 17 2025
configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em armv8m.main armv8.1m.main
will use ld-classic for: armv6 armv7 armv7s i386 armv6m armv7k armv7m armv7em
LTO support using: LLVM version 17.0.0 (static support for 29, runtime is 29)
TAPI support using: Apple TAPI version 17.0.0 (tapi-1700.3.8)
% uname -a
Darwin Mac.fritz.box 25.1.0 Darwin Kernel Version 25.1.0: Mon Oct 20 19:32:56 PDT 2025; root:xnu-12377.41.6~2/RELEASE_ARM64_T8132 arm64
%