SPRU513Y August 2001 – June 2022 SM320F28335-EP
Declare Union Type
[utag] .union [expr]
[mem0
] element [expr0]
[mem1 ] element [expr1]
. . .
[memn ] .tag
utag [exprn ]
. . .
[memN ] element [exprN]
[size] .endunion
label .tag utag
The .union directive assigns symbolic offsets to the elements of alternate data structure definitions to be allocated in the same memory space. This enables you to define several alternate structures and then let the assembler calculate the element offset. This is similar to a C union. The .union directive does not allocate any memory; it merely creates a symbolic template that can be used repeatedly.
A .struct definition can contain a .union definition, and .structs and .unions can be nested.
The .endunion directive terminates the union definition.
The .tag directive gives structure or union characteristics to a label, simplifying the symbolic representation and providing the ability to define structures or unions that contain other structures or unions. The .tag directive does not allocate memory. The structure or union tag of a .tag directive must have been previously defined.
Following are descriptions of the parameters used with the .struct, .endstruct, and .tag directives:
These examples show unions with and without tags.
1
2 .global employid
3 xample .union ; utag
4 0000 ival .int ; member1 = int
5 0000 fval .float ; member2 = float
6 0000 sval .string ; member3 = string
7 0002 real_len .endunion
8
9 00000000 employid .usect ".ebss", real_len ; allocate memory
10
11 employid .tag xample ; name an instance
12
13 00000000 08A1- ADD AR1, #employid.ival
00000001 0000
1
2 .union ; utag
3 0000 x .long ; member 1= long
4 0000 y .float ; member 2 = float
5 0000 z .int ; member 3 = int
6 0002 size_u .endunion ; size_u = 2