|
It is a perfectly reasonable operation to create an array of records. To do so, you simply create a record type and then use the standard array declaration syntax. The following example demonstrates how you could do this:
type recElement: record << fields for this record >> endrecord; . . . static recArray: recElement[4];
To access an element of this array you use the standard array indexing techniques. Because recArray is a single dimension array, you'd compute the address of an element of this array using the formula "baseAddress + index*@size(recElement)". For example, to access an element of recArray you'd use code like the following:
// Access element i of recArray: intmul( @size( recElement ), i, ebx ); // ebx := i*@size( recElement ) mov( recArray.someField[ebx], eax );
Note that the index specification follows the entire variable name; remember, this is assembly, not a high level language (in a high level language you'd probably use "recArray[i].someField").
Naturally, you can create multidimensional arrays of records as well. You would use the row major or column major order functions to compute the address of an element within such records. The only thing that really changes (from the discussion of arrays) is that the size of each element is the size of the record object.
static rec2D: recElement[ 4, 6 ]; . . . // Access element [i,j] of rec2D and load "someField" into EAX: intmul( 6, i, ebx ); add( j, ebx ); intmul( @size( recElement ), ebx ); mov( rec2D.someField[ ebx ], eax );
|