This project implements a simple five-stage pipeline MIPS CPU in Verilog. It has basic hazard-handling mechanisms like forwarding and stalling. It can handle basic integer arithmetic operations such as addition, subtraction, multiplication, and division. It can also handle conditional, unconditional, and register-based branches or jumpings. It supports the use of subprocedures.
test_data
contains testing data of various instructions.docs
contains textbooks and instruction sets of two subsets of MIPS.src
contains the Verilog source code of the CPU implementation.tools
contains a Mars simulator with debugging facility.
- Open an ASM file (found from the
test_data
) in the Mars simulator and dump the code in hex format to a text file namedfunc.txt
. - Open the
src
folder in a Xilinx project. Compile the Verilog source code. - Ensure the file
func.txt
can be accessed by the Verilog code and run the simulation in Xilinx. - Optionally use the
src/utils/inspect.v
to show the time-series diagram of instruction flowing through the pipeline.
src/
βββ comp # Major functional components.
β βββ alu.v # ALU.
β βββ cmp.v # Comparator required by beq and bne.
β βββ ctrl.v # Istruction controller.
β βββ dm.v # Data memory.
β βββ ext.v # Signed/Zero extensions of integers.
β βββ fmux.v # Multiplexers at the input of functional units.
β βββ grf.v # General register files.
β βββ mips.v # The cpu that pulls everything together.
β βββ mux.v # Another set of muliplexers.
β βββ IF.v # Instruction memory and fetching.
β βββ npc.v # Next PC generator.
βββ forward # Forwarding modules.
β βββ forward_btype.v # Forward B-type instructions.
β βββ forward_grf.v # Forward from GRF.
β βββ forward_ji.v # Forward Jump-immediate (JI).
β βββ forward_jr.v # Forward Jump-register (JR).
β βββ forward_rs_alu.v # Forward RS-type from ALU.
β βββ forward_rt_alu.v # Forward RT-type from ALU.
β βββ forward_rt_mem.v # Forward RT-type from DM.
βββ stage # Pipeline registers of different stages.
β βββ EXE.v # ID/EX reg.
β βββ ID.v # IF/ID reg.
β βββ MEM.v # EX/MEM reg.
β βββ WB.v # MEM/WB reg.
βββ stall # Stalling modules.
β βββ hctrl.v # Hazard stalling controller.
β βββ hstall.v # Stalling controllers for all stages.
βββ utils # Debugging utilities and entrypoint file.
βββ inspect.v # Debugging utilithy.
βββ main.v # Simulation entrypoint.
This code was inspired by the textbook Digital Design and Computer Architecture. Thanks to the authors for their great book.
If you find our code useful in your research, please consider citing us as follows:
@misc{cong_mips-pipeline-cpuverilog_2017,
title = {mips-pipeline-cpu.verilog: a simple five-stage pipeline {MIPS} {CPU} that handles integer operations as well as conditional and unconditional jumps.},
shorttitle = {mips-pipeline-cpu.verilog},
url = {https://github.com/cgsdfc/mips-pipeline-cpu.verilog},
abstract = {This project implements a simple five-stage pipeline MIPS CPU in Verilog. It has basic hazard-handling mechanisms like forwarding and stalling. It can handle basic integer arithmetic operations such as addition, subtraction, multiplication, and division. It can also handle conditional, unconditional, and register-based branches or jumpings. It supports the use of subprocedures.},
author = {Cong, Feng},
year = {2017},
}