Skip to content

Instantly share code, notes, and snippets.

@menzenski
Created February 4, 2015 15:24
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save menzenski/74dab45619ca69a00df3 to your computer and use it in GitHub Desktop.
Save menzenski/74dab45619ca69a00df3 to your computer and use it in GitHub Desktop.
Hello World in Assembly language (x86-64 Unix-like operating systems, NASM syntax)
; MacOS X: /usr/local/bin/nasm -f macho64 *.s && ld -macosx_version_min 10.7 *.o
; Solaris/FreeBSD/DragonFly: nasm -f elf64 -D UNIX *.s && ld *.o
; NetBSD: nasm -f elf64 -D UNIX -D NetBSD *.s && ld *.o
; OpenBSD: nasm -f elf64 -D UNIX -D OpenBSD *.s && ld -static *.o
; OpenIndiana: nasm -f elf64 -D UNIX *.s && ld -m elf_x86_64 *.o
; Linux: nasm -f elf64 *.s && ld *.o
%ifdef NetBSD
section .note.netbsd.ident
dd 7,4,1
db "NetBSD",0,0
dd 200000000 ; amd64 supported since 2.0
%endif
%ifdef OpenBSD
section .note.openbsd.ident
align 2
dd 8,4,1
db "OpenBSD",0
dd 0
align 2
%endif
section .text
%ifidn __OUTPUT_FORMAT__, macho64 ; MacOS X
%define SYS_exit 0x2000001
%define SYS_write 0x2000004
global start
start:
%elifidn __OUTPUT_FORMAT__, elf64
%ifdef UNIX ; Solaris/OI/FreeBSD/NetBSD/OpenBSD/DragonFly
%define SYS_exit 1
%define SYS_write 4
%else ; Linux
%define SYS_exit 60
%define SYS_write 1
%endif
global _start
_start:
%else
%error "Unsupported platform"
%endif
mov rax,SYS_write
mov rdi,1 ; stdout
mov rsi,msg
mov rdx,len
syscall
mov rax,SYS_exit
xor rdi,rdi ; exit code 0
syscall
section .data
msg db "Hello, world!",10
len equ $-msg
@mcandre
Copy link

mcandre commented Jun 30, 2020

needs moar windows

@mcandre
Copy link

mcandre commented Jun 30, 2020

big sur arm64 ready?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment