83/317
4 - Architecture of the ST7 core
A[I] = B[J] + C[K]
Where A, B and C are arrays of numbers, and I, J and K the indexes to these arrays. The high-
level language compiler translates this so as to read the
Ith element of array A using the avail-
able machine-language instruction. If these are arrays of bytes whose base address is some-
whereinpagezero,thefollowinginstructionsequencecanbeused:
LD X, I ; Set Index register to value of index I of array A
LD A, ([A],X); Get value A[I]
LD X, J ; Set Index register to value of index J of array B
ADD A, ([B],X); Add value of B[J]
LD X, K ; Set Index register to value of index K of array C
LD ([C],X), A; Put result into C[K]
This is only one of the many examples where powerful addressing modes help translate high-
level languages efficiently. In this case, the whole addition is performed in 22 cycles, or 5.5 µs
at 8 MHz, and consumes 12 bytes of code.