Midterm-spring-2012 - Name RUID Number Section(1 T 8:55am(2 T 5:15pm(3 Th 3:35pm CS 211 Computer Architecture Midterm I Spring 2012 Instructor Thu D

Midterm-spring-2012 - Name RUID Number Section(1 T 8:55am(2...

  • Rutgers University
  • CS 211
  • Test Prep
  • HimadriB
  • 11
  • 75% (8) 6 out of 8 people found this document helpful

This preview shows page 1 out of 11 pages.

You've reached the end of your free preview.

Want to read all 11 pages?

Unformatted text preview: Name: RUID Number: Section: (1) T 8:55am ____ (2) T 5:15pm ____ (3) Th 3:35pm ____ CS 211 Computer Architecture Midterm I Spring 2012 Instructor: Thu D. Nguyen Instructions: • • • • • • • Do not open the test until we tell you to start. Write your name and student number, and choose your section, in the above space NOW. Exam is closed book. You may use a calculator, but only for +, -­‐, *, /, power, and log. (You should not need log.) If you complete the test before 2:50pm, you may hand in the test and leave. Otherwise, please stay in your seat and wait for everyone to finish and hand in the test in an orderly fashion. There are 5 questions totaling 75 points. Show as much of your work as you can. Partial credit is possible for incorrect answers, but only if you show the intermediate steps so we can see what went wrong. Page 1 Problem 1. Number Conversion. 24 points. Fill out the following tables by converting the given number to the appropriate base. All numbers are positive. Binary 1011110001 Octal Decimal Hexadecimal 453 568 ABC Binary 101.1011 Octal Decimal Hexadecimal 12.41 23.53125 B.8A Page 2 Problem 2. C Programming and Data Representation. 10 points. a. What would the following snippet of code print if the character `a’ is encoded in ASCII as the value 0x61. (The 0x indicates that the number is a hexadecimal number. The %x in a printf prints out a given number in hexadecimal.) char a[5] = “aaaa”; printf(“0x%x\n”, *((int*)a)); b. Complete the following function by doing two things: (1) identify the C programming error and correct it, and (2) fill in the expression for “overflow condition”. The function is meant to add two integers, return the sum in the parameter sum, and return -­‐1 if there was an overflow, 0 otherwise. (Ignore tiny syntax errors if there is any; those are not what we are looking for.) int add2I(int x, int y, int sum) { sum = x + y; if (overflow condition) { return -1; } return 0; } Page 3 c. What is wrong with this code? char *strcpy(char *s) { char *d; int i, len; len = strlen(s); for (i=0; i<len; i++) { d[i] = s[i]; } d[i] = ‘\0’; return d; } d. What is wrong with this code? /* print numbers from 1 to 10 */ int i; for (i=0; i=10; i++) { printf(“%d …”, i); } printf(“\n”); Page 4 Problem 3. Two’s Complement Arithmetic. 9 points. Fill in the following table. All numbers are 10 bits, two’s complement. Result should be 10 bits, two’s complement. Result (10 bits) 0111001111 + 0011011010 0100111101 -­‐ 0110011010 1111110011 * 0000000011 Overflow (y/n)? Page 5 Problem 4. Data Representation. 12 points. a. Fill in table: Decimal 10-­‐bit 1-­‐complement 10-­‐bit 2-­‐complement 45 -­‐33 b. Give the decimal numbers in scientific notation corresponding to the following 32-­‐bit IEEE 754 representations. As a reminder: • Normalized form: 0x0 < exponent < 0xFF, Bias 127, “implied leading one” • Denormalized form: exponent = 0, Bias 127. Your calculator may not have the precision to calculate part d. In this case, you may write the expression (e.g., 1 x 2-­‐6 + 1 x 2-­‐12 + …) that would correctly compute the decimal number. a. b. c. d. 0 10000100 00001100000000000000000 1 10000001 01101000000000000000000 1 00000000 00000000000000000000000 0 00000000 10100000000000000000000 Page 6 Blank page for extra space. Page 7 Problem 5. Assembly Language Programming. 20 points. a. Given the following content of three registers: %eax: 5 %edx: 10 %ebp: 8450 what do the following two lines of assembly code do? addl %edx, %eax movl %eax, 8(%ebp) Page 8 b. Tell us: i. What do the two lines marked with ?? (that is, the ones with instructions movss and cvttss2si) do? You do not need to give the exact meaning of the instructions; just deduce and tell us what they are logically doing. (Hints: (1) %xmm0 is a register; and (2) the C code where foo() is invoked gives some important information.) ii. The equivalent C code for foo. foo: pushl movl subl %ebp %esp, %ebp $8, %esp ; function entry setup movss cvttss2si 8(%ebp), %xmm0 %xmm0, %eax ; ?? ; ?? subl 12(%ebp), %eax ; subtract two integers leave ret ; function exit cleanup ; return value in %eax /* C code giving example of how “foo” is called */ int z, x; float y; … z = foo(y, x); Page 9 c. Give the C equivalent for the following assembly code. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 _bar: pushl movl subl %ebp %esp, %ebp $24, %esp ; function entry setup movl movl movl cmpl jg movl jmp 8(%ebp), %eax %eax, -4(%ebp) -4(%ebp), %eax $0, %eax LBB1_2 $0, -12(%ebp) LBB1_3 ; ; ; ; ; ; ; copy ?? to %eax copy %eax to memory (where?) copy memory (where?) to %eax compare %eax to 0 jump to LBB1_2 if ?? copy ?? to memory (where?) jump to LBB1_3 movl subl movl call movl addl movl -4(%ebp), %eax $1, %eax %eax, (%esp) _bar -4(%ebp), %ecx %ecx, %eax %eax, -12(%ebp) ; ; ; ; ; ; ; copy memory (where?) to %eax decrement %eax copy %eax to memory (where?) recursively call _bar copy memory (where?) to %ecx %eax <- %ecx + %eax copy %eax to memory (where?) movl movl movl -12(%ebp), %eax %eax, -8(%ebp) -8(%ebp), %eax ; copy memory (where?) to %eax ; copy %eax to memory (where?) ; copy memory (where?) to %eax addl popl $24, %esp %ebp ; clean up for function exit LBB1_2: LBB1_3: ret ; return value is in %eax Page 10 Blank page for extra space. Page 11 ...
View Full Document

  • Spring '08
  • Chakraborty
  • Return statement, len, eax, D.  Nguyen

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture