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 →al02h--; print char indl08h--; read char, no echo →al09h--; print$-terminated string atds:dx0ah--; buffered line input intods:dx3ch--; create/truncate file (ds:dxname,cxattrs) →axhandle3dh--; open file (almode) →axhandle3eh--; close handle inbx3fh--; readcxbytes from handlebxintods:dx40h--; writecxbytes fromds:dxto handlebx42h--; seek handlebx(alorigin,cx:dxoffset)4ch--; exit with 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=00h--; set video mode (al= mode)ah=0eh--; teletype: print char inal, advance cursorah=02h--; set cursor pos (dhrow,dlcol,bhpage)ah=13h--; write string (es:bpptr,cxlen)
; teletype one char, real mode (bootloader-style)
mov ah, 0eh
mov al, 'x'
int 10h
int 16h --; bios keyboard
ah=00h--; wait for key →alascii,ahscancodeah=01h--; key available? result inzf
; block until a key; ascii lands in al
xor ah, ah ; ah=00h
int 16h
int 13h --; bios disk
ah=00h--; reset drive indlah=02h--; readalsectors (ch/clcyl/sector,dhhead,dldrive) →es:bxah=03h--; writealsectors (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(ebxcode)3--; read(ebxfd,ecxbuf,edxlen)4--; write(ebxfd,ecxbuf,edxlen)5--; open(ebxpath,ecxflags,edxmode)6--; close(ebxfd)11--; 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 = number; args in rdi, rsi, rdx, r10, r8, r9.
0--; read(rdifd,rsibuf,rdxlen)1--; write(rdifd,rsibuf,rdxlen)2--; open(rdipath,rsiflags,rdxmode)3--; close(rdifd)59--; execve(rdipath,rsiargv,rdxenvp)60--; 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