SLAU131Y October 2004 – June 2021
Declare Structure Type
[stag] .struct [expr]
[mem0] element [expr0]
[mem1] element [expr1]
. . .
. . .
. . .
[memn] .tag stag [exprn]
. . .
. . .
. . .
[memN] element [exprN]
[size] .endstruct
label .tag stag
The .struct directive assigns symbolic offsets to the elements of a data structure definition. This allows you to group similar data elements together and let the assembler calculate the element offset. This is similar to a C structure or a Pascal record. The .struct directive does not allocate memory; it merely creates a symbolic template that can be used repeatedly.
The .endstruct directive terminates the structure definition.
The .tag directive gives structure characteristics to a label, simplifying the symbolic representation and providing the ability to define structures that contain other structures. The .tag directive does not allocate memory. The structure tag (stag) of a .tag directive must have been previously defined.
Following are descriptions of the parameters used with the .struct, .endstruct, and .tag directives:
The only directives that can appear in a .struct/.endstruct sequence are element descriptors, conditional assembly directives, and the .align directive, which aligns the member offsets on word boundaries. Empty structures are illegal.
The following examples show various uses of the .struct, .tag, and .endstruct directives.
1 REAL_REC .struct ;stag
2 0000 NOM .int ;member1 = 0
3 0002 DEN .int ;member2 = 2
4 0004 REAL_LEN .endstruct ;real_len = 4
5
6 0000 .bss REAL, REAL_LEN
7
8 0000 .text
9 0000 521B ADD.W &REAL + REAL_REC.DEN,R11
0002 0002!
10
11 0000 .data
12 CPLX_REC .struct
13 0000 REALI .tag REAL_REC ; stag
14 0004 IMAGI .tag REAL_REC ; member1 = 0
15 0008 CPLX_LEN .endstruct ; cplx_len = 8
16
17 COMPLEX .tag CPLX_REC ; assign structure attrib
18
19 0004 .bss COMPLEX, CPLX_LEN
20
21 0004 .text
22 0004 521B ADD &COMPLEX.REALI,R11 ; access structure
0006 0004!
1 0000 .data
2 .struct ; no stag puts mems into
3 ; global symbol table
4 0000 X .int ; create 3 dim templates
5 0002 Y .int
6 0004 Z .int
7 0006 .endstruct
1 0000 .data
2 BIT_REC .struct ; stag
3 0000 STREAM .string 64
4 0040 BIT7 .field 7 ; bits1 = 64
5 0040 BIT9 .field 9 ; bits2 = 64
6 0042 BIT10 .field 10 ; bits3 = 65
7 0044 X_INT .int ; x_int = 66
8 0046 BIT_LEN .endstruct ; length = 67
9
10 BITS .tag BIT_REC
11
12 0000 .bss BITS, BIT_REC
13
14 0000 .text
15 0000 521B ADD &BITS.BIT7,R11 ; move into R11
0002 0040!
16 0004 F03B AND #127,R11 ; mask off garbage bits
0006 007F