This page does not represent the most current semester of this course; it is present merely as an archive.

1 Page 2

Question 1

  • full credit for mentioning condition codes
  • half credit for nop
  • none for incorrect statements

Question 2

  • full credit for nop
  • none for incorrect statements

2 Page 3

Questions 3–7

  • Full credit for getting the right answer.
  • Partial for one of
    • having one extra modification
    • missing the modification
    • having the wrong value in the correct register
    • having the wrong register with the correct value
  • No credit if have tow or more of above problems

extraneous %, 0x, etc OK.

Correct answers:

  • Q3
    • RAX = 190
  • Q4
    • RSP = 1F8 or 192 or 198 (full for any of the three: hex conversion was not the point of this question)
  • Q5
    • RSP = 208
  • Q6
    • RDI = 120
  • Q7
    • RDX = 1C3F5678 (also accept 21C3F5678)

3 Page 4

> It became clear that we either failed to teach the error detection topics adequately or there was some unnoticed ambiguity in the questions about it; as a consequence, we added 0.75 to every score on each of the questions on this topic to help correct our failure, whichever one it was.

Question 8

  • full credit for D
  • half credit for C
  • no credit for the others

Question 9

  • full for none
  • half for T or L

Question 10

  • full for T

Question 11

  • full for P
  • Also accept “none” if accompanied by explanation about not being wrong in comments, strings, etc

Question 12

  • full for L
  • half for T

Question 13

  • full for 7

4 Page 5

Question 14

  • full for 20
  • half for 8

Question 15

  • full for 16
  • half for 14

Question 16

The bug is the malloc is too small; it should have a sizeof(int) term. This creates a second bug: we could go off the end of the array (heap buffer overflow) both in the copying loop and potentially in every other access to s.data[index].

The leak is fixed by adding a free(s.data) after the for and before the s.data = tmp;.

Graded in four parts:

  • Q16 found bug
    • full if identify either (a) the malloc or (b) every s.data[index] (there are three of them)
    • partial for identifying just one s.data[index] or the memory leak
  • Q16 explained bug
    • full if description suggests they understand why what they identified is wrong
    • partial if description unclear (e.g., “missing sizeof” without why)
  • Q16 fixed leak
    • full if free(s.data)
    • partial if free(tmp) – note there is no non-buggy way to do this, so they miss the next points too
  • Q16 leak fix not buggy
    • full if free in correct place
    • partial if free before or in loop or after s.data = tmp

5 Page 6

Question 17

The set of correct solutions includes

do {
    y += 1;
    if (x&1) {
        x *= 3;
        x += 1;
    } else {
        x >>= 1;
    }
} while (x > 1);

There are other solutions; for example,

y += 1; x = (x%2==0) ? x/2 : x*3+1;
while (x>1) { y += 1; x = (x%2==0) ? x/2 : x*3+1; }

… as well as things like for(;;) with an internal break, etc.

Don’t be picky on ;, etc., unless expressly called out below.

Graded in three parts:

  • Q17 goto-free C
    • full if
      • no goto or labels
      • no loop-breaking ; like(...);{ or do{ ... }; while
      • no major (more than delimiter) mistakes
    • partial if just one of the above mistakes
    • none if two or more of the above
  • Q17 if case
    • full if
      • there is an if/else (or two complimentary if, etc)
      • the x-is-odd case has the *3+1 and the even has the >>1 (or equivalent)
    • partial if missing/always does one case or has the two backwards
  • Q17 do-loop semantics
    • full if both
      • is a loop
      • does the body once before first check
      • terminates on the right conditions
    • partial if a loop with one of the other two cases
    • none if not a loop, or both check-first and wrong-condition