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 point to allocate (using malloc) an array of 100 integers. For each one of the following scenarios indicated 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.
a. The pointer is in the stack and the array is in the heap ptr = (int *)malloc(100*sizeof(int));
b. Both the pointer and the array are in the heap
int ** ptr;
ptr = (int **)malloc(sizeof(int *)); (*ptr) = (int *)malloc(100*sizeof(int));
c. Both the pointer and the array are in the stack
Can’t happen, malloc allocates in heap, but the pointer can be a local variable in stack.
d. The array is in the stack and the pointer is in the heap Can’t happen, malloc allocates in heap.
3. (4 points) Virtual memory system has problems related two 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
sizemulti-level page table speed TLB
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.
M= 15 and N = 9
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).
offset needs 4 bits (blk size = 24)
#sets = 32/2 = 16 = 24also 4 bits for the set
The address length is 20 bits (5 hexadecimal digits as seen in the addresses) tag needs 12 bits
(b) (8 points) For each memory reference, indicate whether it will result in hit or miss.
TAG SET H/M 55c 7 M 557 b M 547 b M 557 b H 557 7 M 55c 7 H 567 b M 547 7 M
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com