5.1.7 · D3 · HinglishInstruction Set Architecture (ISA)

Worked examplesRISC-V base ISA (RV32I - RV64I)

2,950 words13 min read↑ Read in English

5.1.7 · D3 · Hardware › Instruction Set Architecture (ISA) › RISC-V base ISA (RV32I - RV64I)


Scenario matrix

Kuch bhi compute karne se pehle, territory ko map karte hain. Instruction encoding mein thodi si independent "axes" hoti hain jo har ek flip ho sakti hain. Ek worked example tab hi useful hai jab, doosron ke saath milke, woh har cell visit kare.

Axis (kya vary ho sakta hai) Cell A Cell B Cell C
Immediate sign positive imm negative imm zero / edge (-2048, +2047)
Format & field layout I-type (contiguous imm) S-type (imm do mein split) B/J-type (imm split aur scaled ×2)
Ek instruction mein fit hota hai? haan (≤12 bits) nahi → lui+addi pair chahiye bahut bada → 64-bit RV64I
Branch direction forward (imm > 0) backward (imm < 0) not-taken (fall through)
Degenerate / x0 x0=0 use karta hai nop (all-zero effect) overflow wrap-around
RV32I vs RV64I 32-bit sign-extend 64-bit sign-extend addw 32-bit wrap on 64-bit reg

Neeche, har example ko un cells se tag kiya gaya hai jo wo cover karta hai. Example 9 tak upar ki har cell kam se kam ek baar visit ho chuki hogi.


Example 1 — Positive I-type immediate (cells: positive imm · I-type · fits · RV32I)


Example 2 — Negative I-type immediate (cells: negative imm · I-type · sign-extend RV32I)


Example 3 — Immediate ki boundaries (cells: edge imm -2048/+2047 · degenerate)


Example 4 — S-type: split immediate (cells: negative imm · S-type split)

Figure — RISC-V base ISA (RV32I - RV64I)
dekho: store immediate ko ek high piece imm[11:5] (7 bits, word ka top) aur ek low piece imm[4:0] (5 bits, jahan doosre formats mein rd hota hai) mein toda gaya hai. Teal brackets dikhate hain ki kaunse bits kahan jaate hain.


Example 5 — Ek bada constant load karna (cells: fit nahi hota · lui+addi · signed-low correction)


Example 6 — Jab low part positive ho (koi rounding nahi) (cells: positive imm · lui+addi)


Example 7 — Backward branch (ek loop) (cells: negative imm · B-type split+scaled · backward)

Figure — RISC-V base ISA (RV32I - RV64I)
dekho: ek address line pe do instructions hain. bne 0x104 pe hai; arrow backward curve karta hai loop 0x100 pe, toh offset negative aur small hai.


Example 8 — Forward jump range aur ±1 MiB limit (cells: positive imm · J-type · limiting value · exam twist)


Example 9 — Degenerate & RV64I wrap (cells: nop · overflow wrap · RV64I addw)


Active recall

Recall Example 9 ke baad kaunse cells abhi bhi uncovered hain? (answer)

Koi bhi nahi — matrix ki har row (sign, format layout, fit, direction, degenerate, RV32I/RV64I) hit ho gayi. ✓

Recall Reveal

0xEEF lui part pe +1 kyun force karta hai lekin 0x678 nahi karta? ::: 0xEEF ka bit 11 set hai → signed-negative → addi subtract karta hai, isliye upper part compensate karne ke liye pre-increment hota hai. 0x678 ka bit 11 clear hai → positive → koi correction nahi. 12-bit signed immediate ka range? ::: . jal (J-type) ki real reach? ::: bytes = MiB (offsets 2 se scale hote hain). addi x0, x0, 0 kya hai? ::: Canonical nopx0 mein write discard ho jaati hai.

Related: RISC vs CISC · Assembler & Pseudo-instructions (li aur nop expansions wahan hain).