----- Original Message ----- From: Soon Lee To: Sent: Wednesday, November 20, 2002 2:44 PM Subject: Test for OverFlow in 2' complement systems > Hi all > > As I am pretty new to math in PIC just to check what are the method that > we can use to check whether a math operation have cause any overflow. > > Can any one please enlighten me on this > thanks Others have responded saying that the carry should be checked in the status register, implying that this is somehow an overflow flag. This is only correct for unsigned arithmetic. For signed arithmetic it is ONLY a carry and NOT an overflow. Overflow of signed arithmetic occures when the sign bit is wrong. To check for overflow: A, B are the inputs D is the output e.g. movf A,w addwf B,w movwf D ((A XOR B XOR D) AND 0x80) == 0x80 for overflow ((A XOR B XOR D) AND 0x80) == 0 for NO overflow I think you can use the carry (after the add or subtract) and bit 7 of D in place of (A XOR B) but I cannot remember exectly what this should be for the PIC off hand. Regards Sergio Masci http://www.xcprod.com - Free XCSB compiler -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.