Me variable dimensions explicit indexing tradional

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

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 2, 1, 3 }; zip_dig mit = { 0, 2, 1, 3, 9 }; zip_dig ucb = { 9, 4, 7, 2, 0 }; ¢༊  ¢༊  #define UCOUNT 3 int *univ[UCOUNT] = {mit, cmu, ucb}; univ 160 36 164 16 168 56 mit 1 16 5 20 0 ucb 36 56 2 24 2 40 9 1 28 1 44 4 60 4 bytes Each pointer points to array of int’s —༉  ¢༊  cmu Variable univ denotes array of 3 elements Each element is a pointer 32 3 48 7 64 3 9 52 2 68 36 56 0 72 76 15 ELEMENT ACCESS IN MULTI- LEVEL ARRAY int get_univ_digit (int index, int dig) { return univ[index][dig]; } movl movl movl movl 8(%ebp), %eax univ(,%eax,4), %edx 12(%ebp), %eax (%edx,%eax,4), %eax # # # # index p = univ[index] dig p[dig] ¢༊  Computa?on (IA32) —༉  —༉  Element access Mem[Mem[univ+4*index]+4*dig] Must do two memory reads First get pointer to row array ¢༊  Then access element within array ¢༊  16 ARRAY ELEMENT ACCESSES Nested array int get_pgh_digit (int index, int dig) { return pgh[index][dig]; } Mul?- level array int get_univ_digit (int index, int dig) { return univ[index][dig]; } Accesses looks similar in C, but addresses very different: Mem[pgh+20*index+4*dig] Mem[Mem[univ+4*index]+4*dig] 17 N X N MATRIX CODE ¢༊  Fixed dimensions —༉  K...
View Full Document

This document was uploaded on 04/05/2014.

Ask a homework question - tutors are online