Interrupts

The INT instruction

INT n triggers software interrupt n: the CPU saves state and jumps to the handler the interrupt table names. DOS programs used INT 21h for every service, and 32-bit Linux used INT 80h for syscalls:

mov eax, 4 ; sys_write (32-bit) mov ebx, 1 ; stdout mov ecx, msg ; buffer mov edx, len ; count int 0x80 ; old 32-bit Linux syscall

int 0x80: the 32-bit path

On 64-bit Linux, int 0x80 still works but truncates arguments to 32 bits. The SYSCALL instruction is the 64-bit path: faster, and with a different register assignment (RAX, RDI, RSI, RDX, R10, R8, R9).

Interrupt handlers

Hardware interrupts (keyboard, timer, disk) arrive through the same mechanism. Writing a handler means filling an interrupt descriptor table entry and preserving every register the caller expects intact - which is why user-space programs almost never install their own.

The code on this page was assembled with NASM 3.01 and linked with GNU ld 2.45.1, and the program was run on Alpine Linux 3.24.3 (x86_64) in a Docker container.

Article author: Arthur Isaev