RISC-V documentation and reference

On this page

Getting Started

Quick start

StudyRISC-V runs entirely in your browser. No installation, no account required. Open the simulator and start typing.

1

Write or load assembly in the editor.

2

Click Assemble to compile your program.

3

Click Step to execute one instruction at a time.

Your first program

# Your first RISC-V program
addi x1, x0, 10    # x1 = 10
addi x2, x0, 20    # x2 = 20
add  x3, x1, x2    # x3 = x1 + x2 (should be 30)

After assembling and stepping three times, x3 in the register file will show 0x0000001E (30 in decimal).

Open in Simulator →

Controls reference

AssembleCompile the assembly source and load into simulator
StepExecute one instruction, advance PC
Step BackUndo the last instruction
RunExecute continuously until halt or trap
ResetClear all state and return to assembled state
Keyboard Action
EnterAssemble when the editor is not focused
Step
Shift+↓Step Back
RRun / Stop
EscapeReset

Simulator Panels

Assembly editor

Syntax highlighting, line numbers, and tab support make it easy to write class-style assembly quickly.

Watch for: label coloring, inline comments, and the sample selector for fast starting points.

Disassembly view

Shows instruction address, hex encoding, mnemonic, and operands. The highlighted row is the current PC.

Watch for: the highlighted row moving as you step and branch targets snapping into focus.

Pseudo-C explainer

Translates the current instruction into a C-like expression. x1 = x2 + 10 is clearer than addi x1, x2, 10 for building intuition.

Watch for: the destination, operator, and source coloring as you step.

Call stack visualizer

Shows live stack frames as functions are called and returned from. Load the Function call sample to see it.

Watch for: saved ra, saved registers, local slots, and the current sp row moving.

Effect log

Every register change, memory write, and PC update from each step. Use the REG, MEM, and PC filters to focus.

Watch for: branch redirections, stores to memory, and which register changed most recently.

Memory panel

Shows a window of memory around a chosen address. Use the follow dropdown to track sp or another register.

Watch for: stack writes landing near 0x7FFFFFFC and data segment writes near 0x10000000.

Register file

All 32 RISC-V registers with ABI names and current values. Changed registers flash when updated.

Watch for: calling convention groupings, ABI aliases, and hex values stabilizing across steps.

RISC-V Reference

Register table

Register ABI Name Role
x0zeroConstant value 0
x1raReturn address
x2spStack pointer
x3gpGlobal pointer
x4tpThread pointer
x5-x7t0-t2Temporaries
x8s0/fpSaved register / frame pointer
x9s1Saved register
x10-x11a0-a1Function args / return values
x12-x17a2-a7Function arguments
x18-x27s2-s11Saved registers
x28-x31t3-t6Temporaries

Instruction set

ArithmeticFormatOperationExample
addrd, rs1, rs2rd = rs1 + rs2add x3, x1, x2
addird, rs1, immrd = rs1 + immaddi x1, x0, 10
subrd, rs1, rs2rd = rs1 - rs2sub x3, x1, x2
luird, immrd = imm << 12lui x1, 0x10000
auipcrd, immrd = PC + (imm << 12)auipc x1, 0
ComparisonFormatOperationExample
sltrd, rs1, rs2rd = (rs1 < rs2) ? 1 : 0slt x3, x1, x2
sltird, rs1, immrd = (rs1 < imm) ? 1 : 0slti x1, x2, 5
slturd, rs1, rs2unsigned comparesltu x3, x1, x2
sltiurd, rs1, immunsigned compare with immsltiu x1, x2, 5
BitwiseFormatOperationExample
andrd, rs1, rs2rd = rs1 & rs2and x3, x1, x2
orrd, rs1, rs2rd = rs1 | rs2or x3, x1, x2
xorrd, rs1, rs2rd = rs1 ^ rs2xor x3, x1, x2
andird, rs1, immrd = rs1 & immandi x1, x2, 15
orird, rs1, immrd = rs1 | immori x1, x2, 1
xorird, rs1, immrd = rs1 ^ immxori x1, x2, 1
ShiftsFormatOperationExample
sllrd, rs1, rs2rd = rs1 << rs2sll x3, x1, x2
srlrd, rs1, rs2rd = rs1 >> rs2 (logical)srl x3, x1, x2
srard, rs1, rs2rd = rs1 >> rs2 (arithmetic)sra x3, x1, x2
sllird, rs1, immshift left immediateslli x1, x2, 2
srlird, rs1, immshift right logical immediatesrli x1, x2, 1
sraird, rs1, immshift right arithmetic immediatesrai x1, x2, 1
M ExtensionFormatOperationExample
mulrd, rs1, rs2rd = rs1 * rs2 (lower 32 bits)mul x3, x1, x2
mulhrd, rs1, rs2rd = (rs1 * rs2) >> 32 signedmulh x3, x1, x2
divrd, rs1, rs2rd = rs1 / rs2 signeddiv x3, x1, x2
divurd, rs1, rs2rd = rs1 / rs2 unsigneddivu x3, x1, x2
remrd, rs1, rs2rd = rs1 % rs2 signedrem x3, x1, x2
remurd, rs1, rs2rd = rs1 % rs2 unsignedremu x3, x1, x2
Control flowFormatOperationExample
jalrd, labelrd = PC+4; PC = labeljal ra, func
jalrrd, rs1, immrd = PC+4; PC = rs1+immjalr x0, ra, 0
beqrs1, rs2, labelif rs1==rs2 branchbeq x1, x2, done
bners1, rs2, labelif rs1!=rs2 branchbne x1, x2, loop
bltrs1, rs2, labelif rs1<rs2 branch (signed)blt x1, x2, less
bgers1, rs2, labelif rs1>=rs2 branch (signed)bge x1, x2, ge
blturs1, rs2, labelunsigned less thanbltu x1, x2, lessu
bgeurs1, rs2, labelunsigned greater or equalbgeu x1, x2, geu
MemoryFormatOperationExample
lwrd, imm(rs1)rd = mem[rs1+imm] (32-bit)lw x3, 0(x1)
lhrd, imm(rs1)rd = mem[rs1+imm] (16-bit sign-ext)lh x3, 0(x1)
lbrd, imm(rs1)rd = mem[rs1+imm] (8-bit sign-ext)lb x3, 0(x1)
lhurd, imm(rs1)16-bit zero-extendedlhu x3, 0(x1)
lburd, imm(rs1)8-bit zero-extendedlbu x3, 0(x1)
swrs2, imm(rs1)mem[rs1+imm] = rs2 (32-bit)sw x3, 0(x1)
shrs2, imm(rs1)mem[rs1+imm] = rs2 (16-bit)sh x3, 0(x1)
sbrs2, imm(rs1)mem[rs1+imm] = rs2 (8-bit)sb x3, 0(x1)
SystemFormatOperationExample
ecallEnvironment call (syscall)ecall
ebreakBreakpointebreak
The M extension (multiply/divide) is part of RV32IM and is covered in ECE 2035 at Georgia Tech. StudyRISC-V supports the full M extension including mul, div, rem, and their unsigned and upper-word variants.

Pseudo-instructions

PseudoExpands toMeaning
li rd, immaddi rd, x0, imm (small) or lui+addi (large imm)Load immediate
mv rd, rsaddi rd, rs, 0Copy register
nopaddi x0, x0, 0No operation
j labeljal x0, labelUnconditional jump
retjalr x0, ra, 0Return from function
call labelauipc ra, hi20; jalr ra, lo12Call function
la rd, lblauipc+addiLoad address

Memory map

0x7FFFFFFCStack (grows down) · sp initialized here
0x10000000Data segment (.data section)
0x00000000Text segment (instructions)

Not to scale.

Calling Convention

The RISC-V calling convention is a set of rules that functions agree to follow so they can call each other correctly. StudyRISC-V's call stack panel visualizes these rules in real time.

Caller-saved registers (ra, t0-t6, a0-a7) may be overwritten by any function you call. Save them yourself if you need them after the call.
Callee-saved registers (s0-s11, sp) must be restored to their original values before a function returns. If you use them, save and restore them.

Stack frames

A typical function prologue moves sp downward to allocate space, saves ra and any callee-saved registers it uses, then writes local variables into that frame.

example frame 16 bytes
0x7FFFFFF8 0x00000028 saved ra
0x7FFFFFF4 s0 = 0x00000015 saved reg
0x7FFFFFF0 0x00000015 local var
→ sp 0x7FFFFFEC

Example walkthrough

  1. addi sp, sp, -16

    Allocates a new stack frame by moving the stack pointer down 16 bytes.

    This is the start of the function prologue.

  2. sw ra, 12(sp) and sw s0, 8(sp)

    Saves the return address and a callee-saved register into the new frame.

    This follows the rule that anything you promise to preserve must be restored before return.

  3. addi a0, x0, 21 and jal ra, double

    Places the argument in a0 and calls the callee, writing the return address into ra.

    The call stack panel pushes a new frame when this happens.

  4. add a0, a0, a0

    The callee computes its result in a0, which is where return values belong.

    This is why argument registers double as return-value registers.

  5. lw ra, 4(sp), addi sp, sp, 8, jalr x0, ra, 0

    Restores the saved return address, deallocates the callee frame, and jumps back to the caller.

    The call stack panel collapses the frame and shows the symmetry of call and return.

# Watch the CALL STACK panel on the right.
# Step through to see the frame grow, save ra and s0, call double, and return.
main:
  addi sp, sp, -16
  sw   ra, 12(sp)
  sw   s0, 8(sp)
  addi a0, x0, 21
  jal  ra, double
double:
  addi sp, sp, -8
  sw   ra, 4(sp)
  add  a0, a0, a0
  jalr x0, ra, 0
Try it in the simulator →

ECE 2035 at Georgia Tech

StudyRISC-V was built while taking ECE 2035 (Assembly and C language) at Georgia Tech. The simulator covers the full RV32IM subset used in that course.

TopicFeature
Assembly programming fundamentalsEditor with syntax highlighting, built-in samples
Register file and data typesLive register panel, ABI name labels, hex/decimal context
Memory addressing and load/storeMemory panel with address following, byte-level view
Control flow (branches and jumps)Disassembly with PC highlighting, effect log
Function calls and calling conventionCall stack visualizer that shows frame building live
M extension (multiply/divide)Full mul/div/rem support including edge cases

Sample programs

Start with the calling convention demo or recursive factorial if you want to see stack growth clearly. For data-segment practice, use the built-in string copy or bubble sort examples.