x86_64 Assembly Linux
Introduction
Hi!
This is a small and practical introduction to x86_64 assembly on Linux.
The focus is on understanding how syscalls work at a low level – no C runtime, no main, direct kernel interaction.
x86_64 Assembly Basics
On x86_64 Linux, system calls use CPU registers such as:
rax– syscall number / return valuerdi– first argumentrsi– second argumentrdx– third argument
Syscalls are executed using the syscall instruction.
Hello World in x86_64 Assembly
section .data
msg db 'Hello World', 0x0a
msglen equ $ - msg
section .text
global _start
_start:
mov rax, 1 ; write syscall
mov rdi, 1 ; stdout
mov rsi, msg ; buffer
mov rdx, msglen ; length
syscall
mov rax, 60 ; exit syscall
mov rdi, 0 ; status
syscallBuild & Run
nasm -f elf64 hello.asm -o hello.o
ld hello.o -o hello
./helloReferences
- /usr/include/asm/unistd_64.h
- man 2 write
- man 2 exit
- https://syscalls.w3challs.com/?arch=x86_64