A modular 32-bit, single-cycle MIPS processor implementation in Verilog. This project simulates a fully functional CPU capable of executing core R-type, I-type, and J-type instructions, following the classic MIPS architecture. The processor is organized as a collection of reusable Verilog modules, mirroring distinct hardware elements found in real-world MIPS CPUs.
The codebase is organized into the following Verilog modules, each corresponding to a datapath or control component:
| File | Description |
|---|---|
| Circuit.v | Top-level module connecting all subcomponents |
| ALU.v | Arithmetic Logic Unit for computation |
| ALUControl.v | ALU operation decoder |
| Control.v | Main controller, decodes opcodes and issues control signals |
| Registers.v | Register file (32 x 32-bit registers) |
| DataMemory.v | Data RAM for load/store instructions |
| InstructionMemory.v | Stores program code, loads from program.mem |
| PC.v | Program Counter register |
| Adder.v | Used for PC update and address calculation |
| Mux2to1.v | Multiplexers for datapath selection |
| SignExtend.v | Extends 16-bit immediates to 32-bit |
| ShiftLeft2.v | Left shifter for branch/jump address offset alignment |
| TestBanch.v | Testbench for top-level simulation |
The processor implements a subset of the MIPS instruction set, featuring:
- Arithmetic/Logic:
add,sub,and,or,slt - Immediate Arithmetic:
addi - Memory Operations:
lw(load),sw(store) - Control Flow:
beq(branch if equal),j(jump)
You can extend or modify the instruction set by editing the control logic and memory initialization.
- Verilog simulator (e.g., ModelSim, QuestaSim, or Icarus Verilog)
- ModelSim project file:
SingleCycleProcessor.mpf(included)
- Launch ModelSim and open the project file
SingleCycleProcessor.mpf. - Compile all Verilog source files (
.v). - Ensure
program.memis present in the simulation directory (contains hex machine code). - Simulate the
TestBanchmodule as the testbench. - Run the simulation, for example:
run 100ns.
To run your own MIPS programs, edit the program.mem file using hexadecimal machine instructions. The processor will load and execute whatever code is present in this file.
- Waveform Files:
mips_test.vcd: VCD-format output for external waveform viewersvsim.wlf: ModelSim-specific waveform output
- Signal Monitoring:
- Recommended signals:
ALU_Result,pc_current,write_data_reg
- Recommended signals:
These outputs allow you to inspect datapath values, trace program execution, and verify correct processor operation.
- Register
$0: Always hardwired to zero per MIPS standard. - Memory Addressing: Both data and instruction memories are word-addressed (
address[31:2]). - Reset Logic: Activate the
resetinput in the testbench to initialize the program counter.
Feel free to fork, modify, or extend this project to experiment with additional MIPS features or to learn about computer architecture design!