Lecture 8

# Washington nested array row access code int

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: shington Nested Array Row Access   Row vectors   T A[R][C]: A[i] is array of C elements   Each element of type T requires K bytes   StarNng address A + i * (C * K) int A[R][C]; A[0] A [0] [0] A • • • A[i] A [0] [C-1] • • • A [i] [0] • • • A+i*C*4 Nested Arrays A[R-1] A [i] [C-1] A • • • [R-1] [0] • • • A+(R-1)*C*4 A [R-1] [C-1] University of Washington Nested Array Row Access Code int *get_sea_zip(int index) { return sea[index]; } Nested Arrays #define zip_dig {{ 9, { 9, { 9, { 9, PCOUNT 4 sea[PCOUNT] = 8, 1, 9, 5 }, 8, 1, 0, 5 }, 8, 1, 0, 3 }, 8, 1, 1, 5 }}; University of Washington Nested Array Row Access Code int *get_sea_zip(int index) { return sea[index]; } #define zip_dig {{ 9, { 9, { 9, { 9, PCOUNT 4 sea[PCOUNT] = 8, 1, 9, 5 }, 8, 1, 0, 5 }, 8, 1, 0, 3 }, 8, 1, 1, 5 }}; # %eax = index leal (%eax,%eax,4),%eax # 5 * index leal sea(,%eax,4),%eax # sea + (20 * index)   Row Vector   sea[index] is array of 5 ints (a zip_dig data type)   StarNng address sea+20*index   IA32 Code   Computes and returns address   Compute as sea+4*(index+4*index)=sea+20*index Nested Arrays University of Washington Nested Array Row Access int A[R][C]; A[0] A [0] [0] A • • • A[i] A [0] [C-1] • • • A • • • [ i ] • • • [j] A + i*C*4 Nested Arrays A[R-1] A • • • [R-1] [0] • • • A + (R-1)*C*4 A [R-1] [C-1] University of Washington Nested Array Row Access   Array Elements   A[i][j] is element of type T, which requires K bytes   Address A + i * (C * K) + j * K = A + (i * C + j)* K int A[R][C]; A[0] A [0] [0] A • • • A[i] A [0] [C-1] • • • A • • • [ i ] • • • [j] A[R-1] A • • • [R-1] [0] A + i*C*4 A + i*C*4 + j*4...
View Full Document

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern