CSCI-UA.0201-003
Computer Systems Organization
Exam 1 Fall 2018 (time: 60 minutes)
Cs计算机代考 Questions vary in difficulty; it is strongly recommended that you do not spend too much time on any one question.
Notes:
- 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.(5 points) Circle the correct answer among the choices given. Cs计算机代考
If you circle more than one answer, you will lose the grade of the corresponding question.
(A) If you write a C program that consists of one C file, then we don’t need a linker:
1.True 2. False 3. depends on OS 4. depends on the hardware
(B) By seeing the following signed number: 0xFF0070FF we know for sure that it is:
- negative int
- negative short int
- negative floating point
- We do not know for sure
(C) Suppose we have a 32-bit machine. The size of “double” is:
- 4 bytes
- 8 bytes
- 2 bytes
- Depends on the compiler. Cs计算机代考
(D) Suppose we have a 64-bit machine. The size of “double” is:
- 4 bytes
- 8 bytes
- 2 bytes
- Depends on the compiler.
(E) If we see a binary file that cannot be opened by a text editor, then it has been generated by (choose the most precise):
- the compiler
- the assembler 3. the linker
- 1 or 2
- 1 or 3
- 2 or 3
2. [6 points] For single precision floating point numbers, calculate the following and show all your steps (correct final answer without steps will not earn you any credits). You can leave your answer at the form: xyz*2abc Cs计算机代考
- The largest positive number (infinity is not counted):
- The smallest positive non-zero number:
3.[8 points] Suppose you want to include this condition in your C code: if( x & mask) x is a char. You want the condition to be true if the third bit from the right of x is set to 1.
- What value mask must have in binary?
- What value mask must have in hexadecimal?
- Suppose x = 1, will the condition be true? Show the value of x, mask, and x & mask in binary to justify.
- What if x = -1? Show the value of x, mask, and x & mask in binary to justify.
4.Suppose we have the following piece of C code (%p in printf just prints the address in hex):
int main() { foo(2); } foo(int x) { printf(“The address of x is %p\n”, &x); foo1(x-1); } foo1(int y) { char k; printf(“The address of y is %p\n”, &y); scanf(“%c”, &k); }
a.[3 points] If x is stored at address A1, and y at address A2, will A1>A2 always be true? Or will A2 > A1 always be true? Or can it sometime go this way and sometimes the other in different executions? Justify your answer. Cs计算机代考
b.[4 points] k in foo1 is a char. Specify the range of numbers that k can present [Hint: You already know whether k is signed or unsigned, so don’t ask!]
c.[2 points] If the user inputs a number larger than the range that k can present, what will happen?
d.[2 points] When we reach the scanf line, how many stack frames exist in the memory?
5. Given the following piece of code: Cs计算机代考
void process(int *x){ int y[10]; x = (int *)malloc(10*sizeof(int)); }
a.[4 points] How many bytes does the array of y[] consume? and how many does x[] consume?
- Array x[] needs:
- Array y[] needs:
b.[4 points] Where in memory is the array y[] stored? and where is x[] stored? (data, text, heap,or stack) Cs计算机代考
- x[] is stored in:
- y[] is stored in:
c.[4 points] What happens to arrays x[] and y[] when the function process() returns?
d.[2 points] Suppose, instead of the malloc(), we want to make x points to array y[]. Write the C statement to do so.
e.[2 points] Why do we need the typecasting with malloc?
f.[4 points] Suppose that, after malloc is executed, x[0] is stored at address 1000. And assume that some extra code is written to initialize the array x[] as follows: x[0] = 0, x[1] = 1, …. till x[9] = 9. So element i of array x contains value i. What are the values stored in the following: