## ALP Programming Guide and Reference

[prev][next][parent][TOC]

### Initialization of Aggregate Types

An aggregate data item is a collection of one or more sub-items of possibly dissimilar types that are allocated, initialized, and treated as a single unit. The sub-items usually have unique names, and their positions relative to other sub-items is significant. The assembler provides the ability to define aggregate types through use of the RECORD, STRUCT, and UNION directives.

Initialization of an aggregate data item requires a programming notation that isolates the entire aggregate from surroundings constructs, and denotes the position of each sub-item within the aggregate. The syntax for this construct is as follows:

Aggregate-Initializer:
{ [Initializer-List] }
< [Initializer-List] >
Initializer-List:
Initializer-Item
Initializer-List, [LineBreak] Initializer-Item
Initializer-Item:
[Scalar-Initializer]
[Aggregate-Initializer]
[Array-Initializer]

The syntax requires that an Aggregate-Initializer be enclosed in an outer set of braces or angle brackets, but the Initializer-List or individual comma-separated Initializer-Items may be left unspecified, in which case a default initializer value is used. Commas are used to denote the position of each sub-item within the entire aggregate, and nested initializers are allowed to accomodate imbedded occurrences of other aggregates (or vector types, which share the same initializer syntax).

When initializing an instance of a union, the assembler only allows an initializer to be specified for the first field defined in the union type.

Examples

Here are some examples of aggregate initialization:

    YES     equ    1
    NO      equ    0
    MAYBE   equ   - 1

    BOOL _ T   typedef   sbyte

    IDEAS _ T   struct
       sanctum    BOOL _ T   ?            ;   For   scalar   data ,   use   the   ?   operator
       peace      BOOL _ T   ?            ;     to   request   an   uninitialized   value .
       pilzner    BOOL _ T   ?
    IDEAS _ T   ends

    PROBLEM _ T   struct
        work     BOOL _ T    YES          ;   Establish   default   initial   values   that
        car      BOOL _ T    NO           ;     can   be   inherited   when   an   instance   of
        house    BOOL _ T    MAYBE        ;     the   structure   is   allocated
    PROBLEM _ T   ends

    SOLUTION _ T   struct
         fixing   PROBLEM _ T   { }        ;   Outermost   set   of   braces   required   even
                 IDEAS _ T     { }        ;    with   unspecified   ( default )   initializers
    SOLUTION _ T   ends

    DATA   segment
       ProblemWith   PROBLEM _ T    {   NO ,   ,   MAYBE   }           ;   First - level   structure
       ThinkOf       SOLUTION _ T   {   {   YES ,   YES ,   YES   } ,      ;   Intializer   syntax   for
                                  {    NO ,    NO ,    NO   }   }     ;     imbedded   structures
    DATA   ends

    CODE     segment
            assume   ds : DATA
            mov   al ,   NO
            or    al ,   ProblemWith . work
            or    al ,   ProblemWith . car
            or    al ,   ProblemWith . house
            jz    exit
            mov   ThinkOf . fixing . work ,   NO       ;   References   to   named   fields   in
            mov   ThinkOf . fixing . car ,   NO        ;     imbedded   structures   must   be
            mov   ThinkOf . fixing . house ,   NO      ;     fully   qualified .
    exit :    mov   ThinkOf . pilzner ,   YES          ;   Reference   to   " promoted "   field
            ret
    CODE     ends
    end