Skip to content

Instantly share code, notes, and snippets.

@Cxarli
Created October 28, 2015 20:51
Show Gist options
  • Save Cxarli/538e6b78b0c2089bee91 to your computer and use it in GitHub Desktop.
Save Cxarli/538e6b78b0c2089bee91 to your computer and use it in GitHub Desktop.
hello.asm
;; ---- HELP ----
;; rax [64x] CPU cache — temporary register. `syscal` uses this
;; rdi [64x] CPU cache — 1st argument.
;; rsi [64x] CPU cache — 2nd argument.
;; rdx [64x] CPU cache — 3rd argument.
;; syscall [all] Call a system function. ID gotten from `rax`
;; - See: https://github.com/torvalds/linux/blob/097f70b3c4d84ffccca15195bdfde3a37c0a7c0f/include/linux/syscalls.h
;; * 1 sys_write: Output an array
;; * 60 sys_exit: Exit
;; long sys_write(unsigned int fd, const char __user *buf, size_t count);
;; long sys_exit(int error_code);
;; Compile and run with
;; ```nasm -f elf64 -o hello.o hello.asm
;; ld -o hello hello.o
;; ./hello```
section .data ;; Variables here
msg db "Hello, world!", 10 ;; Hello world variable as `msg`
len equ $-msg ;; Length of `msg`
section .text ;; Code below here
global _start ;; Define _start
_start: ;; Initialize _start, then run
mov rax, 1
mov rdi, 1
mov rsi, msg
mov rdx, len
syscall
mov rax, 60
mov rdi, 0
syscall
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment