Link Search Menu Expand Document

Page 1

Question 1

  • full credit for nop

Question 2

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

Page 2

Questions 3–6

  • 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 two or more of above problems

extraneous %, 0x, etc OK.

Correct answers:

  • Q3
    • RDX = 0x100000009 (half for the 32-bit register answer 0x9)
  • Q4
    • RSP = 28 (also accept 22)
  • Q5
    • none (condition codes are not program registers)
  • Q6
    • accept RSI = 1110 or RSI = 11110

Page 3

Question 7

This code (a) changes %rsp and (b) jumps to flub. Hence,

  • Full credit for C or H
  • Half credit for G or I
  • No credit for the other options

Question 8

  • full credit for 4
  • half credit for 6

Question 9

  • full for 16, half for 12

Question 10

  • full for our

Page 4

The following errors are in the code:

  • Line 1 does nothing (i.e., unused thereafter)
  • Line 12 uses wrong sizeof
  • Line 21 should be *array not *ans
  • Line pair (12, 23) constitute a memory leak

Question 11

  • full for 22
  • half for any other not-in-loop before-return line (12 through 15)

Question 12

  • full for ans

Question 13

  • blank 1: 18; this is subtle enough, full credit for none as well
  • blank 2: none
  • blank 3: 13, 18, 19
  • blank 4: none
  • blank 5: none
  • blank 6: 12

Page 5

Question 14

An example correct solution:

    int i = 0;
loop:
    if (i >= n) goto end;
    if (i % x == 0) y *= i;
    if (i % x != 0) z += 1;
    i += 1;
    goto loop;
end:

The if/else can be done as either of

    if (i % x == 0) y *= i;
    if (i % x != 0) z += 1;

or

    if (i % x == 0) goto ifcase;
    z += 1;
    goto endif
ifcase:
    y *= i;
endif:

And the loop can be done as either of

    int i = 0;
loop:
    if (i >= n) goto end;
    // if goes here
    i += 1;
    goto loop;
end:

or

    int i = 0;
    goto guard;
loop:
    // if goes here
    i += 1;
guard:
    if (i < n) goto loop;

Page 6

Question 15

  • Should comment freeing a, b, and d (half if one left, 0 if all);
  • Should not comment freeing c (all or nothing)

Question 16

  • Full of L, half for R

Question 17

  • Full of R, half for C

Question 18

  • Full of C

Copyright © 2022 John Hott, portions Luther Tychonievich.
Released under the CC-BY-NC-SA 4.0 license.
Creative Commons License