Arrays Module (arrays.hhf)

The HLA Arrays module provides a set of datatypes, macros, and procedures that simplify array access in assembly language (especially multidimensional array access).  In addition to supporting standard HLA arrays with static size declarations, the HLA arrays module also supports dynamic arrays that let you specify the array size at run-time.

Note: be sure to read the chapter on “Passing Parameters to Standard Library Routines” (parmpassing.rtf) before reading this chapter.

 

The Arrays Module

To use the array macros in your application, you will need to include one of the following statements at the beginning of your HLA application:

#include( “arrays.hhf” )

or

#include( “stdlib.hhf” )

 

Array Data Types

The array namespace defines the following useful data types:

 

#macro array.dArray( type, dimensions );

The first feature in the array package to consider is the support for dynamic arrays.  HLA provides a macro/data type that lets you tell HLA that you want to specify the array size under program control.  This macro/data type is array.dArray (dArray stands for dynamic array).  You use this macro invocation in place of a standard data type identifier in an HLA variable declaration.

The first macro parameter is the desired data type;  this would typically be an HLA primitive data type like int32 or char, although any data type identifier is legal.

The second parameter is the number of dimensions for this array data type  Generally this value is two or greater (since creating dynamic single dimensional arrays using only malloc is trivial).  Because of the way array indicies are computed by HLA, it is not possible to specify the number of dimensions dynamically.

Note: since array.dArray is not a data type identifier (it’s a macro), you cannot directly create a dynamic array of dynamic arrays.  I.e., the following is not legal:

 

static

    DAofDAs: array.dArray( array.dArray( uns32, 2), 2 );

 

However, you can achieve exactly the same thing by using the following code:

 

type

    DAs: array.dArray( uns32, 2 );

 

static

    DAofDAs: array.dArray( DAs, 2 );

 

The TYPE declaration creates a type identifier that is a dynamic array.  The STATIC variable declaration uses this type identifier in the array.dArray invocation to create a dynamic array of dynamic arrays.

 

 

 

 

Array Allocation and Deallocation

 

#macro array.daAlloc(  dynamicArrayName, <<list of dimension bounds>> );

 The array.dArray macro allocates storage for a dynamic array variable.  It does not, however, allocate storage for the dynamic array itself; that happens at run-time.  You must use the array.daAlloc macro to actually allocate storage for your array while the program is running.  The first parameter must be the name of the dynamic array variable you’ve declared via the array.dArray macro. The remaining parameters are the number of elements for each dimension of the array.  This list of dimension bounds must contain the same number of values as specified by the second parameter in the array.dArray declaration.  The dimension list can be constants or memory locations (note, specifically, that registers are not currently allowed here;  this may be fixed in a future version).

The following code demonstrates how to declare a dynamic array and allocate storage for it at run-time:

 

program main;

static

    i:uns32;

    j:uns32;

    k:uns32;

    MyArray: array.dArray( uns32, 3 );

 

begin main;

 

    stdout.put( "Enter size of first dimension: " );

    stdin.get( i );

    stdout.put( "Enter size of second dimension: " );

    stdin.get( j );

    stdout.put( "Enter size of third dimension: " );

    stdin.get( k );

 

    // Allocate storage for the array:

 

    array.daAlloc( MyArray, i, j, k );

 

    << Code that manipulates the 3-D dynamic array >>

 

end main;

 

 

#macro array.daFree( dynamicArrayName );

Use the array.daFree macro to free up storage you’ve allocated via the array.daAlloc call.  This returns the array data storage to the system so it can be reused later.  Warning: do not continue to access the array’s data after calling array.daFree.  The system may be using the storage for other purposes after you release the storage back to the system with array.daFree.

Note: You should only call array.daFree for arrays you’ve allocated via array.daAlloc.

 

Example:

 

    // Allocate storage for the array:

 

    array.daAlloc( MyArray, i, j, k );

 

    << Code that manipulates the 3-D dynamic array >>

 

array.daFree( MyArray );

 

Array Predicates

 

#macro array.IsItVar( objectName )