Midterm review: numbers, logic, memory, von Neumann, LC-3
A one-page summary of weeks 1-8, the exam recipe for each topic and mixed practice questions. Start here the evening before the exam.
This page is a compressed version of the first eight weeks. We collected the recipe of each topic in a table, then gave the solutions of mixed questions. This is a procedure course: most of the points come from questions solved with the same steps every time. First read the table, then solve the questions against the clock, and go back to the page of the topic you got wrong.
The scope of the midterm may change from semester to semester (in some semesters weeks 1-6, in some the LC-3 is included). Decide which block to emphasize according to the announcement on the course page.
Topic → question type → recipe
| Topic | Typical question | Recipe |
|---|---|---|
| Conversions | dec ↔ bin ↔ hex | subtract powers of 2; for hex group in fours from the right |
| Four readings | the 4 values of an 8-bit pattern | if MSB = 0 they are all the same; 2’s = unsigned - 256 |
| 2’s complement | write -X | invert + 1 |
| Addition/subtraction | A - B, overflow | A + (-B), discard the 9th bit, write the sign rule |
| Sign extension | 5 bits → 8/16 bits | copy the MSB to the left |
| IEEE 754 | encode/decode | 1.xxx × 2^e, E = e + 127, do not write the hidden 1 |
| Bit mask | set/clear/test/toggle | OR / AND (mask with 0s) / AND / XOR |
| ASCII | letter and digit conversion | subtract x30; bit 5 = x20 |
| Circuit reading | diagram → table → expression | name the intermediate outputs, fill in row by row |
| Simplification | minimal SOP | pairs that differ in one variable, X + X’ = 1 |
| Complement | F’ | DeMorgan, then multiply out and simplify |
| NAND-only | only NAND | double-complement the SOP |
| Σm / ΠM | canonical forms | 1 rows / 0 rows |
| Decoder/mux/FA | short answer | input = the selected number |
| Latch | Q tracing | NAND: 11 holds, the letter that is 0 does the job |
| Memory | address bits, size | locations × m bits |
| FSM | trace, number of flip-flops | table row; |
| von Neumann | 5 parts, registers | PC address, IR instruction, MAR address, MDR data |
| Instruction cycle | phases, FETCH | MAR ← PC, PC ← PC+1, MDR ← M[MAR], IR ← MDR |
| I/O | polling | LDI KBSR, BRzp, LDI KBDR |
| LC-3 encoding | encode/decode | opcode table, fields, incremented PC |
| LC-3 tracing | register/CC/memory | line-by-line trace table |
Five reminders for exam day
- Write the representation. An expression like “8-bit 2’s complement” should be at the start of your answer.
- Do the check. In every conversion, go back to decimal and verify. Five seconds, one point.
- For overflow, write the rule sentence: “Overflow occurs only if both operands have the same sign and the result has the opposite sign.”
- In simplification, write the name of the rule: distributive, complement, DeMorgan…
- In the LC-3, add the offset to the incremented PC. The most commonly lost point.
Mixed examples
Numbers: the four readings of 0x9C and sign extension
0x9C = 1001 1100
unsigned 128+16+8+4 = 156
SM minus, 001 1100 = 28 = -28
1's flip 0110 0011 = -99
2's 156 - 256 = -100
sign extension to 16 bits: 1111 1111 1001 1100 = 0xFF9C (still -100)
IEEE: encode 19.5
19 = 10011, 0.5 = .1 → 10011.1 = 1.00111 × 2^4
S = 0, E = 4 + 127 = 131 = 1000 0011, F = 00111 0...
0 10000011 00111000000000000000000 = 0x419C0000
Logic: Σm(2, 3, 6, 7)
m2 = A'BC' m3 = A'BC m6 = ABC' m7 = ABC
A'B(C' + C) + AB(C' + C) = A'B + AB = B(A' + A) = B
Four minterms were reduced to a single letter: every row where B = 1.
Memory and FSM
locations × 32 bits = bytes = 64 KB. An FSM with 12 states: → 4 flip-flops.
von Neumann
FETCH when PC = x4A3F: MAR ← x4A3F, PC ← x4A40, MDR ← M[x4A3F], IR ← MDR. The increment of the PC in hex: F + 1 = 10, the carry goes left.
LC-3: encode, decode, trace
LDR R5, R1, #-2 → 0110 101 001 111110 = x6A7E.
xA9FE at x3000 → 1010 100 111111110 → LDI R4, offset -2 → pointer address x3001 - 2 = x2FFF; R4 ← M[M[x2FFF]].
AND R1, R1, #0 R1 = 0
ADD R2, R1, #3 R2 = 3
AGAIN ADD R1, R1, R2 | round R1 R2
ADD R1, R1, R1 | 1 6 2
ADD R2, R2, #-1 | 2 16 1
BRp AGAIN | 3 34 0 (Z, fall through)
HALT
Overflow: three additions, three decisions
| Addition (8 bits) | Result | Decimal | Carry-out | Overflow | Why |
|---|---|---|---|---|---|
| 01100100 + 00111100 | 10100000 | 100 + 60 → -96 | 0 | yes | (+) + (+) = (−) |
| 11000000 + 10111111 | 01111111 | -64 + (-65) → 127 | 1 | yes | (−) + (−) = (+) |
| 11110110 + 00001100 | 00000010 | -10 + 12 → 2 | 1 | no | the signs differ |
The third row is the trap the exam likes: there is a carry-out but the result is correct. In the second row the true sum is -129, which went past the lower limit of 8 bits, -128.
Circuit: a NOR and an AND
Gate 1 NOR(A, B) = X, gate 2 AND(B, C) = Y, gate 3 OR(X, Y) = F. When you fill in the table with the intermediate columns, you get F = Σm(0, 1, 3, 7) = A’B’ + BC (week 3, the circuit reading section). In the exam, give a name to every intermediate output; partial credit comes from there.
I/O: a three-line wait loop
POLL LDI R1, KBSRP ; read KBSR
BRzp POLL ; bit 15 = 0 → wait
LDI R0, KBDRP ; the character is in R0
When ready, KBSR = x8000, that is negative. That is why BRzp. KBSRP is a .FILL xFE00; LD cannot reach that far, LDI is needed.
Instruction cycle: the phases of LDR
LDR R4, R2, #-3, R2 = x4005: FETCH (MAR ← PC, PC ← PC + 1, IR ← instruction), DECODE (opcode 0110), EVALUATE ADDRESS (x4005 - 3 = x4002), FETCH OPERANDS (MDR ← M[x4002]), no EXECUTE, STORE RESULT (R4 ← MDR, the CC is set). Memory was accessed twice.
Quick checklist
| Do you know? | Answer |
|---|---|
| 6-bit 2’s complement range | -32..31 |
| The 16-bit hex of -1 | 0xFFFF |
| The IEEE code of 1.0 | 0x3F800000 |
| ‘A’ and ‘a’ | x41, x61 |
| When does an n-MOS conduct | gate = 1 |
| 3-to-8 decoder, input 011 | D3 |
| 16-to-1 mux selects | 4 |
| FA 1+1+1 | S = 1, Cout = 1 |
| D latch WE = 0 | holds |
| LC-3 memory size | 128 KB |
| The phase ADD skips | EVALUATE ADDRESS |
| KBSR address | xFE00 |
| RET | JMP R7 = xC1C0 |
Common mistakes
| Wrong idea | The truth |
|---|---|
| Carry-out = overflow | Look at the sign rule |
| In IEEE, the hidden 1 goes into the fraction | It is not written |
| m5 = A’BC’ | AB’C |
| In a NAND latch S = 1 sets | S = 0 sets |
| The PC points to the current instruction | To the next one |
| LD address = instruction address + offset | (instruction address + 1) + offset |
| BRzp and BRp are the same | BRzp also branches on zero |
| ST changes the CC | It does not |
Test yourself
Exam-style questions. Solve them on paper first, then reveal the answer.
Give the decimal value of 0xB7 as unsigned, sign-magnitude, 1's complement and 2's complement.
Show answer
0xB7 = 1011 0111. Unsigned: 128+32+16+4+2+1 = 183.
SM: minus, 011 0111 = 55 → -55. 1's: flip 0100 1000 = 72 → -72. 2's: -128 + 55 = -73 (or 183 - 256).
In 8-bit 2's complement, A = 01001110 and B = 10111000. Compute A - B and state whether overflow occurred.
Show answer
A = 78, B = -72. -B = 01001000 (+72). A + (-B) = 01001110 + 01001000 = 10010110 (MSB 1, read as -106).
The true result is 150 > 127. The two numbers added (A, -B) are positive and the result is negative → overflow.
What is the minimum number of bits needed to represent -129 in 2's complement?
Show answer
8 bits go down to -128 at most. 9 bits: . The answer is 9.
Encode -7.375 in IEEE 754 single precision (hex).
Show answer
7 = 111, 0.375 = .011 → 111.011 = 1.11011 × 2^2. S = 1, exponent = 129 = 1000 0001, fraction = 11011 and zeros.
1 10000001 11011000... → 1100 0000 1110 1100 0000 ... = 0xC0EC0000.
Decode the IEEE 754 single-precision value 0x3E200000.
Show answer
0011 1110 0010 0000 ... → S = 0, exponent = 0111 1100 = 124 → e = -3, fraction = 01.
1.01 × 2^-3 = 0.00101 = 1/8 + 1/32 = 0.15625.
The ASCII code of 'd' is 0x64. Which operation and mask give 'D'?
Show answer
The difference between upper and lower case is bit 5 (0x20). Clear bit 5: AND 1101 1111 = 0xDF. 0x64 AND 0xDF = 0x44 = 'D'.
F(A,B,C) = A'B'C + A'BC + ABC. Simplify F and write it as ΠM(…).
Show answer
A'B'C + A'BC = A'C(B' + B) = A'C. A'BC + ABC = BC(A' + A) = BC (A'BC was used twice).
F = Σm(1, 3, 7), the rows where F = 0 are 0, 2, 4, 5, 6 → ΠM(0, 2, 4, 5, 6).
Using DeMorgan, find F' for F = A'C + BC as a sum of products.
Show answer
F' = (A'C)'·(BC)' = (A + C')(B' + C') = AB' + AC' + B'C' + C'C' = AB' + C'(A + B' + 1) = AB' + C'.
Check: the rows where F' = 1 are 0, 2, 4, 5, 6; its union with the set {1, 3, 7} of F is {0..7}.
A NAND R-S latch starts with Q = 0. (S, R) = 01 → 11 → 10 → 11 → 01. Give Q after each step.
Show answer
Active-low: 01 set → 1, 11 hold → 1, 10 reset → 0, 11 hold → 0, 01 set → 1.
A memory has 13 address bits and 16-bit addressability. What is its size in KB? How many flip-flops does a 7-state FSM need?
Show answer
bits = 8192 × 2 bytes = 16384 bytes = 16 KB. 7 states: → 3 flip-flops.
Decode the LC-3 instructions x6A7E and x0BF8 (the second one is at address x3010).
Show answer
x6A7E = 0110 101 001 111110: LDR, DR = R5, BaseR = R1, offset6 = -2.
x0BF8 = 0000 101 111111000: n = 1, z = 0, p = 1 → BRnp, offset = -8, target = x3011 - 8 = x3009.
What are R1, R2 and the condition codes when this program halts?
AND R1, R1, #0
ADD R2, R1, #3
AGAIN ADD R1, R1, R2
ADD R1, R1, R1
ADD R2, R2, #-1
BRp AGAIN
HALTShow answer
R1 = 0, R2 = 3. Round 1: R1 = (0+3)·2 = 6, R2 = 2. Round 2: R1 = (6+2)·2 = 16, R2 = 1. Round 3: R1 = (16+1)·2 = 34, R2 = 0 → Z, BRp falls through.
The last CC was set by ADD R2: Z.
Verification: Every answer was recomputed with node: numbers at the bit level, IEEE 754 with DataView, Boolean expressions with all input combinations, the latch at the gate level, the LC-3 instructions and the program on our own assembler + simulator (verify/SEN2201/09.mjs, lc3.mjs).