5.1.7 · D1 · Hardware › Instruction Set Architecture (ISA) › RISC-V base ISA (RV32I - RV64I)
Ek computer ka brain (CPU) sirf bits se bane numbers samajhta hai, aur ek ISA ek fixed rulebook hai jo kehta hai "32 bits ka yeh exact pattern matlab hai: in do boxes ko add karo aur answer us box mein rakh do." Parent note ki saari cheezein — registers, formats, immediates, sign-extension — bas un 32 bits ko meaningful chunks mein slice karne ke alag-alag tarike hain taaki hardware jaane ki kya karna hai.
Pehle aap parent RISC-V base ISA (RV32I - RV64I) note ki ek bhi line padh sakein, aapko ek toolbox chahiye. Yeh page har tool ko scratch se banata hai. Har item mein hai: plain words mein kya matlab hai, uski picture, aur kyun yeh topic uske bina nahi chal sakta.
Ek bit ek aisa single box hai jo sirf do values mein se ek rakh sakta hai: 0 ya 1 . Bus itna. Yeh sabse chhoti piece of information hai jo ek computer store kar sakta hai.
Ek light switch imagine karo. Off = 0, on = 1. Ek bit ek switch hai. Computer mein isse chhota kuch nahi hota. Jab hum "32 bits" kehte hain toh matlab hai ek row mein 32 switches .
Topic ko yeh kyun chahiye? Kyunki RV32I ka har instruction literally "32 switches ek specific pattern mein set hain" hota hai. Poora chapter isi ke baare mein hai ki un switches ka matlab kya hai.
Definition Bit-string aur width
Ek bit-string kai bits ko side by side likha hota hai, jaise 1011. Uski width yeh hai ki usme kitne bits hain. Hum inhe likhe hue number ki tarah padhte hain: sabse left wala bit "most significant" hota hai (sabse bada place value), sabse right wala "least significant" hota hai (ones place).
Gaadi ke odometer ke baare mein socho, lekin har pehiya sirf 0 ya 1 dikhata hai. Sabse right wala pehiya sabse tez ticks karta hai (place value 1); uske left ka har pehiya apne right wale se double worth hota hai.
Toh ek 4-bit string jaise 1011 ka matlab hai, place by place:
1 ⋅ 8 + 0 ⋅ 4 + 1 ⋅ 2 + 1 ⋅ 1 = 11
Ek bit-string sirf wahi hai jo parent ka data kabhi bhi hota hai: ek register ek rakhta hai (uski width ko XLEN kehte hain, §7 mein bana hai), aur ek instruction 32-wide wala hota hai. Aage hum seekhenge ki aisi string ke part ko kaise point karein.
[high:low] slice
Jab hum in s t [ 31 : 20 ] likhte hain toh matlab hai: inst naame ki 32-bit string se, boxes number 31 se lekar 20 tak lo (12 boxes). Box numbers right se 0 se ginते hain, toh box 31 sabse far-left box hai aur box 0 sabse far-right box hai.
32 numbered lockers ko ek row mein lagao. in s t [ 31 : 20 ] ek bracket hai jo lockers 31…20 ke around khicha gaya hai — ek contiguous chunk jise aap nikaal kar apne chhote number ki tarah padhte hain.
Topic ko yeh kyun chahiye: cheh instruction formats (R, I, S, B, U, J) sirf named rules hain ki kaunsa slice opcode hai, kaunsa rd hai, kaunsa instruction mein baka hua constant hai. Slice notation seekh lo aur formats padhne layak ho jaate hain. (Un field names ke meanings aur bit-widths §10 mein milte hain.)
Definition Hexadecimal (hex)
Hex ek shorthand hai jahan har 4 bits ka group ek symbol ban jaata hai 0–9 phir A–F se (A=10, B=11, C=12, D=13, E=14, F=15). Hum ek hex number ko prefix 0x se flag karte hain.
32 switches padhna thakane wala hai. Inhe 8 packets of 4 mein group karo, aur har packet ko ek single label do. 0xDEADBEEF sirf 8 labels hain jo 32 switches ko represent karte hain — same information, ek-chauthai likhai.
Worked example Ek hex digit padhna
0xF = binary 1111 = 8 + 4 + 2 + 1 = 15 . 0xE = 1110 = 14 . 0xA = 1010 = 10 .
Toh 0xEEF = 1110 1110 1111 — barah bits, teen hex digits. Yeh exactly woh value hai jo parent ke constant-loading example mein hai.
Topic ko yeh kyun chahiye: parent 0xDEADBEEF aur 0xEEF jaisi constants likhta hai. Hex ke bina aap 32-digit binary mein doob jaoge.
Definition Unsigned interpretation
Agar hum ek bit-string ko unsigned treat karein, toh hum bas place values add karte hain — answer hamesha ≥ 0 hota hai. Ek n -bit unsigned number [ 0 , 2 n − 1 ] pe hota hai.
Lekin computers ko negative numbers bhi represent karne hote hain, aur unke paas sirf 0s aur 1s hain — koi minus-sign switch nahi. Trick hai Two's Complement .
Definition Signed (two's complement), briefly
Two's complement mein, sabse left wala bit sign flag hota hai: agar yeh 1 hai, toh number negative hai. Ek negative value padhne ka shortcut hai: top bit ka place value negative count hota hai.
4-bit odometer phir se lo, lekin far-left wala pehiya + 8 ki jagah − 8 worth hai. Toh 1111 padha jaata hai − 8 + 4 + 2 + 1 = − 1 ki tarah, aur 1000 padha jaata hai − 8 + 0 = − 8 ki tarah. Poora walk-through Two's Complement mein hai.
Intuition "Negative place value" kahan se aata hai: invert-and-add-one
Kisi number ko negate karne ka doosra roz-ka recipe hai: har bit flip karo, phir 1 add karo. 4-bit +1 = 0001 pe try karo: flip → 1110, add 1 → 1111, jise hum abhi − 1 padha. Yeh kaam karta hai kyunki saare n bits flip karna ek value v ko ( 2 n − 1 ) − v mein badal deta hai (har place value minus v ), aur 1 add karne se yeh 2 n − v ho jaata hai. Ek n -bit odometer pe, 2 n wrap back karke 0 ho jaata hai, toh 2 n − v bilkul − v jaisa behave karta hai. Woh wrap-around hi wajah hai ki top bit − 2 n − 1 count ho sakta hai: yeh woh ek place value hai jo aapko wrap point se aage "negative territory" mein push karta hai.
Topic ko yeh kyun chahiye: parent ka poora "kyun 0xDEADC na ki 0xDEADB" argument tabhi sense banata hai jab aap jaante ho ki 0xEEF (top bit set) two's complement ke under ek negative number hai.
Definition Sign-extension
Ek narrow signed number ko wider width mein sign-extend karna matlab hai left pe saare naye boxes mein uska sabse left (sign) bit copy karna . Likhi hui value same rehti hai; sirf width barhti hai.
Definition Function notation
sext(...)
Parent kuch aisa likhta hai sext ( imm ) ya sext X L E N ( ⋯ ) . sext ( x ) ko ek machine ki tarah padho jo ek narrow signed bit-string x leti hai aur same number, widened, wapas deti hai . Chhota subscript, jaise sext 32 mein, sirf yeh batata hai ki output kitna wide hona chahiye (yahan 32 boxes). Yeh multiplication ya variable nahi hai — yeh "sign-extend operation apply karo" hai. Toh sext 32 ( 1111 1111 1111 ) ka matlab hai "yeh 12 bits lo aur inhe sign bit copy karke 32 bits tak badhao."
Ek positive number ko left pe 0s se pad kiya jaata hai (jaise 7 ko 007 likhna). Ek negative number ko 1s se pad kiya jaata hai — kyunki two's complement mein woh leading 1s hi "negative" ka spelling hai har width pe.
addi x1, x0, -1 all-ones deta hai
− 1 ka 12-bit immediate hai 1111 1111 1111. 32 bits tak sign-extend karne pe leading 1 leftward copy hota hai → 1111...1111 (saare 32 ones) = 0xFFFFFFFF. Signed padhe toh yeh abhi bhi − 1 hai. Yeh hai parent ka sext X L E N action mein.
Topic ko yeh kyun chahiye: RV32I mein har immediate narrow store hota hai (12 ya 20 bits) aur register width XLEN tak sign-extend hota hai (aage define). Yeh miss karo toh aadhe worked examples toot jaate hain.
XLEN sirf ek naam hai register width in bits ke liye . ==XLEN = 32 RV32I ke liye, XLEN = 64 RV64I ke liye.== Parent ek symbol use karta hai taaki ek rule likhke dono machines cover ho sakein.
Common mistake Do "32" unrelated hain
RV32I mein, 32 XLEN hai (register width ). Registers ki sankhya hamesha 32 hoti hai RV32I aur RV64I dono mein — yeh sirf ek coincidence hai ki same number appear ho raha hai. Register count ≠ register width .
Ek register CPU ke andar ek fast storage box hai jo ek XLEN-bit value rakhta hai. Register file unka collection hai; RISC-V mein 32 hain, named x0–x31.
Chef ke counter pe 32 labelled cups socho (parent se [!recall] chef analogy). Instructions ingredients ko cups ke beech move karte hain. Cup x0 glued empty hai — hamesha 0 padhta hai, usme kuch bhi dalo ignore kar deta hai. Woh "always zero" cup mv, li, nop, aur branch-if-zero ke peeche ki trick hai.
Topic ko yeh kyun chahiye: instructions apne inputs aur output ko register number se name karte hain (fields rs1, rs2, rd), toh pehle jaanna zaroori hai ki register kya hota hai, format decode karne se pehle.
Definition Program counter (pc)
pc ek special XLEN-bit register hai jo current instruction ka address rakhta hai — yani memory mein abhi hum kahan execute kar rahe hain.
Ek recipe ki ek line pe point karta hua finger. Normally finger ek instruction neeche slide karta hai; ek branch ya jump finger uthata hai aur kahin aur drop kar deta hai. Parent ka target = p c + sext ( imm ) exactly "finger ko is signed offset se move karo" hai — jahan sext (§6 se) pehle narrow stored offset ko XLEN bits tak widen karta hai taaki full-width pc mein add ho sake.
Definition Ek instruction ke named slices
opcode — woh slice jo batata hai ki yeh kis family ki operation hai (add-family, load-family, branch-family…).
funct3 / funct7 — extra slices jo opcode ko refine karte hain (exactly kaunsi add-family op).
rd — "register d estination": woh cup jisme answer jaata hai.
rs1, rs2 — "register s ource 1 aur 2": woh cups jo inputs rakhte hain.
immediate (imm) — ek constant number jo seedha instruction bits mein baka hua hai, kisi register se nahi padha jaata.
Intuition "Immediate" kyun?
Value instruction se hi immediately available hai — koi memory ya register lookup nahi chahiye. Yeh Addressing Modes se connect karta hai: immediate addressing matlab "operand woh number hai jo instruction mein likha hai."
Topic ko yeh kyun chahiye: yeh woh words hain jo parent ke har format diagram pe hain. funct7 | rs2 | rs1 | funct3 | rd | opcode sirf yeh vocabulary hai, bit order mein upar ke widths ke saath laid out.
Neeche ke arrows kehte hain "tail wale box ko pehle samajhna zaroori hai, tabhi head wala box sense banega," aur har edge label batata hai ki kya flow ho raha hai — taaki aap trace kar sako, jaise ki "powers of two" woh single idea hai jo hex aur signed range dono ko unlock karta hai.
Place values powers of two
Saare raaste parent RISC-V base ISA (RV32I - RV64I) mein drain hote hain. Related big-picture context Instruction Set Architecture (ISA) , RISC vs CISC , Pipelining , aur Assembler & Pseudo-instructions mein milta hai.
Reveal karne se pehle har ek ka answer dene ki koshish karo. Agar koi stumps kare, toh upar woh section dobara padho.
Ek sentence mein bit kya hai? Ek single box jo do values mein se ek rakhta hai, 0 ya 1.
Bit number i (right se, 0 se ginkar) ka place value kya hai? 2 i .
n bits kitne distinct patterns rakh sakte hain?2 n .
Slice in s t [ 31 : 20 ] ka kya matlab hai? String inst ke box 31 se box 20 tak ke 12 bits.
0xE ko 4 bits aur decimal number mein convert karo.1110, jo 14 hai.
Two's complement mein kaunsa bit sign batata hai, aur 1 wahan kya matlab rakhta hai? Sabse left (most significant) bit; 1 matlab number negative hai.
4-bit 0001 ko invert-and-add-one se negate karo; kaunsa pattern aur value milti hai? Flip karke 1110, add 1 → 1111, jo − 1 hai.
12-bit two's-complement field ki signed range kya hai? [ − 2048 , 2047 ] .
sext 32 ( x ) kya karta hai?Narrow signed bit-string x ko 32 bits tak widen karta hai uska sign bit leftward copy karke, value same rakhte hue.
Jab aap ek negative number ko wider width tak sign-extend karte ho, toh aap kya pad karte ho? Sign bit ki copies, yaani 1s (0s agar number positive ho).
XLEN ka kya matlab hai, aur uski do values kya hain? Register width in bits; RV32I ke liye 32, RV64I ke liye 64.
RISC-V mein kitne registers hain, aur kaunsa special hai? 32 (x0–x31); x0 hardwired to zero hai.
rd field exactly 5 bits wide kyun hai?Kyunki 2 5 = 32 , 32 registers mein se ek ko name karne ke liye just enough.
opcode, funct3, funct7, aur ek I-type immediate kitne wide hain? Krama se 7, 3, 7, aur 12 bits.
pc kya rakhta hai?Current instruction ka address.
Destination register kaunsa field hai, aur sources kaunse hain? rd destination hai; rs1, rs2 sources hain.