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.

This complete 64-bit program still uses int 0x80 to print and to exit, and the 32-bit register names carry the arguments:

default rel section .data msg db "old", 10 section .text global _start _start: mov eax, 4 ; 32-bit sys_write mov ebx, 1 ; stdout mov ecx, msg ; buffer mov edx, 4 ; count int 0x80 mov eax, 1 ; 32-bit sys_exit xor ebx, ebx ; status 0 int 0x80

nasm -f elf64 -o old.o old.asm
ld -o old old.o
./old
echo $?

old
0

The first snippet is a fragment: it shows the 32-bit call and does not set up the buffer. The complete program was assembled with NASM 3.01, linked with GNU ld 2.45.1, and run on Alpine Linux 3.24.3 (x86_64) in a Docker container.

Questions

A new set of questions in a new order every time. Choose one answer for each, then check.

  1. What does int 0x80 do?

    Answer

    It triggers software interrupt 0x80

    INT n enters the handler the interrupt table names for vector n.

  2. Which service did DOS programs call with int 21h?

    Answer

    Every DOS service, from printing to file access

    INT 21h was the central DOS API for console, file and system services.

  3. Which registers carry a 32-bit Linux syscall with int 0x80?

    Answer

    eax, ebx, ecx, edx, esi, edi, ebp

    The 32-bit path uses the 32-bit names and different argument registers.

  4. What is the call number of 32-bit sys_write?

    Answer

    4

    The 32-bit table numbers write as 4, while the 64-bit table numbers it 1.

  5. What happens to pointers in int 0x80 on a 64-bit kernel?

    Answer

    They are truncated to 32 bits

    The 32-bit interface reads the low 32 bits of each argument.

  6. Which instruction is the fast 64-bit system call path?

    Answer

    syscall

    syscall enters the kernel without the interrupt gate overhead.

  7. What does this program print? default rel section .data msg db "old", 10 section .text global _start _start: mov eax, 4 mov ebx, 1 mov ecx, msg mov edx, 4 int 0x80 mov eax, 1 xor ebx, ebx int 0x80

    Answer

    old

    The 32-bit write prints the three letters and the newline.

  8. What exit status does that program return?

    Answer

    0

    The 32-bit exit takes the status in ebx, which is cleared before int 0x80.

  9. What does the CPU consult to find an interrupt handler?

    Answer

    The interrupt descriptor table

    Each vector has an IDT entry with the handler address and the privilege rules.

  10. Why do user-space programs almost never install their own interrupt handlers?

    Answer

    The IDT belongs to the kernel and the handler must preserve kernel state

    Handlers run at a privileged level and must save and restore every register the interrupted code expects.

Article author: Arthur Isaev