CS代考 CSCI-UA.0201-003

CSCI-UA.0201-003
Computer Systems Organization
Final Exam Fall 2014 (75 mins) Last name: First name:
 If you perceive any ambiguity in any of the questions, state your assumptions clearly

Copyright By PowCoder代写 加微信 powcoder

 Questions vary in difficulty; it is strongly recommended that you do not spend too much
time on any one question.
 This exam is open book/notes
1. (5 points) Circle the correct answer among the choices given. If you circle more than one answer, you will lose the grade of the corresponding question.
(A) A cache memory is needed:
1. To make virtual memory work correctly 2. Because the disk is very slow
3. Because the memory is very slow
4. Because the memory size is not enough
(B) If the system memory is huge (i.e. as big as we need), then
1. We do not need virtual memory 2. We still need virtual memory
3. May need or not need virtual memory depending on the application types
(C) The machine code generated by the compiler is machine dependent
1. This statement is correct 2. This statement is wrong
3. This statement is correct or wrong depending on the operating system
(D) The presence of critical section may result in:
1. deadlock 2. performance loss 3. wrong result 4.all of them
(E) Semaphores are needed the most when we have: 1. Several threads not sharing any variables
2. Several threads sharing a lot of variables
3. Several threads sharing read only variables
4. Only single thread and no concurrency

2. (8 points) Suppose we have a pointer to an integer, and we use that pointer to allocate (using malloc) an array of 100 integers. For each one of the following scenarios indicate if this scenario is possible. If it is possible, write the few C lines that implement it (no need to write full functions, just the 1 or more lines needed). If it is not possible, indicate the reason. Make any assumptions you find necessary.
a. The pointer to the array is in the stack and the array is in the heap
b. Both the pointer to the array and the array itself are in the heap
c. Both the pointer to the array and the array itself are in the stack
d. The array is in the stack and the pointer to the array is in the heap
3. (4 points) Virtual memory system has problems related to speed (need to go to memory twice for any memory access) and size (page table is huge). Explain in 1-2 sentences how designers overcome these two problems

4. (2 points) Consider the source code below, where M and N are constants defined with #define.
int array1[M][N]; int array2[N][M];
int copy(int i, int j) {
array1[i][j] = array2[j][i]; }
Suppose the above code generates the following assembly code:
pushl %ebp
movl %esp, %ebp
pushl %ebx
movl 8(%ebp), %ecx movl 12(%ebp), %ebx leal (%ecx,%ecx,8), %edx sall $2, %edx
movl %ebx, %eax
sall $4, %eax
subl %ebx, %eax
sall $2, %eax
movl array2(%eax,%ecx,4), %eax movl %eax, array1(%edx,%ebx,4) popl %ebx
movl %ebp, %esp popl %ebp
What are the values of M and N? Show all the steps. Final answer without correct steps is a zero.

5. Consider a small 2-way set associative cache with a total of 32 blocks and a block size of 16 bytes. The cache uses LRU replacement policy. Assume that the cache is initially empty. The CPU accesses the following memory locations, in that order (you can deduce the address length from the addresses given below):
0x55c78, 0x557b4, 0x547bc, 0x557b0, 0x55774, 0x55c70, 0x567b8, 0x54778.
(a) (3 points ) Show how is the address split as TAG, SET, and OFFSET (i.e. how many bits for each).
(b) (8 points) For each memory reference, indicate whether it will result in hit or miss.

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com