GATE Computer ScienceVery hardGATE CS (PYQ pattern)

An 8-bit x86-style SUB computes 0x01 − 0xFF. In this convention CF = 1 exactly when the unsigned subtraction needs a borrow, OF = signed overflow, SF = sign of the result and ZF = zero. Which result and flags are produced?

  1. A. 0x02; SF=0 ZF=0 CF=0 OF=0
  2. B. 0x02; SF=0 ZF=0 CF=1 OF=1
  3. C. 0x02; SF=0 ZF=0 CF=1 OF=0
  4. D. 0xFE; SF=1 ZF=0 CF=1 OF=0

Correct answer: C. 0x02; SF=0 ZF=0 CF=1 OF=0

Unsigned 1 − 255 needs a borrow, so CF = 1 and the byte is 0x02. Signed it is 1 − (−1) = 2, which fits, so OF = 0. CF = 0 would be the ARM convention, where C is the inverted borrow; 0xFE is 0xFF − 0x01 (operands swapped).

More Computer Organization and Architecture questions

Exams that ask this topic