News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Using Structures in Assembly

Started by riversr54, November 13, 2019, 08:29:43 AM

Previous topic - Next topic

riversr54

I'm trying to use structures within structures and am having some problems with initialization. As you can see below, I've created two structs. The first one (COOR) is a simple coordinate structure that contains two bytes, row and col. The second structure one (CoorGrp) is intended to contain three of the COOR structures. I am able to initialize COOR structures and use them successfully but I can't seem to find the right syntax to initialize one of the CoorGrp structures. I created three COOR variables, testa, testb and testb and then tried to add them to the CoorGrp with no luck. My ultimate goal is to create an array of the CoorGrp structures but that seems impossible given the problem that I am having with creating a single CoorGrp variable. The ERROR that if get with this code is: "Error A2181: initializer must be a string or single item" on both the lines where I try to initialize a CoorGrp variable.

I would really appreciate any help/suggestions.



;x/y coordinate structure
COOR STRUCT
row BYTE ?
col BYTE ?
COOR ENDS
CoorSize EQU 2

;group of three COORs structure
CoorGrp STRUCT
CoorA COOR <>
CoorB COOR <>
CoorC COOR <>
CoorGrp ENDS

;declare three COOR variables
testa COOR <65,65>
testb COOR <66,66>
testc COOR <67,67>

;declare a single CoorGrp variable
Grp1 CoorGrp <testa, testb, testc>

;declare an array of 2 CoorGrp elements
CoorGroups CoorGrp <testa, testb, testc>, <testa, testb, testc>



riversr54

I tried add a PTR in the CoorGrp initialization to specify exactly what the variable is but that didn't seem to make any difference. The second line below does in fact assembly but that is not what I really want to do.


Grp1 CoorGrp <COOR PTR testa, COOR PTR testb, COOR PTR testc>
Grp2 CoorGrp <<1,1>,<2,2>,<3,3>>


fearless

testa TEXTEQU <65,65>
testb TEXTEQU <66,66>
testc TEXTEQU <67,67>

;declare a single COORGRP variable
Grp1 COORGRP <<testa>, <testb>, <testc>>

;declare a single COORGRP variable
Grp2 \
COOR <65,65>
COOR <66,66>
COOR <67,67>

CoorGroups COORGRP 2 dup (<>) ; declare an empty array of 2 COORGRP elements

riversr54

Thanks for the feedback but I still have one requirement that doesn't seem to work.

I need to be able to create the COORGRP items and then add them all to an array. Something like this:


;declare a single COORGRP variable
Grp1 COORGRP <<testa>, <testb>, <testc>>

;declare a single COORGRP variable
Grp2 \
COOR <65,65>
COOR <66,66>
COOR <67,67>

;now add the two COORGRP items to an array
CoorGroups COORGRP <Grp1, Grp2>

;this syntax gets the A2181 Error that I mentioned


HSE

Equations in Assembly: SmplMath

aw27

CoorGroups COORGRP 1 dup (<<1,2>, <3,4>, <5,6>>,<<7,8>, <9,10>,<11,12>>, <<13,14>, <15,16>, <17,18,>>, <<19,20>, <21,22>, <23,24>>)

riversr54

HSE:
I do have an array in my code, but that is how I would like it to work, that syntax doesn't assemble.

AW:
Thanks, that is getting closer to what I want to do. My ultimate goal is to define several COOR items in an array (positions) of COORs and then use those to populate the array of COORGRPs (CoorGroups) so that I don't have to redefine all the COOR items that already exist in the positions array. Something like this:


COOR STRUCT
row BYTE ?
col BYTE ?
COOR ENDS

;group of three COORs structure
CoorGrp STRUCT
CoorA COOR <>
CoorB COOR <>
CoorC COOR <>
CoorGrp ENDS

  ;;this works just fine
positions COOR <10,11>,<10,15>,<10,19>,\
       <12,11>,<12,15>,<12,19>,\
       <14,11>,<14,15>,<14,19>

   ;;Now I want to create multiple COORGRP items in another array
   ;; this does NOT work,  error A2181: initializer must be a string or single item
   ;;Maybe this is just not possible
         coorGroups COORGRP <positions[0], positions[1], positions[2]>, <positions[3], positions[4], positions[5]>

nidud

#7
deleted