I found The same Question in the assembly Tag, But I can't find it to reference it !! (it's very helpful) Sorry.
So, Why we Multiply the index by 3/2 To Get the index of the Next cluster ??
First of all we need clarify some ideas :
What is an Enrty in the FAT table ??
Is a peace of memory of 12-bits in long.So, FAT table is an ensemble of this Entries.
What there is in this Entries ??
In this peace of Memory there is an index (Number), this index refer to an entry in the same FAT table (how many Entry from the FAT Start address).
Each Entry is 12 bits long :
<---- 12 bits ----><---- 12 bits ----><---- 12 bits ----><---- 12 bits ---->
1st index 2nd index 3rd index 4th index
When we get The first Index from the Root Directory (for Example: 4), So we should Go to This index in The FAT table to find the index for the next cluster number. How we will proceed ??
We need the start address of FAT table (easy to find), And will Just add the index.Like this:
mov bx, [FAT address] ; Strat address of FAT table
mov ax, [cluster] ;the index (for ex: 4)
add bx, ax ;Start address + index = the next Entry (cluster).
Easy :-)!!
But where is the 3/2 fraction ?? :-D .
the above code is Wrong, why ??
The logic is Correct ,but there is a misunderstand of "The addressing unit".
in most CPUs The Unit addressing is BYTE(8-bits), so When we Make [index] that's mean: index * 8-bits in the Memory.
so when we made [cluster] ---> index * 8-bits,Like this we will indexing Entries of 8-bits long.
As against this, Our index is 12-bits not 8-bits !!! So how solve this Big problem lool??
The Solution:
We should just Multiply the [cluster] by 3/2, So :
index * 8bits * 3/2 = index* 12bits. that's what we need !! Now we can indexing the memory By 12-bits unit (1.5 byte).
The correct code is :
mov bx, [FAT address] ; Strat address of FAT table
mov ax, [cluster] ;the index (for ex: 4)
mov dx, ax ; make copy of index
shr dx, 0x0001 ; divide it By 2.
add ax, dx ; index/2 + index = index * 3/2.
add bx, ax ;Start address + index = the next Entry (cluster).
I'm newbie , so if there is something wrong just Notify it ;-D !! Thankx.