{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

15 - Heterogeneous Data Structures Alignment 1 Outline...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Heterogeneous Data Structures & Alignment
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
2 Outline Struct Union Alignment Chap 3.9, 3.10 
Background image of page 2
3 Structures Group objects into a single object struct rect { int llx; /* X coordinate of lower-left corner */ int lly; /* Y coordinate of lower-left corner */ int color; /* Coding of color */ int width; /* Width (in pixels) */ int height; /* Height (in pixels) */ };
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
4 Structure Each object is referenced by name struct rect r; r.llx = r.lly = 0; r.color = 0xFF00FF; r.width = 10; r.height = 20;
Background image of page 4
5 Structure 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; }
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
6 Structures Memory layout All the components are stored in a contiguous region of memory A pointer to a structure is the address of its first byte
Background image of page 6
7 Structure struct rec { int i; int j; int a[3]; int *p; } *r; i j a[0] a[1] a[2] p Contents Offset 0 4 8 20
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
8 Structure References to structure elements Using offsets as displacements r->j = r->i ( 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 i j a[0] a[1] a[2] p Contents Offset 0 4 8 20
Background image of page 8
9 Structure &(r->a[i]) r in %eax, i in %edx 1 leal 8(%eax,%edx,4),%ecx Generate &r->a[i] i j a[0] a[1] a[2] p Contents Offset 0 4 8 20
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}