Sub topic 13
Datapath and register transfer notation
This chapter assumes you know the stored-program model, the fetch-decode-execute cycle, and what a register, a bus and a multiplexer are. Here you will learn to describe, step by step, how data moves between registers and the ALU while an instruction runs. GATE questions about this topic usually ask you to count control steps, name the signals active in a step, or find the minimum number of time steps for an instruction.
What a datapath is
The datapath is the set of hardware that stores and moves data and computes on it. It has three kinds of parts:
- Storage: the program counter (PC), memory address register (MAR), memory data register (MDR), instruction register (IR), general-purpose registers, and sometimes an accumulator (ACC) or status register.
- Computation: the ALU, which combines operands and produces a result and flags.
- Interconnect: one or more buses, plus multiplexers or tri-state gates that decide which register drives a bus.
The control unit is not part of the datapath. It sends control signals, such as "R2 drives the bus" or "load Z from the ALU", and the datapath obeys them. The next chapters cover how the control unit produces those signals.
| Register | Holds | Typical role in fetch |
|---|---|---|
| PC | Address of the next instruction | Source of the address |
| MAR | Address sent to memory | Receives PC |
| MDR | Word read from or written to memory | Receives the instruction word |
| IR | Instruction being executed | Receives MDR, feeds the decoder |
| Y, Z | Temporary ALU input and output | Hold operands and results on a single bus |
Register transfer notation
Register transfer notation (RTN) describes one hardware action per line. The rules are small:
A <- Bcopies the contents of register B into register A. B is unchanged.M[MAR]means the memory word at the address in MAR.MDR <- M[MAR]is a memory read.M[MAR] <- MDRis a memory write.R1 <- R1 + R2means the ALU adds and the result is stored in R1.- Actions separated by commas on one line happen in the same time step, for example
MDR <- M[MAR], PC <- PC + 1. T0, T1, ...label time steps, one clock period each, though a memory access may take longer in a real machine.
The copy is a hardware copy, so the right-hand side is read at the start of the step and the left-hand side is written at the end. That is why two transfers in the same step can swap values safely. A <- B, B <- A exchanges them if they use separate paths.
The fetch sequence
Every instruction starts with the same steps:
Fetch sequence as register transfers:
T0: MAR <- PC
T1: MDR <- M[MAR], PC <- PC + 1
T2: IR <- MDR
T3: decode IR; control unit selects the execute sequenceT0 puts the address on the memory interface. T1 reads memory and increments the PC at the same time, since they use different hardware (the memory and an incrementer or the ALU path). T2 moves the word into IR. T3 decodes it.
A single-bus datapath
The simplest datapath has one internal bus. Only one register can drive the bus in a given step. The ALU has two inputs, but one of them comes from a temporary register Y, so the second operand can come straight from the bus. The ALU output goes to a temporary register Z, because it cannot be written back to the bus in the same step it is computed.
flowchart LRThe block above is not valid as a diagram, so use the figure below.
Each register has two control signals. One enables its output onto the bus (often called Rout), and one loads it from the bus (Rin). In a given step, at most one out signal may be active, otherwise two registers would drive the same wires.
Executing instructions on the single bus
Register-register add, ADD R1, R2 meaning R1 <- R1 + R2:
T0: Y <- R1 (R1out, Yin)
T1: Z <- Y + R2 (R2out, Add, Zin)
T2: R1 <- Z (Zout, R1in)R1 and R2 cannot both be on the bus together, so R1 is parked in Y first. This is why three steps are needed after fetch, not one.
Load from a direct address, LOAD X with the address X in the instruction:
T0: MAR <- IR.address
T1: MDR <- M[MAR]
T2: ACC <- MDRStore, STORE X:
T0: MAR <- IR.address
T1: MDR <- ACC
T2: M[MAR] <- MDRIndirect addressing adds a second memory access. For LOAD @X:
T0: MAR <- IR.address
T1: MDR <- M[MAR] (this word is the effective address)
T2: MAR <- MDR
T3: MDR <- M[MAR] (this word is the operand)
T4: ACC <- MDR| Instruction | Execute steps | Fetch steps | Total |
|---|---|---|---|
| ADD R1, R2 (single bus) | 3 | 3 | 6 |
| LOAD X (direct) | 3 | 3 | 6 |
| STORE X (direct) | 3 | 3 | 6 |
| LOAD @X (indirect) | 5 | 3 | 8 |
These counts count the decode step as part of the control unit's work, not as a transfer. Always check how the question treats decode and whether memory takes one step or several.
Tracing transfers in code
This Python model applies each step, so a transfer such as MDR <- M[MAR], PC <- PC + 1 uses the old values on the right-hand side.
regs = {"PC": 0, "MAR": 0, "MDR": None, "IR": None, "ACC": 0}
memory = {0: ("LOAD", 10), 10: 42}
def step(label, **updates):
# Update the registers named in updates at the end of the step.
regs.update(updates)
print(f"{label:<34} {regs}")
step("T0: MAR <- PC", MAR=regs["PC"])
step("T1: MDR <- M[MAR], PC <- PC+1",
MDR=memory[regs["MAR"]], PC=regs["PC"] + 1)
step("T2: IR <- MDR", IR=regs["MDR"])
opcode, address = regs["IR"]
assert opcode == "LOAD"
step("T3: MAR <- IR.address", MAR=address)
step("T4: MDR <- M[MAR]", MDR=memory[regs["MAR"]])
step("T5: ACC <- MDR", ACC=regs["MDR"])After the last step, ACC is 42 and PC is 1.
Multiple buses and fewer steps
A three-bus datapath has two input buses and one output bus. The ALU can read two registers at once and write a third in the same step. Then ADD R1, R2 takes one step:
T0: R1 <- R1 + R2 (R1 and R2 on input buses, ALU output bus to R1)The trade-off is hardware cost. More buses means more wires and more tri-state gates or multiplexers. The register file also needs more read and write ports. In exchange, instructions finish in fewer clock cycles.
Common errors
- Two drivers on one bus. Writing
Y <- R1, Z <- R2in one step on a single bus is impossible if both values come over the bus. Only one value travels per step. - Forgetting Y and Z. The ALU on a single bus needs a holding register. If a question shows no Y, an operand must come from another source such as the accumulator.
- Mixing up MAR and MDR. MAR holds addresses and MDR holds data. In indirect addressing, a data word is later moved into MAR.
- Reading a changed register. Within one step, every right-hand side uses the value from before the step. A later step sees the new value.
- Leaving out the PC increment. Branches overwrite the PC (
PC <- IR.address). Non-branches rely on the increment done during fetch.
Exercise
On a single-bus datapath with registers Y and Z, write the register transfers for SUB R3, R4 meaning R3 <- R3 - R4, and give the number of execute steps.
Show answer
T0: Y <- R3. T1: Z <- Y - R4 (R4 on the bus, ALU set to subtract). T2: R3 <- Z. This takes 3 execute steps, plus the 3 fetch steps.
Exercise
For LOAD @X on the single-bus datapath above, how many memory reads occur in the whole instruction, including fetch, and what is the total number of steps?
Show answer
Three reads: the instruction fetch, the read of the pointer, and the read of the operand. The total is 3 fetch steps plus 5 execute steps, which is 8.