Skip to content

Appendix A — RISC-V Instruction Card (RV32IM)

This appendix provides a quick reference for the RV32IM unprivileged ISA (RV32I base integer + RV32M integer multiply/divide). Syntax uses ABI register names or placeholders:

  • rd: destination register
  • rs1/rs2: source registers
  • imm: immediate
  • shamt: shift amount

RISC-V instructions are 32 bits and use several encoding formats. R/I/S/B formats are covered in Chapter 5’s encoding table; this appendix adds U/J format notes.

Bits[31:12][11:7][6:0]
Fieldimm[31:12]rdopcode
Bits[31][30:21][20][19:12][11:7][6:0]
Fieldimm[20]imm[10:1]imm[11]imm[19:12]rdopcode

Notes:

  • U-type places the 20-bit immediate into the upper bits of the destination register (effectively imm << 12).
  • J-type encodes a signed PC-relative offset. The effective offset has bit 0 = 0 (2-byte alignment), so the immediate is reconstructed and then shifted left by 1.

Table A.1: U-type and J-type instruction encoding (RV32).

InstrTypeSyntaxDescription
LBILB rd, imm(rs1)load byte, sign-extend to 32 bits
LHILH rd, imm(rs1)load halfword, sign-extend
LWILW rd, imm(rs1)load word (32-bit)
LBUILBU rd, imm(rs1)load byte, zero-extend
LHUILHU rd, imm(rs1)load halfword, zero-extend
SBSSB rs2, imm(rs1)store low 8 bits of rs2
SHSSH rs2, imm(rs1)store low 16 bits of rs2
SWSSW rs2, imm(rs1)store 32 bits of rs2
InstrTypeSyntaxDescription
SLLRSLL rd, rs1, rs2logical left shift by rs2[4:0]
SRLRSRL rd, rs1, rs2logical right shift (zero-fill)
SRARSRA rd, rs1, rs2arithmetic right shift (sign-fill)
SLLIISLLI rd, rs1, shamtlogical left shift immediate
SRLIISRLI rd, rs1, shamtlogical right shift immediate
SRAIISRAI rd, rs1, shamtarithmetic right shift immediate
InstrTypeSyntaxDescription
ADDRADD rd, rs1, rs2rd = rs1 + rs2 (wrap on overflow)
ADDIIADDI rd, rs1, immrd = rs1 + sign_ext(imm)
SUBRSUB rd, rs1, rs2rd = rs1 − rs2 (wrap on overflow)
LUIULUI rd, immrd = imm << 12 (low 12 bits zero)
AUIPCUAUIPC rd, immrd = PC + (imm << 12)
InstrTypeSyntaxDescription
MULRMUL rd, rs1, rs2low 32 bits of signed product
MULHRMULH rd, rs1, rs2high 32 bits (signed × signed)
MULHSURMULHSU rd, rs1, rs2high 32 bits (signed × unsigned)
MULHURMULHU rd, rs1, rs2high 32 bits (unsigned × unsigned)
DIVRDIV rd, rs1, rs2signed division (toward zero)
DIVURDIVU rd, rs1, rs2unsigned division
REMRREM rd, rs1, rs2signed remainder
REMURREMU rd, rs1, rs2unsigned remainder
InstrTypeSyntaxDescription
XORRXOR rd, rs1, rs2bitwise XOR
XORIIXORI rd, rs1, immXOR with sign-extended imm
ORROR rd, rs1, rs2bitwise OR
ORIIORI rd, rs1, immOR with sign-extended imm
ANDRAND rd, rs1, rs2bitwise AND
ANDIIANDI rd, rs1, immAND with sign-extended imm
InstrTypeSyntaxDescription
SLTRSLT rd, rs1, rs2signed less-than → 1/0
SLTIISLTI rd, rs1, immsigned compare with imm
SLTURSLTU rd, rs1, rs2unsigned less-than
SLTIUISLTIU rd, rs1, immunsigned compare with imm

Branch targets are PC-relative; immediates are 2-byte aligned (range ≈ ±4 KiB).

InstrTypeSyntaxDescription
BEQBBEQ rs1, rs2, immif rs1==rs2, PC ← PC + sign_ext(imm)
BNEBBNE rs1, rs2, immif rs1!=rs2, branch
BLTBBLT rs1, rs2, immsigned less-than
BGEBBGE rs1, rs2, immsigned ≥
BLTUBBLTU rs1, rs2, immunsigned less-than
BGEUBBGEU rs1, rs2, immunsigned ≥
InstrTypeSyntaxDescription
JALJJAL rd, immrd=PC+4; PC ← PC + sign_ext(imm)
JALRIJALR rd, rs1, immrd=PC+4; PC ← (rs1+sign_ext(imm)) & ~1
InstrTypeSyntaxDescription
FENCEIFENCE pred, succordering barrier for memory/I/O
FENCE.IIFENCE.Iinstruction/data sync barrier
InstrTypeSyntaxDescription
ECALLIECALLenvironment call trap
EBREAKIEBREAKbreakpoint trap
InstrTypeSyntaxDescription
CSRRWICSRRW rd, csr, rs1read then write
CSRRSICSRRS rd, csr, rs1read then set bits
CSRRCICSRRC rd, csr, rs1read then clear bits
CSRRWIICSRRWI rd, csr, immimmediate write
CSRRSIICSRRSI rd, csr, immimmediate set bits
CSRRCIICSRRCI rd, csr, immimmediate clear bits

These pseudo-instructions expand to reading a specific CSR (conceptually CSRRS rd, csr, x0).

PseudoCSRSyntaxDescription
RDCYCLEcycleRDCYCLE rdread low 32 bits of cycle counter
RDCYCLEHcyclehRDCYCLEH rdread high 32 bits of cycle counter
RDTIMEtimeRDTIME rdread low 32 bits of real-time counter
RDTIMEHtimehRDTIMEH rdread high 32 bits of real-time counter
RDINSTRETinstretRDINSTRET rdread low 32 bits of retired-instruction counter
RDINSTRETHinstrethRDINSTRETH rdread high 32 bits of retired-instruction counter

Table A.2: Counter read pseudo-instructions.

CSR addresses encode access permissions and the minimum required privilege level. The list below includes the most commonly used CSRs in RV32 implementations.

NameAddressAccessPurpose
(Machine mode status & control)
mstatus0x300MRWglobal machine status (MIE/MPIE/MPP, etc.)
misa0x301MRWISA description (XLEN and extension bits)
mie0x304MRWmachine interrupt enables (MEIE/MTIE/MSIE)
mtvec0x305MRWtrap vector base and mode (Direct/Vectored)
(Machine mode trap handling)
mscratch0x340MRWscratch register for trap handlers
mepc0x341MRWexception PC (return target for MRET)
mcause0x342MRWtrap cause (MSB=1 indicates interrupt)
mtval0x343MRWtrap value (bad address / illegal instruction bits, etc.)
mip0x344MRWmachine interrupt pending (reflects interrupt signals)
(Machine performance counters)
mcycle0xB00MRWcycle counter low 32 bits
minstret0xB02MRWretired instruction counter low 32 bits
mcycleh0xB80MRWcycle counter high 32 bits
minstreth0xB82MRWretired instruction counter high 32 bits
(User-mode read-only counters)
cycle0xC00UROuser view of mcycle low 32 bits
time0xC01UROreal-time counter low 32 bits (platform-defined)
instret0xC02UROretired instruction counter low 32 bits
cycleh0xC80UROcycle counter high 32 bits
timeh0xC81UROreal-time counter high 32 bits
instreth0xC82UROretired instruction counter high 32 bits

Table A.3: Common CSR registers.