Since Marcel will need to save the 12(16)-bit number from one iteration to the next, Andy's otherwise perfectly working routine needs a slight modification. Andrew Warren wrote: > MOVF OLDLO,W > SUBWF NEWLO,W > MOVF OLDHI,W > SKPC > INCFSZ OLDHI,W > SUBWF NEWHI,W MOVF NEWLO,W MOVWF OLDLO MOVF NEWHI,W MOVWF OLDHI > BC NEW_IS_LARGER_OR_EQUAL > GOTO NEW_IS_SMALLER It's hardly worth showing, but it's possible to shave a cycle off of this 'compare and save' algorithm: movf new+1,W ;W = LSB of new subwf old+1,W ;W = old - new (LSB) subwf old+1,F ;old = old - (old - new) = new ;at this point, the carry bit is set if the low byte of old ;is greater than or equal to the low byte of new. Also, new ;has been copied to old's location. movf new,W skpc incfsz new,W ; subwf old,W movf new,W ;Now copy the high byte. Note that movwf old ;the subwf trick won't work here. ;But then again, Dmitry hasn't put his ;two rubles in yet. skpnc goto old_is_larger_or_equal goto old_is_smaller BTW Andy, you forgot your comments! Scott