School/□ Systems Engineer/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?
About 35 min · 3 goals · Checked by automated tests
1.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.
2.Predict
Registers A = 3, B = 5. On one clock edge both A ← B and B ← A happen. What are A and B afterwards?
Guess first. Being wrong here is how the surprise works.
3.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'.
Explorer 05 — Digital logic
Build answers out of ones and zeros
Every digital chip is built from a handful of simple gates. Flip the inputs to watch signals travel through a circuit, then wire your own gates to meet a target truth table.
- 1 (high)
- 0 (low)
- Unknown
- Inverting output
A single two-input gate. Change its type and watch the truth table change.
Inputs
Gates (1 of 8)
G1 = 0
Add a gate
Outputs
- Gates
- 1
- Depth
- 1
- Longest chain of gates a signal passes through
- Rows
- 4
- 2^2 input combinations
- Check
- —
| Set inputs | A | B | Y |
|---|---|---|---|
| 0 | 0 | 0 | |
| 0 | 1 | 0 | |
| 1 | 0 | 0 | |
| 1 | 1 | 1 |
State
Inputs A = 0, B = 0. Outputs Y = 0.
Inputs A = 0, B = 0. Outputs Y = 0.
How to read this
Signals flow left to right. Circles on the left are the inputs, boxes are gates and squares on the right are outputs. A thick bright wire carries a 1, a thin grey wire carries a 0, and each gate shows the value it outputs. A small circle on a gate's output means it inverts (NOT, NAND, NOR, XNOR).
The truth table lists every possible input combination and what the circuit outputs for each, so it describes the circuit completely. Two circuits with the same truth table are equivalent, however differently they are built. That is why NAND alone can make any other gate. Choose a row to set the inputs to it.
Assumptions & limitations
- Ideal logic: every wire is exactly 0 or 1. Real gates use voltage ranges (for example near 0 V and near 3.3 V or 5 V) and an input between them is undefined.
- Gates switch instantly here. Real gates take nanoseconds each, so a deeper circuit is slower, and outputs can glitch briefly while signals race through different paths.
- Only combinational circuits are allowed: no output may feed back into its own input. Feedback is how memory (latches and flip-flops) works, but it needs timing this model does not simulate, so loops are reported as an error.
- Gates here have one input (NOT) or two inputs. Real chips also have three- and four-input gates, and limits on how many inputs one output can drive (fan-out).
- Gate counts are a simple measure of size; real designs also weigh speed, power and the number of transistors per gate.
Can't use the interactive? Read a description instead
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.
4.Checkpoint: guided practice
Check what you just discovered before going on. Hints appear after a wrong answer.
Practice 1
Why does A ← B, B ← A in one cycle swap correctly in hardware?
Practice 3
A = 1, B = 1. Each cycle: A ← B, B ← A + B. What is B after 4 cycles?
5.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
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.
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.
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)…
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.
6.Practice on your own
Practice, not a test. Wrong answers get a hint and another try.
Practice 2 · a fresh version every time
An 8-bit register R starts at 210. Each clock edge performs R ← (R + 7) mod 256. What does R hold after 3 cycles?
Practice 4
Which block lets a register choose between keeping its value and loading a new one?
Practice 5 · a fresh version every time
Two 8-bit registers start at A = 0, B = 4. On every clock edge both transfers happen at once: A ← B and B ← (A + B) mod 256. What does B hold after 6 clock cycles?
7.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.
8.Reflect
Concepts: Register-transfer-level design · Sequential logic and memory