Armature wrote:
Hey, I've read through your code and some other tutorials on how to convert LBA to CHS but I'm left really confused. I understand the maths behind the code and how the CHS are calculated but what I don't understand is the storing of the variables calculated. The outputs are stored in 16 bit registers when the interrupt using the 8bit registers to read and write data. Would you be able to explain this to me please?
For Floppy Drives, 8-bit registers only might be okay. However, CHS (Cylinder/Head/Sector) values are stored in three 8-bit registers, though each 8-bit register is *not* exclusive to only one of the values.
Code:
CH = low eight bits of cylinder number
CL = sector number 1-63 (bits 0-5)
high two bits of cylinder (bits 6-7, hard disk only)
DH = head number
The indication that the high two bits are hard-drives only is simply because a floppy disk doesn't have that many cylinders. You still have to place the high two bits of the cylinder (which for floppy disks will be 00b) into the high two bits of CL.
Let's show an example. CX is the 16-bit register, consisting of CH and CL. Therefore, shown is the 16-bit representation of the cylinder and sector bits: (assuming that your version of this forum uses fixed width fonts for all code blocks)
Code:
11111100 00000000
54321098 76543210
CCCCCCCC CCSSSSSS
Where 'C' = Cylinder and 'S' = Sector. However, the 10-bit cylinder value is actually:
Code:
76543210 98xxxxxx
CCCCCCCC CCxxxxxx
To get the actual Cylinder number from CX above, you can do something like:
Code:
; CX = 10-bit cylinder number in CHS form (zero based)
mov dh,cl
shr dh,6
mov dl,ch
; DX now is 10-bit cylinder number (zero based)
and DX will now contain a valid 10-bit cylinder number. Convert from a 10-bit number back to CHS, you could do something like:
Code:
; DX = 10-bit cylinder number (zero based)
; AL = 6-bit sector number (1 based)
mov ch,dl
mov cl,dh
shl cl,6
and al,3Fh
or cl,al
; CX now is 10-bit cylinder number in CHS form (zero based)
The code that I directed you to might not be near as clear on what it is doing, but this is because a boot sector needs all of the room it can get. For boot sectors, if you can do the conversion in 16 bytes and have unclear code, compared to 32 bytes to have clear code, you do the 16-byte version and include a well-documented comment block indicating what you are doing.
Does this help?
Ben