Addressing Array Elements
. Arrays are stored in a block of consecutive locations
. assume width of each element is w
. ith element of array A begins in location
base + (i - low) x w
where base is relative address of A[low]
. the expression is equivalent to
i x w + (base-low x w)
i x w + const
Elements of an array are stored in a block of consecutive locations. For a single dimensional array, if low is the lower bound of the index and base is the relative address of the storage allocated to the array i.e., the relative address of A[low], then the i th Elements of an array are stored in a block of consecutive locations
For a single dimensional array, if low is the lower bound of the index and base is the relative address of the storage allocated to the array i.e., the relative address of A[low], then the i th elements begins at the location: base + (I - low)* w . This expression can be reorganized as i*w + (base -low*w) . The sub-expression base-low*w is calculated and stored in the symbol table at compile time when the array declaration is processed, so that the relative address of A[i] can be obtained by just adding i*w to it.
|