RISC-V is an open standard instruction set architecture (ISA) based on reduced instruction set computing (RISC) principles. RV32 is the 32-bit version, supporting 32-bit registers, addresses, and data types. It is widely used in embedded and academic environments for its simplicity and extensibility.
This tutorial covers the basics and lets you interactively explore and test your knowledge!
Type | Fields | Description |
---|---|---|
R-type | opcode, rd, funct3, rs1, rs2, funct7 | Register-register operations |
I-type | opcode, rd, funct3, rs1, imm[11:0] | Immediate, loads, jalr, system |
S-type | opcode, imm[4:0], funct3, rs1, rs2, imm[11:5] | Stores |
B-type | opcode, imm[11], imm[4:1], funct3, rs1, rs2, imm[10:5], imm[12] | Branches |
U-type | opcode, rd, imm[31:12] | LUI, AUIPC |
J-type | opcode, rd, imm[20|10:1|11|19:12] | JAL |
Name | Format | Opcode | funct3 | Description |
---|---|---|---|---|
ADD | R | 0110011 | 0x0 | rd = rs1 + rs2 |
SUB | R | 0110011 | 0x0 | rd = rs1 - rs2 |
XOR | R | 0110011 | 0x4 | rd = rs1 ^ rs2 |
OR | R | 0110011 | 0x6 | rd = rs1 | rs2 |
AND | R | 0110011 | 0x7 | rd = rs1 & rs2 |
SLL | R | 0110011 | 0x1 | rd = rs1 << rs2 |
SRL | R | 0110011 | 0x5 | rd = rs1 >> rs2 (logical) |
SRA | R | 0110011 | 0x5 | rd = rs1 >> rs2 (arith) |
SLT | R | 0110011 | 0x2 | rd = (rs1 < rs2)?1:0 |
SLTU | R | 0110011 | 0x3 | rd = (rs1 < rs2 unsigned)?1:0 |
ADDI | I | 0010011 | 0x0 | rd = rs1 + imm |
XORI | I | 0010011 | 0x4 | rd = rs1 ^ imm |
ORI | I | 0010011 | 0x6 | rd = rs1 | imm |
ANDI | I | 0010011 | 0x7 | rd = rs1 & imm |
SLLI | I | 0010011 | 0x1 | rd = rs1 << imm[0:4] |
SRLI | I | 0010011 | 0x5 | rd = rs1 >> imm[0:4] (logical) |
SRAI | I | 0010011 | 0x5 | rd = rs1 >> imm[0:4] (arith) |
SLTI | I | 0010011 | 0x2 | rd = (rs1 < imm)?1:0 |
SLTIU | I | 0010011 | 0x3 | rd = (rs1 < imm unsigned)?1:0 |
LB/LH/LW | I | 0000011 | 0x0/0x1/0x2 | rd = M[rs1+imm][0:7/15/31] |
LBU/LHU | I | 0000011 | 0x4/0x5 | rd = M[rs1+imm][0:7/15] (unsigned) |
SB/SH/SW | S | 0100011 | 0x0/0x1/0x2 | M[rs1+imm][0:7/15/31] = rs2 |
BEQ/BNE/BLT/BGE/BLTU/BGEU | B | 1100011 | 0x0/0x1/0x4/0x5/0x6/0x7 | Conditional branches |
JAL | J | 1101111 | - | rd = PC+4; PC += imm |
JALR | I | 1100111 | 0x0 | rd = PC+4; PC = rs1+imm |
LUI | U | 0110111 | - | rd = imm << 12 |
AUIPC | U | 0010111 | - | rd = PC + (imm << 12) |
ECALL/EBREAK | I | 1110011 | 0x0 | System call / Break |
Register | ABI Name | Description |
---|---|---|
x0 | zero | Zero constant |
x1 | ra | Return address |
x2 | sp | Stack pointer |
x3 | gp | Global pointer |
x4 | tp | Thread pointer |
x5-x7 | t0-t2 | Temporaries |
x8 | s0/fp | Saved/frame pointer |
x9 | s1 | Saved register |
x10-x11 | a0-a1 | Function args/return values |
x12-x17 | a2-a7 | Function args |
x18-x27 | s2-s11 | Saved registers |
x28-x31 | t3-t6 | Temporaries |