flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > How to create an "array" of structures? |
| Author |
|
|
revolution 12 Aug 2026, 02:10
The code doesn't match the description. There is an extra field at the beginning "dd last_de".
Is "dd XT_##nameId" intended to be a link to the next structure? It looks like a doubly linked list, is that the intention? BTW: struc might be a better choice. Code: last_de equ 0 struc dictEntry name, len, flags { dict_#.: dd last_de dd XT_#. db flags, len, name times 31 - ($ - dict_#.) db 0 db 0 last_de equ dict_#. XT_#.: } name1 dictEntry 'test',1,2 name2 dictEntry '123456789012345678901',1,2 ; maximum length name3 dictEntry '1234567890123456789012',1,2 ; too long Last edited by revolution on 12 Aug 2026, 02:12; edited 1 time in total |
|||
|
|
macomics 12 Aug 2026, 02:11
Code: xt rd 1 flags rb 1 len rb 1 name rb 26 ; Macro to create a dictionary entry last_de equ 0 struc dictEntry name, len, flags { local next dict_#.: dd last_de .next dd next .flags db flags .len db len .name db name times 27 - ($ - .name) db 0 next: last_de equ dict_#nameId } virtual at ebx NextNameId dictEntry ?, ?, ? end virtual NewNameId dictEntry "abracadabra", 11, 0 TestData dd 1234, 5678 SomeNameId dictEntry "abracadabra", 11, 0 lea eax, [dict_NewNameId.name] movzx ecx, [dict_NewNameId.len] mov dl, [dict_NewNameId.flags] mov ebp, [dict_NewNameId.next] ; TestData mov ebx, [dict_NewNameId] ; SomeNameId mov edi, [dict_NextNameId] lea esi, [dict_NextNameId.name] mov dh, [dict_NextNameId.flags] mov ch, [dict_NextNameId.len] revolution wrote: Is "dd XT_##nameId" intended to be a link to the next structure? It looks like a doubly linked list, is that the intention? "dd XT_##nameId" just points to the end of the structure. If they go in a row, then it duplicates the first value. What if there are gaps between these structures? Last edited by macomics on 12 Aug 2026, 02:33; edited 2 times in total |
|||
|
|
chriscurl 12 Aug 2026, 02:27
revolution wrote: The code doesn't match the description. There is an extra field at the beginning "dd last_de". yes, it is currently a linked list of variable-length dictionary items for a Forth dictionary. The XT_# is the pointer to the code, currently right after the (null-terminated) name. I want to remove the link (the 'last_de') and make each entry the same size, 32 bytes. This will also now be placed in a data area with only the entries, and the XTs will point to addresses in the code area. That will make it exceedingly easy to navigate through the dictionary. It looks like the 'times 31-($-dict_#)' is the trick I need, thanks! |
|||
|
|
macomics 12 Aug 2026, 02:33
chriscurl wrote: I want to remove the link (the 'last_de') and make each entry the same size, 32 bytes. Then the pointer to the next one can be found by simply adding the length of the structure to the base pointer. Just like the previous one. ADD: Code: struc dictEntrySameLen [name, len, flags] { .flags db flags .len db len .name db name times 30 - ($ - .name) db 0 } struc dictEntryVarLen [name, len, flags] { .: local .next .next dd next .flags db flags .len db len .name db name, 0 next: } dictArraySameLen dictEntrySameLen \ "abracadabra", 11, 0,\ "banana", 6, 0 dictArrayVariableLen dictEntryVarLen \ "abracadabra", 11, 0,\ "banana", 6, 0 lea esi, [dictArraySameLen.name] ; "abracadabra" lea ebx, [dictArraySameLen.name + 32 * 1] ; "banana" lea esi, [dictArrayVariableLen] ; "abracadabra" mov ebx, [dictArrayVariableLen.next] ; "banana" |
|||
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2026, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.