RISC-V Emulator Reference

This document describes the supported instruction set and runtime behavior for the RISC-V emulator.


Quick Start

To run your first RISC-V program:

  1. Paste the following into the emulator’s Program Input area.
  2. Click LoadStep or Run to execute.
  3. Inspect registers (x0–x31 or ABI names like a0, sp) and memory updates.
ADDI x1, x0, 5
ADDI x2, x0, 10
JAL x5, sum_func
SW x3, 3(x1)
ECALL

sum_func:
  ADD x3, x1, x2
  JALR x0, 0(x5)

Memory Model


Registers

ABI Namex#Description
zerox0Constant zero
rax1Return address
spx2Stack pointer (0x0FFC)
gpx3Global pointer (0x0800)
tpx4Thread pointer
t0–t6x5–x7, x28–x31Temporaries
s0–s11x8–x9, x18–x27Saved registers
a0–a7x10–x17Function arguments / return values

Use either numeric (x5) or ABI (t0) notation — both are supported interchangeably.


Pseudo-Instructions

PseudoEquivalent Expansion / Behavior
LI rd, imm
  • If −2048 ≤ imm ≤ 2047: ADDI rd, x0, imm
  • Otherwise: LUI rd, upper(imm) + ADDI rd, rd, lower(imm)
MV rd, rsADDI rd, rs, 0
J labelJAL x0, label
JR rsJALR x0, 0(rs)
RETJALR x0, 0(x1) (return to caller)
LA rd, label Computes the address of label using LUI + ADDI with sign-extension.

Supported Instructions

Implements the RV32I base integer instruction set as defined by the RISC-V Foundation.

For detailed bit fields and encodings, see the Official RISC-V Reference Card (PDF).


Execution Model


Author & Credits

Darrel Wihandi
RISC-V Web Emulator Project
Built with C++ (Emscripten) + HTML/JS Frontend

Based on the RISC-V Reference Card (RV32I Base) by the RISC-V Foundation.

Last Updated: