interrupts
the x86 interrupt calls i actually reach for. the full firehose is ralf brown's list, and this is just my slice of it.
jump to int 21h · int 10h · int 16h · int 13h · linux 32-bit · linux 64-bit
int 21h (dos api)
ah picks the function.
01hreads a char from stdin with echo →al02hprints the char indl08hreads a char without echo →al09hprints the$-terminated string atds:dx0ahreads a buffered line intods:dx3chcreates or truncates a file (ds:dxname,cxattrs) →axhandle3dhopens a file (almode) →axhandle3ehcloses the handle inbx3fhreadscxbytes from handlebxintods:dx40hwritescxbytes fromds:dxto handlebx42hseeks handlebx(alorigin,cx:dxoffset)4chexits with the code inal
; 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=00hsets the video mode (al= mode)ah=0ehis teletype output, it prints the char inaland moves the cursor forwardah=02hsets the cursor position (dhrow,dlcol,bhpage)ah=13hwrites a string (es:bpptr,cxlen)
; teletype one char, real mode (bootloader-style)
mov ah, 0eh
mov al, 'x'
int 10h
int 16h (bios keyboard)
ah=00hwaits for a key →alascii,ahscancodeah=01hchecks whether a key is available, with the result inzf
; block until a key; ascii lands in al
xor ah, ah ; ah=00h
int 16h
int 13h (bios disk)
ah=00hresets the drive indlah=02hreadsalsectors (ch/clcyl/sector,dhhead,dldrive) →es:bxah=03hwritesalsectors (same args)ah=08hgets the 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 is the number, and the args go in ebx, ecx, edx, esi, edi.
1is exit(ebxcode)3is read(ebxfd,ecxbuf,edxlen)4is write(ebxfd,ecxbuf,edxlen)5is open(ebxpath,ecxflags,edxmode)6is close(ebxfd)11is execve(ebxpath,ecxargv,edxenvp)
; 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 is the number, and the args go in rdi, rsi, rdx, r10, r8, r9.
0is read(rdifd,rsibuf,rdxlen)1is write(rdifd,rsibuf,rdxlen)2is open(rdipath,rsiflags,rdxmode)3is close(rdifd)59is execve(rdipath,rsiargv,rdxenvp)60is exit(rdicode)
; 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