四川大学系统级编程-2017-A卷答案

2017F-SLP-A卷答案

一.每题2分,共40分 BACBD ACAAC DADAB CBDBB

二. 每题5分,共10分 int NegativeNum (int x) {

return ~((~x) & (~0x80000000)); }

int SetByte (int x,int n) {

return x|(0xFF <<(n<<3)); }

三.共13分

9分(每两个填空1分)

+--------------------------------+

| unknown | 0xffff1004 +--------------------------------+

| 3 | 0xffff1000 +--------------------------------+

| unknown | 0xffff0ffc +--------------------------------+

| unknown | 0xffff0ff8 +--------------------------------+

| unknown | 0xffff0ff4 +--------------------------------+

| 2 | 0xffff0ff0 +--------------------------------+

| 0x08048407 | 0xffff0fec +--------------------------------+

| 0xffff0ff8 | 0xffff0fe8 +--------------------------------+

| unknown | 0xffff0fe4 +--------------------------------+

| 1 | 0xffff0fe0 +--------------------------------+

| 0x08048432 | 0xffff0fdc +--------------------------------+

| 0xffff0fe8 | 0xffff0fd8 +--------------------------------+

| unknown | 0xffff0fd4 +--------------------------------+

| 0 | 0xffff0fd0 +--------------------------------+

| 0x08048407 | 0xffff0fcc +--------------------------------+

| 0xffff0fd8 | 0xffff0fc8 +--------------------------------+

| 0 | 0xffff0fc4 +--------------------------------+

| unknown | 0xffff0fc0 +--------------------------------+

esp: 0xffff0fcc (2分)

ebp: 0xffff0fd8 (2分)

四.共12分 Code min max incr square A 1 91 90 90 B 91 1 90 90 C 1 1 90 90

This problem illustrates some of the subtle effects of memory aliasing, and it cannot be used to swap two values (2 scores).

As the commented code below shows, the effects will be to set the value at xp to zero when xp equals to xy. 1 *xp = *xp + *xp; // 2x

2 *xp = *xp - *xp; // 2x – 2x = 0

3 *xp = *xp - *xp; // 0 – 0 = 0 (4 scores)

This example illustrates that our intuition about program behavior can often be wrong. We naturally think of the case where xp and yp are distinct but overlook the possibility that they might be equal. Bugs often arise due to conditions the programmer does not anticipate.

五.

1. (5分)答:如编译执行环境是逐行访问内存,如C语言,则此代码有良好的空间局部性。如果如编译执行环境是逐列访问内存,如matlab, 且N较大,则该代码需跨行读取数据,则此代码 空间局部性就较差。

2. (10分)

A. 16*16*4

B. 256, 每行一个cold miss

C. 25%, 每4个整数产生一个cold miss D. 25%, cache 大小没有什么影响

六.

1. 【备注:非标准化考试】

1)CSAPP:

中文:computer system: a programmer’s perspective 英文:深入理解计算机系统

2)可以(不限于)从下面的角度

A)整个计算机系统的核心部件:软件(如编译器和OS)和硬件(CPU、存储系统登)

B)程序的生命周期

2.

1)概念:An exception is an abrupt change in the control flow in response to some change in the processor’s state.(说明:以上是教材/授课课件的答案。也可以用中文)

2)类型:四个

英文:interrupt,trap,fault,abort 中文:中断,陷入,故障,终止 3)画图:可以用下面的任何一个 A)

B)

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4