The CPU — ALU, control unit, registers
1.1.10· Coding › How Computers Work
WHAT is the CPU made of?

HOW a CPU runs a program: the Fetch–Decode–Execute cycle
The cycle, pehle principles se derived (ek instruction run karne ke liye kya hona chahiye?):
- Tumhe pata hona chahiye ki agle instruction kaun sa hai. → uski address ek special register mein rakho, Program Counter (PC).
- FETCH: Control Unit address
PCpar jo instruction hai usse memory se Instruction Register (IR) mein copy karta hai. - Tumhe baad ke liye agle instruction ki taraf point karna hoga. →
PC ← PC + 1(agli instruction tak advance karo). - DECODE: Control Unit IR ko padhta hai aur figure out karta hai ki kaunsa operation hai aur yeh kaunse registers ko touch karta hai.
- EXECUTE: Control Unit ALU (ya memory) ko kaam karne ka signal deta hai; result ek register mein land karta hai.
- Repeat.
HOW the ALU actually adds (deriving binary addition)
Truth table for :
| carry | sum | ||
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 |
| 1 | 1 | 1 | 0 |
Worked Example 1 — running ADD R1, R2 (R1 = R1 + R2)
Maano , , aur instruction address 10 par hai.
| Step | Kya hota hai | Yeh step kyun? |
|---|---|---|
| Fetch | IR ← memory[10] = ADD R1,R2 |
CU ko act karne se pehle instruction milna chahiye |
| PC+1 | PC ← 11 | taaki agle loop mein agli instruction fetch ho |
| Decode | CU dekhta hai: op=ADD, dest=R1, srcs=R1,R2 | CU ko pata hona chahiye kaunse wires on karne hain |
| Execute | ALU compute karta hai ; result → R1 | sirf ALU hi add kar sakta hai |
Result: . CU ne kabhi arithmetic nahi ki — usne sirf orchestrate kiya.
Worked Example 2 — a loop via the Program Counter
addr 0: SET R1, 0 ; counter = 0
addr 1: ADD R1, 1 ; counter += 1
addr 2: CMP R1, 3 ; compare to 3 (sets a flag)
addr 3: JLT 1 ; if R1 < 3, jump back to addr 1
addr 4: ... ; done
CMPALU kyun use karta hai? Comparing = subtract karna aur result ka sign/zero flag check karna.- Loop kaam kyun karta hai?
JLTPC ko overwrite kar deta hai 1 se, usse 4 banne ki jagah. Jab finally 3 tak pahunchta hai, flag kehta hai "less than nahi," PC apni natural value 4 rakhta hai, loop khatam.
Recall Feynman: ek 12-saal ke bachche ko explain karo
Ek computer ek bachche jaisa hai jo worksheet kar raha hai. Registers woh kuch numbers hain jo bachcha apne dimag mein rakhe. ALU bachche ka actual adding-aur-comparing brain hai. Control Unit teacher hai jo worksheet ki har line zor se padhta hai: "ab yeh dono add karo, ab check karo kya yeh bada hai." Program Counter teacher ki ungli hai jo point karti hai ki hum kaunsi line par hain. Loop banane ke liye, teacher apni ungli wapas upar le jaata hai page par. Bas itna hi hai — poora computer ek list padhna aur ungli point karna hai.
Flashcards
CPU ke teen core components kya hain?
ALU kya karta hai?
Control Unit kya karta hai?
Registers kya hain?
Program Counter (PC) mein kya hota hai?
Instruction cycle ke teen stages list karo.
Instruction fetch karne ke baad PC normally kaise change hota hai?
CPU level par loops aur if-statements kaise kaam karte hain?
Half-adder outputs derive karo.
Full-adder ka sum bit kya hai?
CMP (compare) ALU kyun use karta hai?
"ADD R1, R2" ka result kahan jaata hai, aur kaun compute karta hai?
Connections
- How Computers Work
- Binary and number representation
- Logic gates — AND, OR, NOT, XOR
- RAM and the memory hierarchy
- Machine code and assembly
- The clock and clock speed
- Fetch–Decode–Execute cycle