Hi Dmitriy, Something like this: (untested) ; Multi byte BCD increment ; by Regulus Berdin ; INC: MOVLW BCD_LSB MOVWF FSR MOVLW BCD_CNT MOVWF CNT LOOP: MOVLW 67 ADDWF INDF,F MOVLW -60 SKPDC MOVLW -66 SKPC ADDWF CNT,F SKPZ RETURN INCF FSR,F DECFSZ CNT,F GOTO LOOP RETURN ; Multi byte BCD decrement ; by Regulus Berdin ; DECR: MOVLW BCD_LSB MOVWF FSR MOVLW BCD_CNT MOVWF CNT LOOP: MOVLW 0xFF ADDWF CNT,F MOVLW -6 SKPC MOVLW -66 SKPDC ADDWF CNT,F XORLW -0x66 SKPZ RETURN INCF FSR,F DECFSZ CNT,F GOTO LOOP RETURN Also have posted similar to this many years ago. I think it is also in the archive but not on the piclist code repository. regards, Reggie On 8/3/05, Dmitriy Kiryashov wrote: > Hi Reggie. > > Nice logical approach indeed :) > How would you cascade this approach > if bcd number is several bytes sized ? > > > WBR Dmitriy. > > > > > I had posted this about 6 or 7 years ago. 7 cycles :) excluding return. > > radix is HEX. > > > > BCD_INCR: > > MOVLW 67 > > ADDWF CNT,F > > MOVLW -60 > > SKPDC > > MOVLW -66 > > SKPC > > ADDWF CNT,F > > RETURN > > > > BCD_DECR: > > MOVLW 0xFF > > ADDWF CNT,F > > MOVLW -6 > > SKPC > > MOVLW -66 > > SKPDC > > ADDWF CNT,F > > RETURN > > > > On BCD_INCR, Z flag is set when overflow occurs. > > But on BCD_DECR, adding "XORLW -0x66" at the end will set Z flag during > > an underflow. > > > > regards, > > Reggie > -- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist