Using the STRUC, UNION, and FIELD directives you can define data items which are grouped together. Such a group is called a structure and can be thought of in the same way as a structure or union in C. Structured types are bracketed between STRUC and ENDSTRUC and should contain only FIELD directives; similarly, unions are bracketed between UNION and ENDUNION and should only contain FIELD directives.

##### Example

We could declare a structure type called Amount which has two members, Pounds and Pence like this:

    Amount STRUC
    Pounds FIELD   LONG
    Pence  FIELD   BYTE
           ENDSTRUC

The field Pounds is declared to be of type LONG and Pennies is of type BYTE (we can count lots of Pounds, and a small amount of loose change).

In structures, fields are allocated one after another, increasing the size of the structure for each field added. For a union, all fields are overlaid, and the size of the union is the size of the largest field within the union.

##### Example

For a 32-bit big-endian machine, we could overlay four bytes over a 32-bit word like this::

    Word    UNION
    asWord  FIELD	WORD
    asBytes FIELD	BYTE[4]
            ENDUNION

The most useful thing about user-defined structures is that they act like any builtin data type, so you can allocate space for variables of structure type:

    Balance DV     Amount

Here we've declared enough storage for the variable Balance to hold an Amount, and the assembler also knows that Balance is of type Amount. Because the assembler knows what type Balance is and how big an Amount is, and because the assembler tracks type information, you can specify which members of Balance to operate on. Assuming that the instruction LDB loads a byte value and LDW loads a word value, then

            LDB    Balance.Pence

will load a single byte which is the Pence part of Balance. We could equally well have written:

            LDW    Balance.Pounds

which loads the Pounds part of Balance.