Searching \ for '[PIC]: OV status flag' in subject line. ()
Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=pic
Search entire site for: 'OV status flag'.

Exact match. Not showing close matches.
'[PIC]: OV status flag'
2004\02\16@110922 by

Dear all,

I read from datasheet regarding OV flag.

"This bit is used for signed arithmetic. It indicates an overflow of the
7-bit magnitude, which causes the sign bit to change."

Is that mean whenever the MSB toggled (not include the result from bsf &
bcf), this flag will be set?

Thanks & regards.

WH Tan

--
Dear all,

I read from datasheet regarding OV flag.

"This bit is used for signed arithmetic. It indicates an overflow of the
7-bit magnitude, which causes the sign bit to change."

Is that mean whenever the MSB toggled (not include the result from bsf &
bcf), this flag will be set?

Thanks & regards.

WH Tan

--

At 11:48 PM 2/16/2004 +0800, you wrote:
>Dear all,
>
>I read from datasheet regarding OV flag.
>
>"This bit is used for signed arithmetic. It indicates an overflow of the
>7-bit magnitude, which causes the sign bit to change."
>
>Is that mean whenever the MSB toggled (not include the result from bsf &
>bcf), this flag will be set?

No. One counterexample will suffice. Consider the case of:

movlw   0x20            ; 32

result: 0xA0 (-96), the MSB of w has changed, but there is no OV

You can see that overflow is not possible if the signs of the two

What Microchip means is that the sign of the result is always incorrect
when there has been overflow.

For example,

movlw 0x80 (-128)

result 0x00 (0)

or:

movlw 0x7F (127)

result 0xFE (-2)

I'll leave checking the rest of the possibilities or finding a proof
as an exercise. ;-)

missed when writing math routines.

Best regards,

Spehro Pefhany --"it's the network..."            "The Journey is the reward"
speffinterlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com

--
At 11:48 PM 2/16/2004 +0800, you wrote:
>Dear all,
>
>I read from datasheet regarding OV flag.
>
>"This bit is used for signed arithmetic. It indicates an overflow of the
>7-bit magnitude, which causes the sign bit to change."
>
>Is that mean whenever the MSB toggled (not include the result from bsf &
>bcf), this flag will be set?

No. One counterexample will suffice. Consider the case of:

movlw   0x20            ; 32

result: 0xA0 (-96), the MSB of w has changed, but there is no OV

You can see that overflow is not possible if the signs of the two

What Microchip means is that the sign of the result is always incorrect
when there has been overflow.

For example,

movlw 0x80 (-128)

result 0x00 (0)

or:

movlw 0x7F (127)

result 0xFE (-2)

I'll leave checking the rest of the possibilities or finding a proof
as an exercise. ;-)

missed when writing math routines.

Best regards,

Spehro Pefhany --"it's the network..."            "The Journey is the reward"
speffinterlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com

--

WH Tan <PICLISTmitvma.mit.edu> wrote:

> I read from datasheet regarding OV flag.
>
> "This bit is used for signed arithmetic. It indicates an overflow
> of the 7-bit magnitude, which causes the sign bit to change."
>
> Is that mean whenever the MSB toggled (not include the result from
> bsf & bcf), this flag will be set?

No.  The Overflow flag indicates that the result is too large to fit
in 8 bits; it should be set whenever:

1.  There was an internal carry generated between bit 6 and bit 7
of the result, but NO carry was generated out of bit 7 of
the result.

OR

2.  There was NO internal carry generated between bit 6 and bit
7 of the result, but there WAS a carry generated out of bit
7.

-Andy

=== Andrew Warren -- aiwcypress.com
=== Principal Design Engineer
=== Cypress Semiconductor Corporation
===
=== Opinions expressed above do not
=== necessarily represent those of
=== Cypress Semiconductor Corporation

--
WH Tan <PICLISTmitvma.mit.edu> wrote:

> I read from datasheet regarding OV flag.
>
> "This bit is used for signed arithmetic. It indicates an overflow
> of the 7-bit magnitude, which causes the sign bit to change."
>
> Is that mean whenever the MSB toggled (not include the result from
> bsf & bcf), this flag will be set?

No.  The Overflow flag indicates that the result is too large to fit
in 8 bits; it should be set whenever:

1.  There was an internal carry generated between bit 6 and bit 7
of the result, but NO carry was generated out of bit 7 of
the result.

OR

2.  There was NO internal carry generated between bit 6 and bit
7 of the result, but there WAS a carry generated out of bit
7.

-Andy

=== Andrew Warren -- aiwcypress.com
=== Principal Design Engineer
=== Cypress Semiconductor Corporation
===
=== Opinions expressed above do not
=== necessarily represent those of
=== Cypress Semiconductor Corporation

--

> Dear all,
>
> I read from datasheet regarding OV flag.
>
> "This bit is used for signed arithmetic. It indicates an overflow of the
> 7-bit magnitude, which causes the sign bit to change."
>
> Is that mean whenever the MSB toggled (not include the result from bsf &
> bcf), this flag will be set?
>
> Thanks & regards.
>
> WH Tan
>

I am assuming you are referring to an 18F series PIC.

Actually, the description is true, but rather poorly worded. What it could
say is:

This OV bit is used for signed arithmetic. When adding or subtracting two
eight-bit signed values it is possible for the correct result to not be
representable as an eight bit signed value. This bit is set in those cases.

For example:

+100        decimal
+100        decimal
------
+200         OV will be set, because +200 is not a valid eight-bit signed
value.

The same this will happen with

-100        decimal
-100        decimal
-----
-200

Note that it is never possible to get an overflow if the operands are of
opposite signs (for addition), or the same sign (for subtraction).

Bob Ammerman
RAm Systems

--
> Dear all,
>
> I read from datasheet regarding OV flag.
>
> "This bit is used for signed arithmetic. It indicates an overflow of the
> 7-bit magnitude, which causes the sign bit to change."
>
> Is that mean whenever the MSB toggled (not include the result from bsf &
> bcf), this flag will be set?
>
> Thanks & regards.
>
> WH Tan
>

I am assuming you are referring to an 18F series PIC.

Actually, the description is true, but rather poorly worded. What it could
say is:

This OV bit is used for signed arithmetic. When adding or subtracting two
eight-bit signed values it is possible for the correct result to not be
representable as an eight bit signed value. This bit is set in those cases.

For example:

+100        decimal
+100        decimal
------
+200         OV will be set, because +200 is not a valid eight-bit signed
value.

The same this will happen with

-100        decimal
-100        decimal
-----
-200

Note that it is never possible to get an overflow if the operands are of
opposite signs (for addition), or the same sign (for subtraction).

Bob Ammerman
RAm Systems

--