Section 8.6: Indirect addressing in action (Frame 4)                     [prev][home][next]

Here is a segment of CSC-1 code to implement stuff[i]=j. Assume that variable i is stored at address 2000 and variable j is stored at address 2500.

LDI 1000
ADD 2000
A2S
LOD 2500
STS

The first line above puts the address of the beginning of the array into A, &stuff[0] in C notation. ADD 2000 then adds the value currently stored in i. Now A has the address of the desired word but since A will hold j's value, this address is shuffled over to the S register by the A2S instruction. Next, j's value can be loaded into the A register by LOD 2500, and finally the STS instruction stores this value into the correct memory location given by the contents of S.