ALU Operations, Flags, Overflow
VLSI → Datapath + Parameterized RTL
What an ALU actually does
An ALU does ADD/SUB/AND/OR/XOR/SHIFT and produces flags describing the result: Zero (result is all 0s), Carry (unsigned overflow out of the top bit), Overflow (signed overflow), and Negative (the result's MSB). "Implement an N-bit ALU with flags" is a common fresher RTL written-round question at companies like Intel and AMD India.
Carry vs Overflow — the flag interviewers actually probe
Carry and Overflow are easy to mix up because they're both "something went wrong at the top bit" — but they answer different questions:
Carry = did the unsigned result not fit in N bits? (a carry out of bit N-1)
Overflow = did the signedresult not fit in N bits? This only happens when both operands have the same sign but the result's sign is different — adding two positives can't legitimately produce a negative, so if it does, that's overflow.
Overflow = did the signedresult not fit in N bits? This only happens when both operands have the same sign but the result's sign is different — adding two positives can't legitimately produce a negative, so if it does, that's overflow.
Try it — pick operands and watch the flags
Result (4-bit) = 1100 (-4 signed / 12 unsigned)
Zero = 0
Carry = 0
Overflow = 1
Negative = 1
Signed overflow: A and B have the same sign but the result's sign flipped — exactly the case the formula above defines.
Completion saves automatically after you read through to the end.
Next lesson →