---
title: Register-transfer design
heading: A datapath that computes and a controller that steers it
eyebrow: C7 · Lesson 40 · Register-transfer design
xp: 40
---

::: hook
A multiplier, a GCD engine or a checksum unit isn't one big formula; it's a sequence of small steps, each moving values between registers through an adder or a comparator. Digital designers describe such machines at the **register-transfer level**: what each register receives on each clock. The design splits into a **datapath** (the registers and the arithmetic) and a **controller** (a state machine that decides which transfer happens next). Every processor is built this way.

::: play
- The curves compare a combinational array multiplier, which finishes an n-bit product in one long clock, with a sequential shift-and-add multiplier, which reuses one adder for n short clocks, in units of a full adder's delay.
- At small n the sequential design is slower; it always uses far less hardware.
- Watch the area readouts: n full adders against n², the price of doing it all at once.
:::
:::

```sim plot
view: graph
x: n = 4..64
y: t = 0..5000
slider: r = 1..10 step 0.5 = 2
plot: 2*n + r | label: array multiplier, one clock | samples: 100
plot: n*(n + r) | color: ch2 | label: shift-and-add, n clocks | samples: 100
readout: array multiplier full adders = 64*64 | digits: 5
readout: shift-and-add full adders = 64 | digits: 3
```

::: predict
## A sequential multiplier adds one shifted copy of the multiplicand per clock. How many clocks does it take to multiply two 8-bit numbers?

- [ ] 1
- [ ] 2
- [x] 8, one for each bit of the multiplier
- [ ] 64, one for each pair of bits

::: reveal
Eight: on each clock the controller looks at one multiplier bit and, if it's 1, adds the multiplicand shifted into place. One adder does the work of eight, at the price of eight clocks. An array multiplier spends 64 full adders to finish in one (longer) clock.
:::
:::

::: nameit
## Register transfers

RTL notation writes what happens on a clock edge: $A \leftarrow A - B$ means register A loads the difference. Several transfers in the same state happen together, on the same edge.

## Datapath and controller

- The **datapath** holds the registers, the arithmetic units and the multiplexers that route values between them. It reports **status** signals, such as $A > B$ or a counter reaching zero.
- The **controller** is a state machine. In each state it asserts **control** signals: which registers load, what the ALU does, which multiplexer inputs pass. Its transitions depend on the status signals.

An **ASM chart** (algorithmic state machine) draws the controller: a box per state listing its transfers, diamonds for decisions on status signals.

## Trading time for hardware

- **Single-cycle:** all the work of one operation in one long clock.
- **Multi-cycle:** one shared unit used over several short clocks: less hardware, the same or more time per result.
- **Pipelined:** separate hardware for each step, with registers between, so a new operation starts every short clock: the most hardware and the most throughput.
:::

::: example
## A GCD machine repeats "if A > B, then A ← A − B, else B ← B − A" until A = B. Trace it from A = 48, B = 18.

::: solution
1. **Trace it.** (48, 18) → (30, 18) → (12, 18) → (12, 6) → (6, 6): four subtractions, and the controller's equality test then stops it with A = B = 6.
2. **The datapath.** It needs two registers, a subtractor (shared through multiplexers), and comparators for A > B and A = B.
3. **The controller.** It has an idle state, a run state and a done state.
4. **Its weakness.** Subtraction is slow for very different inputs: GCD(100, 1) takes 99 steps.

**Answer:** four subtractions, stopping at A = B = 6.
:::
:::

::: example
## Multiply 13 by 11 with a 4-bit shift-and-add multiplier.

::: solution
1. **Write the multiplier in binary.** 11 = 1011.
2. **Bit 0 is 1.** The accumulator gets 13.
3. **Bit 1 is 1.** Add 13 shifted once, 26:
   $$13 + 26 = 39$$
4. **Bit 2 is 0.** Add nothing.
5. **Bit 3 is 1.** Add 13 shifted three times, 104:
   $$39 + 104 = 143$$
6. **Count the cost.** Four clocks, one adder, and the product 143 = 13 × 11; the controller is little more than a counter that stops after four bits.

**Answer:** 143, in four clocks.
:::
:::

::: example
## An operation has three steps of 4 ns each, plus 0.5 ns of register overhead per clock. Compare single-cycle, multi-cycle (one shared unit) and pipelined designs.

::: solution
1. **Single-cycle.** One 12.5 ns clock per result.
2. **Multi-cycle.** Three 4.5 ns clocks per result:
   $$3 \times 4.5 = 13.5\ \text{ns}$$
   with a third of the arithmetic hardware.
3. **Pipelined.** A 4.5 ns clock and a new result every clock:
   $$\frac{12.5}{4.5} = 2.8$$
   times the throughput of single-cycle, though each result takes 13.5 ns to emerge.
4. **Choosing.** The choice depends on whether hardware, latency or throughput matters most.

**Answer:** single-cycle gives a result every 12.5 ns, multi-cycle every 13.5 ns with a third of the hardware, and pipelined every 4.5 ns, 2.8 times the throughput, with 13.5 ns of latency.
:::
:::

::: check
kind: parts
given: n = 8 | 16 | 32; T = 1 | 2.5; r = 0.5 | 1

## An n-bit shift-and-add multiplier with n = {n} adds in {T} ns, plus {r} ns of register overhead per clock.

::: part
answer: n
tolerance: 0

### How many clocks per product?

::: misses
- [any] One per multiplier bit.
:::
:::

::: part
answer: n*(T + r)
unit: ns
tolerance: 0.5%

### How long does a product take?

::: misses
- [n*T] Each clock also pays the register overhead.
- [any] $n(t_\text{add} + t_\text{reg})$.
:::
:::
:::

::: check
kind: parts
given: k = 2 | 3 | 5; t = 2 | 4; r = 0.2 | 0.5

## An operation has {k} steps of {t} ns each, with {r} ns of register overhead per clock.

::: part
answer: k*t + r
unit: ns
tolerance: 0.5%

### What's the time per result in a single-cycle design?

::: misses
- [any] One clock holding all the steps.
:::
:::

::: part
answer: t + r
unit: ns
tolerance: 0.5%

### And in a pipelined one, once it's full?

::: misses
- [k*(t + r)] That's the latency; a pipeline delivers a result every clock.
- [any] One short clock per result.
:::
:::
:::

::: check
given: a = 30 | 50 | 85; b = 12 | 18
answer: floor(a/b)
tolerance: 0

## The GCD machine starts with A = {a} and B = {b}. How many times does it subtract B from A before A first drops below B?

::: right
Right: {answer}. The loop divides by repeated subtraction, and the remainder is left in A.
:::

::: misses
- [any] Each step removes B once, while A is still larger.
:::
:::

::: check
kind: boolean
vars: S1, S0, G
answer: ~S1 & S0 & G
ops: and, or, not

## The GCD controller has states IDLE = 00, RUN = 01, DONE = 10. It loads A (with A − B) only in RUN when G = (A > B) is 1. Write load_A.

::: right
Right: $\bar S_1S_0G$.
:::

::: misses
- [any] Not yet. It's asserted in state 01 when G is 1.
:::
:::

::: check
kind: derivation
vars: k = 1..20, t = 0.0000000001..0.00000001, r = 0.00000000001..0.000000001, N = 1..1000000

## An operation of k steps, each taking t, runs N times; every clock costs r of register overhead.

::: step
answer: N*(k*t + r)

### How long does a single-cycle design take?
:::

::: step
answer: N*k*(t + r)

### A multi-cycle design?
:::

::: step
answer: (N + k - 1)*(t + r)

### A k-stage pipeline?
:::

::: right
Right. For large N the pipeline approaches one short clock per result.
:::
:::

::: check
kind: python

## Write `gcd_rtl(a, b)` returning `(g, steps)`: the GCD found by the subtraction machine, and the number of subtractions it performed.

```python starter
import math

def gcd_rtl(a, b):
    return math.gcd(a, b), 0

print(gcd_rtl(48, 18))
```

```python solution
def gcd_rtl(a, b):
    steps = 0
    while a != b:
        if a > b:
            a -= b
        else:
            b -= a
        steps += 1
    return a, steps

print(gcd_rtl(48, 18))
```

```python tests
assert gcd_rtl(48, 18) == (6, 4), f"48, 18: GCD 6 in 4 steps; got {gcd_rtl(48, 18)}"
assert gcd_rtl(35, 21) == (7, 3), "35, 21: GCD 7 in 3 steps."
assert gcd_rtl(100, 1) == (1, 99), "Very different inputs take many steps."
```

::: right
Right. The Python loop is the controller; the variables are the datapath's registers.
:::
:::

::: explain
## Why do designers split a digital system into a datapath and a controller?

::: model
The datapath and the controller change for different reasons and are designed in different ways. The datapath is about moving and transforming values: how wide the registers are, which arithmetic units exist, how values are routed. The controller is about sequence: which transfer happens in which state, and how decisions depend on what the datapath reports. Separating them lets each be designed with its own tools: the datapath from standard blocks like adders and multiplexers, and the controller as a state machine. It also lets the same datapath run different algorithms by changing only the controller, which is exactly what a programmable processor does.
:::
:::

::: practice

::: check
given: n = 12 | 24; T = 0.8 | 2; r = 0.3 | 0.6
answer: n*(T + r)
unit: ns
tolerance: 0.5%

## {n}-bit shift-and-add, {T} ns add, {r} ns overhead. Time per product?

::: misses
- [any] $n(t_\text{add} + t_\text{reg})$.
:::
:::
:::
