Clase(7)

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: in general 5 1 zip_dig cmu; 16 5 20 2 24 1 28 32 36 Register %edx contains starting address of array ¢༊  Register %eax contains array index ¢༊  Desired digit at 4*%eax + %edx ¢༊  Use memory reference (%edx, %eax,4) ¢༊  int get_digit (zip_dig z, int dig) { return z[dig]; } IA32 # %edx = z # %eax = dig movl (%edx,%eax,4),%eax 3 # z[dig] 6 ARRAY LOOP EXAMPLE (IA32) void zincr(zip_dig z) { int i; for (i = 0; i < ZLEN; i++) z[i]++; } # edx movl .L4: addl addl cmpl jne =z $0, %eax # %eax = i # loop: $1, (%edx,%eax,4) # z[i]++ $1, %eax # i++ $5, %eax # i:5 .L4 # if !=, goto loop 7 POINTER LOOP EXAMPLE (IA32) void zincr_p(zip_dig z) { int *zend = z+ZLEN; do { (*z)++; z++; } while (z != zend); } movl leal .L9: addl addl cmpl jne 8(%ebp), %eax 20(%eax), %edx $1, (%eax) $4, %eax %eax, %edx .L9 # # # # # # # z zend loop: *z += 1 z++ zend:z if !=, goto loop 8 NESTED ARRAY EXAMPLE #define PCOUNT 4 zip_dig pgh[PCOUNT] = {{1, 5, 2, 0, 6}, {1, 5, 2, 1, 3 }, {1, 5, 2, 1, 7 }, {1, 5, 2, 2, 1 }}; zip_dig pgh[4]; 15206152131521715221 76 ¢༊  116 136 156 “zip_dig pgh[4]” equivalent to “int pgh[4][5]” —༉  —༉  ¢༊  96 Variable pgh: array of 4 elements, allocated con?guously Each element is an array of 5 int’s, allo...
View Full Document

This document was uploaded on 04/05/2014.

Ask a homework question - tutors are online