Unions declared using the keyword union allow an

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: ect. For an expression AddrExpr denoting an address, *Addr-Expr gives the value at that address. The expressions Expr and *&Expr are therefore equivalent. The array subscripting operation can be applied to both arrays and pointers. The array reference A[i] is identical to the expression *(A+i). It computes the address of the th array element and then accesses this memory location. Expanding on our earlier example, suppose the starting address of integer array E and integer index i are stored in registers %edx and %ecx, respectively. The following are some expressions involving E. We also show an assembly code implementation of each expression, with the result being stored in register %eax. Expression E E[0] E[i] &E[2] E+i-1 *(&E[i]+i) &E[i]-E Type int * int int int * int * int int Value Å Å Ñ ÜE · ÜE · ÜE · Å Ñ ÜE · · ÜE Ñ ÜE movl movl movl leal leal movl movl Assembly Code %edx,%eax (%edx),%eax (%edx,%ecx,4),%eax 8(%edx),%eax -4(%edx,%ecx,4),%eax (%edx,%ecx,8),%eax %ecx,%eax In these examples, the leal instruction is used to generate an address, while movl is used to reference memory (except in the first case, where it copies an address). The final example shows that one can compute the difference of two pointers within the same data structure, with the result divided by the size of the data type. 3.8. ARRAY ALLOCATION AND ACCESS Pr...
View Full Document

This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.

Ask a homework question - tutors are online