Skip to content

Instantly share code, notes, and snippets.

@ushu
Last active September 25, 2017 12:19
Show Gist options
  • Save ushu/97487aad4411297432e96baa75ab16b7 to your computer and use it in GitHub Desktop.
Save ushu/97487aad4411297432e96baa75ab16b7 to your computer and use it in GitHub Desktop.
Hello World on NASM that runs on a Mac
; Basic Hello World that compiles on MacOS
; nasm -fmacho64 test.asm && cc test.o -Wl,-no_pie && ./a.out
global _main
extern _puts, _exit
section .text
_main:
; Saves the stack, not really useful here but will ensure the stack is 16 bits-aligned
; BEWARE: the mac is super strict on pointer alignment, misaligned stack segfaults on
; function calls !!!
push rbp
mov rdi, qword hw ; First argument is a pointer to the message
; (added "qword" qualifer so it compiles on yasm too)
call _puts
; cleanup
pop rbp
ret
section .data
hw db "Hello from NASM", 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment