CS代考 CSCI-UA.0201-003

CSCI-UA.0201-003
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 int 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 heaps does the system currently have?
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 TLB 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. The number of sets 1. increases 2. decreases 3. stays fixed
4. depends on whether we will change block size or not.

2. Suppose we have a cache memory of 32 blocks. The address length is 32 bits. address is divided as follows:
* 5 bits for the offset * 4 bits for the set
(a) [3 points] What is the associativity of that cache?
(b) [3 points] What is the block size?
(c) [3 points] What is the total cache size in bytes [leave it in the form of 2x]?
(d) [3 points] Suppose the main memory access time is 200 cycles and the cache has an access type of 2 cycles. The cache hit rate is 80%. What is the average memory access time?
(e) [3 points] Based on what you calculated in (d) above, did the system benefit from having a cache or not? Justify.

3. [6 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.
cmpl %esi, %edi
subl leal ret
(%rdi,%rsi), %eax
%edi, %esi 10(%rsi), %eax
int square(int a, int b ) { int sum = _______;
if( a > b)
sum = ___________;
else _________________;
return sum; }
edi esi eax
a. [2 points] Even though all the variables are int, in the above example, and hence we use the e- version of registers (e.g. eax, edi, etc) yet, there two leal instructions above use the r-version of the registers in the source part, why?
b. [1 point] How many times does the instruction leal 10(%rsi), %eax access memory?

4. For the following piece of code:
void par() {
if (fork() != 0) {
fork(); printf(“3”); }
else printf(“4”);
int main() { printf(“1”);
par(); printf(“2”); exit(0);
a. [2 points] How many times will the digit “2” be printed?
b. [2 points] How many processes exist in the system just before any process exits?
c. [4 points] Based on your answer in part b above, and assuming the OS uses one-level page table and one-level cache, indicate how many of each of the following exist in the system just before any process exits.
• Page Table: • MMU:

5. For each of the following problems, write one x86 instruction that does the action specified in the corresponding problem.
(a) [3 points] Assume the unsigned long x is stored in register rax. Put 9x in register rbx without using multiplication operation.
(b) [3 points] Set the zero flag to 1
(c) [3 points] Set the least significant bit (i.e. right most) of rax to 1.
(d) [3 points] Set the least significant bit and the most significant bit of eax to 0

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