flat assembler
Message board for the users of flat assembler.

Index > Main > Structures?

Author
Thread Post new topic Reply to topic
Chewy509



Joined: 19 Jun 2003
Posts: 297
Location: Bris-vegas, Australia
Chewy509 13 Oct 2004, 06:44
Can someone please hit me with a clue stick! Crying or Very sad

The following code when assembled will generate a "undefined symbol" error, on "movzx eax, word [esi+FATXX.RootEntry]".

Code:
;For the moment we will only support FAT12 and FAT16 loading.
virtual at 0
struc FATXX
{
      .jmp rb 3
   .oemname rb 8
       .BytesPerSec rw 1
   .SecPerClus rb 1
    .ReservedSec rw 1
   .NumFATs rb 1
       .RootEntry rw 1
     .TotalSec16 rw 1
    .Media rb 1
 .FATSz16 rw 1
       .SecPerTrack rw 1
   .NumHeads rw 1
      .HiddenSec rd 1
     .TotalSec32 rd 1
    .Drv_Num rb 1
       .Res1 rb 1
  .BootSig rb 1
       .VolID rd 1
 .VolLabel rb 11
     .FileSys rb 8
}
end virtual

;macro struct name  
;{ virtual at 0  
;   name name  
;   sizeof.#name = $ - name  
;   name equ sizeof.#name  
;   end virtual } 
;
;struct FATXX

;Valid Filesystems
Unknown equ -1
FAT12 equ 01
FAT16 equ 02

;expects esi = disk buffer.
FS_Check_Valid_FS:

;See we only handle FAT12 or FAT16 filesystems, this is going to be pretty easy.
;The correct way of determining the type of FAT, is by using the total cluster count.
;

 movzx eax, word [esi+FATXX.RootEntry]
       movzx ebx, word [esi+FATXX.BytesPerSec]
     shl eax, 5              ;mul RootEntry by 32
        mov ecx, ebx
        dec ebx         ;BytesPerSec - 1
    add eax, ebx    ;add them together
  xor edx, edx
        div ecx         ;divide eax / ecx
   ;eax = RootDirSectors
       push eax                ;save it
    cmp word [esi+FATXX.FATSz16], 0
     jne .not_supported
  movzx eax, word [esi+FATXX.FATSz16]
 movzx edx, byte [esi+FATXX.NumFATs]
 mul edx         ;eax * edx = edx:eax
    movzx edx, word [esi+FATXX.TotalSec16]
      movzx ebx, word [esi+FATXX.ReservedSec]
     sub edx, eax
        sub edx, ebx
        pop eax
     sub edx, eax    ;edx = Count of Clusters!
   
    cmp edx, 4085
       ja .FAT16
   ;if here we are FAT12
       mov dword [FS_Type], FAT12
  clc
 ret
 
.FAT16:
     cmp edx, 65525
      ja .not_supported
   mov dword [FS_Type], FAT16
  clc
 ret
 
.not_supported:
     mov dword [FS_Type], Unknown
        stc
 ret
 
;Data
align 4
FS_Type dd 0    

However if I uncomment the "struct" macro and the following line which runs the macro, the code assembles fine.

Since I defined the structure, I would have thought I would have been able to use it? Or am I missing something?
Post 13 Oct 2004, 06:44
View user's profile Send private message Visit poster's website Reply with quote
mike.dld



Joined: 03 Oct 2003
Posts: 235
Location: Belarus, Minsk
mike.dld 13 Oct 2004, 07:55
Code:
struc FATXX
{
        .jmp rb 3
        .oemname rb 8
        .BytesPerSec rw 1
        .SecPerClus rb 1
        .ReservedSec rw 1
        .NumFATs rb 1
        .RootEntry rw 1
        .TotalSec16 rw 1
        .Media rb 1
        .FATSz16 rw 1
        .SecPerTrack rw 1
        .NumHeads rw 1
        .HiddenSec rd 1
        .TotalSec32 rd 1
        .Drv_Num rb 1
        .Res1 rb 1
        .BootSig rb 1
        .VolID rd 1
        .VolLabel rb 11
        .FileSys rb 8
}
virtual at 0
  FATXX FATXX
end virtual    
Post 13 Oct 2004, 07:55
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Chewy509



Joined: 19 Jun 2003
Posts: 297
Location: Bris-vegas, Australia
Chewy509 13 Oct 2004, 22:31
Alrighty, even though I have defined a structure, I can't use it until I define at least one instance of it...

Makes sense. Cool

PS. Thanks for the answer.
Post 13 Oct 2004, 22:31
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.