Skip to content

Instantly share code, notes, and snippets.

@ianpreston
Created November 29, 2014 22:18
Show Gist options
  • Save ianpreston/8d7ae5546dd75f21b041 to your computer and use it in GitHub Desktop.
Save ianpreston/8d7ae5546dd75f21b041 to your computer and use it in GitHub Desktop.
; Assembly hello world for OSX
; So I can remember how to do basic shit in OSX
;
; $ nasm -g -f macho -o test.o test.asm
; $ ld -o a.out -e _main test.o -lSystem
bits 32
section .data
message db "Hello, world!", 10, 0
section .text
global _main
extern _printf
extern _exit
_main:
; Store argc and argv
pop eax
pop ebx
; 16-bit stack alignment
mov ebp, esp
and esp, 0xFFFFFFF0
sub esp, 16
;push message
mov dword[esp], message
call _printf
mov dword[esp], 0
call _exit
ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment