311143040_系统级编程(B闭)

311143040_系统级编程(B闭)
311143040_系统级编程(B闭)

Problem 1(40 Points) : Multiple choice questions

1. Compared to a sequence of machine code instructions, a fragment of C code

A. describes the actions of the computer, not just of the CPU

B. is the native way to program most computers

C. does not engage any transistors during its execution

D. may describe the same algorithm

2. In c, using default floating point settings, what happens when a floating-point computation results in an overflow?

A. an exception is raised unless disabled by calling _controlfp().

B. an erroneous value is computed and execution continues.

C. a special value "infinity" is computed, testable with _finite().

D. program execution is halted.

3. Programs compiled for an intel pentium processor do not execute properly on a sparc processor from sun microsystems because

A. the operation codes understood by the two processors are different

B. the memory of a sparc cpu is numbered from top to bottom

C. copyrights regarding code cannot be violated

D. the assembly mnemonics for the same "opcode" are different in the two processors

4. When an array passed as an argument to a function, it is interpreted as

A. Number of element of the array

B. Address of the array

C. Address of the first element of the array

D. Value of the first element of the array

5. Consider the following segment of C source code.

int a = 8;

int b = *&a;

What is the value of variable b at the end of execution of the segment?

A. A

B. (int) &a

C. (int) &b

D. &a

6. consider the malloc() function. which one of the following sentences is correct?

A. the malloc() returns the amount of memory allocated

B. the malloc() allocates the desired amount of memory on the stack

C. the malloc() allocates the desired amount of memory on the heap

D. the allocated memory is only local to the function

7. what will be the output ?

#include

void main(){

char *p="hello world!";

int *q;

p++;

q = (int *)p;

q++;

printf("%s%s\n",p,q);

}

A. error

B. ello world! world!

C. hello world!hello world!

D. ello world!llo world!

8. a memory leak is caused by a

A. failure to free allocated memory

B. bug in the memory allocator that fails to free memory

C. function that allocates a large amount of memory from the heap

D. bug in which too much memory is allocated, causing internal fragmentation

9. A garbage collector starts from some "root" set of places that are always considered "reachable", such as

i. CPU registers

ii. stack

iii. global variables

A. i & ii

B. i & iii

C. iii

D. all of them

10. which of the following are useful for observing program performance?

i. direct measurement with a stopwatch.

ii. statistical sampling.

iii. system monitors

A. i and ii only

B. ii and iii only

C. i, ii, and iii

D. i and iii only

11. which of the following is/are related to optimizing program performance by making it

running fast

i. by using faster algorithm

ii. by not using pointer

iii. by using data structure that occupy less memory space

A. ii and iii only

B. i and ii only

C. i, ii, and iii

D. i only

12. what can loader do?

i. translate the c code into machine code

ii. resolution

iii. load or map the executable object file from the disk to memory

A. i and ii only.

B. i and iii only.

C. i, ii and iii.

D. iii only.

13. which of the following manages the transfer of data between the cache and main memory?

A. hardware.

B. compiler.

C. registry.

D. operating system.

14. LRU is an effective cache replacement strategy primarily because programs

A. exhibit locality of reference

B. usually have small working sets

C. read data much more frequently than write data

D. none of the above

15. what is right about trap?

i. it is a kind of exception

ii. it can be used to implement system call

iii. it can be used to implement hard disk interrupt

A. ii only.

B. i and iii only.

C. i, ii and iii.

D. i and ii only.

16. In buflab, a buffer was allocated on the stack. When the user ran the program and typed something in, it was written into the buffer. If the user entered more characters

than the buffer could fit, they could overwrite additional values on the stack. Which of the following regions of the stack could they directly overwrite in this manner?

A. The part of the stack with higher (i.e. larger) addresses than the buffer

B. The part of the stack with lower (i.e. smaller) addresses than the buffer

C. The part of stack with same addresses as the buffer

D. It cannot be determined.

17. a lock is a software mechanism that

A. temporarily makes memory read-only.

B. limits access to a critical section.

C. implements password protection to data.

D. prevents execution except in debug mode.

18. The function foo() is declared in a C program as follows:

void foo(int int_param, char *str_param);

A programmer calls foo() from within the function bar() as follows:

foo(my_int, my_string);

Which of the following is/are true:

A. If foo() changes the value of int_param, the change will propagate back to the calling

function bar(), in other words, the value of my_int will also change.

B. If foo() changes the second character of str_param, the change will propagate back

to the calling function bar(), in other words, the second character of my_string will

also change.

C. If foo() changes the address of str_param to point to a different string, the change

will propagate back to the calling function bar(), in other words, my_string will now

point to a different string.

D. None of the above.

19. What is the output of the following code? Assume that int is 32 bits, short is 16 bits, and the representation is two's complement.

unsigned int x = 0xDEADBEEF;

unsigned short y = 0xFFFF;

signed int z = -1;

if (x > (signed short) y)

printf("Hello");

if (x > z)

printf("World");

A. Prints nothing.

B. Prints "Hello"

C. Prints "World"

D. Prints "HelloWorld"

20. In the following code, what order of loops exhibits the best locality?

// int a[X][Y][Z] is declared earlier

int i, j, k, sum = 0;

for (i = 0; i < Y; i++)

for (j = 0; j < Z; j++)

for (k = 0; k < X; k++)

sum += a[k][i][j];

A. i on the outside, j in the middle, k on the inside (as is).

B. j on the outside, k in the middle, i on the inside.

C. k on the outside, i in the middle, j on the inside.

D. The order does not matter.

Problem 2 (10 Points) : The stack discipline. This problem deals with stack frames in Intel IA-32 machines.

Consider the following C function and corresponding assembly code.

Imagine that a program makes the procedure call even(3). On entry to even(3), the value of esp is 0xffff1000 immediately before the execution of the call instruction.

1.Fill in the stack diagram with the values that would be present immediately before the execution of the ret instruction for odd(0). If a value is unknown, please write UNKNOWN

2.What are the values of esp and ebp immediately before the execution of the ret instruction for odd(0)?

esp = 0x_________________ ebp = 0x_________________

Problem 3(10 Points): Bit operation

Complete the following functions according to the following rules.Each "Expr" is an expression using ONLY the following:

1.Integer constants 0 through 255 (0xFF), inclusive.

2.Function arguments and local variables (no global variables).

3.Some of the problems restrict the set of allowed operators. Y ou are expressly forbidden to:

●Use any control constructs such as if, do, while, for, switch, etc.

●Define or use any macros.

●Define any additional functions in this file.

●Call any functions.

●Use any other operations, such as &&, ||, -, ?, or [] :

●Use any form of casting.

4.Y ou may assume that your machine:

●Uses 2s complement 32-bit representations of integers.

●Performs right shifts arithmetically.

●Has unpredictable behavior when shifting an integer by more than the word size.

/*

* bitAnd - x&y using only ~ and |

* Example: bitAnd(6, 5) = 4

* Legal ops: ~ |

* Max ops: 8

* /

int bitAnd(int x, int y) {

}

Problem 4 (10 Points): Dynamic Memory Allocation

Define your own version of memory allocator my_malloc and my_free by wrapping malloc and free functions. Use a linked list to keep track of the allocated blocks and implement a function to calculate the total size of allocated memory.

Problem 5 (10 Points): What is timer? Please give a description of the different levels of time in the computer system, such as time in hardware, OS and Application.

Problem 6(10 Points): Cache

In this problem, you are asked to simulate the operation of a cache. Y ou can make the

●There is only one level of cache

●Physical addresses are 8 bits long (m = 8)

●The block size is 4 bytes (B = 4)

●The cache has 4 sets (S = 4)

●The cache is direct mapped (E = 1)

A. What is the total capacity of the cache? (in number of data bytes)

B. B. How long is a tag? (in number of bits)

C. Assuming that the cache starts clean (all lines invalid), please fill in the following tables,

describing what happens with each operation. Addresses are given in both hex and binary for your convenience.

Problem 7 (10 Points): Linking

In the tiny-linker lab, you are to implement a two-pass linker in c. Input consists of a series of object modules, each of which contains three parts: definition list, use list, and program text. The following is one of the input files. Do the linking process manually, and fill up the blanks in the output file.

The input file:

1 ab 2

1 c 4

5 R 1004 I 5678 E 2777 R 8002 E 7002

1 c 3

6 R 8001 E 177

7 E 1001 E 3002 R 1002 A 1010

1 c 1

2 R 5001 E 4777

1 c 1

1 ab 2

3 A 8000 E 1777 E 2001

The output file: Symbol T able ab=2

c=14

Memory Map 0: _______ 1: 5678

2: _______ 3: _______ 4: _______ 5: _______ 6: _______ 7: _______ 8: _______ 9: _______ 10: 1010

11: _______ 12: 4014

13: 8000

14: 1002

15: 2002

相关主题
相关文档
最新文档