Search code examples
assemblyx86eflags

ROR turns on the Overflow flag


I have the following lines in assembly emu8086 emulator :

 mov al,00100000b  
 ror al,8

when al is equal to 0000 0001 the two flags Carry & Overflow are turned off, but when al is equal to 1000 0000 the two flags are turned on.

Carry flag is ok - the last digit 1 is in the flag , but why this operation turns on the Overflow flag too?

Thanks for help!!!


Solution

  • From Intel manual Vol 2B

    The OF flag is defined only for the 1-bit rotates; it is undefined in all other cases (except RCL and RCR instructions only: a zero-bit rotate does nothing, that is affects no flags). For left rotates, the OF flag is set to the exclusive OR of the CF bit (after the rotate) and the most-significant bit of the result. For right rotates, the OF flag is set to the exclusive OR of the two most-significant bits of the result.

    Don't exactly know why ROR has this behavior maybe this features may be used to compute a parity bit.