>Peter Baines wrote: > >> does anybody have some code to subtract one 16 bit number from >> another NOT using 2s compliment so that it returns an ABS result >> with a flag (AKA register) to say if it is negative. > >Peter: > >This routine computes DEST = DEST - SOURCE. After it executes, the >Carry flag is valid (i.e., Carry = 0 if the result is negative, >Carry = 1 if the result is zero or positive). Note that the Zero >flag is NOT necessarily valid after execution. > > MOVF SOURCELO,W > SUBWF DESTLO > MOVF SOURCEHI,W > SKPC > INCFSZ SOURCEHI,W > SUBWF DESTHI > >-Andy > Peter, Try this... returns ABS(DEST-SOURCE) in DEST MOVF SOURCELO,W SUBWF DESTLO MOVF SOURCEHI,W SKPC INCFSZ SOURCEHI,W SUBWF DESTHI ; SKPNC GOTO DONE ; DEST > SOURCE ; COMF DESTLO ; NEGATE if SOURCE > DEST INCF DESTLO SKPNZ DECF DESTHI COMF DESTHI DONE ; DEST = ABS( DEST - SOURCE ) I don't know if there is any simpler way, seem like there should be some cleverer way of doing the subtract. Ray Gardiner (DSP Systems) ray@dsp-systems.com http://www.dsp-systems.com private email to:- ray@netspace.net.au