5.1.7 · HinglishInstruction Set Architecture (ISA)

RISC-V base ISA (RV32I - RV64I)

2,017 words9 min readRead in English

5.1.7 · Hardware › Instruction Set Architecture (ISA)


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


WHAT is in the base? The register model


HOW instructions are shaped: the 6 formats

Har RV32I instruction exactly 32 bits ki hoti hai (fixed length → trivial fetch/decode). Bits ko fields mein kaata jaata hai. Genius yeh hai ki fields same jagah rehti hain across formats, isliye decoder unhe parallel mein extract kar sakta hai.

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
  • Kitne GPRs hain, aur x0 mein kya khaas hai? → 32; x0 hardwired zero hai.
  • RV32I mein instruction length? → Fixed 32 bits.
  • S/B immediates split kyun hote hain? → rs1/rs2/rd fields ko fixed positions mein rakhne ke liye taaki fast decode ho sake.
  • RV32I vs RV64I mein difference? → XLEN (32 vs 64) + word (*w) aur ld/sd instructions.
  • Poora 32-bit constant kaise load karte hain? → lui (upper 20) + addi (lower 12), signed low ke liye correct karte hue.
Recall Feynman: explain to a 12-year-old

Ek chef ki imagine karo jiske paas sirf 40 basic moves hain (chop, stir, pour…). Yahi RISC-V base hai. Koi bhi dish (program) bas in moves ki ek lambi list hai. 32 numbered bowls (registers) hain ingredients rakhne ke liye, aur bowl #0 magic hai: yeh hamesha khaali (zero) rehta hai — "nothing" ke liye super handy. Har recipe card same size ki hai isliye chef unhe bahut fast padhta hai. Agar tumhe bada kitchen chahiye, tum extra move-packs add karo (multiply, floating point) — lekin 40 basics kabhi nahi badalte. RV64 bas bade bowls use karta hai jo bade numbers hold karte hain.


Flashcards

How many general-purpose registers does RV32I/RV64I have?
32 (x0–x31), har ek XLEN bits wide.
What is special about register x0?
Hardwired to 0; reads 0 deta hai, writes discard ho jaate hain.
What does XLEN mean and what is it for RV32I vs RV64I?
Register/data width; RV32I ke liye 32, RV64I ke liye 64.
Instruction length in the RV32I base ISA?
Fixed 32 bits (sabhi instructions).
Name the six RV32I instruction formats.
R, I, S, B, U, J.
Why are the S/B immediates split across scattered bits?
Taaki rs1/rs2/rd fields fixed positions mein rahe aur decode/register-read jaldi shuru ho sake.
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), upper part ko round up karo agar low 12 bits negative ho.
How is a branch offset formed?
target = pc + sext(imm), jahan 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) aur 64-bit ke liye ld/sd; results 64 bits tak sign-extended hote hain.
How is nop encoded in RISC-V?
addi x0, x0, 0.
Does RISC-V have a flags/condition-code register?
Nahi; branches directly registers compare karte hain.
Why sign-extend the immediate?
Taaki negative immediates (e.g. addi with -1) all-ones produce kare aur naturally kaam kare.

Connections

  • Instruction Set Architecture (ISA) — parent concept: hardware/software contract.
  • RISC vs CISC — woh design philosophy jo RISC-V embody karta hai.
  • Two's Complement — isliye immediates sign-extend hote hain.
  • Pipelining — fixed-length + fixed field positions decode/pipeline ko simpler banate hain.
  • Addressing Modes — RISC-V memory ke liye sirf base+offset use karta hai.
  • Assembler & Pseudo-instructionsli, mv, nop, j base ops mein expand hote hain.

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