Last name:
CSCI-UA.0201-003
Computer Systems Organization
Midterm Exam – Fall 2014 (60 minutes)
Copyright By PowCoder代写 加微信 powcoder
First name:
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.
This exam is open book/notes.
1. (4 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) Registers usage convention is needed to:
1. make our programs correct
2. make our programs faster
3. make our programs work with other programs and library 4. make our programs more memory efficient
(B) Presenting +17 in signed integer or in IEEE 754 single precision floating point yields the same bit pattern.
1. The above statement is true
2. The above statement is false
3. It depends on whether the machine is 32-bit or 64-bit
4. It depends on whether the machine is big-endian or little endian.
(C) Which of the following has a larger size (in terms of bytes), assuming 32-bit machine?
1. pointer to a character 2. pointer to an integer 3. pointer to a float 4. pointer to pointer
5. They are all of the same size.
(D) Assume a function is called from two different places in a C program running on a 32-bit x86 machine:
1. The stack frame of that function is of the same size each time.
2. The stack frame size of that function differs based on the arguments.
2. Given the following structure definition (assume 32-bit machine): struct {
char c; double *p; int i; double d; short s; } mystruct;
We said in class that a data item of size x must be stored in memory in an address multiple of x. We called this alignment.
a) (3 points) Fill out the following memory snapshot, showing how the structure items are placed in memory, including padding (if any). You start from address 0 (far left of the figure). You must show at which address every item starts and ends, where are the padding (if any), and the total number of bytes taken by the whole structure.
0 1 2 3 4 5 6 7 8 9 1011121314151617181920 2122232425262728293031
b) (3 points) Can we re-order the items of the structure to take less space? If yes, fill the figure below showing the new order and the total space taken by the structure. If not, explain why.
0 1 2 3 4 5 6 7 8 9 1011121314151617181920 2122232425262728293031
3. (4 points) State two scenarios where (some) local variables of a function must be in the stack and not in registers?
Scenario 1:
Scenario 2:
4. For the following two functions (assume n >= 0):
(a) (2 points) What does the function fact do?
(b) (2 points) For which values of n do fact and fact_u2 produce similar results?
(c) (2 points) What is the minimum modification that we can do to fact_u2 such that it always produces same result as fact?
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com