> From: Scott Dattalo SNIP > Uhh, yeah. Sorry. But what about this case: 95 + 90 > > BCD_ADD: ;Y = Y + X > MOVLW 66 W = 66 > ADDWF X,W W = 95 + 66 = FB > ADDWF Y,F Y = 90 + FB = 8B, C=1, DC=0 > MOVLW -60 W = -60 = 0xa0 > SKPDC NOT SKIPPED > MOVLW -66 W = -66 = 0x9a > SKPC SKIPPED > ADDWF Y,F NO ADD, SO RESULT = 8B, C=1 > RETLW 0 > > If C=1 AND the sum of the least significant nibbles is less than 10 > then the result will be incorrect. Very sorry! I guess I should test my routines before posting :). This sould do it: BCD_ADD: ;Y = Y + X MOVLW 66 ADDWF X,W ADDWF Y,F MOVLW 0 SKPDC IORLW 6 SKPC IORLW 60 SUBWF Y,F ANDLW 60 ;What you suggested. RETLW 0 BCD_MINUS: ;Y = Y - X MOVF X,W SUBWF Y,F MOVLW 0 SKPDC IORLW 6 SKPC IORLW 60 SUBWF Y,F ANDLW 60 RETLW 0 > Excellent! However from my simulation results, Z is set only when > the result is 0 (and not for an underflow). If you macro-ize this > routine then the upper nibble of W will have the carry information. > Or perhaps, you can add : > > SUBWF Y,F > ANDLW 0x60 ;Set Z if underflow occurred > RETLW 0 Thanks for the suggestion, I implemented it above. Reggie