interrupts

x86 interrupt calls i actually reach for. the full firehose is ralf brown's list; this is just my slice.

jump to: int 21h · int 10h · int 16h · int 13h · linux 32-bit · linux 64-bit

int 21h --; dos api

ah picks the function.

  • 01h --; read char from stdin, with echo → al
  • 02h --; print char in dl
  • 08h --; read char, no echo → al
  • 09h --; print $-terminated string at ds:dx
  • 0ah --; buffered line input into ds:dx
  • 3ch --; create/truncate file (ds:dx name, cx attrs) → ax handle
  • 3dh --; open file (al mode) → ax handle
  • 3eh --; close handle in bx
  • 3fh --; read cx bytes from handle bx into ds:dx
  • 40h --; write cx bytes from ds:dx to handle bx
  • 42h --; seek handle bx (al origin, cx:dx offset)
  • 4ch --; exit with code in al
; print a string, then exit clean
mov ah, 09h
mov dx, msg          ; ds:dx -> "$"-terminated string
int 21h
mov ax, 4c00h        ; ah=4ch (exit), al=0 (code)
int 21h
msg db "hello$"

int 10h --; bios video

  • ah=00h --; set video mode (al = mode)
  • ah=0eh --; teletype: print char in al, advance cursor
  • ah=02h --; set cursor pos (dh row, dl col, bh page)
  • ah=13h --; write string (es:bp ptr, cx len)
; teletype one char, real mode (bootloader-style)
mov ah, 0eh
mov al, 'x'
int 10h

int 16h --; bios keyboard

  • ah=00h --; wait for key → al ascii, ah scancode
  • ah=01h --; key available? result in zf
; block until a key; ascii lands in al
xor ah, ah           ; ah=00h
int 16h

int 13h --; bios disk

  • ah=00h --; reset drive in dl
  • ah=02h --; read al sectors (ch/cl cyl/sector, dh head, dl drive) → es:bx
  • ah=03h --; write al sectors (same args)
  • ah=08h --; get drive params
; load the sector after the mbr to 0000:7e00
xor bx, bx
mov es, bx           ; es=0
mov bx, 7e00h        ; es:bx = buffer
mov ah, 02h
mov al, 1            ; one sector
mov ch, 0            ; cylinder 0
mov cl, 2            ; sector 2 (1-based)
mov dh, 0            ; head 0
mov dl, 80h          ; first hard disk
int 13h

linux, 32-bit --; int 0x80

eax = number; args in ebx, ecx, edx, esi, edi.

  • 1 --; exit(ebx code)
  • 3 --; read(ebx fd, ecx buf, edx len)
  • 4 --; write(ebx fd, ecx buf, edx len)
  • 5 --; open(ebx path, ecx flags, edx mode)
  • 6 --; close(ebx fd)
  • 11 --; execve(ebx path, ecx argv, edx envp)
; write(1, msg, 3); exit(0)
mov eax, 4
mov ebx, 1           ; stdout
mov ecx, msg
mov edx, 3
int 0x80
mov eax, 1
xor ebx, ebx
int 0x80

linux, 64-bit --; syscall

rax = number; args in rdi, rsi, rdx, r10, r8, r9.

  • 0 --; read(rdi fd, rsi buf, rdx len)
  • 1 --; write(rdi fd, rsi buf, rdx len)
  • 2 --; open(rdi path, rsi flags, rdx mode)
  • 3 --; close(rdi fd)
  • 59 --; execve(rdi path, rsi argv, rdx envp)
  • 60 --; exit(rdi code)
; write(1, msg, 3); exit(0)
mov rax, 1
mov rdi, 1           ; stdout
lea rsi, [rel msg]
mov rdx, 3
syscall
mov rax, 60
xor rdi, rdi
syscall