flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Macroinstructions > Array of Structs, with initialized members

Author
Thread Post new topic Reply to topic
thrawn235



Joined: 26 Oct 2017
Posts: 2
Array of Structs, with initialized members
Hello,
I've read the online docs and searched the forum for a bit but i wasn't able to find an answer.

I wan to create a array of structs that are initialized like that:


Code:

STRUC cell
{
    .value db 16      ;values are important!
    .value2 db 25
}
SEGMENT memory
cells dup 20 (cell)




I've tried quite a few things, but nothing seems to work. In another thread i found the idea to reserve 20 * cell.size bytes. but that would either have random data in it, or it would be relatively bothersome for more complex classes with 20+ members (like cells 20 dup (16,25,...).

maybe i'm just not seeing the obvious...
Post 26 Oct 2017, 17:38
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15301
Location: Bigweld Industries
You will need a bit more programming to do what you need. One thing to realise is that struc is really a macro that requires a leading label. So it is not possible to use it in the operands of anything.

A couple of methods would be to use a repeat loop, or a rept loop depending upon your requirements.

Code:
struc cell {
 ;... definition goes here
}

cells cell
  rept 19 {
    forward
    local dummy_label
    dummy_label cell
  }

Post 26 Oct 2017, 17:57
View user's profile Send private message Visit poster's website Reply with quote
thrawn235



Joined: 26 Oct 2017
Posts: 2
That seems to work. thanks so far.

But, i have tried to include the array in another struct, and that failed. I think its because of the nested {} of rept and the struc

I've tried "repeat" and "end repeat", but that doesn't seem to process the local label correctly.

Is there something else i can try ?
Post 26 Oct 2017, 22:03
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15301
Location: Bigweld Industries
To nest macros you use the backslash.

Code:
struc {
 ;...
  rept \{
    ;...
  \}
}

Post 26 Oct 2017, 22:27
View user's profile Send private message Visit poster's website Reply with quote
_shura



Joined: 22 May 2015
Posts: 60

Code:

struc cell n1
  repeat ncount0
    .item#count.value db 16
    .item#count.value2 db 25
  end repeat
end struc



in fasmg, something similar should work in fasm1
Post 27 Oct 2017, 08:09
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


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.