Skip to content

Instantly share code, notes, and snippets.

@six519
Created January 1, 2019 11:27
Show Gist options
  • Save six519/2275c93925c8d25a4f59570b7713fe23 to your computer and use it in GitHub Desktop.
Save six519/2275c93925c8d25a4f59570b7713fe23 to your computer and use it in GitHub Desktop.
My Hello World Code In Assembly Language On Mac OS X
; Assembling and linking
; ----------------------
; nasm -f macho64 test.asm
; gcc -o test test.o -Wl,-no_pie
section .data ; data section
line1:
db "My name is: " ; constant string
line2:
db "Ferdinand", 0xA ; constant string with newline
global _main
section .text ; text section
_main:
mov rax, 0x2000004 ; syscall number for write
mov rdi, 1 ; set first parameter to 1 (standard output)
mov rsi, line1 ; set second parameter to line1 constant string
mov rdx, 12 ; set third parameter (buffer size)
syscall ; invoke write function
mov rax, 0x2000004 ; syscall number for write
mov rdi, 1 ; set first parameter to 1 (standard output)
mov rsi, line2 ; set second parameter to line2 constant string
mov rdx, 10 ; set third parameter (buffer size)
syscall ; invoke write function
mov rax, 0x2000001 ; syscall number for exit
mov rdi, 0 ; set first parameter to 0 (return 0 to OS)
syscall ; invoke exit function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment