ST20-C1 STMICROELECTRONICS [STMicroelectronics], ST20-C1 Datasheet - Page 42

no-image

ST20-C1

Manufacturer Part Number
ST20-C1
Description
Instruction Set Reference Manual
Manufacturer
STMICROELECTRONICS [STMicroelectronics]
Datasheet
4.5 Forming addresses
Access to a component of an array can be split into two sections; first the address of
the component must be constructed, and then the transfer of data to or from that
component must be performed.
Evaluating a subscript
Array subscripts can be evaluated efficiently using the smul or mul instruction. If array
A has been declared by
where S
have all elements of the array in a contiguous block. For the purposes of this section,
suppose that the elements in the last dimension are stored adjacently; otherwise
change the order of the dimension subscripts. For example Figure 4.1 shows the
elements of a particular three dimensional array (Array) stored in this way.
If an access is required to the following array element
then the code to evaluate the subscript is
For example to evaluate the subscript for element Array[x][y][z], (where Array
is declared as in Figure 4.1) the code sequence is
If x is 1, y is 0 and z is 2, then this evaluates to 8, which as can be seen from Figure
4.1, is the correct offset from the base of the array.
42/205
int A [ S
A [ e
e
ldc S
ldc S
. . .
ldc S
ld x;
ldc 2; mul; ld y; add;
ldc 3; mul; ld z; add;
int Array[ 2 ][ 2 ][ 3 ];
i
1
( i = 1..n ) are the dimensions, then one way of arranging this in memory is to
;
1
Figure 4.1 A possible method of storing an array of integers
2
3
n
] . . . [ e
; mul; e
; mul; e
; mul; e
1
] . . . [ S
2
3
n
n
; add;
; add;
; add;
]
n
];
Increasing
addresses
memory
Array[0][1][0]
Array[1][1][2]
Array[1][1][1]
Array[1][1][0]
Array[1][0][2]
Array[1][0][1]
Array[1][0][0]
Array[0][1][2]
Array[0][1][1]
Array[0][0][2]
Array[0][0][1]
Array[0][0][0]
Contiguous
locations for
words in
memory
space

Related parts for ST20-C1