中国高校课件下载中心 》 教学资源 》 大学文库

复旦大学:《计算机原理 Computer System》课程PPT课件_Heterogeneous Data Structures & Alignment; Putting it Together; Floating Point

文档信息
资源类别:文库
文档格式:PPT
文档页数:81
文件大小:804KB
团购合买:点击进入团购
内容简介
• Struct • Union • Alignment • Pointer – Declaration – referencing, deferencing – memory allocation, memory free • Buffer overflow • Suggested reading • Stack evaluation • Data movement • Set special data • Arithmetic operation • Comparison • Suggested reading
刷新页面文档预览

Heterogeneous Data Structures Alignment heterogeneous:不同种类的

1 Heterogeneous Data Structures & Alignment * heterogeneous: 不同种类的

Outline Struct Uu nion Alignment -chqp3.93.10

2 Outline • Struct • Union • Alignment – Chap 3.9, 3.10

Structures P191 Group objects into a single object Each ob ject is referenced by name 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 References to structure elements Using offsets as displacements

3 Structures P191 • Group objects into a single object • Each object is referenced by name • 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 • References to structure elements – Using offsets as displacements

Structure P192 struct rect in七11x; /*x coordinate of 1。wer-1 eft corner*/ in七1 /* y coordinate of 1。wer-1 eft corner★ int color /★ Coding ofco1ox*/ int width; /* width (in pixels)*/ int height / Height (in pixels)*/

4 Structure P192 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) */ };

Structure P192 struct rect ri r.11x=x.11y=0; r color oxFFooFF r width = 10; rheight 20;

5 Structure P192 struct rect r; r.llx = r.lly = 0; r.color = 0xFF00FF; r.width = 10; r.height = 20;

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

刷新页面下载完整文档
VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
相关文档