CoolFace
Apppublic

mohithnikesh/RISC_V_Emulator

sourceHugging Faceupdated 4mo agoView on Hugging Face
0likes
App README

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:

  • ADD
  • SUB
  • AND
  • OR
  • XOR
  • ADDI
  • LB
  • LH
  • LW
  • SB
  • SH
  • SW
  • BEQ
  • BNE
  • BLT
  • BGE
  • JAL
  • JALR

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

asm
addi x1, x0, 10
addi x2, x0, 20
add  x3, x1, x2
addi x4, x3, -5

Expected final values:

  • x1 = 10
  • x2 = 20
  • x3 = 30
  • x4 = 25

Local development

Install Python dependencies:

bash
pip install -r requirements.txt

Build the C++ runner manually:

bash
cmake -S . -B build -DENABLE_TESTS=OFF -DCMAKE_BUILD_TYPE=Release
cmake --build build --target riscv_web_runner -j 2

Run the app:

bash
python app.py

Hugging Face deployment

  1. 1.Create a new Hugging Face Space.
  2. 2.Select Gradio as the SDK.
  3. 3.Upload all source files and folders from this project.
  4. 4.Do not upload local build/ or .git/ folders.
  5. 5.Wait for Hugging Face Spaces to install dependencies and launch the app.
  6. 6.Test the included arithmetic example.

The Space uses:

  • requirements.txt for Python dependencies.
  • packages.txt for system packages required to compile the C++ emulator.
  • app.py as the Gradio application entry point.
  • src/web_runner.cpp as the bridge between Python and the C++ emulator core.

Architecture

text
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 dump

Notes

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.