Em 16/2/2010 02:39, Scott Dattalo escreveu: > Isaac Marino Bavaresco wrote: > > = >> Attached is an implementation in assembly language for mid-range (14-bit >> instructions) PICs. >> The conversion routine takes 34 program words and runs (always) in 207 >> instruction cycles. >> = > It's been a while since I looked at this stuff, but 10 years ago we came > up with an efficient PIC-based algorithm. I think Nikolai's 16-bit version > can be truncated to 9-bits. This takes 38 cycles (and 38 instructions) for > a 9-bit binary to packed BCD. > > http://www.piclist.com/tecHREF/microchip/math/radix/b2a-16b3a2-ng.htm > > Scott > = Hi Scott, I already knew the code. I just didn't remember it was so efficient :) Anyway, for someone learning how to program it is a bit too complicated. The method I presented although less efficient, can be scaled-up to any number of digits following the same simple mechanism. For the people complaining about MPLAB-C18 library efficiency, take a look at its 'printf' function (vfprintf indeed). It first converts every value to be printed to 32 bits and extracts each digit by division/module. I rewrote most of the MPLAB-C18 library to accept my generic pointers and in the process I optimized the vfprintf function, but I didn't replace the numeric conversion code yet. Someday I'm going to optimize it using some routine in the Piclist source code library. Best regards, Isaac __________________________________________________ Fa=E7a liga=E7=F5es para outros computadores com o novo Yahoo! Messenger = http://br.beta.messenger.yahoo.com/ = -- = http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist