When is the overflow flag used?

206 Views Asked by At

I think I've come to learn the use cases on when the overflow flag is set: when the signed bit changes on signed arithmetic. For example, the following three cases:

    # For example, with overflow:
    mov $0b00100000, %al # 32
    add $0b01100000, %al # 96
    # ---------------------
    #   $0b10000000  # Notice how the signed bit is set so the answer is -128, not +128

    # And with negative numbers (subtracting two negative numbers) where the sign =-bit is different
    # mov $-0b00100000, %al # 
    mov  $0b10000000, %al # -128
    add  $0b10000001, %al # -127
    # ---------------------
    #    $0b00000001  # +1 -- again the sign bit changes, so we have the overflow on

    # Doing the same thing but subtracting a positive number to get the overflow instead
    mov  $0b10000000, %al # -128
    sub  $0b00000100, %al # 4
    # ---------------------
    #    $0b01111100 # + 124 -- result is positive, so again we have overflow

However, what are some applications or use cases when the overflow flag is used? In the minimal asm knowledge I have it seems the Zero and Sign flag are used all the time for comparisons, but in what use cases is the Overflow flag used?

0

There are 0 best solutions below