I've been reading the old posts and confused with the solution below
---------------------------------- from nonevent99 ----------------------------------------------------------
Q11) If a system stores arrays in row-major order, and an array of 4-byte words A[100][200] starts at location 0x8000, give a formula for the location of element A[x][y]. How about if it's in column-major order?
[orange]
In row-major order, each row contains 200 elements. Each element is 4B. So each row is 800 bytes.
I should have mentioned that these arrays are indexed from 0, as in C and Java (but not old-style Basic!)
With that assumption, the location of A[x][y] would be 0x8000 + 800*rownum + 4*colnum, which is 0x8000 + 800*y + 4*x.
In column major order, each column contains 100 elements, or 400 bytes per column. So the location is 0x8000 + 400*colnum + 4*rownum = 0x8000 + 400*x + 4*y
--------------------------------------------------------------------------------------------------------------
>In row-major order, each row contains 200 elements. Each element is 4B. So each >row is 800 bytes.
I agree, but
>With that assumption, the location of A[x][y] would be 0x8000 + 800*rownum + >4*colnum, which is 0x8000 + 800*y + 4*x.
I think it should be 0x8000 + 800*x + 4*y
since in row-major order subscriptions in the right increase more radpidly than the left so the memory layout should be like this: !?
[0 0][0 1][0 2]...[0 199] [1 0][1 1][1 2]...[1 199] [3 0][3 1][3 2]...[3 199] ...
which is reverse with column-major order
----
>In column major order, each column contains 100 elements, or 400 bytes per
> column. So the location is 0x8000 + 400*colnum + 4*rownum = 0x8000 + 400*x + 4*y
so I believe should be 0x8000 + 400*y + 4*x instead !?
Am I wrong !?