4.1.7 · HinglishComputer Architecture (Deep)

Instruction formats — R-type, I-type, J-type (MIPS - RISC-V)

1,772 words8 min readRead in English

4.1.7 · Coding › Computer Architecture (Deep)


HUM kya slice kar rahe hain? Woh 32 bits

Har MIPS instruction = exactly 32 bits. Pehle 6 bits (yani opcode) decoder ko batate hain ki kaunsa format expect karna hai. Yahi master key hai.

Figure — Instruction formats — R-type, I-type, J-type (MIPS - RISC-V)

Bits kaise laid out hain (aur har width WHY itni hai)

R-type

rs, rt source registers hain; rd destination hai.

I-type

J-type


Worked examples


Common mistakes


Recall Feynman: ek 12-saal ke bacche ko explain karo

Socho ek 32-light switchboard hai. Pehle 6 switches ek code word spell karte hain jo batata hai ki yeh kis tarah ka message hai. Agar yeh "teen lockers ke saath math karo" wala message hai, toh agle switches locker A, locker B, locker C ka naam lete hain aur ek chota extra code batata hai ki kaun sa math (add? subtract?). Agar yeh "ek chote number ke saath kuch karo" wala message hai, toh kam switches lockers ka naam lete hain aur baaki number spell karte hain. Agar yeh "door kahi jump karo" wala message hai, toh almost saare switches jagah spell karte hain. Same 32 switches, teen alag rulebooks — aur pehle 6 switches hamesha batate hain ki kaun sa rulebook use karna hai.


Flashcards

MIPS register field kitne bits ka hota hai aur kyun?
5 bits, kyunki registers hain, jiske liye bits chahiye.
Har MIPS instruction ki total width?
32 bits, fixed, uniform decoding ke liye.
Decoder ko kaun sa field batata hai ki instruction kis format mein hai?
6-bit opcode (opcode 0 ⇒ R-type, funct dekho).
R-type bit-field order MSB se?
opcode(6), rs(5), rt(5), rd(5), shamt(6→5), funct(6).
Saari R-type ops opcode 0 kyun share karti hain?
6-bit funct field unhe alag karta hai ( ops), opcode space bachata hai.
R-type mein destination register kaun sa hai?
rd (teesra register field), chahe assembly mein pehle likha jaata hai.
I-type bit-field order?
opcode(6), rs(5), rt(5), immediate(16).
lw $t0,32($s3) mein rs, rt, imm kya hai?
rs=t0 (destination), imm=32 (offset).
beq ke liye branch target formula?
target = (PC+4) + (signed_imm × 4).
Branch/jump offsets ko 4 se kyun multiply karte hain?
Instructions word-aligned hain (4 ke multiples); word counts store karne se reach free mein badh jaati hai.
J-type fields aur target reconstruction?
opcode(6)+address(26); target = PC[31:28] ‖ address ‖ 00.
Effective branch reach?
±128 KB (16 signed bits + 2 implied = 18-bit signed byte range).
j poori memory tak kyun nahi pahunch sakta?
Top 4 bits current PC se aate hain ⇒ 256 MB region tak seemit; full 32-bit jumps ke liye jr use karo.
Shamt kya hai aur kitna wide hai?
Shift amount, 5 bits (ek 32-bit word ke liye 0–31 positions).

Connections

  • MIPS Register File and Conventions — 32 registers kyun ⇒ 5-bit fields
  • Single-Cycle Datapath — fixed positions rs/rt ko hamesha register file feed karne dete hain
  • Control Unit and Decoding — opcode/funct control signals drive karte hain
  • Sign Extension and Immediates — 16-bit imm 32-bit kaise banta hai
  • PC-relative vs Absolute Addressing — branch vs jump target math
  • RISC-V Formats (R, I, S, B, U, J) — RISC-V hardware simplicity ke liye immediates kaise split karta hai

Concept Map

first 6 bits

selects

selects

selects

uses

opcode 0 needs

holds

reused by

PC-relative offset

holds

enforces

32-bit instruction

opcode 6 bits

R-type

I-type

J-type

funct field 6 bits

three registers rs rt rd

16-bit immediate

26-bit address

beq branch

RISC regularity