Structure P192 int area (struct rect *rp) return (*rp).width (*rp). height ⅴ。 id rotate1eft( struct rect*rp) /* Exchange width and height * int t rp-heighti rp->height rp->width rp->width s ti
6 Structure P192 int area (struct rect *rp) { return (*rp).width * (*rp).height; } void rotate_left (struct rect *rp) { /* Exchange width and height */ int t = rp->height; rp->height = rp->width; rp->width = t; }
Structure struct rec int ii int j; int a[3] int p i }*r; Ofset 0 nnt仁1jaoa]a2
7 Structure struct rec { int i; int j; int a[3]; int *p; } *r;
Structure P193 Copy element r->i to element r->j r is in register edx movl(edx),eax e七x->i 2 mov l eax 4(号edx) store in Ofset 0 ontents i 8a [0]a[1]a[2]
8 Structure P193 • Copy element r->i to element r->j: • r is in register %edx. 1 movl (%edx), %eax Get r->i 2 movl %eax, 4(%edx) Store in r->j
Structure P193 Generate the pointer &(r->a[1]) 工in各eax 立in各eax 11ea18(号eax,edx,4),.ecx岩ecx=正x a[了 Ofset 0 ontents i 8a [0]a[1]a[2]
9 Structure P193 • Generate the pointer &(r->a[1]) – r in %eax, – i in %edx 1 leal 8(%eax,%edx,4),%ecx %ecx = &r- >a[i]
Structure x->P=&r->a[r->i+x->j]; r in register号edx: 1m。v1 4(edx),各eax Get r->j 2 addl (岩edx),号eax Add r->i 31ea1 8(各edx,eax,4),号eax Compute cx->a[x-xi+x->元7 4 movl gear I 20(号edx) store in Ofset 0 ontents i 8a [0]a[1]a[2]
10 Structure • r->p = &r->a[r->i + r->j]; – r in register %edx: 1 movl 4(%edx), %eax Get r->j 2 addl (%edx), %eax Add r->i 3 leal 8(%edx,%eax,4), %eax Compute &r->a[r->i + r->j] 4 movl %eax, 20(%edx) Store in r->p