Skip to content

Instantly share code, notes, and snippets.

@dotrinh-DM
Created December 23, 2022 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dotrinh-DM/f90b7d96103429f1ee716ac93a720539 to your computer and use it in GitHub Desktop.
Save dotrinh-DM/f90b7d96103429f1ee716ac93a720539 to your computer and use it in GitHub Desktop.
Hello World Assembly Program on macOS
; ----------------------------------------------------------------------------------------
; Writes "Hello, World" to the console using only system calls. Runs on 64-bit macOS only.
; macOS:
; nasm -f macho64 hello_world.asm
; ld -macosx_version_min 10.7.0 -o hello_world hello_world.o
; ./hello_world
; ----------------------------------------------------------------------------------------
global start
section .text
start:
mov rax, 0x02000004 ; system call for write
mov rdi, 1 ; file handle 1 is stdout
mov rsi, message ; address of string to output
mov rdx, 13 ; number of bytes
syscall ; invoke operating system to do the write
mov rax, 0x02000001 ; system call for exit
xor rdi, rdi ; exit code 0
syscall ; invoke operating system to exit
section .data
message: db "dotrinh", 10 ; note the newline at the end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment