STRUC Define structure type Directive
STRUC name ; Ideal mode
structure_members
ENDS [name]
name STRUC ; MASM mode
structure_members
[name] ENDS
Defines a structure called name containing members.
Structures and unions
Structures and unions let you mix and match various types. A structure
in Turbo Assembler is a data type that contains one or more data
elements called members. The size of a structure is the combined
size of all data elements within it.
Unions are similar to structures, except that all of the members in a
union occupy the same memory. The size of a union is the size of its
largest member. Unions are useful when a block of memory must
represent one of several distinct possibilities, each with different
data storage requirements.
Turbo Assembler lets you fully nest structures and unions within one
another, but this can become complicated. For example, you could have
a structure member that is really a union. A union could also have a
full structure as each member.
Opening and closing a structure or union
TASM considers all data or code emitted between the time a structure
or union data type definition is opened (STRUC or UNION directive) and
the time a corresponding ENDS directive is encountered to be part of
that structure or union data type.
Turbo Assembler treats structure and union data type names as global
but redefinable. You can define the same name as a structure or union
data type more than once in a module.
Specifying members
To create members in a structure or union definition, use the same
directives as those for allocating data and creating labels in an open
segment. Turbo Assembler allows all methods of allocating data with a
structure definition, including instances of other structures, unions,
records, enumerated data types, tables, and objects.
Members may be named or remain nameless. MASM and Ideal mode treat
structure member names differently. In MASM mode, structure member
names are global and cannot be redefined. In Ideal mode, structure
member names are considered local to a structure or union data type.
The LABEL directive lets you create structure members without
allocating data. LABEL directives found inside structure definitions
define members of the structure.
You can use the ALIGN directive within structure definitions to align
structure members on appropriate boundaries.
Example: STRUC testx
mem1 db ?
mem2 dw 5
LABEL xrest WORD
ALIGN 4
mem3 dd ?
ENDS
Nesting structures and unions
TASM lets you nest the STRUC, UNION, and ENDS directives inside open
structure and union data type definitions to control the offsets
assigned to structure members.
In a structure, each data element begins where the previous one ended.
In a union, each data element begins at the same offset as the
previous one. Allowing a single data element to consist of an entire
union or structure provides a high degree of flexibility.
Incorporating one named structure within another
TASM provides a way of incorporating an entire existing structure or
union data type, including member names, into an open structure
definition to assist in the inheritance of objects. It treats the
incorporated structure or union as if it were nested inside the open
structure or union definition at that point. In this way,
incorporating a structure or union into another is intrinsically
different from including an instance of a structure or union in
another; an instance includes only initialized or uninitialized
data, while incorporation includes data, structure, and member
names.
Refer to the TASM documentation for details.
Creating an instance of a structure or union
To create an instance of a structure or union data type, use the
structure or union data name as a data allocation directive.
Examples: stest1 mystruc ? ; uninitialized
stest2 mystruc < > ; initialized to defaults
stest3 mystruc { } ; initialized to defaults
stest4 mystruc {mem2=2, mem4=?} ; initialize named members
stest5 mystruc <,2,,?> ; initialize members
──────────────────────────────────────────────────────────────────────────
Extended STRUC directive:
STRUC name [modifiers] [parent_name] [METHOD [method_list]] ; Ideal mode
structure_members
ENDS [name]
Turbo Assembler 3.1+ objects are also defined as structures having
the extra optional items on the struc line.
name is the name of the object
modifiers can be one or more of: GLOBAL, NEAR, FAR
parent_name is the name of the parent object's data structure
(single inheritance supported)
method_list is like that of TABLE
structure_members are any (additional) data present in an instance
of the object
The extended STRUC directive defines or uses several symbols which
reflect the object being defined:
@Object Text macro containing the name of the current
object
@Table_<objectname> Data type containing the object's method table
@Tableaddr_<objectname> A label describing the address of the
instance of the object's virtual method table
(VMT).