.struct/.endstruct

.struct name

These directives can be used to define a structure - a consecutive group of variables with a fixed format. Here's an example:

; Define it

.struct Point2D
    .var db, X
    .var db, Y
.endstruct

; Use it

.var Point2D, Me

    ld a,10
    ld (Me.X),a
    
    ld a,32
    ld (Me.Y),a
    
    ld hl,10+32*256
    ld (Me),hl

The directive works (in this case) by creating three labels and a new module. One label is Me, pointing to the start of the variable. The module created is added as a child to the current one, with the name Me and has two child labels, X (with a value of Me+0) and Y (with a value of Me+1).

You may only use .var and conditional directives inside a structure's definition. You can nest structures - for example:

.struct Point3D
    .var Point2D, P
    .var db,      Z
.endstruct

.var Point3D, You

    ld a,(You.P.X)

You may not, however, nest a structure onto itself. You might feel tempted, for example, to do the following:

.struct TreeNode
    .var word, Value
    .var TreeNode, RightBranch
    .var TreeNode, LeftBranch
.endstruct

The problem is that that particular structure has an infinite size! If you wish to implement that sort of data structure, you'd use pointers to the branch nodes.