|
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. |