Hello World via Linux syscall
A freestanding x86-64 program that prints and exits using only kernel syscalls.
Code
; nasm -f elf64 hello.asm && ld hello.o -o hello && ./hello
section .rodata
msg: db "Hello, x86-64!", 10
msg_len: equ $ - msg
section .text
global _start
_start:
; write(1, msg, msg_len) syscall #1
mov rax, 1 ; write
mov rdi, 1 ; fd = stdout
lea rsi, [rel msg] ; buffer (RIP-relative)
mov rdx, msg_len
syscall
; exit(0) syscall #60
mov rax, 60
xor edi, edi
syscallExplanation
This is the smallest useful x86-64 Linux program — no libc, no dynamic linker. The syscall instruction enters the kernel with the syscall number in rax and up to six arguments in rdi, rsi, rdx, r10, r8, r9. write=1, exit=60. RIP-relative addressing ([rel msg]) makes the code position-independent so it works whether linked as PIE or not.
More Assembly Snippets
Function Call Convention (System V AMD64)
Pass args in registers, preserve callee-saved regs, keep rsp 16-byte aligned.
Loop Summation (1..N)
Sum integers 1..N with a counted loop using dec/jnz.
strlen — Scan Until NUL
Compute C-string length by scanning memory until a zero byte.
memcpy — Copy with rep movsb
Use the rep movsb string instruction for a tight memory copy.
Bit Manipulation: popcount, ctz, abs
Use BMI/ABM instructions for branchless bit operations.
Read a File via syscalls
open/read/write/close a file using only Linux syscalls.