IAE Academy

GATE 2022 CS Q.18: solution and answer

GATE 2022 · CSQ.18 · 1 mark · MCQ

Let R1 and R2 be two 4-bit registers that store numbers in 2's complement form. For the operation R1+R2, which one of the following values of R1 and R2 gives an arithmetic overflow?

  1. (A)

    R1 = 1011 and R2 = 1110

  2. (B)

    R1 = 1100 and R2 = 1010

  3. (C)

    R1 = 0011 and R2 = 0100

  4. (D)

    R1 = 1001 and R2 = 1111

See the question in the paper

Answer and solution

ANSWER

The correct answer is (B) R1 = 1100 and R2 = 1010.

Official answer: BSource: Official answer key, GATE 2022 CS (IIT Kharagpur)

  1. Recall the overflow rule for 2's complement addition on n bits: overflow happens iff both operands have the same sign and the result's sign differs from that common sign. A 4-bit register represents integers in .

  2. Option A: , (both negative). Binary sum ; discarding the carry-out, the 4-bit result is , matching the true sum and staying negative like the operands, so no overflow.

  3. Option B: , (both negative). Binary sum ; the 4-bit result is , a positive value, while the true sum is , which is outside . Same-sign operands giving an opposite-sign result means arithmetic overflow.

  4. Option C: , (both positive). Sum , matching , within range and same sign, so no overflow.

  5. Option D: , (both negative). Binary sum ; the 4-bit result is , matching the true sum , the boundary value, still representable and negative, so no overflow.

  6. Only option B produces a result whose sign contradicts the common sign of its same-signed operands, so B is the unique case of arithmetic overflow.

KEY IDEA

In 2's complement addition on an -bit register, arithmetic overflow occurs only when both operands have the same sign but the result has the opposite sign. Adding operands of opposite sign can never overflow, since the true sum then always lies strictly between the two operands and hence within range.

WATCH OUT FOR

Confusing arithmetic overflow with a simple carry-out of the MSB. A carry-out (as in option D, 1001+1111) does not by itself indicate overflow; the correct test is whether the sign of the result contradicts the common sign of two like-signed operands.

From the GATE 2022 CS paper. Every question of this paper · Download the full paper · All 5 ALU & control unit questions, with notes

More ALU & control unit questions