5.1.7Instruction Set Architecture (ISA)

RISC-V base ISA (RV32I - RV64I)

2,248 words10 min readdifficulty · medium2 backlinks

WHY does RISC-V exist / why "base + extensions"?


WHAT is in the base? The register model


HOW instructions are shaped: the 6 formats

Every RV32I instruction is exactly 32 bits (fixed length → trivial fetch/decode). The bits are chopped into fields. The genius is that fields stay in the same place across formats so the decoder can extract them in parallel.

Figure — RISC-V base ISA (RV32I - RV64I)

HOW to build the immediate (derivation, not memorization)


Worked examples


RV64I: what changes vs RV32I


Common mistakes


Active recall

Recall Answer before expanding
  • How many GPRs, and what's special about x0? → 32; x0 is hardwired zero.
  • Instruction length in RV32I? → Fixed 32 bits.
  • Why split S/B immediates? → Keep rs1/rs2/rd fields in fixed positions for fast decode.
  • Difference RV32I vs RV64I? → XLEN (32 vs 64) + word (*w) and ld/sd instructions.
  • How do you load a full 32-bit constant? → lui (upper 20) + addi (lower 12), correcting for signed low.
Recall Feynman: explain to a 12-year-old

Imagine a chef with only 40 basic moves (chop, stir, pour…). That's the RISC-V base. Any dish (program) is just a long list of these moves. There are 32 numbered bowls (registers) to hold ingredients, and bowl #0 is magic: it's always empty (zero) — super handy as "nothing". Every recipe card is the same size so the chef reads them super fast. If you need a bigger kitchen, you add extra move-packs (multiply, floating point) — but the 40 basics never change. RV64 just uses bigger bowls that hold bigger numbers.


Flashcards

How many general-purpose registers does RV32I/RV64I have?
32 (x0–x31), each XLEN bits wide.
What is special about register x0?
Hardwired to 0; reads give 0, writes are discarded.
What does XLEN mean and what is it for RV32I vs RV64I?
Register/data width; 32 for RV32I, 64 for RV64I.
Instruction length in the RV32I base ISA?
Fixed 32 bits (all instructions).
Name the six RV32I instruction formats.
R, I, S, B, U, J.
Why are the S/B immediates split across scattered bits?
To keep rs1/rs2/rd fields in fixed positions so decode/register-read can start early.
What is the range of a 12-bit signed I-immediate?
[-2048, 2047].
How do you load a 32-bit constant into a register?
lui (upper 20 bits) + addi (lower 12), rounding the upper part up if the low 12 bits are negative.
How is a branch offset formed?
target = pc + sext(imm), with imm[0]=0 (multiple of 2 bytes).
What extensions make "RV64G"?
I + M + A + F + D (+C conventionally) — general-purpose set.
What new instructions does RV64I add over RV32I?
Word ops (addw, subw, sllw, lwu) and ld/sd for 64-bit; results sign-extended to 64 bits.
How is nop encoded in RISC-V?
addi x0, x0, 0.
Does RISC-V have a flags/condition-code register?
No; branches compare registers directly.
Why sign-extend the immediate?
So negative immediates (e.g. addi with -1) produce all-ones and work naturally.

Connections

Concept Map

defines

allows

includes

sets

32 or 64

contains

enables

has

uses

shaped by

keep

require

RISC-V open ISA

Base integer I

Optional extensions M A F D C

32 registers x0-x31

XLEN width

x0 hardwired zero

Pseudo-instructions

No flags register

Fixed 32-bit instructions

6 instruction formats

Fixed register fields

Split immediates S B J

Hinglish (regional understanding)

Intuition Hinglish mein samjho

RISC-V ek open ISA hai — yaani hardware aur software ke beech ka contract, jise koi bhi bina license fee ke use kar sakta hai. Iska base integer set (RV32I ya RV64I) jaan-boojh ke bahut chhota rakha gaya hai: sirf ~40 basic instructions, jinse pura computer chal jaata hai. Baaki cheezein (multiply, floating point, atomics) extensions ki tarah add hoti hain — M, A, F, D, C jaise letters. Idea simple hai: hardware chhota aur fast rakho, compiler se kaam karwao. Yahi RISC philosophy hai.

Registers: dono me 32 general-purpose registers hote hain (x0 se x31). Sabse important trick — x0 hamesha zero hota hai. Isse nop, mv, zero-compare jaise kaam free me ho jaate hain, alag opcodes ki zaroorat nahi. RV32I me registers 32-bit ke hain (XLEN=32), RV64I me 64-bit (XLEN=64). Yaad rakho: "32" ka matlab register ki width hai, count nahi — count dono me 32 hi hai.

Har instruction fixed 32-bit ka hai, jisse fetch/decode bilkul aasaan ho jaata hai. 6 formats hain: R, I, S, B, U, J. Ek smart cheez — rs1, rs2, rd fields hamesha same jagah rehte hain, isliye immediate ke bits idhar-udhar bikhre hote hain (S/B/J me). Isse decoder register read jaldi shuru kar sakta hai. Immediate hamesha sign-extend hota hai, isliye negative numbers (jaise addi x5, x6, -1) automatically kaam karte hain. Bade constant load karne ke liye lui + addi combo use hota hai — bas dhyaan rakho ki low 12 bits signed hote hain, isliye kabhi upper part ko +1 karna padta hai. RV64I me addw, subw, ld, sd jaise extra instructions aate hain jo 64-bit kaam sambhaalte hain.

Go deeper — visual, from zero

Test yourself — Instruction Set Architecture (ISA)

Connections