Hello I'm Jackson and I have a few questions about tut 6.

First is, Convert CHS to LBA.

the formula is:

LBA = (cluster - 2) * sectors per cluster

ClusterLBA:

sub ax, 0x0002 ;ax = cluster.

xor cx, cx ;clear cx

mov cl, BYTE [bpbSectorsPerCluster] ;cl = the current byte of sectors per cluster

mul cx ;Why multiply cl by cx. Why not moveSectors Per Cluster into the cx and then multiply cx by ax?

add ax, WORD [datasector] ;Add ax to the datasector variable

ret ;return

My next question is about Convert LBA to CHS

The formula is:

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)

LBACHS:

xor dx, dx ;clear dx which I'm guessing is thelogical sector

div WORD [bpbSectorsPerTrack] ; divide dx by sectors per track

inc dl ;Why increase dl instead of dx

mov BYTE [absoluteSector], dl ;absolute sector variable = dl

xor dx, dx ;clear

div WORD [bpbHeadsPerCylinder] ;Why divide by number of heads instead of sectors per track and then divide by number of heads and take the remainder(MOD)?

mov BYTE [absoluteHead], dl ;absolute head variable = dl

mov BYTE [absoluteTrack], al ;Why al?

ret ;ret

Thank you.

## My Questions About Tutorial 6

**Moderator:** Moderators

### Re: My Questions About Tutorial 6

mul cx means "multiply ax by cx and store the result in ax:cx". In x86, multiplication is hardwired to use the [r][e]ax register, which is why you only specify the second operand.Why multiply cl by cx. Why not moveSectors Per Cluster into the cx and then multiply cx by ax?

There is no multiplication by cl. Remember that cl is physically part of cx. Therefore, the load on the previous line is setting up the cx register to be the second operand. The reason cl is used as opposed to cx is that you are reading a single byte from memory, which means the register you are storing it in must be a single byte long.

div is even more wierd than mul. It implicitly used the dx as the LHS operand, and takes a register or memory value as the RHS operand. It will return the integer division result in dx, and will return the remainder (which is the mod) in ax. On x86, you always get the mod as well as the regular division result, by the way in which integer divison is calculated.Why divide by number of heads instead of sectors per track and then divide by number of heads and take the remainder(MOD)?

~Andrew

### Re: My Questions About Tutorial 6

Thanks you. Now I understand.