4.1.6 · D5Computer Architecture (Deep)
Question bank — ALU — operations, flags (zero, carry, overflow, negative)
Quick vocabulary reminder so no symbol appears "for free":
- , — the two -bit input numbers (operands).
- — the -bit result the ALU produces.
- — the most significant bit (MSB): the leftmost, highest-value bit of .
- — the carry into the sign-bit column; — the carry out of it.
- , , , — the four flags: Zero, Carry, Negative, oVerflow.
- — XOR, "these two bits differ" (1 if exactly one is 1).
True or false — justify
TRUE or FALSE: If the Carry flag is set after an addition, the signed answer is definitely wrong.
FALSE. Carry only reports unsigned overflow; the signed answer can be perfectly correct. In (i.e. ), but the signed result is exactly right, so .
TRUE or FALSE: The Negative flag being 1 means the value stored is a negative number.
FALSE. is only the copy of the MSB . If you are interpreting the bits as unsigned, that same set bit just means "value ", not negative.
TRUE or FALSE: You can get signed overflow by adding a positive and a negative number.
FALSE. Adding opposite signs, the magnitude of the true sum is smaller than the larger operand, so it always stays in range. Overflow needs same-sign operands whose result-sign flips.
TRUE or FALSE: The Zero flag depends on which operation was requested.
FALSE. is computed purely from the output bits — a NOR over all of . Whether it was ADD, SUB, or XOR, exactly when every result bit is 0.
TRUE or FALSE: For a logic op like AND, the Carry flag reports whether the operands overlapped in high bits.
FALSE. AND/OR/XOR have no arithmetic carry chain, so most ISAs simply clear (and ). Carry is meaningless for bitwise logic; only and carry information.
TRUE or FALSE: On subtraction, Carry set () signals that a borrow happened.
FALSE (ARM/x86 convention). Because , a carry-out means no borrow, i.e. . is the borrow case ().
TRUE or FALSE: Overflow can occur when both operands are zero.
FALSE. keeps its sign (non-negative in, non-negative out), and ; the sign never flips, so . Zero is a degenerate, always-safe case.
TRUE or FALSE: If and after a signed add, the true signed result really is negative.
TRUE. With no overflow, the sign bit is trustworthy, so means the correct signed answer is negative. The catch is only when , where has been corrupted by the wrap-around.
TRUE or FALSE: Two 8-bit inputs can produce and simultaneously.
TRUE. Add two large negatives, e.g. : this both wraps signed (neg+neg→"pos", ) and carries out of the MSB (). and are independent, so all four combinations exist.
Spot the error
Find the flaw: "To check if unsigned , branch on the Overflow flag ."
Wrong flag. Unsigned comparisons use the Carry flag ( after SUB). answers a signed question and would give wrong branches for unsigned data — see Signed vs Unsigned Comparison Instructions.
Find the flaw: "Overflow is , the carry out of the top adder."
Overflow is , the disagreement between the carry out of and the carry into the sign bit — not alone. Using alone would confuse it with the Carry flag.
Find the flaw: "The ALU stores the flags from the last op, so it must contain memory."
The ALU itself is combinational (no memory); the flags are latched into a separate status register, which is the sequential part. Don't attribute the register's memory to the ALU — see Combinational vs Sequential Logic.
Find the flaw: " therefore no overflow happened, since a zero result is safe."
Independent conditions. in 8 bits gives () yet , because the true answer is far out of range. says nothing about whether the value is correct.
Find the flaw: "Negating for subtraction is just inverting its bits: ."
Missing the . is only the ones' complement; two's complement needs , and that is supplied as carry-in = 1 to the adder. Without it you compute .
Find the flaw: "For a left shift, the Carry flag is set from the MSB of the input, so it just copies the sign."
Carry captures the bit shifted out of the top — which for a left shift is the old MSB, but the point is it is the departing bit that would be lost, enabling multi-word shifts to chain. Calling it "copies the sign" hides its role of preserving the spilled bit.
Why questions
WHY does the same adder circuit handle both addition and subtraction?
Two's complement makes equal , so becomes an ordinary addition . One adder plus an invert-and-carry-in switch does both — the reason two's complement was chosen at all.
WHY is overflow defined as rather than by looking at the result alone?
The sign bit gets used up holding the answer's top bit, so after the fact you can't tell a valid negative from a wrapped positive. Watching whether the carry passing into and out of the sign column agree catches the corruption at the moment it happens.
WHY can you never overflow (signed) when adding numbers of opposite sign?
The result lies strictly between the two operands' values, so its magnitude can't exceed the larger operand, which was already in range. Overflow requires pushing past a boundary, and opposite signs pull inward, not outward.
WHY does the Carry flag mean "NOT borrow" on subtraction?
Because subtraction is implemented as : a carry-out of the top means the addition completed without needing to borrow from beyond the MSB, i.e. . No carry-out means a borrow was needed, .
WHY do ISAs bother computing separately when it is "just" the MSB wire?
So conditional-branch logic has a ready-made signed-sign signal without re-deriving it. It costs almost nothing (one wire), and combined with it lets a single flag test decide signed comparisons — the plumbing for Condition Codes and Conditional Branches.
WHY is the Zero flag built as a NOR over all result bits and not, say, an AND?
We want only when every bit is 0. OR-ing the bits gives 1 if any bit is set, so NOT-of-OR (NOR) gives 1 exactly for the all-zeros pattern. An AND would instead detect the all-ones pattern.
Edge cases
EDGE CASE: What are the flags for (8-bit)?
so ; MSB is 0 so ; no borrow since so ; no sign flip so . The " on equal" surprises people but it correctly means .
EDGE CASE: Add the most negative number to itself: in 8 bits.
, keep 8 bits → . So , , , and (neg+neg gave "non-negative"): a case where , , and are all set at once.
EDGE CASE: Negating the most negative number, , in 8 bits.
again — it's its own negative. The magnitude can't be represented, so this signed negation overflows (); it's the one asymmetric point of two's complement.
EDGE CASE: What does report when you add ?
: nothing spilled past the MSB, unsigned fits trivially. This is the boundary that shows Carry tracks unsigned overflow, and zero can never trigger it on addition.
EDGE CASE: Largest unsigned add that does NOT set Carry, in 8 bits.
Any pair whose unsigned sum is , e.g. : (it just fits), but note because the MSB is set — a reminder is meaningless under an unsigned interpretation.
EDGE CASE: For AND/OR/XOR, can the Overflow flag ever be 1?
No. There is no arithmetic sign to overflow, so ISAs force (and usually ) for logic ops. Only and are derived from the result bits.
Recall One-line survival summary
= unsigned-too-big / not-borrow; = signed-sign-flipped (); = MSB (meaningful only when signed); = all-bits-zero (NOR). and are independent — any of the four combos can appear.
Connections
- Parent topic
- Two's Complement Representation
- Full Adder and Ripple-Carry Adder
- Condition Codes and Conditional Branches
- Status / Flags Register (PSR / EFLAGS)
- Signed vs Unsigned Comparison Instructions
- Combinational vs Sequential Logic