The formula to convert CHS to LBA:
Code: Select all
CHS to LBA
Formula
LBA = (cluster - 2 ) * sectors per cluster
And here the code:
sub ax, 0x0002 ; subtract 2 from cluster number
xor cx, cx
mov cl, BYTE [bpbSectorsPerCluster] ; get sectors per cluster
mul cx ;Why multiply by cx? Why not ax?
LBA to CHS
Formula:
absolute sector = (logical sector / sectors per track) + 1
absolute head = (logical sector / sectors per track) MOD number of heads
absolute track = logical sector / (sectors per track * number of heads)
Code:
LBACHS:
xor dx, dx
div WORD [bpbSectorsPerTrack]
inc dl
mov BYTE [absoluteSector], dl
xor dx, dx
div WORD [bpbHeadsPerCylinder]
mov BYTE [absoluteHead], dl
mov BYTE [absoluteTrack], al
ret
Code: Select all
xor dx, dx
div WORD [bpbSectorsPerTrack]
push dx
inc dx
mov BYTE [absoluteSector]
pop dx
;Then somehow get the MOD
mov BYTE[absoluteHead], dx
mov dx, WORD [bpbSectorPerTrack]
mul BYTES [bpbNumberOfHeads]
xor ax, ax
div dx