My Daily Gist | Ferdinand Silva


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
view raw test.asm hosted with ❤ by GitHub