I read 2 explanations about overflow flag:
-------------------------------------
1-)It is set (status: 1) when the last operation changed the highest bit of the register that gets the result of an operation. For example: EAX holds the value 7FFFFFFF. If you use an operation now, which increases EAX by 1 the O-Flag would be set, because the operation changed the highest bit of EAX

2-)In computer processors, the overflow flag is usually a single bit in a system status register used to indicate when an arithmetic overflow has occurred in an operation.

An example of the use of the overflow flag is what happens if you were to add 127 and 127 using 8-bit signed integers. The mathematical answer is 254, but in binary this is 1111 1110 in Two's complement which is negative (-2). The overflow flag is set to indicate a problem, so the software can be aware of the problem and act accordingly to compensate or mitigate the error. The overflow flag is usually computed as the xor of the carry into the sign bit and the carry out of the sign bit.
--------------------------------
Which one is true? Or both of them true?
This is the first time that i read such a thing about OF Flag in first explanation. Can you please verify this?

Thank you...
Posted on 2007-01-16 05:08:51 by sawer
If you add 127 to 127, no overflow occurs.
Overflow means your value exceeds what is able to be encoded in a given bitlength (typically 32 bits at the moment).

Assuming you were working in 8 bit, the maximum value you can encode in 8 bits is 255.
If you added 128 and 127, you get 255 (11111111 in binary) with overflow bit in the clear (0) - in hex that would be FF....
but if you added 128 and 128, you get 00000000 with overflow bit set (1).

128 + 128 is 256, which needs more than 8 bits to encode.
In 16 bits, it would be 00000001-00000000 (the separator for your benefit) which in hex, would be 0100

Does this make sense to you?
Posted on 2007-01-16 06:15:06 by Homer
ok.
thank you
Posted on 2007-01-16 10:07:58 by sawer
Homer: your info is wrong. Overflow flag (OF) is set when signed overflow occurs. What you described is behavior of carry flag (CF).

in 8 bit number, OF is set when value crosses 10000000b boundary. So 127+127 sets OF. So does 127+1, or -128-1, etc...
Posted on 2007-01-16 15:21:26 by vid
Can you please explain differences between CF and OF?
Thanks
Posted on 2007-01-16 16:48:42 by sawer

Can you please explain differences between CF and OF?
Thanks


I found a (seemingly) beginner-friendly page on Google, and general graphical reference, to help highlight and explain jumps/flags.

----->http://www.unixwiz.net/techtips/x86-jumps.html<-----
Posted on 2007-01-16 17:38:31 by SpooK
Heh, my bad.
It was 42 degrees here yesterday, and my brain wasn't working too well.
Posted on 2007-01-16 21:40:45 by Homer
sawer,

    This topic was beat to death in the following threads http://www.masm32.com/board/index.php?topic=2923.0
http://www.masm32.com/board/index.php?topic=5852.0

1-)It is set (status: 1) when the last operation changed the highest bit of the register that gets the result of an operation. For example: EAX holds the value 7FFFFFFF. If you use an operation now, which increases EAX by 1 the O-Flag would be set, because the operation changed the highest bit of EAX


    The above explanation is incomplete.  The OF will be set when the carry out of bit 31 is NOT matched by a carry in from bit 30 OR a borrow in of bit 31 is NOT matched by a borrow out to bit 30.  In the above example, there was no carry out of bit 31, but there was a carry in from bit 30.  So up goes the OF.  A change in bit 31 is not a sufficient condition by itself to affect the OF.

The mathematical answer is 254, but in binary this is 1111 1110 in Two's complement which is negative (-2).


    There is no mathematical answer for such an addition using only 8-bit hardware and signed numbers.

The overflow flag is usually computed as the xor of the carry into the sign bit and the carry out of the sign bit.


    And also the XOR of the borrow into the sign bit and the borrow out of the sign bit.

Which one is true? Or both of them true?


    The second is true.

This is the first time that i read such a thing about OF Flag in first explanation. Can you please verify this?


    The first definition is incomplete, therefore wrong.  Ratch

Posted on 2007-01-17 16:04:34 by Ratch