Skip to content
Tutorials Center
My learning

Topics

Lesson 27 of 67 ยท CPU Design

Register Transfer and Micro-operations

Learn register transfer notation (R2 <- R1), bus and memory transfers, and arithmetic, logic and shift micro-operations, with a Python register-transfer simulator.

A computer instruction looks like one action, but hardware builds it from many tiny steps: copy this register to that one, add two registers, shift a value one place. These elementary steps are called micro-operations, and a notation called register transfer language (RTL) describes them precisely. It is the vocabulary hardware designers use when they sketch what a processor does on each clock tick.

In this lesson you will learn the notation, see how registers share a common bus, and meet the families of micro-operations: transfer, arithmetic, logic and shift. A small Python simulator lets you write micro-operations and watch them execute. It follows CPU registers and the instruction cycle and leads into the datapath.

Register transfer notation

Registers are named with capital letters (R1, PC, MAR). A transfer is written with an arrow:

Text
R2 <- R1

It means: at the next clock edge, copy the contents of R1 into R2. R1 is unchanged. A transfer that only happens under a condition uses a control signal, written before a colon:

Text
P: R2 <- R1

Here P is a control signal, a wire that is 1 when the step should happen. When P is 0, nothing changes. Several transfers listed on the same line with commas happen at the same time: R1 <- R2, R2 <- R1 swaps the two registers, because both right-hand sides are read before either register is written.

Memory is written as M[address]:

Text
MDR <- M[MAR]        (read)
M[MAR] <- MDR        (write)

Parts of a register use brackets for bit numbers: R1(7:0) is the low byte, and R1(15) is the top bit of a 16-bit register.

Moving data over a bus

With many registers, giving each one a private wire to every other register would require a lot of wires. A bus is a shared set of wires: a multiplexer (or tri-state gates) selects which register drives the bus, and any register can load from it.

flowchart LR
  R1["R1"] --> MUX["Bus select<br/>(multiplexer)"]
  R2["R2"] --> MUX
  R3["R3"] --> MUX
  MUX --> BUS["Common bus"]
  BUS --> R1
  BUS --> R2
  BUS --> R3

A bus transfer: select the source, then load the destination. Only one source drives the bus at a time.

To perform R3 <- R1 the control sets the bus select to R1 and enables the load input of R3. The price of sharing is that only one transfer can happen per bus per cycle. A processor with more buses can do more transfers in parallel.

Families of micro-operations

Arithmetic micro-operations use the adder: R3 <- R1 + R2, R3 <- R1 + 1 (increment), R3 <- R1 - R2 (really R1 + NOT R2 + 1, two's complement), and R2 <- NOT R2 + 1 (negate).

Logic micro-operations work on each bit independently: AND, OR, XOR, and complement. They are used to clear bits (AND with a mask), set bits (OR), flip bits (XOR) and test them. For example, R1 <- R1 AND 0x00FF clears the high byte.

Shift micro-operations move bits sideways:

Kind Effect Typical use
Logical shift left/right zeros enter at the vacated end unsigned multiply/divide by 2, bit fields
Arithmetic shift right the sign bit is copied in signed divide by 2
Rotate bits leaving one end re-enter at the other cryptography, bit manipulation

A shift by one place is the cheapest multiplication or division by 2. A barrel shifter can shift by any amount in one cycle using a tree of multiplexers.

A register-transfer simulator

The simulator below keeps 8-bit registers, executes lines written in a small RTL-like text, and handles simultaneous transfers (lines with commas read all sources first).

Python Run micro-operations

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Try changing the last-but-one line to two separate lines (R1 <- R2 and then R2 <- R1) and compare: the sequential version loses a value, because the second step reads the already-overwritten R1. That is why the comma matters.

Micro-operations inside an instruction

An instruction is a sequence of micro-operations, one group per clock cycle. Fetching an instruction takes three groups:

Text
T0: MAR <- PC
T1: MDR <- M[MAR], PC <- PC + 1
T2: IR <- MDR

Here T0, T1 and T2 are timing signals produced by a counter in the control unit, one per clock cycle. Notice that PC <- PC + 1 shares a cycle with the memory read because they use different hardware and do not conflict. An ADD instruction that adds a memory value into an accumulator would continue with T3: MAR <- IR(address), T4: MDR <- M[MAR], and T5: ACC <- ACC + MDR. The control unit is the circuit that generates these signals; a microprogrammed one literally stores each group as a word of micro-instructions.

When you read a datapath diagram, ask which micro-operation each control wire enables. The diagram and the RTL describe the same machine from two sides.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. What does the RTL statement R2 <- R1 do?

    A register transfer copies the source; the source register keeps its value.
  2. 2. What is the effect of 'R1 <- R2, R2 <- R1' on one clock edge?

    Both sources are read before either register is loaded, so the values are exchanged.
  3. 3. Which logic micro-operation clears the high byte of a 16-bit register and keeps the low byte?

    AND with a mask keeps the bits where the mask is 1 and clears the others.
  4. 4. Which shift preserves the sign of a two's complement number when halving it?

    Arithmetic shift right copies the sign bit into the vacated position.
  5. 5. Why can a single bus carry only one register transfer per clock cycle?

    A shared bus has one set of wires, so two sources driving it at once would conflict.

Summary

  • Register transfer language describes processor steps: R2 <- R1, M[MAR], and conditional steps P: ....
  • Statements separated by commas happen simultaneously; sources are read before destinations are written.
  • A bus shares wires between registers using a selector, at the cost of one transfer per cycle.
  • Micro-operations fall into transfer, arithmetic, logic and shift families.
  • An instruction is a timed sequence of micro-operations, which the control unit generates.

Continue with the CPU datapath.