mohithnikesh/RISC_V_Emulator
0
RV32I RISC-V Emulator
This Hugging Face Space provides a professional web interface for a C++20 educational RV32I RISC-V emulator. The app lets users enter a small RISC-V assembly program or raw 32-bit machine-code words, run the emulator, step through execution, and inspect CPU state.
Features
- Interactive Gradio interface
- Assembly editor for a supported RV32I subset
- Raw hex machine-code input
- Example program selector
- Run, step, and reset controls
- Program counter display
- Register table for x0-x31 with ABI names
- Instruction trace table
- Decoded instruction table
- Memory dump viewer
- Console and validation messages
- Clear supported/unsupported ISA scope
Supported instruction subset
The current educational emulator supports:
ADDSUBANDORXORADDILBLHLWSBSHSWBEQBNEBLTBGEJALJALR
Current limitations
This version does not currently support:
- ELF loading
- RV64
- Compressed instructions
- Floating point instructions
- Linux booting
- Virtual memory
- Privileged mode
- Interrupts
Example assembly program
addi x1, x0, 10
addi x2, x0, 20
add x3, x1, x2
addi x4, x3, -5Expected final values:
x1 = 10x2 = 20x3 = 30x4 = 25
Local development
Install Python dependencies:
pip install -r requirements.txtBuild the C++ runner manually:
cmake -S . -B build -DENABLE_TESTS=OFF -DCMAKE_BUILD_TYPE=Release
cmake --build build --target riscv_web_runner -j 2Run the app:
python app.pyHugging Face deployment
- Create a new Hugging Face Space.
- Select
Gradioas the SDK. - Upload all source files and folders from this project.
- Do not upload local
build/or.git/folders. - Wait for Hugging Face Spaces to install dependencies and launch the app.
- Test the included arithmetic example.
The Space uses:
requirements.txtfor Python dependencies.packages.txtfor system packages required to compile the C++ emulator.app.pyas the Gradio application entry point.src/web_runner.cppas the bridge between Python and the C++ emulator core.
Architecture
Gradio UI (app.py)
|
| writes temporary .hex program file
v
C++ web runner (riscv_web_runner)
|
| links against existing emulator_lib
v
CPU + Memory + Decoder + Executor
|
| returns structured JSON
v
Gradio tables: registers, trace, decoded fields, memory dumpNotes
The original C++ emulator core is preserved. The web interface adds a thin runner and UI layer without changing the CPU, memory, decoder, or executor logic.
