Lesson 3 — Beginner
Instruction Set Architecture (ISA)
CPU ko jo instructions samajh aati hain unke set ko ISA kehte hain — jaise insaan ki apni bhasha. Is lesson mein hum dekhenge instruction banti kaise hai (opcode + operands), kitne type ki instructions hoti hain, aur ISA design ke factors kya hain jo GATE aur interview dono mein aate hain.
ISA kya hai
WHAT
Instruction Set Architecture (ISA) wo instructions, registers, data types aur addressing modes ka set hai jo processor directly samajhta hai. Ye CPU ka "bhasha-kosh" hai — compiler isi ke against code banata hai.
WHEN
Jab bhi tum koi code compile karo, koi processor khareedo, ya kisi platform pe program chalao — ISA decide karta hai chalega ya nahi.
WHERE
x86 (Intel/AMD, laptops), ARM (phones, Apple M-series), MIPS/RISC-V (padhai + embedded) — har processor kisi na kisi ISA ka hai.
Ek program likhna jaise Hindi mein likhna — lekin CPU ko sirf apni bhasha aati hai. Compiler/interpreter wo translator hai jo tumhari code ko ISA ki bhasha mein badalta hai. ISA alag hui toh binary alag — isi liye Windows x86 ke liye bana hai, phone ka app ARM ke liye.
Instruction format — opcode + operands
Instruction = OPCODE + OPERAND field(s)
Opcode : operation ka code (ADD, SUB, MOV, JMP) — kya karna hai
Operand : data ya address — kis pe karna hai
16-bit instruction example (4-bit opcode + 12-bit address):
| Opcode | Address |
4 bits 12 bits
→ 2^4 = 16 alag instructions, 2^12 = 4096 memory locations
Address field ki jagah REGISTER bhi ho sakta hai :
| Opcode | Reg | Reg | Reg | (register format — RISC ka style)
Addressing kaise : register direct, register indirect,
memory direct, immediate (operand instruction mein hi)
Ek instruction ka format ISA ka core hissa hai — kitne bits ka instruction, kitne bits opcode, kitne address field. Ye decide karta hai instruction kitni lambi hogi (fixed vs variable length) aur memory mein kitni jagah legi.
- 0-address instruction: stack-based machines — operands implicit (top of stack).
- 1-address: accumulator-based — ek operand accumulator mein (purane machines).
- 2-address: destination = destination + source (CISC mein common: ADD R1, R2).
- 3-address: ADD R1, R2, R3 → R1 = R2 + R3 — RISC ka style, compiler ko aasaan.
Instructions ke main types
1. Data Transfer : MOV R1, R2 | LOAD R1, [addr] | STORE [addr], R1
(ALU ko data pahunchana — register/memory beech)
2. Arithmetic : ADD, SUB, MUL, DIV, INC, DEC
3. Logical : AND, OR, XOR, NOT, CMP (compare sets flags)
4. Shift/Rotate : SHL, SHR, ROL, ROR — bit manipulation
5. Control Transfer : JMP, JZ, JNZ, BEQ, CALL, RET
(program counter badal ke flow kaatna/lena)
6. I/O & Misc : IN, OUT (I/O mapped), NOP, HLT, HALT
Example flow :
LOAD R1, [A] ; data transfer
ADD R1, R2 ; arithmetic
STORE [C], R1 ; result wapas memory
JMP loop ; control transfer
Har program — chahe game ho ya Excel — inhi 6 type ke instructions ke combinations se bana hai. Data transfer sabse zyada chalta hai (roughly aadhi instructions), isliye RISC mein isse alag category (load/store) banayi gayi.
ISA design ke factors
- Instruction length: fixed (RISC, aasaan decode) ya variable (CISC, dense code).
- Number of address fields: 0 se 3 tak — format decide karta hai.
- Number of registers: zyada registers = kam memory access (RISC mein 32+).
- Data types supported: integer, float, character, vector (SIMD).
- Addressing modes: immediate, direct, indirect, indexed — flexibility.
- Set size: CISC = 100-300 complex instructions, RISC = 50-100 simple.
ISA design ka balance :
Instruction set BADA → code chhota, lekin decode mushkil (CISC)
Instruction set CHHOTA → CPU simple + tez, lekin code bada (RISC)
Registers zyada → memory traffic kam, lekin instruction mein
register numbers encode karne padte hain
Ek exam fact : instruction count badhega toh program size badhega,
lekin CPI kam ho sakta hai — final time = IC × CPI × T dekhna padta hai
Exercise
Question: Instruction mein jo operation ka code hota hai usse kya kehte hain? (opcode / operand / address)
Question: JMP, BEQ, CALL kis type ki instructions hain? (control transfer / arithmetic / data transfer)
Question: LOAD aur STORE kis type ke instructions hain? (data transfer / logical / shift)
Common mistakes
- Opcode aur operand ka farak ulta bolna: Opcode = kya karna hai (operation), operand = kis pe karna hai (data/address). Dono ek hi instruction ke hisse hain.
- 3-address aur 2-address format confuse karna: 3-address: ADD R1, R2, R3 (destination alag). 2-address: ADD R1, R2 (R1 = R1 + R2, reused) — RISC vs CISC ka farak yahin se shuru hota hai.
- JMP ko data transfer samajhna: JMP/branch control flow badlati hai (PC update), data move nahi karti. Exam mein type poochh liya jaata hai.
Tum jaise Hindi mein sochte ho, CPU apni ISA bolta hai. Tumhare paas jo shabd hain wahi tum bol sakte ho — utne hi instructions CPU kar sakta hai:
Tumhare shabd = instruction set (ADD, MOV, JMP)
Naya shabd = invalid instruction (CPU reject)
Compiler = translator (tumhari bhasha → CPU ki bhasha)
x86 vs ARM = Hindi vs English — do alag bhashayein- GATE: instruction format (opcode + address bits) par memory/number of instructions numerical.
- UGC-NET: instruction ke parts aur types — definitions poochhi jaati hain.
- TCS NQT: "Operand kya hai?" aur instruction type classification classic hai.
- Trap: "Operand = operation code" — galat, operand data/address hai.
Instruction format clear. Agla lesson — Addressing Modes — mein dekhenge operand ko memory se kaise dhoondha jaata hai (immediate, direct, indirect aur bhi).