flat assembler
Message board for the users of flat assembler.

Index > Main > struct/virtual usage

Author
Thread Post new topic Reply to topic
bubach



Joined: 17 Sep 2004
Posts: 341
Location: Trollhättan, Sweden
bubach 03 Feb 2012, 18:04
Hi, I'm having trouble getting some struct and virtual usage working, and after checking the manual I'm still not sure. Actually I'm not even sure if I should use a combination of both, as I am right now, or just one of them and if so which one?

The usage is in my FAT12 driver where I have a large struct called "disk", it includes some values and also another struct for the bootsector, so I can easily access those values.

It looks like this:

Code:
      struc disk
      {
          .disk_number         db  0                  ; which disk?
          .root_dir            dw  0                  ; position of rootdir
          .fat_1               dd  0                  ; position of fat1
          .fat_2               dd  0                  ; position of fat2
          .data_area           dw  0                  ; position of dataarea
          .disk_size           dd  0
          .free_space          dd  0
          .boot                bootsector  
          ; ..... some other values
      }
      struc bootsector                                ; 512 bytes
      {
          .jumper              db  0,0,0
          .oem                 db  0,0,0,0,0,0,0,0
          .sectorsize          dw  0
          .sect_per_clust      db  0  
          ;.... more values here
      }

      virtual at 0
          bootsector bootsector
          sizeof.bootsector = $
      end virtual

      virtual at 0
          disk disk 
          sizeof.disk = $     
      end virtual     


It worked fine when I used a "hardcoded" copy of it with command like:

Code:
fd0 disk            ; define fd0 data.. 
;...........
     ;-----------------------------;
     ;   calculate root location   ;
     ;-----------------------------;
          xor     eax, eax
          mov     al, byte [fd0.boot.fats_per_drive]
          mul     word [fd0.boot.sectors_per_fat]
          add     ax, word [fd0.boot.reserved_sect]
          mov     [fd0.root_dir], ax        


And so on, but now I have changed "fd0" to a "dsk dd 0" where I save location of dynamically allocated memory for the structure. I request the amount of memory I want with "sizeof.disk" and save the allocated memory position to "drv".

Now I load the bootsector into the structure with "mov edi, drv+disk.boot" which seems to assembly fine.

But this however refuses to assemble: "mov ax, word [drv+disk.boot.sectorssize]"

I simply do not understand what's wrong, I've tried with dot (.) instead of + and many rearrangements of the struct/virtual code but it refuses to assemble... The manual doesn't help me, and I've been taking a 3+ year break from asm-programming so I'm a bit rusty at this.

Any help or tips on how to better implement what I'm trying to accomplish would be greatly appreciated!

_________________
BOS homepage: http://bos.asmhackers.net/
Post 03 Feb 2012, 18:04
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 03 Feb 2012, 18:51
So, you must first load the pointer from dsk into some register (it is assembly, not HLL).
Code:
mov  si, [dsk]
mov  ax, [si+disk.boot.sectorssize]
    


Note that as long as .sectorsize is defined with "dw" you don't need to use "word" prefix.
Post 03 Feb 2012, 18:51
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
bubach



Joined: 17 Sep 2004
Posts: 341
Location: Trollhättan, Sweden
bubach 03 Feb 2012, 19:11
Doh, ok thanks! Is there any better way of doing it, to avoid always using a register? "[fd0.boot.fats_per_drive]" just looks so much better.. Sad
Anyway, that explains why it worked to set address with variable, but not get content at the address - so thanks again! Smile
Post 03 Feb 2012, 19:11
View user's profile Send private message Reply with quote
bubach



Joined: 17 Sep 2004
Posts: 341
Location: Trollhättan, Sweden
bubach 03 Feb 2012, 19:44
Ok, so I removed the "drv" variable to use esi as base instead, but now i can't do "mov edi, esi+disk.boot"... eh, so... should i mov esi to edi first, then add disk.boot? Or wth? Forgot how annoying assembly can be Wink

Seems to have worked, assembles at least, but the FAT12 and VFS driver is so full of dependencies towards each other that I can't even test it without being finished with almost all code... That should be a fun debug session. Rolling Eyes
Post 03 Feb 2012, 19:44
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 03 Feb 2012, 20:13
Your problems have nothing to do with "struc" and "virtual" directives.
You should read some assembly tutorial first. At least the chapter about addressing.
Read Main FAQ - there are useful links to reading materials.
Post 03 Feb 2012, 20:13
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
bubach



Joined: 17 Sep 2004
Posts: 341
Location: Trollhättan, Sweden
bubach 03 Feb 2012, 21:36
It's not that bad, I'll figure it out Wink
Post 03 Feb 2012, 21:36
View user's profile Send private message 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.