ALU 101 Control Signals and Flags 2 — Questions and Answers
Question 1: In a typical ALU, when is the Auxiliary Carry (AF) flag set?
- When carry occurs from bit 7 to bit 8
- When carry occurs from bit 3 to bit 4 (half-carry) (Correct answer)
- When the result is zero
- When overflow occurs in bit 15
Correct answer: When carry occurs from bit 3 to bit 4 (half-carry)
The Auxiliary Carry flag captures a carry from the lower nibble (bit 3) to the upper nibble (bit 4), used in BCD arithmetic adjustments.
Question 2: How does a CPU use the Zero and Sign flags together to implement a 'less than' comparison for signed integers?
- ZF=1 AND SF=1
- SF ≠ OF (sign flag differs from overflow flag) (Correct answer)
- CF=1 AND ZF=0
- OF=1 AND ZF=1
Correct answer: SF ≠ OF (sign flag differs from overflow flag)
After a signed subtraction, A < B is true when SF ≠ OF, accounting for overflow-induced sign inversion.
Question 3: What ALU control signal is used to implement a NOT operation on a single operand?
- Passing the operand through a subtractor with zero
- Feeding the operand to the inverter path and selecting it via the operation MUX (Correct answer)
- Setting the carry-in to 1
- Using the shift-right control line
Correct answer: Feeding the operand to the inverter path and selecting it via the operation MUX
The ALU routes the input through inverter logic and the operation MUX selects the inverted result when the NOT opcode is applied.
Question 4: When an ALU performs a left shift by 1, what value is shifted into the LSB?
- The previous MSB
- A zero (logical shift) or the carry flag (rotate) (Correct answer)
- A copy of the MSB (arithmetic shift)
- The overflow flag value
Correct answer: A zero (logical shift) or the carry flag (rotate)
A logical left shift fills the vacated LSB with 0, while a rotate-left fills it with the carry flag bit.
Question 5: What is the difference between an arithmetic right shift and a logical right shift?
- They shift in opposite directions
- Arithmetic shift preserves the sign bit; logical shift fills with zero (Correct answer)
- Logical shift is faster
- Arithmetic shift only works on unsigned numbers
Correct answer: Arithmetic shift preserves the sign bit; logical shift fills with zero
Arithmetic right shift replicates the MSB (sign bit) into vacated positions to preserve the sign of two's complement numbers, while logical shift always inserts zeros.
Question 6: What does it mean when the ALU's Carry Out and Overflow flags are set simultaneously after an addition?
- The result is always correct
- Both unsigned and signed interpretations of the addition produced incorrect results (Correct answer)
- Only unsigned overflow occurred
- The operation was a subtraction
Correct answer: Both unsigned and signed interpretations of the addition produced incorrect results
CF set means unsigned overflow occurred; OF set means signed overflow occurred; both set means the result is invalid under both unsigned and signed interpretations.
In a typical ALU, when is the Auxiliary Carry (AF) flag set?