INT 13h is the lowest level a DOS program normally reaches for disks. It knows nothing about files, directories or FAT: it reads and writes sectors, 512-byte blocks addressed by their physical position. DOS itself uses it to reach the disks; a program uses it to read a boot sector or partition table, copy a whole floppy, or run before DOS is there (boot loaders do nothing else).
| AH | Service |
|---|---|
| 00h | reset the disk system |
| 01h | status of the last operation |
| 02h | read sectors into ES:BX |
| 03h | write sectors from ES:BX |
| 04h | verify sectors |
| 05h | format a track |
| 08h | drive parameters: cylinders, heads, sectors per track |
| 15h | drive type (AT) |
| 41h..48h | extensions: LBA addressing for large disks (later BIOSes) |
Drive numbers
DL selects the drive by BIOS number, not by DOS letter: 00h is the first floppy (A:), 01h the second, 80h the first hard disk, 81h the second. Bit 7 is the hard-disk bit. The BIOS keeps the number of hard disks it found at 0040:0075h. DOS letters come later: C: is usually the first primary partition on 80h, but it can be anything, and network or substituted drives have no BIOS number at all.
Cylinder, head, sector
A sector is addressed by CHS: the cylinder (the track position of the heads), the head (which surface) and the sector within the track. Sectors count from 1, cylinders and heads from 0. The registers pack this tightly: CH holds the low 8 bits of the cylinder, CL bits 0-5 the sector (1..63) and CL bits 6-7 the two high bits of the cylinder (so cylinders go up to 1023), DH the head. A 1.44 MB floppy has 80 cylinders, 2 heads and 18 sectors per track; the first sector of a disk, its boot sector or partition table, is always cylinder 0, head 0, sector 1.
; cylinder 300 (12Ch), head 2, sector 5:MOV CH, 2Ch ; low 8 bits of the cylinderMOV CL, 05h OR 40h ; sector 5, plus cylinder bits 8-9 (01b) in bits 6-7MOV DH, 2 ; head
CHS caps a disk at 1024 × 255 × 63 sectors, about 8 GB, and older BIOSes at 504 MB. The extensions (AH=42h read, 43h write) take a 64-bit linear block address in a packet instead.
Errors
Every function returns CF = 0 on success and CF = 1 with a status in AH on failure: 01h bad command or drive, 02h address mark not found, 03h write protected, 04h sector not found, 06h disk changed, 80h timeout (no disk in the drive). Floppies fail often for harmless reasons, a motor not up to speed or a just-changed disk, so the rule for floppies is three tries with a reset (INT 13h AH=00h) in between before reporting an error.
The example asks the BIOS data area how many hard disks the BIOS found:
MOV AX, 40hMOV ES, AX ; the BIOS data areaMOV AL, ES:[75h] ; number of hard disksXOR AH, AHCALL PDECMOV DX, OFFSET DISKS1MOV AH, 09h ; DOS: print the $-string at DS:DXINT 21hDISKS1 DB " hard disk(s) known to the BIOS", 13, 10, "$"PDEC PROC NEAR ; print AX in decimal; keeps every registerPUSH AXPUSH BXPUSH CXPUSH DXMOV BX, 10XOR CX, CX ; digits on the stackDECD1:XOR DX, DXDIV BX ; AX = AX / 10, DX = the last digitPUSH DXINC CXTEST AX, AXJNZ DECD1DECD2:POP DX ; the digits come back first to lastADD DL, "0"MOV AH, 02hINT 21hLOOP DECD2POP DXPOP CXPOP BXPOP AXRETPDEC ENDP
In DOSBox-X
DOSBox-X has two kinds of drives. A folder of the host mounted with MOUNT is a DOS drive only: DOS sees files, but there are no sectors, and the BIOS has no disk behind the letter. A disk image attached with IMGMOUNT is a real BIOS disk with sectors, and INT 13h works on it as on a PC. The workbench's drive C is a mounted folder, so INT 13h on drive 80h does not reach a real disk there (see INT 13h AH=02h for what it returns instead), even though the BIOS data area claims two hard disks: DOSBox-X writes that count unconditionally, for programs that check it before looking further.