Search code examples
assemblyx86integer-overflowemu8086eflags

CF, OF in flag register during data overflow


With Intel x86 / emu8086 emulator, when there is an overflow of a byte with following values:

mov al,-128
sub al,128

How come the CF is 0, and OF is also 0? Thanks


Solution

  • -128 and 128 are the same number in 8-bit (2's complement or unsigned). i.e. the immediate for both instructions is 0x80.

    x - x = 0 with no carry (unsigned) or overflow (signed).