This preview shows page 1. Sign up to view the full content.
Unformatted text preview: ffset of ﬁeld i is 0, the address of this ﬁeld is simply the value of r. To store into ﬁeld 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 ﬁeld’s offset to the structure address. For example, we can generate the pointer &(r->a) 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 ﬁnal 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 ﬁelds of a structure is handled completely at compile time. The machine code contains no information about th...
View Full Document
- Spring '10
- The American