Computer Systems: A Programmer's Perspective (3rd Ed.)

csapp3e-cover.jpg

Part I: Program Structure and Execution

  • [X] 1. A Tour of Computer Systems p.1
  • [-] 2. Representing and Manipulating Information p.31
  • [ ] 3. Machine-Level Representation of Programs p.163
  • [ ] 4. Processor Architecture p.351
  • [ ] 5. Optimizing Program Performance p.495
  • [ ] 6. The Memory Hierarchy p.579

Part II: Running Programs on a System

  • [ ] 7. Linking p.669
  • [ ] 8. Exceptional Control Flow p.721
  • [ ] 9. Virtual Memory p.801

Part III: Interaction and Communication between Programs

  • [ ] 10. System-Level I/O p.889
  • [ ] 11. Network Programming p.917
  • [ ] 12. Concurrent Programming p.971

Practice Problems

Practice Problem 2.1 (solution page 144)

  1. 0x39A7F8 to binary

    3 9 A 7 F 8
    0011 1001 1010 0111 1111 1000
  2. 1100100101111011 to hexadecimal

    1100 1001 0111 1011
    C 9 7 B
  3. 0xD5E4C to binary

    D 5 E 4
    1101 0101 1110 0100
  4. 1001101110011110110101 to hexadecimal

    0010 0110 1110 0111 1011 0101
    2 6 E 7 B 5
  5. bonus: 2048 to hex
    • \(2048=2^x\)
    • \(log_2(2048)=11\)
    • \(2048=2^{11}\)
    • \(2^{11}=2^{i+4j}\)
    • \(11=i+4j\)
    • \(11=3+4*2\)
    • 0x800

      8 0 0
      1000 0000 0000
  6. bonus: 512 to hex
    • \(512=2^x\)
    • \(log_2(512)=9\)
    • \(2048=2^{9}\)
    • \(2^{9}=2^{i+4j}\)
    • \(9=i+4j\)
    • \(9=1+4*2\)
    • 0x200

      2 0 0
      0010 0000 0000
  7. bonus: 32 to hex
    • \(32=2^5\)
    • \(2^{5}=2^{i+4j}\)
    • \(5=i+4j\)
    • \(5=1+4*1\)
    • 0x20

      2 0
      0010 0000

Practice Problem 2.2 (solution page 144)

\(n\) \(2^n\) \(2^n\) (hexadecimal) \(n=i+4j\)
9 512 0x200 \(9=1+4*2\)
19 524288 0x80000 \(19=3+4*4\)
14 16384 0x4000 \(14=2+4*3\)
16 65536 0x10000 \(16=0+4*4\)
17 131072 0x20000 \(17=1+4*4\)
5 32 0x20 \(5=1+4*1\)
7 128 0x80 \(7=3+4*1\)

Practice Problem 2.3 (solution page 144)

Decimal Binary Hex \(x=q*16+r\)
0 0000 0000 0x00 \(0=0*16+0\)
167 1010 0111 0xA7 \(167=10*16+7\)
62 0011 1110 0x3E \(62=3*16+14\)
188 1011 1100 0xCB \(188=11*16+12\)
55 0011 0111 0x37 \(55=3*16+7\)
136 1000 1000 0x88 \(136=8*16+8\)
243 1111 0011 0xF3 \(243=15*16+3\)
82 0101 0010 0x52 \(x=5*16+2\)
172 1010 1100 0xAC \(x=10*16+12\)
231 1110 0111 0xE7 \(x=14*16+7\)

Practice Problem 2.4 (solution page 144)

  1. 0x503c + 0x8 = 0x5044
  2. 0x503c – 0x40 = 0x4ffc
  3. 0x503c + 64 = 0x507c
  4. 0x50ea – 0x503c = 0xae

Practice Problem 2.5 (solution page 144)

int val = 0x87654321;
byte_pointer valp = (byte_pointer) &val;
show_bytes(valp, 1); /* A. */
show_bytes(valp, 2); /* B. */
show_bytes(valp, 3); /* C. */
  1. Little endian: 21 Big endian: 87
  2. Little endian: 21 43 Big endian: 87 65
  3. Little endian: 21 43 65 Big endian: 87 65 43

Practice Problem 2.6 (solution page 145)

  1. 0x00359141 00000000001 101011001000101000001
    0x4A564504 → 010010100 101011001000101000001 00
  2. Shifting the second string right by two positions gives 21 matching bits
  3. The most significant bit of the integer doesn't match the bit in the the float

Practice Problem 2.7 (solution page 145)

a b c d e f
0x61 0x62 0x63 0x64 0x65 0x66

Practice Problem 2.8 (solution page 145)

Operation Result
a 0110 1001
b 0101 0101
~a 1001 0110
~b 1010 1010
a & b 0100 0001
a | b 0111 1101
a ^ b 0011 1100

Practice Problem 2.9 (solution page 146)

  1. Color complements.

    R G B Color R' 'G' 'B' Color'
    0 0 0 Black 1 1 1 White
    0 0 1 Blue 1 1 0 Yellow
    0 1 0 Green 1 0 1 Magenta
    0 1 1 Cyan 1 0 0 Red
    1 0 0 Red 0 1 1 Cyan
    1 0 1 Magenta 0 1 0 Green
    1 1 0 Yellow 0 0 1 Blue
    1 1 1 White 0 0 0 Black
  2. Boolean operations on colors.

    R G B Color   R G B Color   R G B Color
    0 0 1 Blue   1 1 0 Yellow   1 0 0 Red
          |         &         ^
    0 1 0 Green   0 1 1 Cyan   1 0 1 Magenta
          =         =         =
    0 1 1 Cyan   0 1 0 Green   0 0 1 Blue

Practice Problem 2.10 (solution page 146)

  1. inplace swap function. ^ = xor = ⊕

    Step *x *y *x bits *y bits *x dec. *y dec
    Init. a b 0001 0010 1 2
    1. a a ^ b 0001 0011 1 3
    2. a ^ (a ^ b) = (a ^ a) ^ b = b a ^ b 0010 0011 2 3
    3. b b ^ (a ^ b) = (b ^ b) ^ a = a 0010 0001 2 1

Practice Problem 2.11 (solution page 146)