5.1.2 · D1 · HinglishInstruction Set Architecture (ISA)

FoundationsInstruction formats and encoding

3,090 words14 min read↑ Read in English

5.1.2 · D1 · Hardware › Instruction Set Architecture (ISA) › Instruction formats and encoding

Is page pe assume kiya gaya hai ki tumne pehle kuch nahi dekha. Hum har woh symbol build karenge jo parent note Instruction formats and encoding mein use hota hai — ek ek karke, har ek ko ek picture se anchor karke, har ek ko use karne se pehle earn karke. Yahan kuch bhi memorise nahi karna; sab kuch derive hota hai.


0. Sabse basic object: ek bit

Figure s01 neeche aath bulbs ki ek row draw karta hai: jale hue bulbs (butter-yellow) 1 hain, dim grey bulbs 0 hain. Sabse baayi taraf ka bulb dekho — woh ek bit hai, aur chhota arrow us par point karta hai. Neeche ki green line saare aath bulbs ko bracket karti hai; us grouping ko hum abhi ek second mein byte kahenge.

Figure — Instruction formats and encoding

1. Bits ka ek group: binary numbers aur

Agar ek bit 2 possibilities hold karta hai, toh bits ka ek group kitna hold karta hai?

Ek bit add karo → har purana pattern ab 0 ya 1 mein end ho sakta hai → patterns ki sankhya double ho jaati hai. Toh:

  • 1 bit → 2 patterns
  • 2 bits → 4 patterns
  • 3 bits → 8 patterns
  • bits → patterns.

Figure s02 isko ek bar chart mein dikhata hai: har bar pichle se do ke factor se ooncha hai, aur bars ke beech coral arrows kehte hain "×2 again". Woh visual doubling hi ka matlab hai.

Figure — Instruction formats and encoding

Bit pattern se actual number tak: positional weights

Hum kehte rehte hain " ek number hai" — chaliye isko earn karte hain, kyunki poora topic isi par lean karta hai.

lo (paanch bits). Right se positions line karo:

Jahan bit hai wahan weights add karo: .


2. Ulta sawaal: aur ceiling

Parent note likhta hai . Chaliye har symbol earn karte hain.

Woh sawaal jo hum actually pooch rahe hain: "Mere paas alag cheezein hain (maan lo 32 registers). Mujhe kitne bits chahiye taaki kam se kam ho?"

Lekin — tum 6.64 switches nahi rakh sakte. Bits poore hote hain, aur 6 bits ( patterns) kaafi nahi hain. Hum round up karke 7 karna chahenge.

Figure s03 ek line par , , rakhta hai aur "need 100" par ek coral marker drop karta hai. Tum dekh sakte ho 64 marker ke left mein baithta hai (too few) aur 128 right mein (fits), toh jawab se round up karke hona chahiye.

Figure — Instruction formats and encoding

3. Bits ka ek named group: ek field

Fields name karne se pehle hum agree karna chahte hain ki bit positions kaise count karein — warna "bits 0 through 6" ambiguous hai.

Figure s04 32-bit word ko chhah rounded, pastel boxes ke roop mein draw karta hai. Neeche ke labels dekho: "high bits (left)" aur "bit 0 (right)" — yahi hamari convention visible ho rahi hai. Coral opcode box far right mein baithta hai (bits 0–6); arrow yaad dilata hai ki decoder pehle wahan dekhta hai.

Figure — Instruction formats and encoding

Do field-names jinpe parent lean karta hai:

  • opcode — "kya kaam" field (add? jump? load?). Hamesha same position mein taaki decoder pehle ise dhundh sake.
  • operand fields — "kya usse karna hai": register numbers, ya ek immediate.

4. Do special operands: register aur immediate

registers bits per register field. Woh "5" jo baar baar dikhta hai woh magic nahi hai — yeh 32 pe apply kiya gaya Section 2 hi hai.


5. Negative immediates: two's complement aur sign extension

addi x1, x2, -8 kaam karna chahiye, isliye ek field ko ek negative number mean karne mein capable hona chahiye.

Section 1 ke positional weights se build karte hain. Ek unsigned -bit number mein har bit ka weight hota hai. Two's complement exactly ek cheez change karta hai: top bit ka weight negative ho jaata hai, , jabki har lower bit apna usual rakhta hai.

4 bits pe dekho (, toh top weight hai):

Range phir weights se sidha nikalta hai. Most negative value sirf top bit on karti hai: . Most positive top bit chhor ke har bit on karta hai: . Toh:

Parent ke 12-bit immediate ke liye: to to . Full treatment ke liye Two's Complement and Sign Extension dekho.


6. Symbols ko ek saath rakhna

Ab parent ke tally mein har symbol sight pe samajh mein aata hai:

  • bits mein field widths hain (Section 3).
  • Har aaya se (Sections 2 & 4).
  • Sum exactly hona woh fixed budget hai jis par parent bar bar stress karta hai.

Related building topics jinpe tum ab approach kar sakte ho: Addressing Modes (operand fields memory kaise name karte hain), RISC vs CISC (fixed vs variable width philosophy), Pipelining (kyun fast fixed decode matter karta hai).


Prerequisite map

bit = one on off switch

b bits give 2 to the b patterns

positional weights map bits to a number

log base 2 undoes the doubling

ceiling rounds bits up to whole

field = named slice of bits

register number field 5 bits

immediate constant in the bits

two complement flips top weight negative

sign extension widens keeping value

Instruction format and encoding


Equipment checklist

Har jawab reveal karne se pehle zyaor se bolo.

Ek bit mein kitne possible values store hote hain
Exactly two — 0 ya 1.
Ek byte mein aur yahan ek word mein kitne bits hote hain
Ek byte 8 bits ka hai; ek word 32 bits (4 bytes) ka hai in machines par.
bits mein kitne distinct patterns fit hote hain
.
Binary kaun sa number hai, aur kaise
, position weights sum karke jahan bit 1 hai.
Bit 0 kaun si end par hota hai
Rightmost (lowest-weight, ) bit par; higher indices baayi taraf jaate hain.
kaun sa sawaal answer karta hai
"2 ko kisi power pe uthane se milta hai?" — yeh ko undo karta hai.
mein ceiling kyun
Bits whole numbers hote hain, isliye hum round up karte hain taaki ho.
ke liye formula kya deta hai
— ek zero-width field, kyunki ek choice mein koi information nahi hoti.
32 registers index karne ke liye kitne bits chahiye
.
Field kya hoti hai
Instruction word ka ek fixed, named slice jiska ek agreed meaning ho.
Kaun se field ki position freeze hoti hai, aur kyun
Opcode, taaki decode hamesha "kya kaam" pehle dhundh sake chicken-and-egg problem ke bina.
funct3 aur funct7 kya karte hain
Ek shared opcode family ke andar exact operation sub-select karte hain (jaise add ko sub se tell karna).
Register operand aur immediate mein kya difference hai
Register field ek storage box ko name karne wala number hold karta hai; immediate constant value khud hold karta hai.
Two's complement mein top bit kaun sa weight carry karta hai
(negative), jabki saare lower bits rakhte hain.
12-bit two's-complement immediate ki range kya hai
to , yaani to .
Sign extension top bit kyun copy karta hai zeros pad karne ki jagah
Negative numbers ko negative rakhne ke liye; zero-padding unhe bade positives mein badal deta.