Skip to content

Instantly share code, notes, and snippets.

@orklann
Forked from FiloSottile/32.asm
Last active February 10, 2022 14:11
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 orklann/2738b42df62c81570c00e76d10b50733 to your computer and use it in GitHub Desktop.
Save orklann/2738b42df62c81570c00e76d10b50733 to your computer and use it in GitHub Desktop.
NASM Hello World for x86 and x86_64 Intel Mac OS X(get yourself an updated nasm with brew)
; /usr/local/bin/nasm -f macho 32.asm && ld -macosx_version_min 10.7.0 -o 32 32.o && ./32
global start
section .text
start:
push dword msg.len
push dword msg
push dword 1
mov eax, 4
sub esp, 4
int 0x80
add esp, 16
push dword 0
mov eax, 1
sub esp, 12
int 0x80
section .data
msg: db "Hello, world!", 10
.len: equ $ - msg
;
; The number of the syscall has to be passed in register %rax.
; rdi - used to pass 1st argument to functions
; rsi - used to pass 2nd argument to functions
; rdx - used to pass 3rd argument to functions
; rcx - used to pass 4th argument to functions
; r8 - used to pass 5th argument to functions
; r9 - used to pass 6th argument to functions
; /usr/local/bin/nasm -f macho64 64.asm && ld -macosx_version_min 10.7.0 -lSystem -o 64 64.o && ./64
global start
section .text
start:
mov rax, 0x2000004 ; write
mov rdi, 1 ; stdout
mov rsi, msg
mov rdx, msg.len
syscall
mov rax, 0x2000001 ; exit
mov rdi, 0
syscall
section .data
msg: db "Hello, world!", 10
.len: equ $ - msg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment