A robust 32-bit 5-stage pipelined processor implementation in VHDL, featuring advanced architectural components such as hazard detection, forwarding, and interrupt handling.
This project implements a Von Neumann architecture processor with a 5-stage pipeline:
- Fetch (IF)
- Decode (ID)
- Execute (EX)
- Memory (MEM)
- Write Back (WB)
The design handles various dependencies and hazards to ensure correct execution flow, supporting a rich instruction set including arithmetic, logical, memory, branching, and stack operations.
- 5-Stage Pipeline: Parallel instruction processing for improved throughput.
- Hazard Detection Unit: Automatically detects and resolves data and control hazards (e.g., stalling, flushing).
- Forwarding Unit: Implements data forwarding (bypassing) to minimize pipeline stalls.
- Stack Support: Dedicated Stack Pointer (SP) with PUSH/POP/CALL/RET instructions.
- Branching: Conditional (JZ, JN, JC) and unconditional jumps, including Call/Return mechanisms.
The following diagram illustrates the high-level design and data flow of the processor:
(Click here for a high-quality view)
Processor.vhd: Top-level entity connecting all stages and components.Processor.py: Python script to automate ModelSim simulation setup.components/: Core units (ALU, Register File, Control Unit, Hazard Unit, Forwarding Unit, etc.).components/Pipelined_Registers/: Pipeline registers (IF/ID, ID/EX, EX/MEM, MEM/WB) to pass data between stages.stages/: VHDL files for each pipeline stage (Fetch, Decode, Execute, Memory, WriteBack).simulate/: Generated directory for ModelSim project files (created by the Python script).test/: Testbench files and DO scripts.docs/: Documentation and design assets.
- ModelSim (or compatible VHDL simulator).
- Python 3.x (optional, for using the automation script).
The processor executes machine code stored in a memory file. You can write assembly code and use the provided assembler to generate this file.
- Write Assembly: Edit or create your assembly code in
test/program.asm. - Assemble: Run the assembler script to convert your assembly into a binary memory file:
This generates
python test/assembler.py
test/instruction.mem. - Simulation Input: The
Processor.pyscript and the VHDL memory component are configured to read frominstruction.mem.
The Processor.py script automates the entire process: creating the project, copying memory files, and launching ModelSim.
- Configuration: Open
Processor.pyand ensure therepoPathandmodelsim_exepaths match your local installation. - Run:
This script will take
python Processor.py
test/instruction.mem, move it to the simulation directory, compile all VHDL files, and start the simulation.
- Open ModelSim and create a new project.
- Add all VHDL files from
components/,stages/, and the rootProcessor.vhd. - Place a copy of
instruction.memin your ModelSim project directory. - Compile all files and load the
Processorentity. - Run the simulation (optionally using a
.dofile fromtest/do/).
For a detailed list of supported instructions and their binary codes, please refer to the Opcode Reference.