GetFATEntry details: I have not made it clear in the book. I want to explain it to someone else. Otherwise, I cannot understand it.

Source: Internet
Author: User

Function GetFATEntry. The parameter is stored in the ax register, indicating a cluster number. The output result is the FATENTRY of the cluster number in the FAT table. Its content is still a cluster number, indicating the cluster number of the next part of the file. The difference between the "cluster number" and "cluster" should be carefully understood here, otherwise it is easy to get lost when looking at the code. "Cluster" indicates a set of one or more sectors. In FAT12, a cluster is a slice, 512 bytes. Cluster number, starting from the data area of the floppy disk and starting from 2 (0, 1 is used by the system), is essentially a FAT table-based index.

GetFATEntry:
Push es
Push bx

The functions use es and bx, so they need to be saved and saved on the stack.

Es: bx will be used by the ReadSector function, which is required by int 13 H and points to a buffer zone to store data read from a floppy disk.
Push ax
Mov ax, BaseOfLoader
Sub ax, 0100 h

; The above space is 4 kb after BaseOfLoader. Why is it 0100 h (256) and 4 K?

Because this is the base address of the segment, the 0100h must be multiplied by the last 16.
Mov es, ax
Pop ax
MoV byte [bodd], 0
MoV BX, 3
Mul BX
MoV BX, 2
Div BX
CMP dx, 0
JZ label_even
MoV byte [bodd], 1

The above section is the difficulty of the entire function. The fatentry offset of the user's calculated cluster number in the fat table relative to the first fat address.

From the book, we can know that every fatentry in fat12 is 12 characters. So it is as follows:

7654 | 3210 (byte1) 7654 | 3210 (byte2) 7654 | 3210 (byte3)

The low 4 bits of byte1 and byte2 indicate an entry. According to big-Endian, the entry content is: 3210 (byte2) 76543210 (byte1)

The four-digit high of byte3 and byte2 represents an entry. According to big-Endian, the entry content is: 76543210 (byte3) 7654 (byte2)

Therefore, there is a parity problem, in bytes. For example, the entry0 offset is 0, the entry1 offset is 1, and the entry2 offset is 3.

Add the value in int ["cluster number" * 1.5. This is why the above calculation is based on Multiplication 3 and Division 2.

According to Div instructions, the commercial warranty is in ax, and the remainder is in dx. In this case, ax is the offset of the fatentry in the fat value with the byte boundary.

Bytes --------------------------------------------------------------------------------------------
Label_even:
XOR dx, DX
MoV BX, [bpb_bytspersec]
Div BX

; DX: ax/bpb_bytspersec, so ax is now the number of sectors, dx is the offset in the last sector.
Push DX
MoV BX, 0

ES: BX points to the first address of the target space, which is the 4kb space that the function sets after baseofloader.
Add ax, sectornooffat1

; SectorNoOfFAT1 is the relative fan area number of FAT1, physically 0-side, 0-way, and 1-sector. FAT12 has two identical FAT tables: FAT1 and fat2.
Mov cl, 2

Cl always saves the parameters of the ReadSector function, indicating that two slices must be read consecutively. Another parameter, ax, is provided earlier.
Call ReadSector
Pop dx
Add bx, dx

Before adding, bx is the first address of the target space. The content of this address is the sector that contains the FATEntry. Bx + dx, The FATEntry is located.
Mov ax, [es: bx]

In ax, the content of the space pointed to by es: bx.
Cmp byte [bOdd], 1

; Is it an odd number of clusters or an even number of clusters ??
Jnz LABEL_EVEN_2
Shr ax, 4

; 7654 | 3210 (byte1) 7654 | 3210 (byte2) 7654 | 3210 (byte3)

According to the example above, the odd number of clusters, 1, offset is 1, so when reading the data in ax, because ax is a 16-bit, according to Big-Endian, the content of ax is 7654 | 3210 (byte3) | 7654 | 3210 (byte2), so it can be shifted to four places on the right.

Even number of clusters, 0, offset is 0. After reading ax, the content of ax is 7654 | 3210 (byte2) 7654 | 3210 (byte1). We only need 12 lower digits,

So and ax, 0 FFFh.

Bytes --------------------------------------------------------------------------------------------
LABEL_EVEN_2:
And ax, 0 FFFh

LABEL_GET_FAT_ENRY_ OK:

Pop bx
Pop es
Ret

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.