Table of Contents

IronForgeCyber

Courses

Resources

Blog

Log In



IronForgeCyber

AboutPrivacyTerms

© 2026 IronForgeCyber. All rights reserved.

  1. courses
  2. asm-101
  3. syscalls-interrupts
3 min read

System Calls

A program cannot touch the outside world on its own. Printing text, reading a file, allocating memory, exiting — all of it belongs to the operating system, and the only way to ask for it is a system call. Every "Hello, world!" you have assembled in this course already made two of them: one to write the text, one to exit.

Talking to the Kernel

Your code runs unprivileged: it can do arithmetic and shuffle its own memory, but it cannot speak to hardware. The kernel runs privileged and can. A system call is the one controlled doorway between the two. You fill in registers describing the request, execute a single instruction that traps into the kernel, and the kernel validates the request, does the work, and hands control back with a result. It is the boundary between your program and the machine.

The Syscall Convention

On x86-64 Linux the request is laid out in registers, then the syscall instruction fires:

  • rax holds the syscall number — which call you want.
  • Arguments go in rdi, rsi, rdx, r10, r8, r9, in that order.
  • The return value comes back in rax (a small negative value means an error, -errno).

That list is almost the function calling convention from Stack & Calls, with one deliberate difference: the fourth argument uses r10, not rcx, because the syscall instruction itself overwrites rcx. Here is the write call inside hello, caught the instant before it fires:

gdb
gef➤ break *0x401019Breakpoint 1 at 0x401019gef➤ runBreakpoint 1, 0x0000000000401019 in _start ()gef➤ p/d $rax$1 = 1gef➤ p/d $rdi$2 = 1gef➤ p/x $rsi$3 = 0x402000gef➤ p/d $rdx$4 = 14

Read it straight off the convention: rax = 1 is the write syscall, rdi = 1 is the file descriptor (standard output), rsi = 0x402000 is the address of the string, and rdx = 14 is its length. Letting the program run makes the call for real:

shell
$ ./helloHello, world!

A handful of syscall numbers come up constantly:

NumberNameDoes
0readread bytes from a file descriptor
1writewrite bytes to a file descriptor
2openopen a file
3closeclose a descriptor
9mmapmap memory
59execvereplace the process with a new program
60exitterminate the process

32-bit: int 0x80

Before syscall existed, 32-bit x86 entered the kernel with a software interrupt, int 0x80, and you will still meet it in 32-bit shellcode and older binaries. Two things change. The registers are the 32-bit set — number in eax, arguments in ebx, ecx, edx, esi, edi — and, less obviously, the syscall numbers are completely different: in the 32-bit table write is 4 and exit is 1, not 1 and 60. Mixing a 64-bit number into a 32-bit call (or the reverse) calls something entirely unintended. The modern syscall path is faster, since it avoids the interrupt machinery, and is the right choice for 64-bit code; the 32-bit world is covered in 32-bit x86 (i386).

Finding Syscall Numbers

The numbers live in the kernel headers — unistd_64.h for the 64-bit table, unistd_32.h for the 32-bit one — and, as the two values for write show, you must look in the right table for the mode you are in.

See the radare2 resource's System Calls section for a quick way to look numbers up without digging through headers.