5-stage pipelined RISC-V processor simulator with cycle-accurate execution, hazard detection, and interactive visualization.
- Implemented the 5 stage pipeline simulator (IF -> ID -> EX -> MEM -> WB)
- Pipeline register trace table
- Data hazard with stalling (no forwarding)
- Control hazard with predict not taken and flush on taken branches
- RISC-V instruction encoder / instruction tbale
- Pipeline visualization through the trace tables where the rows = registers, and columns = cycles
- Opcode tab implementation showing the instruction and their corresponding 32 bit opcode hex
- Enhanced api's
- /api/sim/load accepts initial_registers and initial_memory
- /api/sim/step returns complete pipeline snapshop
- Instruction encoding and hex display
- Added support for labels
- Separated Integer and Floating integers in
CPU Statepanel into tabs with scrollable views - Assemble loads program into the simulator allowing
Stepto execute cycle-by-cycle - Implemented the simulator endpoints and services
IDE-like interface for RISC-V assembly validation and simulation.
cd backend
python3 -m pip install -r requirements.txt
python3 -m uvicorn app:app --reload --port 8000Backend runs on: http://localhost:8000
- API Docs: http://localhost:8000/docs
cd web
npm install
npm run devFrontend runs on: http://localhost:5173
Implemented the requirements for Milestone 1 which is to have a program input with error checking for registers and opcode. Went further than the requirement and have already implemented the frontend ide-like interface. Although some of the components aren't functional, the main requirement for Milestone 1 has already been implemented. The error checking indicates which line is causing the error, and which instruction and/or register is invalid as seen on the demo in https://drive.google.com/drive/folders/1Q1kjVfD1sUWo6wxq2oHW6eGPIoVb_-Cl?usp=drive_link (only accessible to a few people).
Frontend:
- React 18 + TypeScript
- Vite 5
- Tailwind CSS 3
- Tokyo Night Storm color palette
Backend:
- FastAPI 0.115
- Python 3.13+
- Pydantic validation
- CORS enabled
- Start servers (see Quick Start section below)
- Open http://localhost:5173/
- Try an example:
# Copy from examples/02_data_hazard.asm ADDI x1, x0, 10 ADDI x2, x0, 20 ADD x3, x1, x2 # Watch for stalls! ADD x4, x3, x3
- Click Assemble → Click Step repeatedly
- Watch the Pipeline Registers table fill with cycle data
See /examples/README.md for 7 complete example programs with expected behaviors.
Arithmetic:
ADD,SUB,ADDI- Addition and subtractionAND,OR,ORI- Bitwise operationsSLL,SLLI- Shift left logicalSLT- Set less than (signed comparison)
Memory:
LW- Load word:LW x1, 0(x2)SW- Store word:SW x2, 4(x1)
Control:
BEQ,BNE- Branch if equal/not equalBLT,BGE- Branch if less than / greater or equal (signed)
Memory Layout (per spec):
- Data segment:
0x0000-0x007F(128 bytes) - Program segment:
0x0080-0x00FF(128 bytes)
- web/src/components/ToolBar.tsx : Top action bar (Run, Pause, Step, Reset, Assemble) and error count.
- web/src/components/CodePanel.tsx : Code editor area (textarea for M1) with inline assembler error display.
- web/src/components/CPUState.tsx : Read-only CPU state panel showing PC, integer (x0..x31) and FP (f0..f31) registers.
- web/src/components/BottomPanel/index.tsx : Bottom tabbed panel (Pipeline Map, Pipeline Registers, Errors/Console).
┌─────────────────────────────────────────────┐
│ ToolBar (Run, Pause, Step, Reset, Assemble) │
├─────────────────────┬───────────────────────┤
│ Code Editor │ CPU State │
│ (CodePanel) │ - Registers │
│ │ - PC │
│ │ - Float Registers │
├─────────────────────┴───────────────────────┤
│ Bottom Panel (Tabs) │
│ - Pipeline Map │
│ - Pipeline Registers │
│ - Errors / Console │
└─────────────────────────────────────────────┘
Validate RISC-V assembly code.
Request:
{
"source": "LW x1, 0(x2)\nAND x3, x1, x2"
}Response:
{
"success": true,
"instructions": [
{"line": 1, "opcode": "LW", "raw": "LW x1, 0(x2)"},
{"line": 2, "opcode": "AND", "raw": "AND x3, x1, x2"}
],
"errors": []
}risc-v-simulator/
├── backend/
│ ├── app.py # FastAPI app
│ ├── simulator/
│ │ ├── assembler.py # Validation logic
│ │ └── __init__.py
│ └── requirements.txt
├── web/
│ ├── src/
│ │ ├── components/ # React components
│ │ ├── services/ # API client
│ │ ├── types.ts # TypeScript types
│ │ └── App.tsx
│ ├── package.json
│ └── vite.config.ts
└── README.md