0

I am not getting why we divide current cluster and adding result to itself.
Here is the code

mov     ax, WORD [cluster]  ; current cluster

mov     cx, ax              ; copy current cluster 

mov     dx, ax              ; copy current cluster

 shr     dx, 0x0001          ; divide by two 

add     cx, dx              ; sum for (3/2) 

mov     bx, 0x0200          ; location of FAT in memory 

add     bx, cx              ; index into FAT 

mov  dx, WORD [bx]       ; read two bytes from FAT 

test    ax, 0x0001 

jnz     .ODD_CLUSTER ; Remember that each entry in the FAT is a 12 but value. If it represents ; a cluster (0x002 through 0xFEF) then we only want to get those 12 bits ; that represent the next cluster    

  .EVEN_CLUSTER:          
 and     dx, 0000111111111111b      ; take low twelve bits       
   jmp     .DONE 

  .ODD_CLUSTER:        
   shr     dx, 0x0004                 ; take high twelve bits     

.DONE:          
    mov     WORD [cluster], dx         ; store new cluster       
    cmp     dx, 0x0FF0                 ; test for end of file           
Bo Persson
  • 90,663
  • 31
  • 146
  • 203
  • You might want to read the comment in your own code after `JNZ .ODD_CLUSTER` that says it all. – tofro Feb 09 '17 at 19:57

1 Answers1

1

The cluster pointers are 12 bits each. A byte is 8 bits, so the byte offset of a cluster pointer within the FAT table is cluster * 12/8 == cluster * 1.5.
To multiply an integer by 1.5 you can do i + (i >> 1), which is what this code does.

Michael
  • 57,169
  • 9
  • 80
  • 125