Skip to content

Instantly share code, notes, and snippets.

@peterc
Created August 23, 2024 14:11
Show Gist options
  • Save peterc/bac82b36c8f6713333779554db6ad992 to your computer and use it in GitHub Desktop.
Save peterc/bac82b36c8f6713333779554db6ad992 to your computer and use it in GitHub Desktop.
Basic assembly Hello World example for macOS on Apple Silicon/arm64

To compile:

as -o hello.o hello.s
ld -o hello hello.o -lSystem -syslibroot `xcrun -sdk macosx --show-sdk-path` -e _main -arch arm64

./hello
.global _main
.align 2
_main:
mov x0, #1 // file descriptor (1 for stdout)
adrp x1, message@PAGE // load the address of the string
add x1, x1, message@PAGEOFF
mov x2, #14 // length
mov x16, #0x04 // syscall number for write
svc 0 // make the syscall
mov x0, #0 // exit code 0
mov x16, #0x01 // syscall number for exit
svc 0 // make the syscall
.section __TEXT,__cstring
message:
.asciz "Hello, World!\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment