Consider the linear arrays AAA[5:50],BBB[-5:10] and CCC[1:8]

Consider the linear arrays AAA[5:50], BBB [-5:10] and CCC[1:8].

(a) Find the number of elements in each array

(b) Suppose Base(AAA) = 300 and w=4 words per memory cell for AAA. Find the address of AAA[35] ,AAA[15], and AAA[55]

(a) Length = Upper Bound – Lower Bound +1
Length(AAA) = 50-5+1 = 46
Length(BBB) = 10-(-5)+1 = 16
Length(CCC) = 18-1+1 = 18

(b) Using the formula: LOC(AAA[k]) = Base(AAA)+w(K-LB)
LOC(AAA[15] )= 300+4(15-5) = 340
LOC(AAA[35] )= 300+4(35-5) = 420
AAA[55] is not an element of AAA since 55 exceeds UB = 50.


Share on