flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
bubach 11 May 2012, 20:17
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.. ![]() 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. ![]() ![]() |
|||
![]() |
|
JohnFound 11 May 2012, 20:22
You can use "struct" following way:
Code: .another_struct the_struct rb sizeof.the_struct * (needed_count-1) |
|||
![]() |
|
bubach 11 May 2012, 20:31
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? |
|||
![]() |
|
JohnFound 11 May 2012, 20:42
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 |
|||
![]() |
|
typedef 11 May 2012, 21:08
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 |
|||
![]() |
|
bubach 11 May 2012, 21:08
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
![]() |
|||
![]() |
|
bubach 11 May 2012, 21:12
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. |
|||
![]() |
|
shutdownall 11 May 2012, 22:34
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. ![]() 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. |
|||
![]() |
|
shutdownall 11 May 2012, 22:47
And this works fine too.
![]() Code: xor eax,eax rept 100h n:0 { add eax,dword [label#n] } I think you could do some really pervert things with rept. ![]() |
|||
![]() |
|
typedef 11 May 2012, 22:52
shutdownall wrote: I think you could do some really pervert things with rept. Yeah, like what ? Rape the stack ? ![]() |
|||
![]() |
|
bubach 11 May 2012, 23:00
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.
|
|||
![]() |
|
edfed 21 Dec 2012, 14:30
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. |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.