Section 8.5: How Indirect Addressing Works (Frame 2)                     [prev][home][next]

For example, consider an array of 100 integers, named stuff.

int stuff[100];

Let's say we wanted to add the 1st and 2nd element. We would use the indexes 0 and 1 as follows:

sum = stuff[0] + stuff[1];

However, if you needed to get at all the elements, or if you wanted to access a random element, you would need an index variable, such as:

n = stuff[i];

The value in variable i can be changed as the program progresses. This number isn't known at assembly time, but must be computed at run-time as needed. This is precisely why arrays need indirect addressing. Only scalars can be addressed using LOD and STD because their addresses are known at compile-time.