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 file
    • MemRead : enable data memory read
    • MemWrite : enable data memory write
    • MemToReg : selects memory data vs. ALU result for write-back
    • ALUSrc : selects second ALU operand (register vs. immediate)
    • Branch : indicates a branch instruction
    • Jump : indicates jal or jalr
    • 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 Control
    • funct7[5] and funct3[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

  1. Instruction fetch → opcode → Main Control
  2. Register operands → ALU inputs; ALUSrc selects imm for I-type
  3. ALU result
    • memory address (load/store),
    • branch comparand (zero flag & Branch signal)
  4. Memory access → data memory (MemRead/MemWrite)
  5. Write-back → MUX selects via MemToReg for register file
  6. PC updateJump, Branch & zero, or PC + 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
  • 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