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