HomeRISC-V from ScratchDay 4
DAY 4 · THE RISC-V ISA

The RV32I Instruction Set in Full

By EcrioniX · Updated Jun 7, 2026

Here's the surprising part: a computer that can run anything needs only about 40 instructions. That's the whole RV32I base — and it's the complete "vocabulary" our CPU must understand. Today we'll meet every instruction, grouped by what it actually does, in plain English. This is the last big ISA lesson before we start building hardware.

1. Only ~40 commands run the world

From Day 2 we have registers; from Day 3 we have formats. Now we fill in the actual operations. RV32I has roughly 40 instructions — that's it. Loops, if-statements, arrays, function calls, entire operating systems: all built from these few simple commands. They fall into a handful of families:

RV32I — the whole vocabulary, in 7 groups Arithmeticadd sub and or… Immediateaddi andi slli… Load / Storelw sw lb sb… Branchesbeq bne blt… Jumpsjal jalr Upper immlui auipc Systemecall fence…
Figure — Every RV32I instruction fits in one of these seven groups.

2. Arithmetic & logic (register-register) — R-type

Take two registers, do math, store the result. The everyday workhorses:

InstrMeaning
add / subrd = rs1 + rs2 / rs1 − rs2
and / or / xorbitwise AND / OR / XOR
sll / srl / srashift left / shift right (logical) / shift right (arithmetic, keeps sign)
slt / sltuset rd = 1 if rs1 < rs2 (signed / unsigned), else 0

3. Same operations, with a constant — I-type

Often one operand is a fixed number, not a register. The immediate versions (note the "i" suffix) bake a 12-bit constant right into the instruction:

InstrMeaning
addird = rs1 + constant  (there's no "subi" — just add a negative)
andi / ori / xoribitwise op with a constant
slli / srli / sraishift by a constant amount
slti / sltiuset 1 if rs1 < constant (signed / unsigned)

4. Talking to memory — loads & stores

Remember (Day 2): RISC-V is load-store, so these are the only instructions that touch memory. The address is always rs1 + offset:

InstrMeaning
lwLoad a 32-bit word from memory into rd
lh / lbload a 16-bit half / 8-bit byte (sign-extended)
lhu / lbuload half / byte, unsigned (zero-extended)
sw / sh / sbStore a word / half / byte from rs2 to memory

Example: lw x5, 8(x10) = "load the word at address (x10 + 8) into x5."

5. Making decisions — branches

This is how a CPU does "if". A branch compares two registers and jumps only if the condition is true (otherwise it just continues):

InstrJump if…
beq / bners1 == rs2 / rs1 != rs2
blt / bgers1 < rs2 / rs1 ≥ rs2 (signed)
bltu / bgeusame, unsigned

6. Going places — jumps & big constants

InstrMeaning
jalJump and link — jump to a label, save the return address in rd (used to call functions)
jalrjump to an address in a register (used to return from functions, and for computed jumps)
luiLoad upper immediate — put a 20-bit constant into the top of a register (for building big numbers)
auipcadd a 20-bit constant to the PC (for position-independent addressing)

System instructions round out the set: ecall (ask the OS for a service), ebreak (debugger trap), and fence (ordering) — we'll only need these much later.

7. Pseudo-instructions — friendly shortcuts

You'll see commands in assembly that aren't in the tables above — like li or mv. Those are pseudo-instructions: convenient shorthands the assembler automatically expands into real RV32I instructions. They make code readable without adding hardware:

You writeReally becomes
li rd, 5addi rd, x0, 5 (load a small constant)
mv rd, rsaddi rd, rs, 0 (copy a register)
nopaddi x0, x0, 0 (do nothing)
j labeljal x0, label (jump, don't save return)
retjalr x0, 0(x1) (return: jump to ra)

💡 Why so few instructions?

A common worry: "only 40 — is that enough?" Yes! It's like an alphabet: ~26 letters spell every English word. RV32I's small, simple set spells every program — and because each instruction is simple, the hardware to run them is simple too, which is exactly why we can build it ourselves.

8. Putting it together

Here's a small program that uses arithmetic, an immediate, a branch and a jump — building a loop that sums 1..10. Copy or download it; our CPU will run code exactly like this from Day 15:

rv32i_demo.s — uses several instruction families
# Sum 1..10 into a0, then load/store a value. Shows 5 instruction families.
        addi t0, x0, 0      # t0 = 0          (arithmetic-immediate)
        addi t1, x0, 1      # t1 = 1  (i)
        addi t2, x0, 11     # t2 = 11 (limit)
loop:   bge  t1, t2, done   # if i >= 11, exit (branch)
        add  t0, t0, t1     # sum += i        (arithmetic R-type)
        addi t1, t1, 1      # i++             (immediate)
        jal  x0, loop       # repeat          (jump)
done:   mv   a0, t0         # a0 = sum (=55)  (pseudo -> addi a0,t0,0)

        # memory demo:
        sw   a0, 0(sp)      # store sum to memory at sp  (store)
        lw   a1, 0(sp)      # load it back into a1       (load)

✅ Day 4 in one line

RV32I is just ~40 instructions in 7 groups: register arithmetic/logic, immediate versions, loads/stores (the only memory ops), branches (the "if"), jumps (calls/returns), upper-immediate (big constants), and a few system ops — plus pseudo-instructions as friendly shortcuts. That small vocabulary can express any program, and it's the complete set our CPU will execute.

🎯 Day 4 takeaways

Quick check

  1. Which instructions are the only ones allowed to access memory?
  2. How does a CPU implement an "if" statement?
  3. What does mv a0, t0 really compile to?
  4. Why is ~40 instructions enough to run any program?

FAQ

How many instructions in RV32I?

About 40 (47 with all variants) — arithmetic, immediates, loads/stores, branches, jumps, upper-immediate and a few system instructions.

What are the main groups?

Register arithmetic/logic, immediate versions, loads, stores, branches, jumps, upper-immediate, and system.

What's a pseudo-instruction?

A shorthand the assembler expands into real instructions — e.g. mvaddi …,0, nopaddi x0,x0,0.

Is RV32I enough for real programs?

Yes — loops, conditionals, arrays and functions all build from it. Multiply/float are optional extensions (M, F).

Previous
← Day 3: Instruction formats

← Back to the full roadmap  ·  Open the Verilog simulator →