PIC Microcontoller Radix Math Method

BCD packed to binary 2 digit to 8 bit

From: Scott Dattalo

         rrf   bcd, W 
        andlw 01111000b  ;W = tens*8 
        movwf temp 
        clrc 
        rrf   temp, F    ;temp = tens*4 
        rrf   temp, F    ;temp = tens*2 
        subwf bcd, W     ;W = tens*16 + ones - tens*8 
                         ;W = tens*8 + ones 
        addwf temp, W    ;W = tens*10 + ones 

Code:

Comments:

Tomas Kocian Says:

Another method, using 6 cycles without additional registers:
swapf bcd,w ;separate tenths
andlw 0F
mullw 0A ;multiply by 10
movf bcd,w
andlw 0F ;separate below 10
addwf PRODL,w ;add to multiply result