Hi Scott. I believe input value range for hex is limited to 0..99d for procedure shown in your post and there is straight coded solution with 18 clocks as well for that case ( I'm getting so lazy I guess .. :) ; hex2bcd : x is original number ; y has tens, W has ones left movfw x clrf y ;we can even reuse x here.. addlw -D'80' ;getting four bits of tens rlf y,F btfss y,0 addlw D'80' addlw -D'40' rlf y,F btfss y,0 addlw D'40' addlw -D'20' rlf y,F btfss y,0 addlw D'20' addlw -D'10' rlf y,F btfss y,0 addlw D'10' >From the other hand if we scale it up ( extra 8 clocks/words see the previous post ) to get hundreds as well converted it will be 2 clocks /words shorter than procedure discussed at : http://www.piclist.com/techref/microchip/math/radix/b2bhp-8b3d.htm WBR Dmitry. Scott Dattalo wrote: > > On Thu, 2006-02-23 at 06:48 -0800, Peter van Hoof wrote: > > > look at app note an544 > > http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1824&appnote=en011088 > > > > > > there are 4 ways described to do this without tables > > fastest: Binary to BCD (8 bit) 10 words 62 cycles 1 byte scratch unused > > When Peter says that the fastest way to solve this problem without tables > takes 62 cycles, what he really means is that the fastest way an544 solves > this problem takes 62 cycles. Of course, there are faster non-table > solutions out there. One in particular takes 18 cycles. > > SWAPF bin, W ;w = A0*16+A1 > ADDWF bin, W ;w = A0+A1 > ANDLW 00001111b ;w = A0+A1 % 16 > SKPNDC ;if A0+A1 > 16 > ADDLW 0x16 ; w += 16 > SKPNDC ;if w % 16 > 10 > ADDLW 0x06 ; w += 6 > ADDLW 0x06 ;w += 6 > SKPDC ;if w < 10 > ADDLW -0x06 ; w -= 6 > > BTFSC bin,4 > ADDLW 0x16 - 1 + 0x6 > SKPDC > ADDLW -0x06 > > BTFSC bin, 5 > ADDLW 0x30 > > BTFSC bin, 6 > ADDLW 0x60 > > ; result is in W > > This was adapted from: > http://www.piclist.com/techref/microchip/math/radix/b2bhp-8b3d.htm > And the algorithm is described: > http://www.piclist.com/techref/method/math/radixs.htm > > Scott -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist