CS代写 CSCI-UA.0201-001

CSCI-UA.0201-001
Computer Systems Organization
Midterm Exam Fall 2015 (time: 60 minutes) Last name: First name:
 If you perceive any ambiguity in any of the questions, state your assumptions clearly.

Copyright By PowCoder代写 加微信 powcoder

 Questions vary in difficulty; it is strongly recommended that you do not spend too much time
on any one question.
1. [1 point] Why do we need to know such information as an integer is 4 bytes in length?
2. [2 points] Beside dynamic allocation, state two other reasons as to why do we need pointers.
3. [4 points] The following C code is buggy. List all the bugs you can find. No need to fix them.
struct _node{ int x;
int populate_list( int M){
struct _node employees;
employees = malloc(M * sizeof(struct _node *));
for( i = 0; i < M; i++){ employees[i].x = i; employees[i].y = i*2; } 4. [2 points] Can the zero flag (ZF) and the sign flag (SF) be both 1 at the same time? If yes, give an example of an operation that does this (no need for assembly code, just describe the operation). If not, explain why not. 5. [2 points] State two reasons for why do we need an assembler and not making the compiler generate the binary presentation right away. 6. [4 points] Suppose we have the following C code (assuming a, b, and b are unsigned integers): if( a == b && b > c) c += a + b;
Write the corresponding assembly code, assuming: a will go in %eax, b in %ebx, and c in %ecx)

7. Suppose x is an integer (i.e. 4 bytes). We want to test whether the 3rd least significant bit of x is 1 or not (i.e. the 3rd bit from the right), so we wrote the expression:
if( (x & mask) != 0)
a. [1 point] What is the value of mask, both in binary and hexadecimal?
b. [2 points] Which of the following expressions generate correct mask? Circle ALL correct answers. There may be more than one correct answer, or there may be none!
 1 << 3  1 << 2  two’s complement of 0xFFFFFFFC  two’s complement of (-2) c. [2 points] Please give the expression that sets the 3rd bit from left of x to 1 and leave all the other bits unchanged. 程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com