Week 9: Digital Logic & Computer System Architecture

This week moves from the abstract Boolean algebra of Week 8 into physical machines: how numbers are represented, how logic gates compose into circuits that add and store, and how a CPU is actually organised — instruction execution, pipelining and the memory hierarchy that makes a computer fast despite slow storage.

Module 2 of 3 Week 9 of 19 ~3.5 Hours Exam-Style Practice Included

By the end of this week, you'll be able to

  • Convert between number systems and perform signed binary arithmetic including two's complement
  • Design and analyse simple combinational and sequential circuits from truth tables
  • Explain instruction pipelining, hazards, and the role of each level of the memory hierarchy

1. Number Systems & Boolean Circuits

Binary, octal, decimal and hexadecimal conversions are foundational and still directly tested. For negative numbers, two's complement is the standard representation: invert all bits and add 1 — its key advantage is that addition and subtraction use the same hardware circuit regardless of sign, and there is exactly one representation of zero (unlike one's complement or sign-magnitude, which have two).

Combinational circuits (output depends only on current inputs — adders, multiplexers, decoders) are designed by writing a truth table, deriving a Boolean expression (often minimised using Karnaugh maps), and implementing it with gates. Sequential circuits (output depends on current inputs AND past state, via memory elements like flip-flops) implement things like counters and registers — the SR, D, JK and T flip-flops are the standard set NTA expects you to know the characteristic equations for.

two's complement of -13, in 8 bits
Step 1: write 13 in binary (8-bit):        0000 1101
Step 2: invert every bit (one's complement): 1111 0010
Step 3: add 1:                               1111 0011   <- this is -13

Check: adding +13 (0000 1101) and -13 (1111 0011) in 8-bit
two's complement gives 1 0000 0000 -> discard the overflow
carry bit -> 0000 0000, confirming the result is exactly 0.
Why two's complement won, historically

One's complement and sign-magnitude both need special-case circuitry for subtraction and both have two representations of zero (+0 and -0). Two's complement needs no special case for subtraction (it's just addition of a negated operand) and has a single, unambiguous zero — which is why virtually every modern CPU uses it.

2. CPU Architecture: Instruction Sets & Addressing Modes

A CPU executes an instruction through the fetch-decode-execute cycle: fetch the instruction from memory (using the Program Counter), decode it to determine the operation and operands, then execute it. Addressing modes determine how an operand's location is specified: immediate (value is embedded in the instruction), direct (address given directly), indirect (instruction holds the address of the address), and indexed/register-indirect (used heavily for arrays and loops).

RISC (Reduced Instruction Set Computer — few, simple, fixed-length instructions, more registers, relies on the compiler) is contrasted with CISC (Complex Instruction Set Computer — many, variable-length, more powerful instructions, e.g. classic x86) — RISC's simplicity is specifically what makes efficient pipelining easier, which is why the RISC/CISC distinction and pipelining are taught together.

3. Pipelining, Memory Hierarchy & I/O

Pipelining overlaps the execution of multiple instructions across stages (fetch, decode, execute, memory access, write-back) to increase throughput. Hazards break this overlap: structural hazards (two instructions need the same hardware resource simultaneously), data hazards (an instruction needs a result a previous instruction hasn't produced yet), and control hazards (a branch instruction means the next instruction to fetch isn't known yet).

The memory hierarchy — registers, cache (L1/L2/L3), main memory (RAM), secondary storage — trades capacity for speed at every level, exploiting the principle of locality of reference: temporal locality (recently accessed data is likely accessed again soon) and spatial locality (nearby data is likely accessed soon too) are exactly why caching works at all. I/O is handled via polling (CPU repeatedly checks device status — simple but wastes CPU cycles), interrupts (device signals the CPU when ready — efficient), and DMA (Direct Memory Access — device transfers data to/from memory without CPU involvement in the transfer itself, freeing the CPU for other work).

The one idea that explains the whole memory hierarchy

Every level of the memory hierarchy exists purely because of locality of reference — if programs accessed memory in a truly random pattern with no locality at all, caching wouldn't help and the entire hierarchy would collapse to "just use the fastest, most expensive memory for everything."

4. Hands-on Exercise

Hands-on

Design a small circuit and trace a pipeline hazard

This week's ideas click fastest when you build a tiny circuit and trace instruction timing by hand.

Part 1 — Circuit design:

  1. Design a 2-bit binary adder: write the truth table for a full adder (two input bits + carry-in, producing sum + carry-out).
  2. Derive the Boolean expressions for Sum and Carry-out from the truth table.
  3. Sketch the gate-level circuit implementing both expressions.

Part 2 — Pipeline hazard:

  1. Write a 4-instruction sequence where instruction 2 needs the result instruction 1 is still computing (a data hazard).
  2. Draw a simple pipeline timing diagram (fetch/decode/execute/writeback per instruction) showing where the hazard forces a stall.
  3. Name one real hardware technique (forwarding/bypassing, or stalling) that mitigates this specific hazard.

5. Exam-Style Practice (UGC NET Pattern)

Five NTA-pattern questions on number systems, circuits and CPU architecture.

Q1

What is the two's complement representation of -5 in 8 bits?

A) 1111 1010
B) 1111 1011
C) 0000 0101
D) 1000 0101

Correct answer: B) 1111 1011. 5 in 8-bit binary is 0000 0101. Inverting gives 1111 1010, and adding 1 gives 1111 1011 — the two's complement representation of -5.

Q2

Which of the following is the main practical advantage of two's complement over sign-magnitude representation?

A) It allows non-integer values to be represented
B) Addition and subtraction can use the same circuitry with no special-case handling, and zero has a single representation
C) It uses fewer bits for the same range
D) It is easier for humans to read directly

Correct answer: B) Addition and subtraction can use the same circuitry with no special-case handling, and zero has a single representation. Two's complement needs no special subtraction circuitry (subtraction is just addition of the negated value) and has exactly one representation of zero, unlike sign-magnitude which needs separate handling and has two zeros.

Q3

In the classic instruction pipeline, a data hazard occurs when:

A) Two instructions require the same physical hardware unit at the same cycle
B) An instruction needs a result that a prior, still-executing instruction has not yet produced
C) A branch instruction's target is not yet known
D) The instruction cache experiences a miss

Correct answer: B) An instruction needs a result that a prior, still-executing instruction has not yet produced. A data hazard specifically arises when an instruction depends on the result of a previous instruction that hasn't completed yet — distinct from structural hazards (resource conflicts) and control hazards (branch uncertainty).

Q4

Which addressing mode embeds the actual operand value directly within the instruction itself?

A) Direct addressing
B) Indirect addressing
C) Immediate addressing
D) Register-indirect addressing

Correct answer: C) Immediate addressing. Immediate addressing places the literal operand value directly in the instruction, requiring no additional memory access to fetch the operand.

Q5

The principle that recently accessed memory locations are likely to be accessed again soon is called:

A) Spatial locality
B) Temporal locality
C) Working-set locality
D) Cache locality

Correct answer: B) Temporal locality. Temporal locality refers specifically to recently accessed data being likely accessed again soon; spatial locality instead refers to nearby memory addresses being likely accessed soon.