flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > How to duplicate a structure? |
| Author |
|
|
macomics 15 Jul 2026, 16:10
Code: use16 struc _trap toffs_l, tsel, tresrv, tattr, toffs_h { .toffs_l DW toffs_l ; offset .tsel DW tsel ; selector .tresrv DB tresrv ; .tattr DB tattr ; attributes .toffs_h DW toffs_h ; offset } struc StrucArray count, offset, proto& { .: rept count i:offset \{ .\#i proto \} } TestLabel StrucArray 10, 0, _trap ?, ?, ?, ?, ? ; equivalent to ; TestLabel0 _trap ?, ?, ?, ?, ? ; TestLabel1 _trap ?, ?, ?, ?, ? ; TestLabel2 _trap ?, ?, ?, ?, ? ; TestLabel3 _trap ?, ?, ?, ?, ? ; TestLabel4 _trap ?, ?, ?, ?, ? ; TestLabel5 _trap ?, ?, ?, ?, ? ; TestLabel6 _trap ?, ?, ?, ?, ? ; TestLabel7 _trap ?, ?, ?, ?, ? ; TestLabel8 _trap ?, ?, ?, ?, ? ; TestLabel9 _trap ?, ?, ?, ?, ? MOV AX, [TestLabel6.toffs_l] |
|||
|
|
Byte 15 Jul 2026, 16:45
macomics wrote:
How complicated everything is... Thank you! It helped. |
|||
|
|
Core i7 16 Jul 2026, 02:48
Read about the rept (repetition) directive in the fasm help.
For example, this construct will insert four structures into the code, with a sequence number appended to their names to make it easier to access each structure later: Code: struct MyStruct_0 .a db 0 .b db 0 ends rept 4 n:0 { MyStruct_#0 } ;<------------ ;----------- Result ------ MyStruct_0 MyStruct_1 MyStruct_2 MyStruct_3 |
|||
|
|
Byte 16 Jul 2026, 07:40
Core i7 wrote: Read about the rept (repetition) directive in the fasm help. Thank you. I'll take that into consideration. |
|||
|
|
macomics 16 Jul 2026, 13:51
But if you need a structure with multiple values, then you need to change it like this.
Code: _Dummy_exc fix ?, ?, ?, ?, ? struc _trap [toffs_l, tsel, tresrv, tattr, toffs_h] { common .: label .toffs_l word at . label .tsel word at .+2 ; size of .toffs_l label .tresrv byte at .+4 ; size of .toffs_l + size of .tsel label .tattr byte at .+5 ; ... label .toffs_h word at .+6 .sizeof = 8 forward DW toffs_l ; offset DW tsel ; selector DB tresrv ; DB tattr ; attributes DW toffs_h ; offset } TrapLabel _trap \ _Dummy_exc, _Dummy_exc,\ _Dummy_exc, _Dummy_exc,\ _Dummy_exc, _Dummy_exc,\ _Dummy_exc, _Dummy_exc,\ _Dummy_exc, _Dummy_exc,\ _Dummy_exc, _Dummy_exc,\ _Dummy_exc, _Dummy_exc ; 14 times ; equivalent to ; TrapLabel: ; .toffs_l DW ? ; .tsel DW ? ; .tresrv DB ? ; .tattr DB ? ; .toffs_h DW ? ; sizeof = 8 ; DW ?, ? ; DB ?, ? ; DW ?, ?, ? ; DB ?, ? ; DW ?, ?, ? ; DB ?, ? ; DW ?, ?, ? ; DB ?, ? ; DW ?, ?, ? ; DB ?, ? ; DW ?, ?, ? ; DB ?, ? ; DW ?, ?, ? ; DB ?, ? ; DW ?, ?, ? ; DB ?, ? ; DW ?, ?, ? ; DB ?, ? ; DW ?, ?, ? ; DB ?, ? ; DW ?, ?, ? ; DB ?, ? ; DW ?, ?, ? ; DB ?, ? ; DW ?, ?, ? ; DB ?, ? ; DW ? MOV AX, [TrapLabel.tsel] MOV BX, [TrapLabel.toffs_h + TrapLabel.sizeof * 4] In this case, it will be possible to set the required number of values to the structure. |
|||
|
|
Byte 17 Jul 2026, 08:14
macomics wrote: But if you need a structure with multiple values, then you need to change it like this. Thanks! I'll try to figure this out. |
|||
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2026, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.