About

CSC203 Problem-Solving Guide

1. Introduction

Lecture 1: units, clock speed, memory sizes, Moore’s and Rock’s laws, generations, the von Neumann model.

1.1 Units: the two kinds of “kilo”

Memory sizes use powers of 2. Speeds, frequencies and disk sizes use powers of 10. Cycle time t=1/ft = 1/f, or the shortcut tns=1000/fMHzt_{\text{ns}} = 1000 / f_{\text{MHz}} (1 GHz is 1 ns, 500 MHz is 2 ns, 2 GHz is 0.5 ns).

PrefixMemory (power of 2)Speed / disk (power of 10)
K (kilo)210=1,0242^{10} = 1{,}02410310^{3}
M (mega)220=1,048,5762^{20} = 1{,}048{,}57610610^{6}
G (giga)2302^{30}10910^{9}
T (tera)2402^{40}101210^{12}
Small unitValue
ms (milli)10−310^{-3} s
µs (micro)10−610^{-6} s
ns (nano)10−910^{-9} s
ps (pico)10−1210^{-12} s
  1. Write the number part as a power of 2, then add the prefix power: 32 GB=25×230=23532\text{ GB} = 2^5 \times 2^{30} = 2^{35} bytes.
  2. For a ratio of sizes, subtract exponents: 2a/2b=2a−b2^a / 2^b = 2^{a-b}.
  3. For a time from a frequency, use t=1/ft = 1/f and convert to ns or ps.
Item in the advertFormulaWorkingAnswer + unit
Clock cycle (CPU / bus)t=1/ft = 1/f
Memory size in bytesnumber × 2prefix\times\ 2^{\text{prefix}}
Ratio of two sizes2a/2b=2a−b2^a / 2^b = 2^{a-b}
Disk “missing” space1012/23010^{12} / 2^{30}
One disk revolution60/RPM60 / \text{RPM} seconds
Screen memorywidth ×\times height ×\times bits per pixel / 8/\ 8

Worked example: a 3.9 GHz PC. 3.9 GHz CPU, 1600 MHz memory, 32 GB RAM, 128 KB L1, 2 MB L2, 1 TB disk at 7200 RPM, 1920 × 1200 screen with 24-bit colour.

QuestionWorkingAnswer
CPU cycle time1/(3.9×109)=0.256×10−91 / (3.9 \times 10^{9}) = 0.256 \times 10^{-9} s0.256 ns
Memory bus cycle1000/16001000 / 16000.625 ns
CPU cycles per bus cycle0.625/0.2560.625 / 0.256about 2.4
32 GB in bytes25×230=2352^5 \times 2^{30} = 2^{35}34,359,738,368 B
L2 ÷\div L12 MB/128 KB=221/217=242\text{ MB} / 128\text{ KB} = 2^{21} / 2^{17} = 2^416 times
Why the OS shows “931 GB”Maker: 1 TB =1012= 10^{12} B; OS divides by 230=1,073,741,8242^{30} = 1{,}073{,}741{,}824931.3 GB
Disk revolution, average delay60/7200=0.0083360/7200 = 0.00833 s; average delay is half a turn8.33 ms, 4.17 ms
Colours per pixel2242^{24}16,777,216
Screen memory1920×1200×24/8=6,912,0001920 \times 1200 \times 24 / 8 = 6{,}912{,}000 B; ÷220\div 2^{20}6.59 MB
  • Do not use 1000 for memory or 1024 for clock speeds.
  • Convert bits to bytes (divide by 8) for screen memory.
  • Convert units (MHz to Hz, ns to s) before dividing.

1.2 Moore’s law and Rock’s law (doubling problems)

Both laws say something doubles every fixed period. Moore: transistors per chip double every 18 months (original 1965 version: every year; Moore later said 2 years). Rock: the cost of a chip factory doubles every 4 years.

New=Old×2 time passed/doubling period\text{New} = \text{Old} \times 2^{\,\text{time passed} / \text{doubling period}}

  1. Put the time passed and the doubling period in the same unit (months or years).
  2. Doublings == time passed ÷\div period.
  3. Factor =2doublings= 2^{\text{doublings}}; new value == old ×\times factor.
  4. To find the time for a growth of GG times: doublings =log⁡2G= \log_2 G, then time == doublings ×\times period. Remember 210=1024≈10002^{10} = 1024 \approx 1000.
Old valueTime passedDoubling periodDoublings = time ÷ periodFactor = 2doublings2^{\text{doublings}}New = old × factor

Worked examples: Moore and Rock

ProblemDoublingsAnswer
2 billion transistors today, 18-month doubling. After 3, 6, 9 years?36/18=236/18 = 2; 72/18=472/18 = 4; 108/18=6108/18 = 68, 32, 128 billion
64 components in 1965, original law (every year). Predict 1975.10/1=1010 / 1 = 1064×210=65,53664 \times 2^{10} = 65{,}536
How long for a 1000-fold increase?log⁡21000≈10\log_2 1000 \approx 1015 years (18 months) or 20 years (2 years)
Chip plant cost USD 12,000 in 1968. Rock’s law for 2012?44/4=1144 / 4 = 1112,000×2048≈12{,}000 \times 2048 \approx USD 24.6 million

Moore and Rock are linked: denser chips need ever more expensive factories, so at some point nobody can pay for the next factory and one of the two trends must stop.

  • Check which doubling period the question gives (1 year, 18 months or 2 years).
  • Do not mix years and months in the exponent.

1.3 Generations, organization vs architecture, von Neumann

Which generation? Look for the switching technology

Gen.YearsTechnology (the clue word)Examples
01642–1945Mechanical gearsPascaline, Babbage’s Difference Engine, Hollerith cards
11945–1953Vacuum tubesENIAC (about 17,000 tubes), UNIVAC
21954–1965Transistors, magnetic core memory, COBOL/FORTRANIBM 7000 series
31965–1980Integrated circuits (ICs)IBM System/360, DEC PDP-8, Cray-1
41980–VLSI: a whole CPU on one chip (microprocessor)Intel 4004/8088, the PC
52000–ULSI: billions of transistors, multicore, GPU, AIsmartphone SoCs, cloud servers

Organization or architecture? Ask: “Can the programmer see it?” Yes: architecture (instruction set, addressing modes, data types, number of bits, whether there is a multiply instruction). No: organization (control signals, clock speed, RAM chip type, multiply done by circuit or by shift-and-add).

Von Neumann model: CPU (control unit + ALU + registers), one memory for program and data, I/O, and a single path between CPU and memory. That single path is the von Neumann bottleneck. A Harvard machine has separate instruction and data memories.

Worked example: the von Neumann bottleneck. The memory bus does one transfer every 10 ns. Each instruction needs 2 transfers (fetch the instruction, then read/write the operand).

  1. von Neumann: 2×10 ns=20 ns2 \times 10\text{ ns} = 20\text{ ns} per instruction, so 1/(20×10−9)1 / (20 \times 10^{-9}) = 50 million instructions per second, however fast the CPU is.
  2. Harvard: the two transfers use two buses at the same time, so 10 ns per instruction = 100 million per second.

Fetch-decode-execute order: fetch the instruction from the address in the PC, then PC + 1, decode the opcode, read the operand from memory, and the ALU executes.

  • Clock speed and RAM type are organization, not architecture.
  • The bottleneck limits instruction rate by bus speed, not CPU speed.

2. Numbers and Arithmetic

Lecture 2: base conversion, signed integers, complement arithmetic, overflow, multiplication, floating point.

2.1 Converting Between Bases

  • Any base → decimal: digit × place value (bkb^k), then add.
  • Decimal whole part → base bb: divide by bb repeatedly; read remainders bottom to top.
  • Decimal fraction → base bb: multiply by bb repeatedly; read whole parts top to bottom.
  • Binary ↔ hex: groups of 4 bits. Binary ↔ octal: groups of 3. Group outward from the point, pad with 0s.

Binary ↔ hex table and powers of 2: see Tables 6.4a–b.

Number ÷ bQuotientRemainder
Fraction × bResultWhole part
Place valueb4b^4b3b^3b2b^2b1b^1b0b^0.b−1b^{-1}b−2b^{-2}b−3b^{-3}
Digit.
Digit × place

Worked example: 147.8125 (decimal) → binary, hex, octal

÷ 2QuotientRemainder
147731
73361
36180
1890
941
420
210
101 ↑
× 2ResultBit
0.81251.6251 ↓
0.6251.251
0.250.50
0.51.01 (stop: fraction is 0)

Whole part (read up): 1001 0011. Fraction (read down): .1101.

  • Binary: 10010011.1101₂
  • Hex: 1001 0011 . 1101 = 93.D₁₆
  • Octal: 010 010 011 . 110 100 = 223.64₈

Check: 128+16+2+1=147128 + 16 + 2 + 1 = 147 ✓ and 0.5+0.25+0.0625=0.81250.5 + 0.25 + 0.0625 = 0.8125 ✓

Worked example: other bases and fractions that never end

  • 2A3162A3_{16} → decimal: 2⋅256+10⋅16+3=512+160+3=2 \cdot 256 + 10 \cdot 16 + 3 = 512 + 160 + 3 = 675
  • 1011.10121011.101_2 → decimal: 8+2+1+0.5+0.125=8 + 2 + 1 + 0.5 + 0.125 = 11.625
  • 104104 → base 3: 104→34104 \to 34 r 2, 34→1134 \to 11 r 1, 11→311 \to 3 r 2, 3→13 \to 1 r 0, 1→01 \to 0 r 1. Read up: 10212₃. Check: 81+0+18+3+2=10481 + 0 + 18 + 3 + 2 = 104 ✓
  • 7A9.C167A9.C_{16} → octal: 0111 1010 1001 . 1100, regroup in 3s from the point: 011 110 101 001 . 110 = 3651.6₈ (both equal 1961.75)
  • 0.10.1 → binary, 8 bits: 0.2→00.2 \to 0, 0.4→00.4 \to 0, 0.8→00.8 \to 0, 1.6→11.6 \to 1, 1.2→11.2 \to 1, 0.4→00.4 \to 0, 0.8→00.8 \to 0, 1.6→11.6 \to 1 → 0.00011001₂. It never ends (0.4, 0.8, 1.6, 1.2 repeat), so the stored value is only 25/256=0.0976562525/256 = 0.09765625.

Bits needed for an unsigned value NN: the smallest nn with 2n>N2^n > N (1000 needs 10 bits, since 210=10242^{10} = 1024). Range of nn unsigned bits: 00 to 2n−12^n - 1.

2.2 Signed Integers: Signed Magnitude, One’s and Two’s Complement

SystemWrite −x-x (start from +x+x)Range with nn bitsZeros
Signed magnitudeChange the sign bit (leftmost) to 1−(2n−1−1)-(2^{n-1}-1) … +(2n−1−1)+(2^{n-1}-1)two
One’s complementFlip every bit−(2n−1−1)-(2^{n-1}-1) … +(2n−1−1)+(2^{n-1}-1)two
Two’s complementFlip every bit, then add 1. Shortcut: copy from the right up to and including the first 1, flip the rest.−2n−1-2^{n-1} … +(2n−1−1)+(2^{n-1}-1)one

8 bits: SM and 1C give −127…+127-127 \ldots +127; 2C gives −128…+127-128 \ldots +127. 4-bit 2C: −8…+7-8 \ldots +7. 16-bit 2C: −32768…+32767-32768 \ldots +32767.

PatternUnsignedSigned magnitudeOne’s complementTwo’s complement
Ruleadd place valuessign bit, then value of the restif MSB = 1: flip all, read, put −MSB weighs −2n−1-2^{n-1}, others normal

Worked example: one pattern, four meanings

Pattern 1011 0101:

  • Unsigned: 128+32+16+4+1=128 + 32 + 16 + 4 + 1 = 181
  • Signed magnitude: sign 1, rest 011 0101 = 53 → −53
  • One’s complement: flip → 0100 1010 = 74 → −74
  • Two’s complement: −128+32+16+4+1=-128 + 32 + 16 + 4 + 1 = −75

Worked example: −18 in 8 bits (+18 = 0001 0010)

System−18
Signed magnitude1001 0010
One’s complement1110 1101
Two’s complement1110 1110

Sign extension (4 → 8 bits): SM puts the extra 0s after the sign bit (1101 → 1000 0101); 1C and 2C copy the sign bit (2C 1011 → 1111 1011).

2.3 Integer Arithmetic and Overflow

SystemHow to add (subtract = add the negative)Overflow when …
Signed magnitudeSame signs: add magnitudes, keep the sign. Different signs: big magnitude − small magnitude, take the sign of the bigger one.a carry comes out of the leftmost magnitude bit
One’s complementAdd all bits including the sign. If a carry comes out of the MSB, add it back to the rightmost bit (end-around carry).two same-sign numbers give the other sign
Two’s complementAdd all bits including the sign. Throw away any carry out of the MSB.carry into MSB ≠ carry out of MSB

Two’s complement overflow: V=Cin, MSB⊕Cout, MSBV = C_{\text{in, MSB}} \oplus C_{\text{out, MSB}}. Quick test: positive + negative never overflows; two same-sign numbers overflow only when the answer has the other sign.

Coutb7 (MSB)b6b5b4b3b2b1b0
carries0
A
B (or −B)
Sum

Carry into MSB = ___   Carry out of MSB = ___   Overflow V = ___   Result in decimal = ___   Check: ___

Worked example (a): 19 − 48 in 8-bit two’s complement

48=48 = 0011 0000, so −48=-48 = 1100 1111 + 1 = 1101 0000.

  carries   0 0 1 0 0 0 0 0     (carry INTO each column)
     19     0 0 0 1 0 0 1 1
  + (-48)   1 1 0 1 0 0 0 0
  ----------------------------
            1 1 1 0 0 0 1 1     carry into MSB 0, carry out 0 -> no overflow

1110 0011 is negative. Flip + 1 → 0001 1101 = 29, so the answer is −29 ✓

Worked example (b): 9 + (−23) in 8-bit one’s complement

−23=-23 = flip(0001 0111) = 1110 1000. 0000 1001 + 1110 1000 = 1111 0001, no carry out, so no end-around carry. Flip → 0000 1110 = 14 → −14 ✓

Worked example (c): 4-bit overflow checks

SumBitsResultC into MSBC outOverflow?
(+5) + (+4)0101 + 01001001 (reads −7)10yes (9 > 7)
(−4) + (−1)1100 + 11111 1011 → 1011 = −511no
(−7) + (−6)1001 + 10101 0011 → 0011 (reads +3)01yes (−13 < −8)
(−7) + (+5)1001 + 01011110 = −200no

Worked example (d): −3 − 5 in 4 bits, both systems

−3−5=(−3)+(−5)-3 - 5 = (-3) + (-5), true answer −8-8.

System−3-3−5-5SumAfter carry ruleOverflow?
One’s complement (range −7 … +7)110010101 0110end-around: 0110 + 1 = 0111 (+7)yes (−8 is out of range, sign flipped)
Two’s complement (range −8 … +7)110110111 1000drop carry: 1000 (−8)no (carry in = carry out = 1)

Worked example (e): a counting loop that wraps (4-bit one’s complement)

j = -2; k = 6; while k ≠ -6 { j = j - 1; k = k + 1 }. Here j−1=j+1110j - 1 = j + 1110 (with end-around carry) and k+1=k+0001k + 1 = k + 0001. The test value −6=1001-6 = 1001.

Passkk beforejj afterkk after
10110 (+6)1100 (−3)0111 (+7)
20111 (+7)1011 (−4)1000 (−7)
31000 (−7)1010 (−5)1001 (−6), stop

0111+1=10000111 + 1 = 1000 is −7-7 (the count wraps), so the loop runs 3 times: j = 1010 = −5.

  • A carry out of the MSB on its own is not overflow in two’s complement.
  • Only throw away the MSB carry in 2C; in 1C it goes back into the rightmost bit.

Adder–subtractor circuit

One control line M feeds an XOR gate on every B input and also the first carry C0C_0.

  • M = 0: B passes unchanged, C0=0C_0 = 0 → A+BA + B.
  • M = 1: every B bit is flipped and C0=1C_0 = 1 → A+B′+1=A−BA + B' + 1 = A - B.
  • Overflow flag (4 bits): V=C3⊕C4V = C_3 \oplus C_4.

Example 6−36 - 3: B⊕1111=1100B \oplus 1111 = 1100, then 0110+1100+1=1 00110110 + 1100 + 1 = 1\,0011 → S=0011=3S = 0011 = 3, C3=C4=1C_3 = C_4 = 1, so V=0V = 0.

Sequential (shift-and-add) multiplier

  1. Set C = 0, A = 0, M = multiplicand, Q = multiplier, Count = nn.
  2. If Q₀ = 1 (rightmost bit of Q): C,A ← A + M. If Q₀ = 0: do nothing.
  3. Shift C, A, Q one place right as one long register (C → left bit of A, right bit of A → left bit of Q, Q₀ falls off). Count − 1.
  4. Repeat steps 2–3 until Count = 0. The product is A Q (2n2n bits).
CycleStepCAQM
0initial0
1Q₀ = ? → add / no add
1shift right
2Q₀ = ? → add / no add
2shift right
……
…shift right

Worked example: 11 × 13 with 4-bit registers (M = 1011, Q = 1101)

CycleStepCAQ
0initial000001101
1Q₀ = 1 → A + M = 0000 + 1011010111101
1shift right001011110
2Q₀ = 0 → no add001011110
2shift right000101111
3Q₀ = 1 → 0010 + 1011011011111
3shift right001101111
4Q₀ = 1 → 0110 + 1011 = 1 0001100011111
4shift right (C goes into A)010001111

Product A Q = 1000 1111₂ = 143 ✓ (11×13=14311 \times 13 = 143).

Keep the carry C: in cycle 4 it becomes the top bit of A after the shift. Without it the top bit is lost.

2.4 Floating Point: the 14-bit Model and IEEE 754

A float is ± 1.F×2e\pm\, 1.F \times 2^{e}, normalized to exactly one 1 before the point. That leading 1 is not stored (hidden bit). Moving the point left kk places adds kk to the exponent. Stored exponent E=e+biasE = e + \text{bias}.

FormatSignExponentFractionBiasValue
Lecture 14-bit model15816(−1)S×1.F×2E−16(-1)^S \times 1.F \times 2^{E-16}
IEEE single (32 bits)1823127(−1)S×1.F×2E−127(-1)^S \times 1.F \times 2^{E-127}
IEEE double (64 bits)111521023(−1)S×1.F×2E−1023(-1)^S \times 1.F \times 2^{E-1023}

Bit layouts, ranges and special patterns of each format: see Table 6.4d.

StepYour work
1. Sign bit (0 = +, 1 = −)
2. |number| in binary
3. Normalize: 1.____×2e1.\_\_\_\_ \times 2^e
4. Stored exponent E=e+E = e + bias (16 or 127), in binary
5. Fraction = bits after “1.” padded with 0s on the right

14-bit model layout (bias 16):

13S (1 bit)
12–8exponent (5 bits)
7–0fraction (8 bits)

IEEE single layout (bias 127):

31S (1 bit)
30–23exponent (8 bits)
22–0fraction (23 bits)

For IEEE hex: write all 32 bits in a row, cut into eight groups of 4, and convert each group to one hex digit.

Worked example: 14-bit model (excess-16)

NumberBinary and normalizedE=e+16E = e + 1614-bit pattern
9.6251001.101=1.001101×231001.101 = 1.001101 \times 2^319 = 100110 10011 00110100
−0.3750.011=1.1×2−20.011 = 1.1 \times 2^{-2}14 = 011101 01110 10000000
1710001=1.0001×2410001 = 1.0001 \times 2^420 = 101000 10100 00010000

Decode 0 10010 10100000: S=0S = 0 (+), E=18⇒e=18−16=2E = 18 \Rightarrow e = 18 - 16 = 2, value =1.101×22=110.12== 1.101 \times 2^2 = 110.1_2 = 6.5

Worked example: IEEE 754 single precision

−12.375-12.375 → IEEE: S=1S = 1. 12.375=1100.011=1.100011×2312.375 = 1100.011 = 1.100011 \times 2^3. E=3+127=130=1000 0010E = 3 + 127 = 130 = 1000\,0010. F=100011F = 100011 then 0s.

S  E          F
1  10000010   10001100000000000000000
1100 0001 0100 0110 0000 0000 0000 0000  ->  C 1 4 6 0 0 0 0

Answer: C1460000₁₆

41C80000\texttt{41C80000} → decimal: 0100 0001 1100 1000 0000… → S=0S = 0, E=1000 0011=131⇒e=4E = 1000\,0011 = 131 \Rightarrow e = 4, F=1001F = 1001 → 1.1001×24=110012=1.1001 \times 2^4 = 11001_2 = 25

0.15625=0.00101=1.01×2−30.15625 = 0.00101 = 1.01 \times 2^{-3}, E=124=0111 1100E = 124 = 0111\,1100 → 3E200000₁₆

Special patterns (single)Exponent EFraction FExample hex
Zero (+0 or −0)0000000000, 80000000
Normal number1 – 254anything3F800000 = 1.0
Infinity (+∞ or −∞)255 (all 1s)07F800000, FF800000
NaN (not a number)255not 07FC00000
  • Subtract the bias when decoding, add it when encoding.
  • A plain 5-bit exponent cannot be negative; the bias (excess-16) lets it run from −16 to +15.

2.5 Floating-Point Arithmetic and Errors

OperationSteps
Add / subtract1. Align: shift the number with the smaller exponent right until exponents match. 2. Add or subtract the significands. 3. Normalize. 4. Truncate to the fraction bits.
MultiplySign = XOR of signs. E=E1+E2−biasE = E_1 + E_2 - \text{bias} (subtract one bias, or it is counted twice). Multiply significands. Normalize.
DivideSign = XOR. E=E1−E2+biasE = E_1 - E_2 + \text{bias}. Divide significands. Normalize.

Worked example: add, subtract and multiply in the 14-bit model

(a) A=A = 0 10010 10000000, B=B = 0 10000 01000000. A=1.1×22A = 1.1 \times 2^2 (= 6), B=1.01×20B = 1.01 \times 2^0 (= 1.25). Align B to 222^2: 0.0101×220.0101 \times 2^2. Add: 1.1000+0.0101=1.1101×221.1000 + 0.0101 = 1.1101 \times 2^2 (already normal). Result 0 10010 11010000 =111.012=7.25= 111.01_2 = 7.25 ✓

(b) 12−1.2512 - 1.25: 12=1.1×2312 = 1.1 \times 2^3, 1.25=1.01×20→0.00101×231.25 = 1.01 \times 2^0 \to 0.00101 \times 2^3. 1.10000−0.00101=1.01011×23=1010.112=10.751.10000 - 0.00101 = 1.01011 \times 2^3 = 1010.11_2 = 10.75. Stored: 0 10011 01011000

(c) 12×1.2512 \times 1.25 with biased fields: E=19+16−16=19E = 19 + 16 - 16 = 19. Significands 1.1×1.01=1.1111.1 \times 1.01 = 1.111. Sign 0⊕0=00 \oplus 0 = 0. Result 0 10011 11100000 =1.111×23=15= 1.111 \times 2^3 = 15 ✓

Never test x == 0.0. 0.1 has no exact binary form, so adding 0.1 ten times is not exactly 1.0. Use a tolerance: abs(x - y) < epsilon. Exponent bits set the range; fraction bits set the precision.

  • Overflow: exponent too big to store. Underflow: exponent too small (number too close to 0), e.g. 2−182^{-18} needs E=−2E = -2 in the 14-bit model. These are blatant errors.
  • Subtle errors give a believable wrong value: 128.75=1.000000011×27128.75 = 1.000000011 \times 2^7 keeps only 8 fraction bits, so it is stored as 128.5.

3. Codes, Error Detection and Error Correction

Lecture 3: ASCII and parity, BCD, recording codes, check digits, CRC, Hamming distance, Hamming codes.

3.1 Character Codes and Parity

Parity bit = the 8th (leftmost) bit, chosen so the total number of 1s in the byte is even (even parity) or odd (odd parity). A wrong count means an error is detected. Parity cannot say which bit is wrong and misses two errors in the same byte.

ASCII landmark (7 bits)Hex
space20
digits ‘0’ … ‘9’30 … 39 (digit + 30)
‘A’ … ‘Z’41 … 5A (‘A’ + position − 1)
‘a’ … ‘z’61 … 7A (capital + 20)
control characters00 … 1F, 7F
  1. Look up each character’s hex code and write its 7-bit binary.
  2. Count the 1s.
  3. Put a leading 0 or 1 so the count becomes even (even parity) or odd (odd parity).
  4. To check a received byte, count its 1s: the wrong parity means an error.
CharHex7-bit binaryNumber of 1sEven-parity byteOdd-parity byte

Worked example: “CAT” with parity, then checking received bytes

CharHex7 bits1sEven parityOdd parity
C43100 001131100 0011 = C30100 0011 = 43
A41100 000120100 0001 = 411100 0001 = C1
T54101 010031101 0100 = D40101 0100 = 54

Received (even parity): 53 C9 D4. 53 = 0101 0011 (four 1s, ok) so the character is 53 = ‘S’. C9 = 1100 1001 (four, ok) so 49 = ‘I’. D4 = 1101 0100 (four, ok) so 54 = ‘T’. Message: “SIT”, no error detected. A byte such as 1000 0011 has three 1s, so an error is detected.

BCD: zoned and packed

Sign nibbles: 1100 (C) = +, 1101 (D) = −, 1111 (F) = unsigned. Zoned: one digit per byte, zone F on every digit except the last, whose zone is the sign. Packed: two digits per byte, sign nibble at the right end; add a leading 0000 if the nibble count is odd.

NumberZoned decimalPacked BCD
+305F3 F0 C50011 0000 0101 1100 = 30 5C
−1265F1 F2 F6 D50000 0001 0010 0110 0101 1101 = 01 26 5D

Unicode: 17 planes × 65,536 = 1,114,112 code points (U+0000 … U+10FFFF, so the largest needs 21 bits). Plane 0 is the Basic Multilingual Plane. ASCII is the first 128 code points.

  • Count the 1s of the 7 data bits only, then add the parity bit. Do not count the parity bit twice.
  • Letters: count from ‘A’ = 41 (A … I = 41 … 49, J … O = 4A … 4F, P = 50, T = 54, Z = 5A).

3.2 Recording and Transmission Codes

Each bit gets a bit cell; the receiver keeps its clock in step by watching for transitions. Cell time = 1 / bit rate (2 Kbps gives 0.5 ms). Density (most data per area): RLL > MFM > FM.

CodeRule (1 = high, 0 = low)Problem / use
NRZ1 = high for the whole cell, 0 = lowlong runs are flat, so sync is lost
NRZIa 1 = a transition (in the middle of the cell); 0 = no changeruns of 0s still flat
Manchesterevery cell flips in the middle: 1 = low to high, 0 = high to low; an extra boundary flip between two equal bitsself-clocking (Ethernet); twice the transitions
FMa flip at every cell boundary (clock) plus a flip in the middle of every 1 celleasy to decode; least dense
MFMa flip in the middle of every 1 cell; a boundary flip only between two 0sfloppy disks; about twice FM density
RLL(2,7)re-code with the table below, then record the code with NRZI2 to 7 zeros between 1s; densest
  1. Write the bits above the grid.
  2. Draw one row (code) at a time.
  3. For each cell ask: does it flip in the middle? does it flip at its left boundary?

Worked example: data 1 0 0 1 1 in every code

Waveform diagram10011bitNRZNRZIManchesterFMMFM
CodeNRZNRZIManchesterFMMFM
Transitions drawn23 (one per 1)5 middle + 2 boundary = 73 middle + 4 boundary = 73 middle + 1 between the 0s = 4

RLL(2,7)

Read the data from the left and cut it into groups:

  • starts with 1: take 2 bits
  • starts with 01 or 000: take 3 bits
  • starts with 001: take 4 bits

Each code is twice as long as its data. Transitions after NRZI = number of 1s in the code.

DataRLL(2,7) code
100100
111000
000000100
010100100
011001000
001000100100
001100001000

Worked example: RLL(2,7) for 1000 1111

Cut 10 | 0011 | 11, so the code is 0100 | 00001000 | 1000. The code has three 1s, so NRZI gives 3 transitions for 8 data bits.

Waveform diagram0100000010001000codeNRZI
  • NRZI: only a 1 causes a flip; a 0 keeps the level.
  • MFM: a boundary flip appears only between two 0s, never next to a 1.
  • Cut RLL data by its leading bits, not into fixed-size blocks.

3.3 Error Detection: Check Digits and CRC

Check digit (UPC-A)

Check digit = 10 − (S mod 10), where S = 3 × (sum of odd positions) + (sum of even positions) over the first 11 digits. If S mod 10 = 0, the check digit is 0.

Worked example: UPC-A check digit for 036000 24145?

Odd positions (1st, 3rd, … 11th): 0 + 6 + 0 + 2 + 1 + 5 = 14, and 14 × 3 = 42. Even positions (2nd … 10th): 3 + 0 + 0 + 4 + 4 = 11. S = 42 + 11 = 53. Check digit = 10 − (53 mod 10) = 10 − 3 = 7.

CRC (modulo-2 division)

Mod-2 add and subtract are both XOR (no carries, no borrows). In the long division, whenever the leftmost remaining bit is 1, write the key under it and XOR; never compare sizes. A key with n+1n+1 bits (degree nn) gives an nn-bit CRC. Key 1101 = x3+x2+1x^3 + x^2 + 1.

  1. Sender: append nn zeros (nn = key length − 1) to the data.
  2. Divide by the key with mod-2 division; the last nn bits are the remainder.
  3. Replace the appended zeros with the remainder. This is the codeword that is sent.
  4. Receiver: divide the whole codeword by the same key (do not add zeros). Remainder 0 means accept; anything else means error, ask for a resend.
Key = ________ (n+1 = ___ bits)  ->  append n = ___ zeros

  data + zeros:            _ _ _ _ _ _ _ _ _ _ _ _
  key under the first 1:   _ _ _ _
  XOR, bring down      ->  _ _ _ _ _ _ _ _ _ _ _ _
  key under the next 1:      _ _ _ _
  XOR                  ->  _ _ _ _ _ _ _ _ _ _ _ _
  ... repeat until fewer than (n+1) bits remain after the last 1 ...
  remainder = last n bits = _ _ _

Codeword = data followed by remainder = ________________

Worked example: data 1111101, key 1101

Sender (key has 4 bits, so append 3 zeros):

        1111101000
        1101           step 1
        0010101000
          1101         step 2
        0001111000
           1101        step 3
        0000010000
             1101      step 4
        0000001010
              1101     step 5
        0000000111   -> remainder 111

Codeword = 1111101 | 111 = 1111101111

Receiver divides what arrives by 1101:

  • 1111101111 gives remainder 000, so accept.
  • 1111100111 gives remainder 101, so reject (bit 4 from the right was flipped).

A CRC with a degree-nn key catches all single-bit errors and all bursts of length at most nn. It only detects; it cannot correct.

  • Append zeros only at the sender, never at the receiver.
  • The remainder must have exactly nn bits: keep leading zeros (for example 011).

3.4 Hamming Distance and Hamming Codes

Hamming distance = number of positions where two code words differ (XOR them, count the 1s). DminD_{min} = smallest distance over all pairs. A code detects up to Dmin−1D_{min} - 1 errors and corrects up to ⌊(Dmin−1)/2⌋\lfloor (D_{min} - 1)/2 \rfloor.

DminD_{min}2345
detects1234
corrects0112

Worked example: DminD_{min} of {00000,01011,10101,11110}\{00000, 01011, 10101, 11110\}

010111010111110
00000334
0101143
101013

DminD_{min} = 3, so the code detects 2 and corrects 1.

How many check bits?

For mm data bits find the smallest rr with m+r+1≤2rm + r + 1 \le 2^r. The code word has n=m+rn = m + r bits.

Data bits mm45–1181012–26163264
Check bits rr34445567
Code word nn79–15121417–31213871

Layout and encoding

Number positions 1 to nn from the right. Check bits sit at the powers of 2 (1, 2, 4, 8, 16). Data bits fill the other positions from the highest position down, in the order written. Check bit PcP_c covers every position whose binary number contains cc (position 11 = 8 + 2 + 1 is checked by P8P_8, P2P_2, P1P_1). Even parity: each check bit = XOR of the data bits it covers.

Every position from 1 to 16 in binary, with the check bits that cover it: see Table 6.4c.

  1. Draw the positions n…1n \ldots 1 and mark the powers of 2 as check bits.
  2. Write the data bits into the remaining positions, highest first.
  3. For each check bit, list the data positions it covers, count their 1s, and set the check bit to 0 (even count) or 1 (odd count).
  4. Read off the code word from position nn down to 1.

Ready lists (use only positions up to your nn; for the check bit itself use data positions only):

Check bitn=7n = 7 (m=4m = 4)n=12n = 12 (m=8m = 8)n=14n = 14 (m=10m = 10)n=21n = 21 (m=16m = 16)
P11, 3, 5, 71, 3, 5, 7, 9, 111, 3, 5, 7, 9, 11, 13all odd positions 1 … 21
P22, 3, 6, 72, 3, 6, 7, 10, 112, 3, 6, 7, 10, 11, 142, 3, 6, 7, 10, 11, 14, 15, 18, 19
P44, 5, 6, 74, 5, 6, 7, 124, 5, 6, 7, 12, 13, 144–7, 12–15, 20, 21
P8none8, 9, 10, 11, 128, 9, 10, 11, 12, 13, 148–15
P16nonenonenone16–21
Data positions (high to low)7, 6, 5, 312, 11, 10, 9, 7, 6, 5, 314, 13, 12, 11, 10, 9, 7, 6, 5, 321 … 17, 15 … 9, 7, 6, 5, 3
Position121110987654321
Typed1d_1d2d_2d3d_3d4d_4P8d5d_5d6d_6d7d_7P4d8d_8P2P1
Bit
Check bitCovers data positionsData bits thereNumber of 1sValue (even = 0, odd = 1)
P13, 5, 7, 9, 11
P23, 6, 7, 10, 11
P45, 6, 7, 12
P89, 10, 11, 12

The 7-bit version (4 data bits) is positions 7 6 5 4 3 2 1 = d1 d2 d3 P4 d4 P2 P1d_1\, d_2\, d_3\, P_4\, d_4\, P_2\, P_1, with P1 from 3, 5, 7; P2 from 3, 6, 7; P4 from 5, 6, 7.

Worked example: encode M = 1101 0110

Position121110987654321
TypeddddP8dddP4dP2P1
Data1101?011?0??
CheckData positions and bits1sValue
P13, 5, 7, 9, 11: 0, 1, 0, 1, 131
P23, 6, 7, 10, 11: 0, 1, 0, 0, 120
P45, 6, 7, 12: 1, 1, 0, 131
P89, 10, 11, 12: 1, 0, 1, 131

Key K = P8 P4 P2 P1 = 1101. Code word (position 12 first): 1101 1011 1001

Finding and correcting an error (syndrome)

Recompute the check bits from the data read (K′K'), XOR with the stored check bits (KK). The result K⊕K′K \oplus K', read as binary (P8 P4 P2 P1), is the position of the wrong bit. 0 = no error; a power of 2 = a check bit itself is wrong (data fine); anything else = flip that data position.

Check bitRecomputed from data read (K′K')Stored (KK)K⊕K′K \oplus K'
P8
P4
P2
P1

Syndrome (P8 P4 P2 P1 as binary) = ______ = position ____

Worked example: data read back as 1101 0100, stored K = 1101

Place the data read at positions 12, 11, 10, 9, 7, 6, 5, 3 = 1, 1, 0, 1, 0, 1, 0, 0.

CheckRecompute from data readK′K'KKK⊕K′K \oplus K'
P89, 10, 11, 12: 1, 0, 1, 1110
P45, 6, 7, 12: 0, 1, 0, 1011
P23, 6, 7, 10, 11: 0, 1, 0, 0, 1000
P13, 5, 7, 9, 11: 0, 0, 0, 1, 1011

Syndrome = 0101 = 5, so the bit at position 5 is wrong. Flip it from 0 to 1. Corrected data: 1101 0110 (P4 and P1 failed, and 4 + 1 = 5).

Worked example: labels M8…M1M_8 \ldots M_1 and C4…C1C_4 \ldots C_1, word read = 01000011 1010

Labels count from the right: C1,C2,C3,C4C_1, C_2, C_3, C_4 sit at positions 1, 2, 4, 8 and M1…M8M_1 \ldots M_8 fill positions 3, 5, 6, 7, 9, 10, 11, 12. Here M8…M1=01000011M_8 \ldots M_1 = 01000011 and C4C3C2C1=1010C_4 C_3 C_2 C_1 = 1010.

Position121110987654321
LabelM8M_8M7M_7M6M_6M5M_5C4C_4M4M_4M3M_3M2M_2C3C_3M1M_1C2C_2C1C_1
Bit010010010110

When the check bit is part of the word, count the 1s of the whole group including the check bit: odd means the check fails.

GroupPositions1sFails?
11, 3, 5, 7, 9, 1131
22, 3, 6, 7, 10, 1131
44, 5, 6, 7, 1211
88, 9, 10, 11, 1220

Syndrome = 0111 = 7 → position 7 = M4M_4 is wrong. Flip it: corrected message M8…M1M_8 \ldots M_1 = 0100 1011 (check bits unchanged, 1010).

  • Number positions from the right.
  • When computing a check bit, use data bits only, never other check bits.
  • A single-error-correcting code (Dmin=3D_{min} = 3) cannot fix two errors: the syndrome then points at the wrong place.

4. Boolean Algebra and Digital Logic

Lectures 4–5: gates, truth tables, Boolean laws, SOP/POS, K-maps, adders, decoders, multiplexers, flip-flops, sequential circuits

4.1 Gates and Truth Tables

Notation: NOT xx is x′x', AND is xyxy, OR is x+yx+y, XOR is x⊕yx \oplus y. Order of work: NOT, then AND, then OR. A function of nn variables has 2n2^n rows. NAND alone (or NOR alone) can build every circuit.

Gate symbols, truth tables and NAND/NOR replacements: see Tables 6.2a–c.

An AND–OR circuit becomes NAND–NAND by double complement and DeMorgan: xy+zw=((xy)′(zw)′)′xy + zw = ((xy)'(zw)')'. Also, x⊕y⊕z=1x \oplus y \oplus z = 1 when an odd number of inputs are 1 (parity bit).

Why OR is NAND of the complements: NAND gives 0 only when both of its inputs are 1. Feeding it a′a' and b′b' gives 0 only when a=b=0a = b = 0, which is exactly when a+b=0a + b = 0.

aabba′a'b′b'NAND(a′a', b′b')a+ba+b
001100
011011
100111
110011

Recipe: any SOP using only NAND gates

  1. Draw the circuit with ordinary NOT, AND and OR gates, straight from the formula.
  2. Replace every gate with its NAND version from Table 6.2a: AND becomes NAND then NOT, and OR becomes NOT on each input then NAND.
  3. On each path from an AND to the OR you now have NAND → NOT → NOT → NAND. Two NOTs in a row cancel, leaving NAND → NAND.
  4. Each NOT on an input variable stays, and becomes NAND with both inputs joined.
  5. Check with a truth table (or one row by hand).
Gate in the ordinary circuitNAND gateIts inputsIts output
NOT
NOT
AND
AND
OR

Worked example: XOR from NAND only, x⊕y=xy′+x′yx \oplus y = xy' + x'y

Step 1, the ordinary circuit: NOT yy makes y′y', and NOT xx makes x′x'. AND(xx, y′y') makes xy′xy', and AND(x′x', yy) makes x′yx'y. An OR joins them.

Ordinary circuit: 2 NOT, 2 AND, 1 ORxyy'x'xy'x'yxy' + x'y

Steps 2–4: swap each gate, then cancel the NOT pairs.

PathOrdinaryAfter swappingAfter cancelling
AND to ORAND → ORNAND → NOT → NOT → NANDNAND → NAND
Input NOTNOTNAND(aa, aa)NAND(aa, aa)
Gate in the ordinary circuitNAND gateIts inputsIts output
NOT xxG1G_1xx, xxx′x'
NOT yyG2G_2yy, yyy′y'
AND xy′xy'G3G_3xx, G2G_2(xy′)′(xy')'
AND x′yx'yG4G_4G1G_1, yy(x′y)′(x'y)'
ORG5G_5G3G_3, G4G_4xy′+x′yxy' + x'y
XOR from five NAND gatesxyy'x'(xy')'(x'y)'x ⊕ y

Check x=1x = 1, y=0y = 0: G1=0G_1 = 0, G2=1G_2 = 1, G3=NAND(1,1)=0G_3 = \text{NAND}(1,1) = 0, G4=NAND(0,0)=1G_4 = \text{NAND}(0,0) = 1, G5=NAND(0,1)=G_5 = \text{NAND}(0,1) = 1 ✓. The 4-gate version shares one gate n1=(xy)′n_1 = (xy)' in place of both inverters, because x(xy)′=xy′x(xy)' = xy' and y(xy)′=x′yy(xy)' = x'y.

  • “Only NAND” means no separate NOT gates: every inverter is NAND(aa, aa).
  • Only cancel two NOTs that are directly in a row on the same wire. The NOTs on the input variables have nothing to cancel with, so they stay.

Worked example: bitwise operations on A=1011 0010A = 1011\,0010, B=0110 1011B = 0110\,1011 (column by column)

OperationResult
A AND B0010 0010
A OR B1111 1011
A XOR B1101 1001
NOT A0100 1101
A NAND B1101 1101
A NOR B0000 0100

4.2 Boolean Laws, DeMorgan, SOP and POS

LawAND formOR form
Identity1x=x1x = x0+x=x0 + x = x
Null0x=00x = 01+x=11 + x = 1
Idempotentxx=xxx = xx+x=xx + x = x
Inversexx′=0xx' = 0x+x′=1x + x' = 1
Commutativexy=yxxy = yxx+y=y+xx + y = y + x
Associative(xy)z=x(yz)(xy)z = x(yz)(x+y)+z=x+(y+z)(x+y)+z = x+(y+z)
Distributivex+yz=(x+y)(x+z)x + yz = (x+y)(x+z)x(y+z)=xy+xzx(y+z) = xy + xz
Absorptionx(x+y)=xx(x+y) = xx+xy=xx + xy = x
DeMorgan(xy)′=x′+y′(xy)' = x' + y'(x+y)′=x′y′(x+y)' = x'y'

Also useful: (x′)′=x(x')' = x, x+x′y=x+yx + x'y = x + y, consensus xy+x′z+yz=xy+x′zxy + x'z + yz = xy + x'z.

Complement of a whole expression (extended DeMorgan): swap every AND and OR, and prime every variable. Keep the brackets so the order of work does not change. Example: F=xy+x′z+yz′F = xy + x'z + yz' gives F′=(x′+y′)(x+z′)(y′+z)F' = (x'+y')(x+z')(y'+z).

SOP (sum of minterms): one AND term per row where F=1F = 1; write xx for bit 1 and x′x' for bit 0; OR the terms. Short form F=Σm(…)F = \Sigma m(\ldots). POS (product of maxterms): one OR term per row where F=0F = 0; write xx for bit 0 and x′x' for bit 1; AND the terms.

#xxyyzzpart 1part 2FFminterm
0000x′y′z′x'y'z'
1001x′y′zx'y'z
2010x′yz′x'yz'
3011x′yzx'yz
4100xy′z′xy'z'
5101xy′zxy'z
6110xyz′xyz'
7111xyzxyz

Worked example: simplify with laws (name the law at every step)

(a) F=(x+y)(x+y′)(xz′)′F = (x+y)(x+y')(xz')'

StepLaw
=(x+yy′)(xz′)′= (x + yy')(xz')'Distributive
=(x+0)(xz′)′= (x + 0)(xz')'Inverse
=x(xz′)′= x(xz')'Identity
=x(x′+z)= x(x' + z)DeMorgan
=xx′+xz= xx' + xzDistributive
=0+xz== 0 + xz = xzxzInverse, Identity

(b) Show x=xy+xy′x = xy + xy': xy+xy′=x(y+y′)xy + xy' = x(y+y') (distributive) =x⋅1= x \cdot 1 (inverse) == xx (identity).

(c) F=Σm(0,2,4,5,6)F = \Sigma m(0,2,4,5,6): the 1s are rows 000, 010, 100, 101, 110. Rows 0, 2, 4, 6 all have z=0z = 0, giving z′z'. Rows 4, 5 have x=1x = 1, y=0y = 0, giving xy′xy'. So F=F = z′+xy′z' + xy'.

4.3 Karnaugh Maps

Rows and columns go in Gray order 00, 01, 11, 10. Circle rectangles of 1s of size 1, 2, 4, 8 or 16 (wrap-around allowed; the four corners form one group). Use as few, as large groups as possible, overlaps allowed, every 1 covered. Don’t-cares may be used as 1s but need not be covered. In each group keep only the variables that do not change (1 gives xx, 0 gives x′x'); a group of 2k2^k cells removes kk variables.

xyz000111100101324576
wxyz00011110000111100132457612131514891110
GroupCellsTerm
A
B
C
D

F=F =

Worked example 1: F(w,x,y,z)=Σm(0,1,2,5,8,9,10)F(w,x,y,z) = \Sigma m(0,1,2,5,8,9,10)

wxyz000111100001111001113021405170601201301501408191110101
  • m0, m1, m8, m9→x'y'
  • m0, m2, m8, m10→x'z'
  • m1, m5→w'y'z

F = x'y' + x'z' + w'y'z

GroupCellsUnchangedTerm
A0, 1, 8, 9x=0x=0, y=0y=0x′y′x'y'
B (corners)0, 2, 8, 10x=0x=0, z=0z=0x′z′x'z'
C1, 5w=0w=0, y=0y=0, z=1z=1w′y′zw'y'z

F=F = x′y′+x′z′+w′y′zx'y' + x'z' + w'y'z

Worked example 2: don’t-cares, F=Σm(1,3,7,11,15)+d(0,2,5)F = \Sigma m(1,3,7,11,15) + d(0,2,5)

wxyz00011110000111100d11312d405d71601201301511408090111100
  • m3, m7, m15, m11→yz
  • m0, m1, m3, m2→w'x'

F = yz + w'x'

Group A is the whole column yz=11yz = 11 giving yzyz. Group B is the top row, using d0 and d2 as 1s, giving w′x′w'x'. d5 is not needed, so leave it as 0. F=F = yz+w′x′yz + w'x'

Worked example 3: word problem (puppy biscuit). Biscuit (F=1F=1) for SWBSWB = 110, 011, 100, 111, otherwise 0.

SWB00011110010010312041507161
  • m3, m7→WB
  • m4, m6→SB'

F = WB + SB'

Group {3,7}\{3,7\} (column 11) gives WBWB; group {4,6}\{4,6\} (wraps around the row) gives SB′SB'. F=F = SB′+WBSB' + WB (1 NOT, 2 AND, 1 OR).

  • Label order is 00, 01, 11, 10, so cells 12–15 sit above 8–11.
  • Groups must be powers of 2 and rectangular, never L-shaped or size 3 or 6.
  • Do not forget wrap-around groups (edges and four corners).

4.4 Combinational Circuits

Half adder: Sum =x⊕y= x\oplus y, Carry =xy= xy. Full adder: Sum =x⊕y⊕Cin= x\oplus y\oplus C_{in}, Cout=xy+Cin(x⊕y)C_{out} = xy + C_{in}(x\oplus y). Sum is 1 for an odd number of 1s; CoutC_{out} is 1 for two or more 1s. Ripple-carry adder: nn full adders chained; each CoutC_{out} feeds the next CinC_{in}. Decoder: nn inputs give 2n2^n outputs, exactly one is 1 (inputs =log⁡2= \log_2 outputs). Multiplexer: 2n2^n data inputs need nn select lines.

xxyyCinC_{in}SumCoutC_{out}
00000
00110
01010
01101
10010
10101
11001
11111
  1. Start with Cin=0C_{in} = 0 at bit 0.
  2. For each bit, add Ai+Bi+CinA_i + B_i + C_{in}: Sum bit is the low bit of the total, carry is the high bit.
  3. Pass the carry to the next bit.
  4. Read the result as Cout,3 Sum3 Sum2 Sum1 Sum0C_{out,3}\,\text{Sum}_3\,\text{Sum}_2\,\text{Sum}_1\,\text{Sum}_0.
Full adderAiA_iBiB_iCinC_{in}Sumi\text{Sum}_iCoutC_{out}
FA0 (bit 0)0
FA1
FA2
FA3 (bit 3)

Result =Cout,3 Sum3 Sum2 Sum1 Sum0=‾= C_{out,3}\,\text{Sum}_3\,\text{Sum}_2\,\text{Sum}_1\,\text{Sum}_0 = \underline{\hspace{3cm}}

Worked example (a): A=1011A = 1011, B=0110B = 0110 in a 4-bit ripple-carry adder

FAAABBCinC_{in}SumCoutC_{out}
010010
111001
201101
310101

Sum =0001= 0001 with final carry 1, so 10001 = 17 (11+611 + 6); it does not fit in 4 unsigned bits.

Worked example (b): decoder and mux sizes. 64 outputs need log⁡264=\log_2 64 = 6 inputs. A 32-input mux needs 5 select lines. A 32-word memory of 8 chips ×\times 4 words with address A4…A0A_4\ldots A_0: top 3 bits go to a 3-to-8 decoder (chip select), low 2 bits pick the word. Address 10110 gives chip 101=5101 = 5, word 10=210 = 2.

Worked example (c): 4-to-1 mux. F=S1′S0′I0+S1′S0I1+S1S0′I2+S1S0I3F = S_1'S_0'I_0 + S_1'S_0I_1 + S_1S_0'I_2 + S_1S_0I_3. With I3I2I1I0=1001I_3I_2I_1I_0 = 1001 and S1S0=01S_1S_0 = 01, the output is I1=I_1 = 0.

Worked example (d): full adder from a 3-to-8 decoder. Inputs x,y,Cinx, y, C_{in}; Sum == OR of outputs 1, 2, 4, 7; Cout=C_{out} = OR of outputs 3, 5, 6, 7.

Worked example (e): 2-bit ALU (f1f0f_1f_0: 00 ADD, 01 OR, 10 NOT A, 11 AND) with A=01A = 01, B=10B = 10: ADD gives 11, OR gives 11, NOT A gives 10, AND gives 00.

4.5 Sequential Circuits: Flip-Flops

A sequential circuit has memory: output depends on the inputs and the present state QQ. Flip-flops change only on the clock edge, all together. Q+Q^+ is QQ after the next clock pulse.

Symbols, characteristic tables, the JK excitation table and how SR, JK, D and T are built from each other: see Tables 6.3a–d.

Worked example: JK sequence. Start Q=0Q = 0; (J,K)(J,K) at six pulses: (1,0) (0,0) (1,1) (1,1) (0,1) (1,1).

Pulse123456
Actionsetholdtoggletoggleresettoggle
QQ110101

Analysis recipe

  1. Name the flip-flops (state variables AA, BB, …) and the inputs (XX, …).
  2. Follow the wires and write an input equation for every flip-flop input (JAJ_A, KAK_A, DBD_B, …).
  3. For every row (present state plus input), evaluate the equations using present values only.
  4. Apply each flip-flop’s rule (Tables 6.3a–c) to get the next state.
AABBXXFF A inputs (JAKAJ_AK_A or DAD_A)FF B inputs (JBKBJ_BK_B or DBD_B)A+A^+B+B^+
000
001
010
011
100
101
110
111

Worked example: two D flip-flops, DA=A⊕XBD_A = A \oplus XB, DB=B⊕XD_B = B \oplus X

AABBXXXBXBDA=A+D_A = A^+DB=B+D_B = B^+
000000
001001
010001
011110
100010
101011
110011
111100

When X=0X = 0, A+B+=ABA^+B^+ = AB (state held). When X=1X = 1: 00, 01, 10, 11, 00, and so on. The circuit is a 2-bit binary up-counter with count enable XX.

  • Use the old AA and BB on the right-hand side of every equation, even if AA changes in the same row.
  • SR input 11 is not allowed; JK 11 toggles.

5. MARIE: CPU, Assembly and the Control Unit

Lectures 6–7: clocks, address lines, memory chips, MARIE ISA, fetch–decode–execute, assembly, control signals, microcode.

6.1 Clocks, Address Lines and Memory Chips

A memory written L × W has L locations, each W bits wide. Address lines = log⁡2\log_2(addressable locations); the width W only decides the data lines. Byte-addressable: locations = L × (W / 8).

Cycle time =1/f= 1/f · instruction time = cycles × cycle time · peak bus bandwidth = (data lines / 8) bytes × transfers per second.

  1. Chips per row = memory width ÷ chip width.
  2. Rows = memory locations ÷ chip locations.
  3. Total chips = rows × chips per row.
  4. Total address bits = log⁡2\log_2(memory locations); bits inside a chip = log⁡2\log_2(chip locations).
  5. Row-select bits = total − inside (feeds a kk-to-2k2^k decoder).
  6. For a given address: high bits = row, low bits = location inside the chip.
QuantityValue
Chips per row
Rows
Total chips
Total address bits
Bits inside a chip
Row-select bits / decoder

Worked examples

ProblemWorkingAnswer
800 MHz clock; instruction of 6 cyclest=1000/800=1.25t = 1000/800 = 1.25 ns; 6×1.256 \times 1.251.25 ns, 7.5 ns
4M × 16, word-addressable4M=22⋅220=2224\text{M} = 2^2 \cdot 2^{20} = 2^{22} words22 lines
4M × 16, byte-addressable2222^{22} words × 2 bytes = 2232^{23} bytes23 lines
MARIE: 4K × 16 words4K=2124\text{K} = 2^{12}12 lines
2M × 32 from 256K × 8 chipsper row 32/8=432/8 = 4; rows 2M/256K=82\text{M}/256\text{K} = 8; address 2212^{21}, inside chip 2182^{18}, select 21−18=321 - 18 = 332 chips, 21 bits = 18 + 3, 3-to-8 decoder
MARIE 4K × 16 from 1K × 8 chips; where is 9AB?per row 2, rows 4 → 8 chips; 12 bits = 2 select + 10 inside; 9AB = 10 01 1010 1011row 2 (from 0), location 1AB
32 data lines, 100 MHz, one transfer per cycle4 bytes×100×1064 \text{ bytes} \times 100 \times 10^6400 MB/s
5 devices fully point-to-pointn(n−1)/2=5⋅4/2n(n-1)/2 = 5 \cdot 4 / 210 links (1 shared bus instead)
Flip-flops for all MARIE registersAC 16 + MAR 12 + MBR 16 + PC 12 + IR 16 + InREG 8 + OutREG 888 D flip-flops
  • Width never changes the number of address lines (unless byte-addressable).
  • Use the number of locations, not bits, inside the log.

6.2 MARIE Architecture and Instruction Set

RegisterBitsHolds
AC16working value / result
MAR12address for memory
MBR16data to/from memory
PC12address of next instruction
IR16current instruction
InREG / OutREG8 / 8input / output

Address registers (MAR, PC) are 12 bits because memory has 4K = 2122^{12} words; data registers (AC, MBR, IR) are 16 bits because a word is 16 bits.

15–12opcode (4 bits)
11–0address X (12 bits)

Bit-by-bit examples (Load 3, Skipcond 800) and the full opcode table in binary and hex: see Section 6.5.

HexInstructionRTN (after fetch/decode)
0JnS XM[X] ← PC; PC ← X + 1
1Load XMAR ← X; MBR ← M[MAR]; AC ← MBR
2Store XMAR ← X, MBR ← AC; M[MAR] ← MBR
3Add XMAR ← X; MBR ← M[MAR]; AC ← AC + MBR
4Subt XMAR ← X; MBR ← M[MAR]; AC ← AC − MBR
5InputAC ← InREG
6OutputOutREG ← AC
7Haltstop
8Skipcondskip next instruction if condition is true
9Jump XPC ← IR[11–0]
AClearAC ← 0
BAddI XAC ← AC + M[M[X]]
CJumpI XPC ← M[X]
DLoadI XAC ← M[M[X]]
EStoreI XM[M[X]] ← AC
InstructionHexSkips next when
Skipcond 0008000AC < 0
Skipcond 4008400AC = 0
Skipcond 8008800AC > 0
  • AC is two’s complement: any value 8000–FFFF is negative (FFFB = −5, so Skipcond 000 skips and Skipcond 800 does not).
  • Input, Output, Halt, Clear, Skipcond have no real address: Halt = 7000, Clear = A000.
  1. Split the word: first hex digit = opcode, last three = address X.
  2. Look up the opcode (or mnemonic) in the table.
  3. Write the address as 3 hex digits, then convert each hex digit to 4 bits for binary.
AssemblyOpcode (hex)Address (3 hex)Hex wordBinary (4 + 12 bits)RTN / meaning

Worked example: encode, decode, indirect addressing

GivenSplitAnswer
Store 1A32 / 1A321A3 = 0010 0001 1010 0011
AddI 20FB / 20FB20F = 1011 0010 0000 1111
C108C / 108JumpI 108 (PC ← M[108])
0010 0000 0000 01112 / 007Store 007 (M[007] ← AC)
1000 1000 0000 00008 / 800Skipcond 800 (skip if AC > 0)

With M[200] = 0205, M[205] = 0042, AC = 0010 (each instruction starts from this state):

InstructionWhat happensResult
Load 200AC ← M[200]AC = 0205
LoadI 200M[200] = 0205 is a pointer, AC ← M[205]AC = 0042
AddI 200AC ← 0010 + M[205]AC = 0052
StoreI 200M[205] ← ACM[205] = 0010
JumpI 200PC ← M[200]PC = 205

6.3 The Fetch–Decode–Execute Cycle

StageRTNMeaning
FetchMAR ← PCsend the address of the next instruction to memory
IR ← M[MAR]read the instruction into the IR
PC ← PC + 1point to the following instruction
DecodeMAR ← IR[11–0]; decode IR[15–12]address field to the MAR; find the opcode
Get operandMBR ← M[MAR]only for instructions that read memory (Load, Add, Subt …)
Executee.g. AC ← AC + MBRthe instruction’s own steps, then back to fetch
  1. Start with the initial register values (PC = first address).
  2. Write one row per microoperation, in the order of the table above.
  3. On each row change only the register on the left of ←; the others keep their value.
  4. Memory reads give the next register its value (use the stated memory contents); AC arithmetic is two’s complement hex.
StageRTNPCIRMARMBRAC
(initial)
FetchMAR ← PC
IR ← M[MAR]
PC ← PC + 1
DecodeMAR ← IR[11–0]
Get operandMBR ← M[MAR]
Execute

Worked example: Load 104, Add 105, Store 106 (M[104] = 0023, M[105] = FFE9, PC = 100)

Instr.RTNPCIRMARMBRAC
(initial)100---------------
Load 104MAR ← PC100----100--------
IR ← M[MAR]1001104100--------
PC ← PC + 11011104100--------
MAR ← IR[11–0]1011104104--------
MBR ← M[MAR]10111041040023----
AC ← MBR101110410400230023
Add 105MAR ← PC101110410100230023
IR ← M[MAR]101310510100230023
PC ← PC + 1102310510100230023
MAR ← IR[11–0]102310510500230023
MBR ← M[MAR]1023105105FFE90023
AC ← AC + MBR1023105105FFE9000C
Store 106MAR ← PC1023105102FFE9000C
IR ← M[MAR]1022106102FFE9000C
PC ← PC + 11032106102FFE9000C
MAR ← IR[11–0]1032106106FFE9000C
MBR ← AC1032106106000C000C
M[MAR] ← MBR1032106106000C000C

FFE9 = −23, so AC = 35 − 23 = 12 = 000C. Final: M[106] = 000C.

  • PC is incremented during fetch, so jumps and JnS see the already-incremented PC.
  • Store has no memory read: it copies AC to MBR, then writes M[MAR].

6.4 MARIE Assembly and the Two-Pass Assembler

A source line is Label, Mnemonic Operand / comment. Directives: ORG n (start at hex address n), DEC n (decimal data word; negatives in two’s complement), HEX n (hex data word), END. Put the data after Halt.

  1. Pass 1: start the location counter (LC) at the ORG value. Give each line one address (every instruction and every DEC/HEX takes one word). Each label and its LC go into the symbol table.
  2. Pass 2: for each line write the opcode hex digit + the label’s address (3 hex digits). DEC/HEX lines give the 4-digit hex value.
Address (LC)LabelInstructionOpcodeOperand addressHex
SymbolAddress

Control structures = test, Skipcond, Jump. Put a value in the AC whose sign answers the question (usually AC = X − Y). Skipcond skips the Jump when the condition is true.

ConditionComputeSkipcond meaning “condition true”
X > YX − Y800 (AC > 0)
X < YX − Y000 (AC < 0)
X = YX − Y400 (AC = 0)

For ≥, ≤ or ≠, test the opposite condition and swap the THEN and ELSE parts.

/ if (X > Y) THEN-part ; else ELSE-part
        Load X
        Subt Y
        Skipcond 800   / X-Y > 0 ?
        Jump Else      / no -> else
        ...THEN-part...
        Jump EndIf
Else,   ...ELSE-part...
EndIf,  ...

/ while (X < Limit) body
Loop,   Load X
        Subt Limit
        Skipcond 000   / X-Limit < 0 ?
        Jump Done      / no -> leave loop
        ...body...
        Jump Loop
Done,   ...

/ subroutine call and return
        JnS Sub        / M[Sub] <- return addr
Sub,    HEX 0          / holds return address
        ...body...
        JumpI Sub      / go back

Worked example: if X > 1 then X = 0 after Y = X + X; then Y = Y + 1 (X = 2, Y = 10)

AddrSourceHex
100If, Load X110D
101Subt One410F
102Skipcond 8008800
103Jump EndIf9109
104Then, Load X110D
105Add X310D
106Store Y210E
107ClearA000
108Store X210D
109EndIf, Load Y110E
10AAdd One310F
10BStore Y210E
10CHalt7000
10DX, Dec 20002
10EY, Dec 10000A
10FOne, Dec 10001
SymbolAddress
If100
Then104
EndIf109
X10D
Y10E
One10F

Trace: AC = 2 − 1 = 1 > 0, so the Jump is skipped. Y = 2 + 2 = 4, X = 0. Then Y = 4 + 1. Result: Y = 5, X = 0. (With X = 1: AC = 0, no skip, Jump EndIf is taken, only Y = Y + 1 = 11 runs.)

  • Skipcond skips the next line, so the line after it must be the Jump that handles the false case.
  • JnS stores the return address in the first word of the subroutine; return with JumpI.

7.1 Control Signals, Timing Diagrams and Microprogramming

DeviceMemoryMARPCMBRACInREGOutREGIR
Bus number000001010011100101110111

One RTL step becomes signals: source number on P2P1P0P_2P_1P_0, destination number on P5P4P3P_5P_4P_3 (list only the bits that are 1). Reading memory adds MRM_R, writing adds MWM_W. ALU into AC: A1A0A_1A_0 = 01 add (A0A_0), 10 subtract (A1A_1), 11 clear; add LALTL_{ALT} and P5P_5. Add the time signal TnT_n (execution starts at T3T_3; fetch/decode use T0T_0–T2T_2) and CrC_r on the last step. One bus means only one bus transfer per clock cycle.

  1. Write the execute steps in RTL, one bus transfer per cycle starting at T3T_3.
  2. For each step find the source and destination device numbers.
  3. Source number gives the P2P1P0P_2P_1P_0 bits that are 1; destination number gives the P5P4P3P_5P_4P_3 bits that are 1.
  4. Add MRM_R / MWM_W / A0A_0 / A1A_1 / LALTL_{ALT} as needed, then TnT_n, and CrC_r on the last cycle.
CycleRTLSource, P2P1P0P_2P_1P_0Dest, P5P4P3P_5P_4P_3Extra (MRM_R, MWM_W, AA, LALTL_{ALT}, CrC_r)Signals that are 1
T3T_3
T4T_4
T5T_5

Worked example: control signals for Add X, Load X, Store X, JumpI X

Instr.CycleRTLSource / DestSignals
Add XT3T_3MAR ← XIR 111 / MAR 001P3P2P1P0T3P_3P_2P_1P_0T_3
T4T_4MBR ← M[MAR]memory 000 / MBR 011P4P3T4MRP_4P_3T_4M_R
T5T_5AC ← AC + MBRALU / AC 100CrA0P5T5LALTC_rA_0P_5T_5L_{ALT}
Load XT3T_3MAR ← XIR 111 / MAR 001P3P2P1P0T3P_3P_2P_1P_0T_3
T4T_4MBR ← M[MAR]memory 000 / MBR 011P4P3T4MRP_4P_3T_4M_R
T5T_5AC ← MBRMBR 011 / AC 100P5P1P0T5CrP_5P_1P_0T_5C_r
Store XT3T_3MAR ← XIR 111 / MAR 001P3P2P1P0T3P_3P_2P_1P_0T_3
T4T_4MBR ← ACAC 100 / MBR 011P4P3P2T4P_4P_3P_2T_4
T5T_5M[MAR] ← MBRMBR 011 / memory 000P1P0T5MWCrP_1P_0T_5M_WC_r
JumpI XT3T_3MAR ← XIR 111 / MAR 001P3P2P1P0T3P_3P_2P_1P_0T_3
T4T_4MBR ← M[MAR]memory 000 / MBR 011P4P3T4MRP_4P_3T_4M_R
T5T_5PC ← MBRMBR 011 / PC 010P4P1P0T5CrP_4P_1P_0T_5C_r

Subt X is the same as Add X except the last step uses A1A_1 (subtract) instead of A0A_0. One-step Jump X in T3T_3: P4P2P1P0T3CrP_4P_2P_1P_0T_3C_r (IR → PC).

Worked example: timing diagram for Add X. One row per signal; a signal is high in exactly the cycles whose list contains it (for example P3P_3 is in the T3T_3 and T4T_4 lists, so it is high in both).

Timing diagram for Add XT3T4T5cycleT3T4T5P0P1P2P3P4P5A0MRLALTCr
  • CrC_r only on the last cycle; MRM_R / MWM_W do not add P bits (memory = 000).
  • Load’s last step (MBR → AC) uses the bus (P5P1P0P_5P_1P_0), not the ALU.

Hardwired control

Opcode bits go to an instruction decoder (one AND gate per instruction); a ring counter gives T0,T1,…T_0, T_1, \dots; each signal = OR of (instruction · time).

  • Add =IR15′ IR14′ IR13 IR12= IR_{15}'\,IR_{14}'\,IR_{13}\,IR_{12} (0011); Load =IR15′ IR14′ IR13′ IR12= IR_{15}'\,IR_{14}'\,IR_{13}'\,IR_{12} (0001).
  • Using only Load and Add:
P3=(Load+Add)(T3+T4),P0=Load⋅T3+Load⋅T5+Add⋅T3P_3 = (\text{Load}+\text{Add})(T_3+T_4),\quad P_0 = \text{Load}\cdot T_3 + \text{Load}\cdot T_5 + \text{Add}\cdot T_3 P5=Cr=(Load+Add)⋅T5,MR=(Load+Add)⋅T4P_5 = C_r = (\text{Load}+\text{Add})\cdot T_5,\quad M_R = (\text{Load}+\text{Add})\cdot T_4

Microprogrammed control

Each instruction is a small routine of microinstructions in a ROM (control store); one microinstruction per clock cycle. Slower (extra fetch/decode level) but easy to change; hardwired is faster but must be redesigned to change.

17–13MicroOp1 (5 bits)
12–8MicroOp2 (5 bits)
7Jump (1 bit)
6–0Dest (7 bits)

18 bits. Dest is 7 bits because the microprogram has at most 27=1282^7 = 128 lines (128 × 18 = 2304 bits of ROM). A routine ends with Jump = 1, Dest = 0000000 (back to fetch).

CodeMicrooperationCodeMicrooperationCodeMicrooperation
00000NOP01001MAR ← MBR10010If AC = 00
00001AC ← 001010MAR ← PC10011If AC > 0
00010AC ← MBR01011MAR ← X10100If AC < 0
00011AC ← AC − MBR01100MBR ← AC10101If IR[11–10] = 00
00100AC ← AC + MBR01101MBR ← M[MAR]10110If IR[11–10] = 01
00101AC ← InREG01110OutREG ← AC10111If IR[11–10] = 10
00110IR ← M[MAR]01111PC ← IR[11–0]11000If IR[15–12] = MicroOp2[4–1]
00111M[MAR] ← MBR10000PC ← MBR
01000MAR ← IR[11–0]10001PC ← PC + 1
  1. List the RTN steps of the instruction (one microoperation per MicroOp field).
  2. Look up each code in the table above; put it in MicroOp1 (MicroOp2 = 00000 if unused).
  3. Number the lines from the start address; Jump = 0, Dest = 0000000 on all but the last line.
  4. On the last line set Jump = 1, Dest = 0000000 (return to fetch). Join the fields into the 18-bit word.
Address (7 bits)MicroOp1MicroOp2JumpDest (7 bits)18-bit word
0000000000000
0000000000000
0000010000000

Worked example: microcode for Load (starting at line 0110000)

AddressMicroOp1MicroOp2JumpDest
011000001000 (MAR ← IR[11–0])0000000000000
011000101101 (MBR ← M[MAR])0000000000000
011001000010 (AC ← MBR)0000010000000

Worked example: decode 11000 00110 1 0101100. 11000 = “if IR[15–12] = MicroOp2[4–1]”; MicroOp2[4–1] = 0011 = Add; Jump = 1 to 0101100 (line 44). If the IR holds 3105 (opcode 3), control jumps to the Add routine; if the IR holds 1104 (Load) there is no match and control goes on to the next line.

  • A routine must end with Jump = 1, Dest = 0000000, or control never returns to fetch.
  • MicroOp2[4–1] drops the last bit: 00110 gives 0011 (opcode 3).

6. Quick Reference

All the formulas on one page, the reference tables the problems refer to (gates, flip-flops, number tables, MARIE format), and the checks to run before you hand in.

6.1 Formulas

Units, time and growth

TopicFormula / rule
Time and frequencyt=1/ft = 1/f · t (ns)=1000/f (MHz)t\,(\text{ns}) = 1000 / f\,(\text{MHz})
Execution timeinstruction time == cycles × t\times\, t · program time == instructions ×\times CPI × t\times\, t
Sizes (memory)K=210K = 2^{10}, M=220M = 2^{20}, G=230G = 2^{30}, T=240T = 2^{40}
Sizes (speed, disk)k=103k = 10^3, M=106M = 10^6, G=109G = 10^9
Doubling lawsnew=old×2t/T\text{new} = \text{old} \times 2^{t/T} · Moore T=18T = 18 months (original: 1 year) · Rock T=4T = 4 years

Number representation and arithmetic

TopicFormula / rule
Range with nn bitsunsigned 0…2n−10 \ldots 2^n - 1 · SM, 1C ±(2n−1−1)\pm(2^{n-1} - 1) · 2C −2n−1…2n−1−1-2^{n-1} \ldots 2^{n-1} - 1
NegationSM: flip sign bit · 1C: flip all bits · 2C: flip all bits, add 1
Overflow2C: V=Cinto MSB⊕Cout of MSBV = C_{\text{into MSB}} \oplus C_{\text{out of MSB}} · 1C: add the end-around carry · 2C: drop the carry
Floating point(−1)S×1.F×2E−bias(-1)^S \times 1.F \times 2^{E - \text{bias}} · bias 16 (14-bit), 127 (single), 1023 (double)
FP multiply / dividemultiply: E=E1+E2−biasE = E_1 + E_2 - \text{bias} · divide: E=E1−E2+biasE = E_1 - E_2 + \text{bias}

Error detection and correction

TopicFormula / rule
CRCkey of n+1n+1 bits → append nn zeros → mod-2 divide → nn-bit remainder replaces the zeros · receiver remainder 00 = accept
Hammingsmallest rr with m+r+1≤2rm + r + 1 \le 2^r · check bits at 1, 2, 4, 8, 16 · syndrome =K⊕K′= K \oplus K' = error position
Dmin⁡D_{\min}detect Dmin⁡−1D_{\min} - 1 errors · correct ⌊(Dmin⁡−1)/2⌋\lfloor (D_{\min} - 1)/2 \rfloor

Boolean algebra and digital logic

TopicFormula / rule
Boolean lawsDeMorgan (xy)′=x′+y′(xy)' = x' + y', (x+y)′=x′y′(x+y)' = x'y' · x+xy=xx + xy = x · x+x′y=x+yx + x'y = x + y · xy+xy′=xxy + xy' = x
AddersSum =x⊕y⊕Cin= x \oplus y \oplus C_{in} · Cout=xy+Cin(x⊕y)C_{out} = xy + C_{in}(x \oplus y)
Decoder / muxdecoder: nn inputs → 2n2^n outputs · mux: 2n2^n data inputs → nn select lines
Flip-flopsSR: Q+=S+R′QQ^+ = S + R'Q · JK: Q+=JQ′+K′QQ^+ = JQ' + K'Q · D: Q+=DQ^+ = D · T: Q+=T⊕QQ^+ = T \oplus Q
Memoryaddress bits =log⁡2(locations)= \log_2(\text{locations}) · chips =(L÷chip L)×(W÷chip W)= (L \div \text{chip } L) \times (W \div \text{chip } W) · select bits == total −- inside chip

MARIE and control

TopicFormula / rule
MARIE word16-bit word == 4-bit opcode ++ 12-bit address · 4K words
Skipcond000000 (<0<0), 400400 (=0=0), 800800 (>0>0)
Control signalssource → P2P1P0P_2P_1P_0, destination → P5P4P3P_5P_4P_3 · Mem 0, MAR 1, PC 2, MBR 3, AC 4, InREG 5, OutREG 6, IR 7
ALUA1A0A_1A_0: 0101 add, 1010 subtract, 1111 clear

6.2 Logic gates

Table 6.2a: the seven gates. AA and BB are the inputs, YY the output.

GateSymbolExpressionY=1Y = 1 whenMade from NAND onlyMade from NOR only
NOTLogic circuit diagramAYY=A′Y = A'the input is 0NAND(AA, AA)NOR(AA, AA)
ANDLogic circuit diagramABYY=ABY = ABall inputs are 1NOT(NAND(AA, BB))NOR(A′A', B′B')
ORLogic circuit diagramABYY=A+BY = A + Bany input is 1NAND(A′A', B′B')NOT(NOR(AA, BB))
XORLogic circuit diagramABYY=A⊕B=AB′+A′BY = A \oplus B = AB' + A'Bthe inputs differ4 NAND gates (see 4.1)5 NOR gates
NANDLogic circuit diagramABYY=(AB)′Y = (AB)'any input is 0NANDNOT(NOR(A′A', B′B'))
NORLogic circuit diagramABYY=(A+B)′Y = (A + B)'all inputs are 0NOT(NAND(A′A', B′B'))NOR
XNORLogic circuit diagramABYY=(A⊕B)′Y = (A \oplus B)'the inputs are equalXOR, then NOT4 NOR gates

Table 6.2b: truth tables

AABBNOT AAANDORXORNANDNORXNOR
001000111
011011100
100011100
110110001

Table 6.2c: how the gates relate

RelationMeaning
A bubble (small circle) means NOTNAND is AND with a bubble on the output; NOR is OR with one; XNOR is XOR with one.
NAND and NOR are universalAny circuit can be built from NAND alone (or NOR alone). They are cheap, fast and low-power, so chips use them.
DeMorgan swaps AND and OR(AB)′=A′+B′(AB)' = A' + B': a NAND is the same as an OR with bubbles on both inputs. (A+B)′=A′B′(A+B)' = A'B': a NOR is an AND with input bubbles.
AND–OR becomes NAND–NANDAB+CD=((AB)′(CD)′)′AB + CD = \big((AB)'(CD)'\big)': every AND and the final OR in a sum of products can become a NAND (see 4.1).
XOR is a “difference” detectorA⊕B=1A \oplus B = 1 when the bits differ; it is the sum bit of a half adder and the parity of the inputs.

6.3 Flip-flops

A flip-flop stores one bit, QQ. Its next value Q(t+1)Q(t+1) (also written Q+Q^+) is set at the clock tick from the inputs and the present Q(t)Q(t). Flip-flops change on the clock edge (edge-triggered) or while the clock is high (level-triggered).

Table 6.3a: SR (set/reset) flip-flop

SymbolInside
Logic circuit diagramSRQQ'SRSCRQTwo NOR gates, each output fed back into the other gate’s input.
SSRRQ(t+1)Q(t+1)Action
00Q(t)Q(t)no change
010reset
101set
11undefinednot allowed (unstable)

Equation (with SR=0SR = 0): Q+=S+R′QQ^+ = S + R'Q.

SR flip-flop inside: two cross-coupled NOR gatesSRQ'Q

Table 6.3b: JK flip-flop

SymbolInside
Logic circuit diagramJKQQ'JKJCKQAn SR flip-flop with two AND gates in front: S=JQ′S = JQ', R=KQR = KQ.
JJKKQ(t+1)Q(t+1)Action
00Q(t)Q(t)no change
010reset
101set
11Q(t)′Q(t)'toggle

Equation: Q+=JQ′+K′QQ^+ = JQ' + K'Q.

Q→Q+Q \to Q^+JJKK
0 → 00d
0 → 11d
1 → 0d1
1 → 1d0

The last table is the JK excitation table (which inputs cause a given change; d = don’t care). Use it when you design or convert a flip-flop.

JK flip-flop inside: an SR flip-flop with AND gatesSRQQ'SRJCKS = JQ'R = KQQ

Table 6.3c: D (data) flip-flop

SymbolInside
Logic circuit diagramDQQ'DDCQAn SR flip-flop with S=DS = D and R=D′R = D' (one inverter).
DDQ(t+1)Q(t+1)Action
00store 0
11store 1

Equation: Q+=DQ^+ = D. The output only changes when DD changes. A row of D flip-flops sharing one clock is a register; the D flip-flop is the basic cell of computer memory.

D flip-flop inside: an SR flip-flop with an inverterSRQQ'SRDCD'Q

Table 6.3d: how the flip-flops relate

Flip-flopBuilt fromInputs 11Use it for
SRtwo NOR gates with feedbacknot allowedthe basic memory cell
JKSR + AND gates S=JQ′S = JQ', R=KQR = KQtogglegeneral design: no forbidden input
DSR + inverter S=DS = D, R=D′R = D'cannot happen (S≠RS \ne R)registers and memory
TJK with J=K=TJ = K = T(one input) 1 = togglebinary counters (Q+=T⊕QQ^+ = T \oplus Q)

6.4 Number tables

Table 6.4a: 4-bit binary → hex (and decimal). One hex digit is exactly 4 bits, so convert binary ↔ hex one group of 4 at a time.

BinaryHexDecimalBinaryHexDecimal
000000100088
000111100199
0010221010A10
0011331011B11
0100441100C12
0101551101D13
0110661110E14
0111771111F15

Table 6.4b: powers of 2 (binary place values; 210=1K2^{10} = 1\text{K}, 220=1M2^{20} = 1\text{M}, 230=1G2^{30} = 1\text{G})

nn01234567891011121620
2n2^n124816326412825651210242048409665 5361 048 576

Fractions: 2−1=0.52^{-1} = 0.5, 2−2=0.252^{-2} = 0.25, 2−3=0.1252^{-3} = 0.125, 2−4=0.06252^{-4} = 0.0625, 2−5=0.031252^{-5} = 0.03125.

Table 6.4c: bit positions in binary (Hamming codes). Positions are counted from 1 at the right. Each 1 in a position’s binary form names a check bit that covers it; the check bits sit at the powers of 2.

PositionBinary (16 8 4 2 1)Covered byPositionBinary (16 8 4 2 1)Covered by
100001P1 (check bit)901001P8, P1
200010P2 (check bit)1001010P8, P2
300011P2, P11101011P8, P2, P1
400100P4 (check bit)1201100P8, P4
500101P4, P11301101P8, P4, P1
600110P4, P21401110P8, P4, P2
700111P4, P2, P11501111P8, P4, P2, P1
801000P8 (check bit)1610000P16 (check bit)

So P1 covers 1, 3, 5, 7, 9, 11, 13, 15; P2 covers 2, 3, 6, 7, 10, 11, 14, 15; P4 covers 4–7 and 12–15; P8 covers 8–15.

Table 6.4d: floating-point formats

FormatTotal bitsSignExponentFractionBiasNormal exponent eePrecision
Lecture 14-bit model1415816E−16E - 168 fraction bits
IEEE single precision321823127−126…127-126 \ldots 127about 7 decimal digits, up to about 3.4×10383.4 \times 10^{38}
IEEE double precision64111521023−1022…1023-1022 \ldots 1023about 15–16 decimal digits, up to about 1.8×103081.8 \times 10^{308}
13sign (1 bit)
12–8exponent (5 bits)
7–0fraction (8 bits)
14-bit model
31sign (1 bit)
30–23exponent (8 bits)
22–0fraction (23 bits)
Single precision (32 bits)
63sign (1 bit)
62–52exponent (11 bits)
51–0fraction (52 bits)
Double precision (64 bits)

Value =(−1)S×1.F×2E−bias= (-1)^S \times 1.F \times 2^{E - \text{bias}}. Special patterns (single; for double read 2047 for 255):

Exponent EEFraction FFMeaningExample (single, hex)
00zero (+0+0 or −0-0)00000000, 80000000
1 – 254anythingnormal number3F800000 = 1.0
255 (all 1s)0+∞+\infty or −∞-\infty7F800000, FF800000
255not 0NaN (not a number)7FC00000

6.5 MARIE instruction format

Every MARIE instruction is one 16-bit word: a 4-bit opcode (bits 15–12, one hex digit) and a 12-bit address (bits 11–0, three hex digits). So the hex word is the opcode digit followed by the address: Load 003 = 1003.

15–12opcode (4 bits)
11–0address (12 bits)
MARIE instruction (16 bits)

Load 3 as it sits in the IR: opcode 1 (0001), address 3.

opcodeaddress
0001000000000011
1514131211109876543210

Skipcond 800 as it sits in the IR: opcode 8 (1000); bits 11–10 = 10 mean “skip the next instruction if AC > 0”.

opcodeaddress
1000100000000000
1514131211109876543210
Bits 11–10Hex wordSkips the next instruction when
008000AC < 0
018400AC = 0
108800AC > 0

Table 6.5: MARIE opcodes

BinaryHexInstructionMeaning
00000JnS Xstore the PC at X, jump to X + 1 (subroutine call)
00011Load Xload the contents of address X into AC
00102Store Xstore the contents of AC at address X
00113Add Xadd the contents of address X to AC
01004Subt Xsubtract the contents of address X from AC
01015Inputinput a value from the keyboard into AC
01106Outputoutput the value in AC to the display
01117Haltterminate the program
10008Skipcondskip the next instruction on a condition
10019Jump Xload the value of X into PC
1010AClearput 0 in AC
1011BAddI Xadd indirect: AC ← AC + M[M[X]]
1100CJumpI Xjump indirect: PC ← M[X]
1101DLoadI Xload indirect: AC ← M[M[X]]
1110EStoreI Xstore indirect: M[M[X]] ← AC

6.6 Exam-day checklist

Number conversion and arithmetic

  • Base conversion: convert the answer back to decimal. Integer remainders are read bottom-up, fraction bits top-down.
  • Signed numbers: is the result within the range of nn bits? Overflow means carry into MSB ≠\ne carry out. Check the answer in decimal.
  • Floating point: bias added (16 or 127)? Hidden 1 not stored? Fraction padded on the right? Decode your pattern to check.

Error codes

  • Parity / CRC: count the 1s again. CRC: the nn zeros are appended at the sender only; the remainder has nn bits; the codeword divides with remainder 0.
  • Hamming: positions counted from the right; check bits at 1, 2, 4, 8; every group (check bit plus the positions it covers) has an even number of 1s.

Logic design

  • K-map: Gray order 00 01 11 10; groups of 1, 2, 4, 8; wrap-around used; every 1 covered; test one 0-row and one 1-row against your answer.
  • Flip-flops: use present values only; JK 1111 = toggle; SR 1111 is not allowed.

MARIE and control

  • MARIE: address is 3 hex digits; DEC negatives in two’s complement; data placed after Halt; symbol-table addresses match the code; trace the AC.
  • Control signals: source → P2P1P0P_2P_1P_0, destination → P5P4P3P_5P_4P_3; MRM_R/MWM_W for memory; CrC_r only on the last step; one bus transfer per cycle.