8. Assuming that an array memory mapping uses row major order, consider the foll
ID: 3701206 • Letter: 8
Question
8. Assuming that an array memory mapping uses row major order, consider the following two arrays, and write the most simplified expression for a mapping function to locate the byte address of each specified element // array storage begin at address 1000 intl] A 1.3, 9.2, 2.1,9.3,9.8,8.2, 6.5, 3.2,9.2; /l array storage begin at address 1500 double[1[] B-{14,1, 4,7, (2,4,3, 5), 18,6,7,6 a) A21 (write the address) b) A [ j (write the 1-D mapping function) c) B[3] 13] (write the address) d) BIi1j] (write the 2-D mapping function) e) B[21 o] (write the 2-D mapping function)Explanation / Answer
Array is stored in row major order i.e. for 2 d array we will first save all elements of a row and then save all elements of another row in memory and so on....
Since size of the elements of array is not given then i will consider it as 1 byte for example. Now for the array A as this is one dimensional, so we have only one row to save in order in memory. Hence first element is stored and then after that second element is stored all side by side.
a) Now we need address for A[2] if starting address is 1000 and every element needs one byte then A[0] is at 1000 and A[1] will be at 1000+1 = 1001 and then A[2] will be at 1001+1 = 1002. So address of A[2] = 1002.
b) Since the pattern we saw in option a if we generalize that then 1-D mapping function for A[i] = baseaddress + i*size of element.
c) Now for 2 d array B if address starts from 1500 then first all the 3 elements of first row is saved so 1500, 1501, 1502 is occupied, now second row as 1503, 1504,1505 and then finally third row as 1506, 1507,1508 hence address for B[3][3] = 1508.
d) According to the address storage pattern above 2D mapping function : baseaddress + size of elememt *[(i-1)*no. of column +j]
e) using above 2d formula 2-d mapping function is : B[2][0] = 1500 + 1*[(2-1)*4 + 0].
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.