## ALP Programming Guide and Reference

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

### Initialization of Vector Types

A vector data item is a linear collection of one or more sub-items of identical type that are allocated, initialized, and treated as a single unit. A vector (more commonly referred to as an array) is defined to have a specific number of items n, which are numbered from 0 to n - 1 and occupy a contiguous area of allocated storage. The items in the vector may be of any type, possibly even other vectors (commonly known as a multi- dimensional array). The assembler provides the ability to define vector types through the use of the standard Type-Declaration syntax.

The syntax required to initialize a vector is similar to that used for an aggegrate data type, and is as follows:

Array-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 Array-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 array, and nested initializers are allowed to accomodate imbedded occurrences of other arrays (or aggregate types, which share the same initializer syntax).

Examples

Here are some examples of vector initialization:

    ;   Data   structures   to   define   a   " computer "   data   type

    TRUE         equ          1
    FALSE        equ          0
    MB           equ       1024                   ;   Megabytes

    BOOL _ T       typedef   BYTE                   ;   true   or   false   value
    INCHES _ T     typedef   BYTE                   ;   number   of   inches
    MONITOR _ T    typedef   INCHES _ T               ;   size   of   monitor   in   inches
    KEYBOARD _ T   typedef   BOOL _ T                 ;   is   a   keyboard   installed ?
    MOUSE _ T      typedef   BOOL _ T                 ;   is   a   mouse   installed ?
    KBYTES _ T     typedef   WORD                   ;   number   of   kilobytes
    MBYTES _ T     typedef   WORD                   ;   number   of   megabytes
    FPRESENT _ T   typedef   BOOL _ T [ 2 ]              ;   up   to   two   floppies   installed
    FSIZE _ T      typedef   KBYTES _ T [ 2 ]           ;   how   big   they   are
    DPRESENT _ T   typedef   BOOL _ T [ 4 ]              ;   up   to   four   hardfiles   installed
    DSIZE _ T      typedef   MBYTES _ T [ 4 ]           ;   how   big   they   are
    RAM _ T        typedef   DWORD                  ;   how   much   memory   we   have
    NAME _ T       typedef   BYTE [ 64 ]               ;   what   we   call   the   system

    FLOPPIES _ T   struct
    DriveCount   FPRESENT _ T   {   TRUE ,   FALSE   }    ;   assume   one   floppy   installed
    DriveSize    FSIZE _ T      {   360 ,   0   }         ;   assume   360KB   in   size   : - )
    FLOPPIES _ T   ends

    DRIVES _ T     struct
    DriveCount   DPRESENT _ T   {   TRUE ,   FALSE ,   FALSE ,   FALSE   }     ;   one   drive   installed
    DriveSize    DSIZE _ T      {   20 ,   0 ,   0 ,   0   }                    ;   20MB   in   size   ( ! )
    DRIVES _ T     ends

    COMPUTER _ T   struct
    Monitor      MONITOR _ T     14                 ;   Assume   a   14   inch   monitor
    Keyboard     BOOL _ T        TRUE               ;   We   have   a   keyboard
    Mouse        BOOL _ T        FALSE              ;   but   no   mouse
    Memory       RAM _ T         640                ;   Assume   640KB
    Floppies     FLOPPIES _ T    { }                 ;   Go   with   the   defaults
    HardFiles    DRIVES _ T      { }                 ;   Go   with   the   defaults
    ModelName    NAME _ T        { }                 ;   No   default   name
    COMPUTER _ T   ends

    DATA   segment
    Circa1997    COMPUTER _ T    \                  ;   initializer   begins   on   next   line
       {   17 ,                                     ;   of   course ,   we   have   a   17 "   monitor
         TRUE ,   TRUE ,                            ;   a   keyboard   and   a   mouse
         32   *   MB ,                               ;   32   Megabytes   of   ram
         {   {   } ,                                 ;   still   one   floppy
           {   1440   }   } ,                          ;   but   it   has   a   1 . 2   MB   capacity
         {   {   ,   TRUE ,   TRUE   } ,                   ;   also   have   second   and   third   hardfiles
           {   512 ,   1024 ,   4096   }   } ,              ;   512MB ,   1   GIG ,   and   4   GIG
         {   " Spiffatron   9000 " ,   10 ,   13 ,         ;   with   a   fancy   system   name
           " Acme   Computers " ,   10 ,   13 ,   0   }   }
    DATA   ends
    end