flat assembler
Message board for the users of flat assembler.

Index > Main > nested struc

Author
Thread Post new topic Reply to topic
bubach



Joined: 17 Sep 2004
Posts: 340
Location: Trollhättan, Sweden
bubach
hi, i got a quick question about nested struc, i've successfully used it in the past such as:

Code:
     struc some_name
     {
          .normal_var          dd  0
          .another_struct      the_struct
     }    


but when I try to have it multiple times, using syntax:

Code:
          .another_struct: times 32   the_struct
    


i get "illegal instruction" error. I know using "times 32" for example works on normal variables, so why wouldn't it on a nested structure? any suggestions, or am i doing it wrong?

_________________
BOS homepage: http://bos.asmhackers.net/
Post 11 May 2012, 14:00
View user's profile Send private message Reply with quote
bubach



Joined: 17 Sep 2004
Posts: 340
Location: Trollhättan, Sweden
bubach
if the struct that i need to replicate inside another is 50bytes I could do like this to get the right size reserved:

Code:
   .another_struct: times 32*50   db 0    


or i could manually replicate it (number of wanted times) 32 times like this:
Code:
.another_struct1   the_struct
.another_struct2   the_struct
.another_struct3   the_struct
.another_struct4   the_struct
.another_struct5   the_struct
;....    

which isn't exactly optimal for my needs. i think that i kind of get why it wouldn't work to do "times 32" on it... i guess it has to do with the naming? it can't have the same "parent.child" names 32 times? erhm.. damnit.. Razz


EDIT:
I think i have found a better way now, if anybody is as stupid as me in the future:
Code:
.another_struct: times 32*sizeof.the_struct   db 0    

seems to be working and i won't have to keep track of the struct size manually, which is a big step forward! i guess this will have to do. Smile addressing individual the_struct.values from within the parent structure might get complicated, but... i'll figure it out somehow Razz
Post 11 May 2012, 20:17
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
You can use "struct" following way:
Code:
.another_struct the_struct
                rb sizeof.the_struct * (needed_count-1)
    
Post 11 May 2012, 20:22
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
bubach



Joined: 17 Sep 2004
Posts: 340
Location: Trollhättan, Sweden
bubach
hi, the diffrence to my solution would be that i could use addressing like

"some_name.another_struct.value" for at least the first entry - right? but other than that, is there any other advantages? i would still have to do some strange stuff when i need to access the second or third "another_struct" members?
Post 11 May 2012, 20:31
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
If you want to use the names for all structure, you have to name them actually:
Code:
Name1 the_struct
Name2 the_struct
; ect.
    


On the other hand, usually you will use some pointer to point to the items of the array. In this case "struct" is your way:
Code:
; copy field from one structure to the next
           mov eax, [esi+the_struct.field]
           add esi, sizeof.the_struct
           mov [esi+the_struct.field], eax
    
Post 11 May 2012, 20:42
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
Are you trying to have linked lists or just fixed size structs?


Last edited by typedef on 11 May 2012, 21:09; edited 1 time in total
Post 11 May 2012, 21:08
View user's profile Send private message Reply with quote
bubach



Joined: 17 Sep 2004
Posts: 340
Location: Trollhättan, Sweden
bubach
yeah, that's a bit more complicated since i might have to do sizeof.the_struct * number before adding too, but hey. better then nothing - i will be able to move forward now. at first i had problems wrapping my head around it Razz BTW, thanks for your input!
Post 11 May 2012, 21:08
View user's profile Send private message Reply with quote
bubach



Joined: 17 Sep 2004
Posts: 340
Location: Trollhättan, Sweden
bubach
typedef wrote:
These are called linked lists.

well, i'm not trying to do a linked list. it's just a big struct will all the data regarding a disk for my fat12 code, and i want to include buffer for 32 file handles (which is defined as another struct) inside the first.

linked list contain pointers to next/prev, this will will be accessed something like "disk.filehandles + sizeof.filehandle*number + filehandle.cluster"...
I know that i can't use a syntax like that, but just as an example.

_________________
BOS homepage: http://bos.asmhackers.net/
Post 11 May 2012, 21:12
View user's profile Send private message Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 518
Location: Munich
shutdownall
Why not code like this ?

Code:
rept 100h n:0 { label#n db 10h dup(#n) }

        dw      label1
        mov     eax,label2
        add     eax,label3   
    


This repeats an instruction, defines numbered labels (with variable n) and works fine. Should work with structures same way I think. Wink

The first line (one line only) creates 256 data strings 10 bytes long with values from 00 to ff and 256 labels automatically.

See section 2.3.5 in the FASM manual.
Post 11 May 2012, 22:34
View user's profile Send private message Send e-mail Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 518
Location: Munich
shutdownall
And this works fine too. Very Happy

Code:
xor eax,eax
rept 100h n:0  {  add     eax,dword [label#n]   }
    


I think you could do some really pervert things with rept. Razz
Post 11 May 2012, 22:47
View user's profile Send private message Send e-mail Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
shutdownall wrote:
I think you could do some really pervert things with rept. Razz


Yeah, like what ? Rape the stack ? Very Happy Or touch it inappropriately
Post 11 May 2012, 22:52
View user's profile Send private message Reply with quote
bubach



Joined: 17 Sep 2004
Posts: 340
Location: Trollhättan, Sweden
bubach
lol. yes that does indeed look perverted. but for dynamic access to a label it doesn't really help to have unique names, i just didn't think it through very well. i will have to calculate offset into the struct at run time.
Post 11 May 2012, 23:00
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4237
Location: 2018
edfed
it would be awsome to access nested structs this way

Code:
mov eax,[meta.sub+3.subsub.part]
    

here, the +3 would be adding the sizeof.sub.

it introduce the need of the directive res to reserve a structure.

Code:
rb 32 ;reserve 32 bytes
res byte 32; reserve 32 bytes too
res mystruct 432 ;reserve 432 times mystruct.
    


this kind of functionnality is really needed when dealing with lists of structures like we have in c or c++ librairies.
Post 21 Dec 2012, 14:30
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-2020, Tomasz Grysztar.

Powered by rwasa.