CSCI-UA.0201-001
Computer Systems Organization
Exam 2 Fall 2018 (time: 60 minutes)
Last name: First name: NetID:
Copyright By PowCoder代写 加微信 powcoder
If you perceive any ambiguity in any of the questions, state your assumptions clearly.
Questions vary in difficulty; it is strongly recommended that you do not spend too much time
on any one question.
The exam consists of 5 pages, 5 questions, and a total of 50 points. Last paper is left
intentionally blank, for you to use if you want.
You answer on the question sheet.
1. (6 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) When you have an unsigned long in your C program, the compiler will use what type of instruction when it generates the x86 assembly?
1. movb 2. movl 3. movq 4. movw
(B) If we have three processes currently being executed in the system, how many caches does the system currently have, assuming the system uses one-level cache?
1. one 2. two 3. three 4.four
(C) The dynamic memory allocator does not need to keep track of allocated blocks in the heap. This statement is:
1. True 2. False 3. Depends on programming language
(D) If a process has a 1MB heap and another process has 100KB heap. Assume the dynamic memory allocator used by both processes uses implicit list. Which statement of the following is true?
1. The memory allocator for the 1MB heap will be slower.
2. The memory allocator for the 100KB heap will be slower.
3. We cannot tell for sure.
4. Depends on the original programming language used in each process.
(E) The page table is accessed with:
1. virtual address 2. physical address 3. depends on the OS 4. depends on the compiler
(F) If we keep the total cache size fixed, and increase the associativity and the block size. The number of sets
1. increases 2. decreases 3. stays fixed
2. [10 points] Given the following x86_64 assembly code and its corresponding C code, fill- in the blanks in the corresponding C code. Also on the far right, fill in the correspondence between each register and its corresponding variable in C.
movl %edi, %eax
cmpl $9, %edi jle .L5
movl $0, %edx
cmpl $99, %edx
jle .L4 ret
%edx, %eax $1, %edx
int compute(int x){ int i ;
int sum = ________;
if(__________)
for(_______; ______; _____)
{_______________;}
sum = ________;
return sum; }
edi edx eax
a. [3 points] The instruction movl $0, %edx puts a zero in edx. Write three other instructions to put 0 in edx (i.e. find three other different ways to put zero in edx and each way is only one instruction).
b. [2 points] Suppose the function compute() was called by main(). During the execution of compute, how many stack frames exist in the stack? What are they (or what is it)?
3. Suppose we have a cache memory of 4096 blocks (i.e. 212 blocks).. The address length is 32 bits. The block size is 16 bytes and the cache is 16 way set associative.
a. [3 points] Show how the address is split into tag, set index, and offset.
b. [3 points] Suppose the above cache has an access time of 2 cycles and the main memory access time is 100 cycles. When executing a program, we found that the average memory access time is 22 cycles. What is the cache hit rate for this program?
c. [2 points] Does the cache have to use replacement policy whenever there is a cache miss? Justify.
d. [1 point] Can two blocks in the cache have the same TAG?
e. [1point] Is the cache accessed with physical address? or virtual address?
4. For each of the following problems, write one x86 instruction that does the action specified in the corresponding problem.
(a) [3 points] Assume the y (of type long) is stored in register rbx. Put 8y in register rbx without using multiplication operation.
(b) [3 points] Set the sign flag to 1
(c) [3 points] Set the most significant bit (i.e. left most) of eax to 1.
(d) [3 points] Set the least significant bit and the most significant bit of eax to 1
(e) [3 points] execute x = a[i] where x is of type int, a[] is an array of int store in memory starting from address 0xA000000000000000. Assume x is in rax and i (also an int) is in ebx.
5. For the following piece of code:
void par() {
if (fork() != 0) {
fork(); printf(“3”); }
else{ fork();
printf(“4”); }
int main() { par();
printf(“1”);
exit(0); }
a. [2 points] How many times will the digit “1” be printed?
b. [2 points] How many stacks exist in the system just before any process exits?
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com