Searching \ for '[PIC]: OV status flag' in subject line. ()
Make payments with PayPal - it's fast, free and secure! 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.
PICList Thread
'[PIC]: OV status flag'
2004\02\16@110922 by WH Tan

flavicon
face
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

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\02\16@110922 by WH Tan

flavicon
face
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

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\02\16@113908 by Spehro Pefhany

picon face
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
addlw   0x80            ; -128

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
numbers being added are different.

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

For example,

movlw 0x80 (-128)
addlw 0x80 (-128)

result 0x00 (0)

or:

movlw 0x7F (127)
addlw 0x7F (127)

result 0xFE (-2)

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

I'm glad they added the OV flag to some newer PICs, it's something I often
missed when writing math routines.

Best regards,

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

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\02\16@113908 by Spehro Pefhany

picon face
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
addlw   0x80            ; -128

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
numbers being added are different.

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

For example,

movlw 0x80 (-128)
addlw 0x80 (-128)

result 0x00 (0)

or:

movlw 0x7F (127)
addlw 0x7F (127)

result 0xFE (-2)

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

I'm glad they added the OV flag to some newer PICs, it's something I often
missed when writing math routines.

Best regards,

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

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\02\16@130726 by Andrew Warren

flavicon
face
WH Tan <PICLISTspamKILLspammitvma.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 -- .....aiwKILLspamspam.....cypress.com
=== Principal Design Engineer
=== Cypress Semiconductor Corporation
===
=== Opinions expressed above do not
=== necessarily represent those of
=== Cypress Semiconductor Corporation

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\02\16@130726 by Andrew Warren

flavicon
face
WH Tan <EraseMEPICLISTspam_OUTspamTakeThisOuTmitvma.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 -- aiwspamspam_OUTcypress.com
=== Principal Design Engineer
=== Cypress Semiconductor Corporation
===
=== Opinions expressed above do not
=== necessarily represent those of
=== Cypress Semiconductor Corporation

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\02\16@131309 by Bob Ammerman

picon face
> 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

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\02\16@131309 by Bob Ammerman

picon face
> 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

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

More... (looser matching)
- Last day of these posts
- In 2004 , 2005 only
- Today
- New search...