1.1.8 · Coding › How Computers Work
Intuition Ek-line picture
Ek akela flip-flop exactly ek bit (0 ya 1) yaad rakhta hai. Agar aapko ek N-bit number yaad rakhna ho, toh bas N flip-flops ko side by side lagao aur unhe ek saath clock karo. Woh bundle hi register hai. Register matlab "aisi memory jo ek clock tick mein grab ho sake."
Register ek aisa group hai N flip-flops ka jo ek common clock line share karte hain, aur ek N -bit binary word store karta hai. Har active clock edge par, saare N flip-flops apne inputs ko simultaneously capture karte hain, isliye poora word ek atomic unit ki tarah update hota hai.
KYA store karta hai: ek N -bit pattern, jaise ki 4-bit register mein 1011.
KYA cheez ise raw flip-flops se alag banati hai: flip-flops synchronised hain (same clock) isliye bits thodi alag timings par nahi badalti — word consistent rehta hai.
Intuition "Ek tick mein" kyun?
Har flip-flop independent hardware hai. Koi scanning nahi, koi looping nahi. Saare N bits wahan electrically maujood hote hain aur parallel mein read/write hote hain. Isi liye CPU registers machine ki sabse fast storage hoti hain — physically logic ke sabse paas, zero addressing overhead.
Intuition D (Data) flip-flop kyun?
Hum chahte hain "jo bhi input wire par hai, use clock edge par freeze kar do." D flip-flop exactly yehi karta hai — uska output input ko sirf rising clock edge par copy karta hai, phir agli edge tak hold karta hai.
Defining behaviour (iska characteristic equation ):
Q next = D (captured at the clock edge)
Yeh equation kyun? "Agla stored value = woh data jo maine present kiya." Edges ke beech Q freeze rehta hai, isliye yeh sach mein memory hai, sirf ek wire nahi.
Flip-flops F F 0 , F F 1 , … , F F N − 1 lagao. Wire karo:
data inputs D 0 … D N − 1 (woh word jo aap store karna chahte ho),
ek shared clock har flip-flop ko,
outputs Q 0 … Q N − 1 (stored word).
Q i next = D i for all i = 0 , 1 , … , N − 1 , at the same clock edge
Clock share kyun karte hain? Taaki word atomically update ho. Agar har bit ka apna clock hota, toh aap half-old, half-new garbage value read kar sakte the (ek race ). Ek clock = ek consistent snapshot.
Ek bare register har clock edge par khud ko overwrite kar leta. Usually aap chahte ho ki woh hold kare jab tak load karne ko na kaha jaye.
Intuition "Value hold kaise karte hain"
Output ko multiplexer ke through input par wapas feed karo. Jab LOAD = 0 , flip-flop apni khud ki value re-store karta hai (koi change nahi). Jab LOAD = 1 , naya data store karta hai.
D i = LOAD ⋅ IN i + LOAD ⋅ Q i
Toh ek loadable register ka actual update rule yeh hai:
Q i next = LOAD ⋅ IN i + LOAD ⋅ Q i
Yeh kyun kaam karta hai: yeh bas ek 2-to-1 multiplexer hai jo "naya data" ya "purana self" select karta hai. Jab LOAD low ho, Q i next = Q i → bit unchanged rehta hai → memory preserved.
Worked example Example 1 — Ek 4-bit register ek number store karta hai
IN = 1011 present karo LOAD = 1 ke saath, phir clock pulse karo.
Kyun: LOAD=1 har flip-flop ke liye IN select karta hai.
Edge ke baad: Q 3 Q 2 Q 1 Q 0 = 1011 (decimal 11).
Agla clock LOAD = 0 ke saath:
Kyun: LOAD=0 har flip-flop ka apna Q select karta hai, isliye Q next = Q .
Output 1011 rehta hai. Register yaad rakhta hai chahe clock chalti rahe. ✅
Worked example Example 2 — Ek 8-bit register kitni values hold kar sakta hai?
N = 8 ⇒ 2 8 = 256 patterns.
Yeh step kyun: 8 flip-flops mein se har ek count ko double karta hai.
Range as unsigned integer: 0 se 2 8 − 1 = 255 tak.
"Minus one" kyun: ek pattern (00000000) value 0 ke liye use ho jaata hai, isliye sabse bada value count se ek kam hota hai.
Worked example Example 3 — Atomic update garbage hone se bachata hai
Purani value 0001, aap chahte ho 1110, lekin imagine karo bit 0 doosron se 1 ns pehle update ho gaya.
1 ns ke liye word 0000 read hota hai — ek aisi value jo aapne kabhi nahi chaahi!
Shared clock kyun theek karta hai: saare chaar flip-flops usi edge par latch karte hain, isliye word 0001 → 1110 jump karta hai bina kisi beech ki galat value ke.
Common mistake "Register apne bits mein se ek ek karke loop karta hai, jaise ek for-loop."
Kyun sahi lagta hai: software arrays ko iterate karke store karta hai, isliye hum imagine karte hain ki hardware bhi aisa hi karta hai.
Fix: Registers parallel hardware hain — saare N flip-flops ek clock edge par simultaneously latch karte hain. Koi loop nahi aur koi per-bit delay nahi. Wahi parallelism ki wajah se registers sabse fast memory hain.
Common mistake "Ek N-bit register N alag numbers store kar sakta hai."
Kyun sahi lagta hai: "N bits" sunne par lagta hai "N numbers ke N slots."
Fix: Yeh ek waqt mein ek number store karta hai, lekin woh number 2 N patterns mein se koi bhi ho sakta hai. N width hai, values ki count nahi.
Common mistake "LOAD line ke bina register phir bhi meri value hold karta rahega."
Kyun sahi lagta hai: flip-flops "memory" hain, toh woh toh hold karenge hi.
Fix: Ek bare D-register har clock edge par apna input reload karta hai . Agar input badal jaye, toh aapki stored value gayi. Hold karne ke liye aapko feedback/multiplexer (LOAD line) chahiye.
Recall Feynman: 12-saal ke bacche ko samjhao
Socho ek row of light switches, har ek ya toh ON ya OFF — yeh ek bit hai. Ek flip-flop ek aisa switch hai jo wahi reh jaata hai jahan aapne use flick kiya. 8 switches ko ek row mein lagao aur agree karo "hum sab ek hi drumbeat (clock) par palatte hain" — ab aap ek beat mein ek 8-bit pattern set kar sakte ho aur woh freeze reh sakta hai jab tak dobara "load" nahi kaho. Switches ki woh row ek register hai: computer ka chhota, super-fast scratch pad jo woh apne brain ke bilkul paas rakhta hai.
"Register = Row of Remembers." Same clock, same instant, 2 N possible patterns. Aur "LOAD low = leave it alone."
Register kya hota hai? N flip-flops ka ek group jo ek clock share karta hai, ek N-bit word store karta hai jo clock edge par atomically update hota hai.
Ek flip-flop kitne bits store karta hai? Exactly ek bit (0 ya 1).
Ek N-bit register kitni distinct values hold kar sakta hai? 2 N patterns (range 0 to 2 N − 1 unsigned).
Saare flip-flops mein ek single clock kyun share karte hain? Taaki saare bits simultaneously latch hon aur word atomically update ho, half-updated garbage values se bachne ke liye.
D flip-flop ki characteristic equation kya hai? Q next = D , active clock edge par capture hoti hai.
LOAD line kya karta hai, aur update rule kya hai? Yeh naya data ya purani value hold karna select karta hai: Q i n e x t = LOAD ⋅ IN i + LOAD ⋅ Q i .
Ek bare D-register (bina LOAD ke) har clock edge par kya hota hai? Woh har edge par apna input reload karta hai, isliye agar input badal jaye toh value hold nahi hoti.
CPU mein registers sabse fast storage kyun hain? Woh saare bits parallel hardware mein store/read karte hain bilkul logic ke paas, bina kisi addressing ya looping overhead ke.
8-bit register mein sabse bada unsigned value kya hoga? 2 8 − 1 = 255 .
Kya N bits ka matlab hai N stored numbers? Nahi — yeh ek waqt mein EK number store karta hai jis ki width N bits hai; N width hai, values ki count nahi.
Flip-Flops — 1-bit memory — building block.
D Flip-Flop and the Clock Edge — ek single bit kaise latch hota hai.
Multiplexers — selecting between inputs — LOAD line implement karta hai.
Binary Numbers and 2^N — capacity 2 N kyun hai.
CPU Architecture — Register File — kai registers grouped aur addressed.
Clock and Synchronous Logic — shared timing signal kyun zaroori hai.
Counters and Shift Registers — registers with feedback jo bits move karte hain.
feedback selects new vs old
Qi next = LOAD IN + notLOAD Qi