Question: 2 . A two - dimensional array in C ( and some other languages ) can be considered as an array of one - dimensional

2. A two-dimensional array in C (and some other languages) can be considered as an array of
one-dimensional array. For example, the following define T as an 16x8 array in C.
int T[16][8];
The two-dimensional array can be considered as an array of 16 elements, each of which is a
one-dimensional array of 8 integers/words. The words are stored in memory in the following
order:
T[0][0], T[0][1],..., T[0][6], T[0][7],
T[1][0], T[1][1],..., T[1][6], T[1][7],
...
T[14][0], T[14][1],..., T[14][6], T[14][7],
T[15][0], T[15][1],..., T[15][6], T[15][7]
Row 0, consisting of T[0][0], T[0][1],..., and T[0][7], goes first. Row i is stored right after
row i 1, for i =1,2,...,15. For example, T[1][0] is stored right after T[0][7]. If T[0][0] is
located at address 1000, T[0][7] is located at address 1028=1000+7*4. And T[1][0] is
located at address 1032. Similarly, we can calculate that T[2][0] is located at 1064, T[3][0] is
located at 1096, and so on.
Translate the following C code to RISC-V instructions. Assume Ts address is already in s9.
As a practice of accessing two-dimensional arrays, do not use pointers. Explain your code,
especially how you implement the loops and how you calculate T[i][j]s address.
for (i =0; i <16; i +=1)
for (j =0; j <8; j +=1)
T[i][j]=256* i + j;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!