Single-Cycle MIPS Processor in Logisim-evolution: Datapath and Control Tutorial
Direct Answer: Building a Single-Cycle MIPS Processor in Logisim-evolution
A single-cycle 32-bit MIPS processor executes exactly one instruction per clock cycle across five fundamental hardware stages: Instruction Fetch (IF), Instruction Decode & Register Fetch (ID), Execute & Address Calculation (EX), Memory Access (MEM), and Write Back (WB). In Logisim-evolution, the datapath consists of a 32-bit Program Counter (incremented by 4 via an adder), a 32-bit Instruction ROM, a dual-port 32×32 Register File, a 32-bit ALU with carry and zero detection, and a Data RAM component. The control path utilizes a main instruction decoder generating 8 primary control signals (RegDst, ALUSrc, MemtoReg, RegWrite, MemRead, MemWrite, Branch, ALUOp) coupled to a secondary 3-bit ALU control decoder that parses the 6-bit funct field.
Recommended Computer Architecture Textbooks and Physical Hardware
Implementing MIPS is the standard capstone for university computer science and electrical engineering curricula worldwide. The following canonical textbooks and development boards are universally referenced for this design:
Digital Design & Computer Architecture (Harris & Harris)
The definitive companion textbook for building MIPS processors. Contains complete schematic diagrams, microarchitectural truth tables, control equations, and Verilog/VHDL implementations.
Digilent Basys 3 FPGA Development Board
Once your MIPS circuit verifies cleanly in Logisim, export the structural Verilog or VHDL directly onto Basys 3. Display register contents on the four 7-segment displays and single-step clock pulses with pushbuttons.
Core MIPS Instruction Formats and Bitfield Dissection
The 32-bit MIPS architecture standardizes instructions into exactly three regular 32-bit formats. This extreme architectural simplicity allows clean splitter logic in Logisim without complex variable-length instruction parsers:
| Instruction Type | Bits [31:26] (6b) | Bits [25:21] (5b) | Bits [20:16] (5b) | Bits [15:11] (5b) | Bits [10:6] (5b) | Bits [5:0] (6b) |
|---|---|---|---|---|---|---|
| R-Type (Register) | Opcode (000000) | rs (Source 1) | rt (Source 2) | rd (Dest Reg) | shamt (Shift) | funct (Function) |
| I-Type (Immediate) | Opcode (!= 0) | rs (Base / Src) | rt (Dest / Target) | immediate [15:0] (16-bit signed offset / constant) | ||
| J-Type (Jump) | Opcode (00001x) | target address [25:0] (pseudodirect jump index) | ||||
Control Unit Decoding Table for Core MIPS Instructions
The Main Control unit takes the 6-bit opcode (instruction[31:26]) as input and sets the control lines across the datapath multiplexers and registers. Below is the full operational truth table implemented via a Logisim ROM or Combinational Analysis block:
| Instruction | Opcode | RegDst | ALUSrc | MemtoReg | RegWrite | MemRead | MemWrite | Branch | ALUOp |
|---|---|---|---|---|---|---|---|---|---|
| R-format (add, sub, and, or, slt) | 000000 | 1 (rd) | 0 (reg) | 0 (ALU) | 1 | 0 | 0 | 0 | 10 |
| lw (Load Word) | 100011 | 0 (rt) | 1 (imm) | 1 (RAM) | 1 | 1 | 0 | 0 | 00 (Add) |
| sw (Store Word) | 101011 | X | 1 (imm) | X | 0 | 0 | 1 | 0 | 00 (Add) |
| beq (Branch Equal) | 000100 | X | 0 (reg) | X | 0 | 0 | 0 | 1 | 01 (Sub) |
| j (Jump) | 000010 | X | X | X | 0 | 0 | 0 | 0 | XX |
Building the Five Execution Stages in Logisim Schematics
Follow this architectural breakdown to build and interconnect the five MIPS stages inside Logisim-evolution:
Stage 1: Instruction Fetch (IF) and Program Counter Logic
Place a 32-bit Register from the Memory library to act as the Program Counter (PC).
- Sequential Increment: Connect the PC output to an Adder with a constant value of
4. In 32-bit MIPS, instructions are word-aligned at 4-byte boundaries. - Instruction Memory: Route the PC output to the address port of a 32-bit data-width ROM. In Logisim, if the ROM address bus is 24 bits, use a splitter to discard the lower 2 bits (word alignment) and upper bits.
- Branch Multiplexer: Feed both
PC + 4and the calculated branch target into a 2-to-1 32-bit MUX. The select line is driven by an AND gate combining theBranchcontrol line and the ALUZeroflag.
Stage 2: Instruction Decode (ID) and Register File
The 32-bit instruction word from the ROM is split into constituent fields using a Logisim Splitter component:
- Splitter Configuration: Fanout: 6. Split into
[31:26](Opcode),[25:21](rs),[20:16](rt),[15:11](rd),[10:6](shamt), and[5:0](funct). - Register File Subcircuit: Build or instantiate a dual-read, single-write 32×32 register file. Port
rsaddresses Read Port 1; portrtaddresses Read Port 2. A 2-to-1 5-bit MUX selected byRegDstdecides whetherrt(for I-type) orrd(for R-type) provides the Write Register address. - Sign Extension: Route bits
[15:0]through a Sign Extender (from Wiring) to convert the 16-bit immediate into a full 32-bit two’s complement value.
Stage 3: Execution and Arithmetic Logic Unit (EX)
The ALU executes arithmetic and logical operations or computes memory addresses:
- ALU Input B MUX: A 2-to-1 32-bit MUX selects between Read Data 2 (from the Register File) and the 32-bit sign-extended immediate, controlled by
ALUSrc. - ALU Core: A 32-bit ALU implementing AND, OR, ADD, SUB, and SLT (Set Less Than). Outputs the 32-bit computation result and a single-bit
Zeroflag (active high when result is zero). - Branch Target Calculation: In parallel with the ALU, add the sign-extended immediate (shifted left by 2 bits) to
PC + 4using an auxiliary adder.
Stage 4 and 5: Memory Access (MEM) and Write Back (WB)
Data memory and register update lines complete the processor loop:
- Data RAM: Connect the ALU result to the RAM address port. Connect Read Data 2 from the Register File to the RAM data input port.
MemWriteenables write on clock edge;MemReadgates output. - Write Back Multiplexer: A final 2-to-1 32-bit MUX selects between the ALU result (for arithmetic/logic instructions) and the RAM output data (for
lw), controlled byMemtoReg. The output routes back into the Register File write data port, clocked whenRegWrite = 1.
Sample MIPS Machine Code for Testing in ROM
To test your assembled datapath in Logisim-evolution, right-click your ROM component, select Edit Contents, and paste the following raw hexadecimal machine code. This benchmark tests immediate loading, register addition, memory store/load, conditional branching, and jumping:
// Address: Hex Code [MIPS Assembly] // Commentary
0x00: 20080005 // addi $t0, $zero, 5 ; Initialize $t0 = 5
0x04: 20090003 // addi $t1, $zero, 3 ; Initialize $t1 = 3
0x08: 01095020 // add $t2, $t0, $t1 ; $t2 = $t0 + $t1 (5 + 3 = 8)
0x0C: ac0a0000 // sw $t2, 0($zero) ; Store 8 into RAM at word address 0
0x10: 8c0b0000 // lw $t3, 0($zero) ; Load word from RAM[0] into $t3
0x14: 114b0001 // beq $t2, $t3, 1 ; Branch to 0x1C if $t2 == $t3 (Taken)
0x18: 200c0001 // addi $t4, $zero, 1 ; Skipped branch penalty instruction
0x1C: 08000007 // j 0x1C ; Infinite halt loop (Jump to PC 0x1C)
Frequent Design Traps in Student MIPS Circuits
Over 85% of simulator errors in computer organization courses stem from four subtle implementation mistakes:
Trap 1: Register Zero Mutation
Problem: In the MIPS architecture, Register 0 ($zero) is hardwired to 0x00000000 and must never change, even if an instruction targets $zero.
The Fix: In your Register File subcircuit, force the write-enable line of Register 0 to ground (0) or multiplex its output to constant zero.
Trap 2: Byte Addressing vs Word Alignment
Problem: The PC increments by 4 bytes each cycle, but Logisim’s ROM and RAM are word-addressed (each address index holds a 32-bit word).
The Fix: Feed PC[31:2] (ignoring the lowest 2 bits) into the ROM address port. Do not feed the raw byte address into a 32-bit word memory.
Trap 3: Branch Offset Calculation
Problem: In MIPS, branch offsets are relative to PC + 4, not current PC, and the 16-bit immediate represents words, not bytes.
The Fix: Sign-extend the immediate to 32 bits, shift left by 2 (multiply by 4), and add the result to the output of the PC + 4 adder.
Trap 4: Inverted Clock Edges
Problem: Mixing rising-edge and falling-edge triggered flip-flops causes write hazards where data is overwritten halfway through the cycle.
The Fix: Ensure all registers (PC, Register File, Data RAM) trigger strictly on the identical clock edge (standard: Rising Edge).
Curriculum Progression from MIPS to Advanced Architecture
Once your single-cycle MIPS CPU operates stably, expand your architectural repertoire across these interrelated topics:
Frequently Asked Questions About Building MIPS in Logisim
Can Logisim-evolution simulate a pipelined MIPS CPU with hazard detection?
Yes. Logisim-evolution can model 5-stage pipelined MIPS architectures (IF/ID, ID/EX, EX/MEM, MEM/WB). Pipeline registers are inserted between stages, and a forwarding unit compares source and destination register numbers to bypass operands directly to the ALU inputs.
How do I implement the dual-port Register File in Logisim?
You can create a subcircuit containing thirty-two 32-bit registers. The write address feeds a 5-to-32 decoder that activates the enable pin of the target register. Two separate 32-to-1 32-bit multiplexers select the contents of the registers specified by the rs and rt read address inputs.
What is the critical path in a single-cycle MIPS processor?
The critical timing path occurs during the lw (Load Word) instruction: T_clock-to-q (PC) + T_ROM + T_RegFile_Read + T_MUX + T_ALU + T_RAM + T_MUX + T_RegFile_Setup. Because every instruction must fit within one cycle, the clock period must be set long enough to accommodate this complete path.
Can I convert this Logisim MIPS processor into synthesizable Verilog for FPGA labs?
Yes. Logisim-evolution includes an FPGA exporter that translates your MIPS subcircuits into structural Verilog or VHDL. You can open the generated HDL project in AMD Vivado, assign physical pins to the Basys 3 board, and synthesize a working hardware microprocessor.
