CSCI-UA.0201-001
Computer Systems Organization
Exam 1 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. (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) If we write a C program that consists of 5 C files. The output of the assembler will be: 1. five files 2. one file 3. depends on the type of the compiler 4. depends on OS
(B) By seeing the number: 0xFFFF700B we know for sure that it is a: 1. negative number 2. positive number
3. unsigned number 4. We do not know for sure
(C) Suppose we have a 32-bit machine. The size of “long int *” is: 1. 4 bytes 2. 8 bytes
3. 2 bytes 4. Depends on the OS.
(D) Suppose we have a 64-bit machine. The size of “long int *” is: 1. 4 bytes 2. 8 bytes
3. 2 bytes 4. Depends on the OS.
(E) If we write a C program that includes a parenthesis that we opened but forgot to close. Then:
1. the compiler will complain 2. the assembler will complain 2. the linker will complain 3. the loader will complain
2. [4 points] We have seen that the floating point presentation has normalized form and denormalized form. State two reasons we need denormalized form. Every reason must not be more than one sentence.
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 left of x is set to 1.
• What value mask must have in binary?
• What value mask must have in hexadecimal?
• Suppose x = 5, will the condition be true? Show the value of x & mask in binary to justify.
• What if x = -5? Show the value if x in binary to justify.
4. Suppose we have the following piece of C code (%p in printf just prints the address in hex):
void foo(int i) {
char a[2]; double d= 3.14;
a[i] = 0xFFFFABCD;
printf(“%d”, d);
a. [2 points] How many bytes does array a require?
b. [2 points] Suppose array a is stored at address A1. What is the address of a[0]? What is the address of a[1]?
c. [3 points] Suppose array a is stored at address A1. Will variable d always be stored in memory after array a? Justify.
d. [3 points] Something is wrong with the line: a[i] = 0xFFFFABCD; What is it?
e. If we call the function foo as follows: foo(2); • [3 points] What will happen?
• [3 points] Will this affect the value of d? Justify
5. Given the following C code:
int compute(int a, int b) {
while (b != 0) {
c = (a & b) << 1;
a=a^b; b=c;
return a; }
a. [4 points] Suppose the two inputs to the above function are: a = 10 and b = 20 What will the function return (both in decimal and in binary)?
b. [3 points] Given the above two inputs ( a= 10, b = 20), how many times will the above loop execute? For each iteration, write down the value of c.
c. [4 points] Assume x = 5 and we call compute(~x, 1), what will be the value returned (in binary and decimal). [Hint, you can use dots “...” to represent repeated bits when you state the binary result]
d. [6 points] Suppose we have two pointer int * k and int * m declared inside compute. Write three statements: one to make k point to a, the second to make m points to be, and the third to execute statement a=a^b; using only k and m.
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com