5.2.1 · D1Processor Datapath & Pipelining

Foundations — Single-cycle datapath design

3,877 words18 min readBack to topic

Before you can read the single-cycle datapath note you must own every symbol it throws at you. Below, each idea is built from nothing, given a picture, and justified by the one question it answers. Read top to bottom — each rung of the ladder needs the one below it.


1. A bit, a wire, and a number

Put 32 wires side by side and you can spell a number. We must agree which wire counts for how much.

Figure 1 — read this: eight little boxes on top are single-bit wires labelled with their place values; the fat red arrow below is the same information carried as one 32-bit bus. Learn that "one fat arrow with a slash and a 32 = thirty-two wires travelling together."

Figure — Single-cycle datapath design

Why the topic needs it: every box in the datapath — the ALU, the memories, the register file — speaks in 32-bit words. When the parent note draws one arrow into the ALU, that arrow is really 32 wires.


2. Registers and the register file

The register file in the parent note has two read ports and one write port:

  • A read port = a lookup: "here is a 5-bit register number, hand me its 32-bit value." Two ports let us read two operands at once (like add needing two inputs).
  • A write port = a store: "here is a register number and a value; on the next bell, put the value there." It only acts when the RegWrite control wire is 1.

Figure 2 — read this: two black arrows on the left (rs, rt) go in, two black arrows on the right (read data 1, read data 2) come out — those are the two read ports. The red arrow at the bottom is the single write port, and it only moves data when RegWrite = 1. Learn: reading is always allowed; writing needs permission.

Figure — Single-cycle datapath design

Why the topic needs it: rs, rt, rd, RegWrite, and the "write-back" stage all live or die by this shelf.


3. Memory and addresses

Figure 3 — read this: each small black box is one byte-mailbox with its own address number underneath. The red outline groups four consecutive bytes into one instruction word. Learn: memory is numbered per byte, but we grab things four bytes at a time.

Figure — Single-cycle datapath design

The parent note has two separate memories:

  • Instruction memory — read-only during running; you hand it PC, it hands back the instruction word there.
  • Data memory — read and write; used only by lw (load word) and sw (store word).

Why the topic needs it: the MEM stage, MemRead, MemWrite, and the load/store instructions are all conversations with these mailboxes.


4. The Program Counter (PC)

Each cycle three things could become the next PC:

  1. The straight-ahead choice PC + 4 (run the next instruction in line).
  2. The branch choice — a conditional redirect if a compare succeeds (see Branch in §8).
  3. The jump choice — an unconditional redirect (see J-type in §5).

A little box called an adder (see §7) computes PC + 4 while the rest of the instruction executes. On the next bell, the chosen value loads into the PC.

Why the topic needs it: the entire Fetch stage is "read instruction at PC, then decide the next PC."


5. Instruction fields: opcode, rs, rt, rd, immediate, funct, jump target

An instruction is a 32-bit word chopped into labelled slots. You do not compute these — you just read off which bits mean what. MIPS uses three carvings: R-type, I-type, and J-type.

Figure 4 — read this: three strips share the same 6-bit red opcode slot. The top (R-type) ends in rd+funct; the middle (I-type) ends in a 16-bit immediate; the bottom (J-type) has one wide 26-bit jump target. Learn: same 32 bits, three different carvings.

Figure — Single-cycle datapath design

Why the topic needs it: every mux in the note (defined in §8) exists because different instruction types pull their operands from different fields of this same 32-bit word — and the jump target is the field that feeds the PC directly.


6. Sign extension, zero extension, and shifting left

The immediate is only 16 bits, but the ALU works on 32-bit words. We must grow it to 32 bits — but how we fill the new high bits depends on the instruction.

Why the topic needs it: the branch-target formula uses sign-extension then shift; the jump uses the same "×4" shift on its 26-bit target; and andi/ori need the zero-extension path instead.


7. Adders, the ALU, and what "delay" means

The ALU also emits one extra 1-bit signal:


8. The multiplexer (mux) and its select signals

Figure 5 — read this: two black arrows enter the red mux on the left; only one leaves on the right. The arrow coming up from the bottom is the select control wire that decides which input wins. Learn: a mux is a controllable one-of-many switch, not a calculator.

Figure — Single-cycle datapath design

Why the topic needs it: these five names appear all over the parent note's control table; here they are defined once, from the mux idea.


How to read the prerequisite map below

The diagram is a dependency ladder: each arrow means "you must understand the box at the tail before the box at the head makes sense." Follow arrows in the direction they point. Everything on the left/top is raw material; all paths funnel into the single node "Single-cycle datapath" at the bottom — that is the note you are preparing for. If any incoming arrow to a box points from something you can't yet explain, go back and re-read that earlier section.

Bits words and bit numbering

Registers and register file

Memory and byte addresses

Program Counter PC

Instruction fields R I and J type

Sign extend zero extend and shift left 2

Adder and ALU with Zero

Multiplexer and select signals

Single-cycle datapath

Control signals and clock period


9. The clock period inequality

Why the topic needs it: the whole "single-cycle is slow" argument, the Performance equation, and the motivation for Pipelining rest on this one inequality.


Prerequisite map

(The reading guide and diagram appear just above §9 — refer back to it for how each foundation feeds the topic.)


Equipment checklist

Test yourself — you should be able to answer each before reading the parent note.

Which bit is the least-significant, and what place value does bit k carry?
Bit 0 is least-significant (the ones place); bit k carries .
How many bits name one of 32 registers, and why?
5 bits, because .
What is special about MIPS register ?
It is hard-wired to 0: reads always return 0 and writes are ignored.
How many bytes is one MIPS instruction, and so what is the next instruction's address?
4 bytes; next address = PC + 4.
Which addresses may lw/sw touch, and what is that property called?
Only multiples of 4 (bottom two bits zero); called word-aligned.
What does a read port of the register file do?
Takes a 5-bit register number and returns that register's 32-bit value.
When does the register file actually write?
On the clock edge, only when RegWrite = 1 (and never into ).
What three field-carvings does MIPS use, and how do they differ?
R-type (rs rt rd shamt funct), I-type (rs rt 16-bit immediate), J-type (26-bit jump target).
How is the PC set for a J-type jump?
Top 4 bits of PC+4, glued to the 26-bit target shifted left 2 — loaded straight into the PC.
What is sign extension and which bit gets copied?
Growing a 16-bit value to 32 bits by copying its top (sign) bit into all new high bits.
When do we zero-extend instead of sign-extend, and why?
For logical immediates like andi/ori, because their immediate is an unsigned bit-mask.
What does shifting left by 2 do to a number, and why?
Multiplies it by 4, since each left shift doubles it.
Correct order for a branch immediate?
Sign-extend to 32 bits first, then shift left 2.
What is the ALU's Zero output and when is it 1?
A 1-bit wire that is 1 exactly when the ALU result equals 0 (used for beq).
What is a multiplexer and what controls it?
A selector that passes one of several input buses to the output, chosen by a select control wire.
What is the Branch control line, and how does it differ from PCSrc?
Branch is 1 only for branch instructions; PCSrc = Branch AND Zero actually redirects the PC.
What do ALUSrc, MemToReg, and RegDst each select?
ALU 2nd input (reg vs imm); write-back source (ALU vs memory); destination field (rt vs rd).
What is a box's "delay"?
The worst-case time for its output to settle after its input changes.
Why is a separate adder needed for PC+4 in single-cycle?
The ALU is busy with the instruction's own arithmetic in the same cycle and can't be time-shared.
What inequality sets the clock period?
the largest total box-delay over all instruction paths.