; hello.asm - a "hello, world" program using NASM ; $ nasm -f macho hello.asm ; $ ld hello.o -o hello -static -macosx_version_min 10.7 -pagezero_size 0 -no_uuid ; $ ./hello ; hello, world SECTION .text mymsg db "Hello, world!", 0xA ; string with a carriage-return mylen equ $-mymsg ; string length global start start: ; print "hello, world" ; syscall write arguments push dword mylen ; length of message push dword mymsg ; address of message push dword 1 ; write to standard output ; syscall write mov eax, 0x4 ; system call number for 'write' sub esp, 4 ; OS X (and BSD) system calls needs "extra space" on stack int 0x80 ; make the actual system call ; clean up the stack add esp, 16 ; 3 args * 4 bytes/arg + 4 bytes extra space = 16 bytes ; exit the program ; syscall exit arguments push dword 0 ; exit status returned to the operating system ; syscall exit mov eax, 0x1 ; system call number for exit sub esp, 4 ; OS X (and BSD) system calls needs "extra space" on stack int 0x80 ; make the system call