1. Main Control Unit
- Role: Generate high-level control signals from the 7-bit opcode
- Inputs:
opcode[6:0]
- Outputs:
RegWrite
: write enable for register fileMemRead
: enable data memory readMemWrite
: enable data memory writeMemToReg
: selects memory data vs. ALU result for write-backALUSrc
: selects second ALU operand (register vs. immediate)Branch
: indicates a branch instructionJump
: indicatesjal
orjalr
ALUOp[1:0]
: high-level ALU operation code for ALU Control
2. ALU Control Unit
- Role: Decode exact ALU operation from
ALUOp
and funct fields - Inputs:
ALUOp[1:0]
from Main Controlfunct7[5]
andfunct3[2:0]
from instruction
- Output:
ALUCtrl[3:0]
selecting operation (ADD, SUB, AND, OR, SLT, …)
2.1 ALU Control Logic Table
ALUOp | funct7 | funct3 | Operation ------|--------|--------|---------- 00 | --- | --- | ADD # for loads/stores 01 | --- | --- | SUB # for branches 10 | 0 | 000 | ADD # R-type add 10 | 1 | 000 | SUB # R-type sub 10 | X | 111 | AND # R-type and 10 | X | 110 | OR # R-type or 10 | X | 010 | SLT # set less than
3. Control Signals by Instruction Type
Type RegWrite MemRead MemWrite MemToReg ALUSrc Branch Jump ALUOp
-------- -------- ------- -------- -------- ------ ------ ---- -----
R-type 1 0 0 0 0 0 0 10
Load 1 1 0 1 1 0 0 00
Store 0 0 1 X 1 0 0 00
Branch 0 0 0 X 0 1 0 01
JAL 1 0 0 0 0 0 1 00
JALR 1 0 0 0 1 0 1 00
X
= don’t care
4. Datapath Connections
- Instruction fetch → opcode → Main Control
- Register operands → ALU inputs;
ALUSrc
selects imm for I-type - ALU result →
- memory address (load/store),
- branch comparand (zero flag &
Branch
signal)
- Memory access → data memory (
MemRead
/MemWrite
) - Write-back → MUX selects via
MemToReg
for register file - PC update →
Jump
,Branch & zero
, orPC + 4
5. Example: R-Type vs Load Execution
- R-type
add x5, x6, x7
:- Main Control:
RegWrite=1
,ALUSrc=0
,ALUOp=10
- ALU Control: funct7=0, funct3=000 →
ALUCtrl=ADD
- ALU computes
x6 + x7
, result → write-back to x5
- Main Control:
- Load
lw x8, 12(x9)
:- Main Control:
RegWrite=1
,MemRead=1
,MemToReg=1
,ALUSrc=1
,ALUOp=00
- ALU Control: ALUOp=00 →
ALUCtrl=ADD
- ALU computes address
x9 + 12
, memory read → write-back to x8
- Main Control: