Lite / Engineering Complex Systems / Week 26
Thinking in register transfers
Can you swap two registers in one clock cycle without a spare? In software you need a temporary variable. In hardware you don't. Why?
Why should I care?
Register-transfer level (RTL) is the language chip designers actually think in: not individual gates, but values moving between registers on clock edges. Hardware description languages like Verilog and VHDL are written at this level.
- Read and write register-transfer notation such as A ← A + B.
- Explain why transfers in the same cycle use the old values.
- Build a datapath from registers, an ALU and multiplexers.
Predict
Registers A = 3, B = 5. On one clock edge both A ← B and B ← A happen. What are A and B afterwards?
- A = 5, B = 5
- A = 5, B = 3
- A = 3, B = 3
- It depends on which happens first
Guess first, then reveal
A = 5, B = 3: a swap. Both flip-flop groups sample their inputs at the same instant, before either output changes. There is no 'first' within one edge, unlike two lines of software.
Discover
Load the 2:1 multiplexer preset and work out its truth table. Then sketch on paper how two multiplexers and two registers implement 'on each clock: if S = 1 then swap A and B, else hold'.
What the interactive shows (text version)
The 2:1 multiplexer outputs A when select S = 0 and B when S = 1. Two of them in front of registers A and B, with S = 1 feeding each register the other's value and S = 0 feeding each its own value, implement 'swap or hold' on each clock edge.
Understand
The notation
A ← A + B means: on the next clock edge, register A loads the value of A + B computed from the current outputs. A condition can guard it: if LOAD: R ← D. Several transfers listed for the same cycle all happen together. RTL hides gate-level detail while keeping exact timing.
Same edge, old values
Every register's input is computed from the values before the edge, and every register loads at the edge. So A ← B and B ← A swap; A ← B and B ← (A + B) steps a Fibonacci pair (3, 5 → 5, 8). Software executes lines in order, so the same two lines would give a different answer: a classic bug when translating between the two.
Datapath building blocks
Registers hold values (with a load-enable). Multiplexers choose which value goes where. The ALU computes (add, subtract, AND…). Buses carry values between them. A control unit sets the multiplexer selects, ALU operation and load-enables each cycle, deciding which transfers happen.
Explain it another way
Intuitive
Picture everyone in a room passing a ball on a whistle. On the whistle, everyone throws at once and catches at once, so two people can swap balls without dropping one.
Technical
In Verilog, non-blocking assignments (a <= b; b <= a;) model this simultaneous behaviour inside a clocked block; blocking assignments (=) behave like software and would not swap.
Mathematical
State update as a vector function: (A, B)ₖ₊₁ = F((A, B)ₖ). For A ← B, B ← A + B mod 256 from (3, 5): (5, 8), (8, 13), (13, 21)…
Applied
A processor's program counter is a register with an incrementer and a multiplexer: PC ← PC + 1 normally, PC ← target on a jump. That single RTL line is in every CPU.
Worked example 1
A = 2, B = 7. Each cycle: A ← A + B, B ← A. Find A and B after 2 cycles.
Cycle 1 uses old values: A = 9, B = 2. Cycle 2: A = 9 + 2 = 11, B = 9.
Common mix-ups
Transfers written in the same cycle happen one after another.
✓ They all read old values and load together on the clock edge.
Practice
Practice, not a test. Answers are checked on our server; a wrong answer gets a hint and another try. Nothing is saved.
Apply it
Write the RTL (one cycle per line) for a datapath that computes the sum of M[0]…M[3] into register S using a counter I, and say which multiplexers and load-enables the control unit must drive each cycle.
Reflect
What bug would you expect when someone translates RTL directly into ordinary sequential code?
Write your answer on paper or in your own notes. Lite never stores what you write.