V1 printfip p ip p ip dn ip ip ip

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: ffset of field i is 0, the address of this field is simply the value of r. To store into field j, the code adds offset 4 to the address of r. To generate a pointer to an object within a structure, we can simply add the field’s offset to the structure address. For example, we can generate the pointer &(r->a[1]) by adding offset · ¡ ½ ½¾. For pointer r in register %edx and integer variable i in register %eax, we can generate the pointer value &(r->a[i]) with the single instruction: r in %eax, i in %edx 1 leal 8(%eax,%edx,4),%ecx %ecx = &r->a[i] As a final example, the following code implements the statement: r->p = &r->a[r->i + r->j]; starting with r in register %edx: 1 2 3 4 movl addl leal movl 4(%edx),%eax (%edx),%eax 8(%edx,%eax,4),%eax %eax,20(%edx) Get r->j Add r->i Compute &r->[r->i + r->j] Store in r->p As these examples show, the selection of the different fields of a structure is handled completely at compile time. The machine code contains no information about th...
View Full Document

Ask a homework question - tutors are online