flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > How to duplicate a structure?

Author
Thread Post new topic Reply to topic
Byte



Joined: 21 Mar 2026
Posts: 31
Byte 15 Jul 2026, 15:07
I have the structure:
Code:
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
  }
    

I need duplicate this. In MASM i use:
Code:
_trap   14 DUP (<_Dummy_exc>)    

How to write it in FASM? All my attempts give an error:
Code:
error: extra characters on line.    
Post 15 Jul 2026, 15:07
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1228
Location: Russia
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]    
Post 15 Jul 2026, 16:10
View user's profile Send private message Reply with quote
Byte



Joined: 21 Mar 2026
Posts: 31
Byte 15 Jul 2026, 16:45
macomics wrote:
Code:
use16

struc StrucArray count, offset, proto& { .: rept count i:offset \{ .\#i proto \} }

TestLabel StrucArray 10, 0, _trap ?, ?, ?, ?, ?
    

How complicated everything is... Thank you! It helped.
Post 15 Jul 2026, 16:45
View user's profile Send private message Visit poster's website Reply with quote
Core i7



Joined: 14 Nov 2024
Posts: 172
Location: Socket on motherboard
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    
Post 16 Jul 2026, 02:48
View user's profile Send private message Reply with quote
Byte



Joined: 21 Mar 2026
Posts: 31
Byte 16 Jul 2026, 07:40
Core i7 wrote:
Read about the rept (repetition) directive in the fasm help.
For example, ...

Thank you. I'll take that into consideration.
Post 16 Jul 2026, 07:40
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1228
Location: Russia
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.
Post 16 Jul 2026, 13:51
View user's profile Send private message Reply with quote
Byte



Joined: 21 Mar 2026
Posts: 31
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.
Post 17 Jul 2026, 08:14
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-2026, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.