Skip to content

Instantly share code, notes, and snippets.

@jcreager
Created May 3, 2016 01:06
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 jcreager/546b85bee004cc53ec3b05d1d789fb0f to your computer and use it in GitHub Desktop.
Save jcreager/546b85bee004cc53ec3b05d1d789fb0f to your computer and use it in GitHub Desktop.
; ----------------------------------------------------------------------------------------
;Source: http://cs.lmu.edu/~ray/notes/x86assembly/
;Writes "Hello, World" to the console using only system calls. Runs on 64-bit Linux only.
; To assemble and run:
;
; nasm -felf64 hello.asm && ld hello.o && ./a.out
; ----------------------------------------------------------------------------------------
global _start
section .text
_start:
; write(1, message, 13)
mov rax, 1 ; system call 1 is write
mov rdi, 1 ; file handle 1 is stdout
mov rsi, message ; address of string to output
mov rdx, 13 ; number of bytes
syscall ; invoke operating system to do the write
; exit(0)
mov eax, 60 ; system call 60 is exit
xor rdi, rdi ; exit code 0
syscall ; invoke operating system to exit
message:
db "Hello, World", 10 ; note the newline at the end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment