Skip to content

Cycle-accurate LC-3 CPU simulator modeling pipelined execution, hazards, forwarding, and interrupt handling, with performance instrumentation

Notifications You must be signed in to change notification settings

shanehnguyen/RISC-CPU-Simulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pipelined RISC CPU in Verilog

This project implements a simplified, MIPS-like 5-stage pipelined CPU entirely in Verilog HDL, designed with:

Accurate instruction flow through classic pipeline stages: IF → ID → EX → MEM → WB

The Verilog model was developed after a full-featured C++ simulator used to prototype pipeline behavior and cache performance.


Verilog Features

  • 5-stage CPU Pipeline
  • Load-use hazard detection and stalling
  • Data forwarding (EX→EX and MEM→EX paths)
  • Pipeline flush on control hazards
  • Waveform-debuggable control signals

Verification

  • Testbenches for each pipeline feature
  • Assembly-style test programs (in Verilog hex format)
  • Simulated using Icarus
  • Observed via GTKWave waveform viewer

Instruction Set

  • ADD, SUB, ADDI
  • LOAD, STORE
  • BEQ, JAL
  • NOP, HALT

C++ Reference Model (Pre-Verilog Phase)

  • The initial design phase included a C++ cycle-accurate simulator with:
  • Instruction-level simulation
  • Set-associative cache with LRU
  • CPI and hazard statistics
  • This model served as a reference for RTL validation

Build and Run Verilog

iverilog -o cpu_test.vvp testbenches/test_cpu.v
vvp cpu_test.vvp

Add instructions in verilog/modules/instruction_memory.v

Build and Run C++

cd src
g++ main.cpp -o sim
./sim

About

Cycle-accurate LC-3 CPU simulator modeling pipelined execution, hazards, forwarding, and interrupt handling, with performance instrumentation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published