On Mon, 15 Feb 2010, Isaac Marino Bavaresco wrote: > Em 15/2/2010 10:35, Isaac Marino Bavaresco escreveu: > > There is an interesting implementation which is used by MPLAB-C18 > > library (file itobcd.asm). > > It is a very efficient serialized method, it uses only shifts and adds. > > It is worthy a try. > > > > Best regards, > > > > Isaac > > > > 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. > > Best regards, > > Isaac > Interesting, thank you for sharing that. I haven't worked my way through it but it feels good. I'll have to work my may through it in detail :-) With regards to optimisation, have you considered changing: BIN2BCD9Bits: movlw 0x01 ; Mask out the 7 higher bits of the value andwf BinValue+1,f bcf STATUS,C ; Here we add a twist to allow 9bit conversion rrf BinValue+1,f ; Instead of pre-shifting left 7times, we rotate rrf BinValue+0,f ; right once an will use the bytes in reversed order. rrf BinValue+1,f to BIN2BCD9Bits: ; Mask out the 7 higher bits of the value rrf BinValue+1,f ; Instead of pre-shifting left 7times, we rotate rrf BinValue+0,f ; right once an will use the bytes in reversed order. clrf BinValue+1 rrf BinValue+1,f Regards Sergio Masci -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist