All operation results exist simultaneously; the select lines drive a MUX so only one
appears at F. Adding a new operation = add its circuit + one more MUX input.
Recall Predict before revealing (Forecast-then-Verify)
Why can one control bit turn an adder into a subtractor?
→ Because A−B=A+B+1; XOR B with Ssub and feed Ssub as c0.
What makes overflow V=cn⊕cn−1?
→ Carry into vs out of sign bit disagree ⇒ sign corrupted.
Where does the "selection" of operation happen?
→ A MUX driven by the select lines picks one parallel result.
Recall Feynman: explain to a 12-year-old
Imagine a calculator that already computed every answer — the plus answer, the minus
answer, the "compare" answer — all at once, and lined them up. Then a little switch (the
select lines) just points to the one drawer you asked for and hands you that answer. That's
the ALU: do everything, then pick. Subtraction is a sneaky trick — flip all of B's bits and
add one, and you've turned "add" into "subtract" without new machinery.
Dekho, ALU ka core idea bahut simple hai: CPU ko add, subtract, AND, OR, compare — sab karna
padta hai, lekin har operation ke liye alag machine banane ki zaroorat nahi. Hum ek hi block
banate hain jo saare operations parallel mein compute kar leta hai, aur phir ek MUX
(multiplexer) select lines ki madad se sirf wahi answer bahar bhejta hai jo tumne manga. Yehi
"compute everything, then pick one" trick ALU design ka dil hai.
Subtraction ka jugaad bahut mast hai. Two's complement mein A−B=A+B+1.
Matlab agar tum B ke har bit ko ek control bit Ssub ke saath XOR kar do, aur wahi
Ssub ko sabse pehle carry-in (c0) bana do — to Ssub=0 pe pure addition hota hai
aur Ssub=1 pe subtraction. Sirf ek control bit se adder ko subtractor bana diya, koi
extra hardware nahi! Yeh 80/20 wala concept hai — isko samjhe to aadha chapter clear.
Flags bhi yaad rakhna zaroori hai: Z (result zero hai kya, NOR of all bits), C (carry
out, unsigned overflow), N (MSB, negative sign), aur V (cn⊕cn−1, signed
overflow). Sabse common galti — Carry aur Overflow ko same samajhna. Carry unsigned ke liye
hai, Overflow signed ke liye. Aur ek aur baat: ALU khud purely combinational hai, uske
andar koi memory ya clock nahi — output sirf current inputs pe depend karta hai. Yaad rakhna,
memory registers mein hoti hai, ALU mein nahi.