1. Two's Complement Arithmetic Execution
Two's complement system ka sabse bada hardware advantage ye hai ki CPU ko subtraction ke liye separate circuit nahi chahiye hota. Subtraction is performed by adding the 2's complement of the subtrahend:
Carry-out ($C_{out} = 1$) ka matlab Overflow nahi hota! For example, $-1 + -1 = 1111 + 1111 = 11110_2$. Here carry-out is $1$, but discarding it leaves $1110_2$ ($-2_{10}$), which is 100% correct and has NO overflow! Carry indicates unsigned overflow, while the Overflow Flag indicates signed boundary violation.
2. The 30-Second Rules for Overflow Detection
Agar tum ek Positive ($MSB=0$) aur ek Negative ($MSB=1$) number ko add kar rahe ho, toh Overflow KABHI NAHI HO SAKTA! Sum hamesha bounds ke andar rehta hai. Immediate option elimination!
Overflow SIRF TAB hota hai jab do same-sign numbers add ho aur result ka sign flip ho jaye:
• $\text{Positive} + \text{Positive} = \mathbf{Negative}$ → Overflow!
• $\text{Negative} + \text{Negative} = \mathbf{Positive}$ → Overflow!
In computer ALU hardware:
$$\text{Overflow Flag } V = C_{in} \oplus C_{out}$$
Overflow occurs if and only if carry into MSB ($C_{in}$) does NOT equal carry out of MSB ($C_{out}$). If $C_{in} = C_{out}$, NO overflow!
- Signs: Both numbers have $MSB = 0$ (Positive).
- Sum: $0101 + 0100 = 1001_2$.
- Result MSB: The result's MSB is $1$ (Negative!).
- Conclusion: $\text{Positive} + \text{Positive} = \text{Negative}$. Mathematical sum $+9$ exceeds 4-bit range $[-8, +7]$. Yes, OVERFLOW OCCURS!