John Dammeyer wrote: > The extra code penalty without the ability to use a jump table on a > PIC is much too high. John: Jump tables are trivially easy (and fast) on the PIC: MOVF STATE,W ;switch (state) ADDWF PCL ;{ ; GOTO CASE0 ; case 0: .... GOTO CASE1 ; case 1: .... GOTO CASE2 ; case 2: .... etc... ;} On some parts, you need to do a little fiddling with the PCLATH register, but I'm sure you get the idea. > I'll post the result when I'm done and like your example I'll make > it small bite capable. BTW, to be fair you need to pack the > result; mine was. 8-). Or else I need to unpack mine 8-(. If you can deal with an unpacked result, just use the excellent routine that John Payson posted here a few months ago. It's extremely fast, easily broken-up into small pieces, and it takes very little code space. Since John has inexplicably decided not to end this binary-to-BCD thread by reposting it, I will (repost it, that is... Feel free to continue the thread): ------------------------------------------------------------------- ; ; Binary-to-BCD. Written by John Payson. ; ; Enter with 16-bit binary number in NumH:NumL. ; Exits with BCD equivalent in TenK:Thou:Hund:Tens:Ones. ; org $0010 ;Start of user files for 16c84 NumH: ds 1 NumL: ds 1 TenK: ds 1 Thou: ds 1 Hund: ds 1 Tens: ds 1 Ones: ds 1 Convert: ; Takes number in NumH:NumL ; Returns decimal in ; TenK:Thou:Hund:Tens:Ones swapf NumH,w andlw $0F ;*** PERSONALLY, I'D REPLACE THESE 2 addlw $F0 ;*** LINES WITH "IORLW 11110000B" -AW movwf Thou addwf Thou,f addlw $E2 movwf Hund addlw $32 movwf Ones movf NumH,w andlw $0F addwf Hund,f addwf Hund,f addwf Ones,f addlw $E9 movwf Tens addwf Tens,f addwf Tens,f swapf NumL,w andlw $0F addwf Tens,f addwf Ones,f rlf Tens,f rlf Ones,f comf Ones,f rlf Ones,f movf NumL,w andlw $0F addwf Ones,f rlf Thou,f movlw $07 movwf TenK ; At this point, the original number is ; equal to TenK*10000+Thou*1000+Hund*100+Tens*10+Ones ; if those entities are regarded as two's compliment ; binary. To be precise, all of them are negative ; except TenK. Now the number needs to be normal- ; ized, but this can all be done with simple byte ; arithmetic. movlw $0A ; Ten Lb1: addwf Ones,f decf Tens,f btfss 3,0 goto Lb1 Lb2: addwf Tens,f decf Hund,f btfss 3,0 goto Lb2 Lb3: addwf Hund,f decf Thou,f btfss 3,0 goto Lb3 Lb4: addwf Thou,f decf TenK,f btfss 3,0 goto Lb4 retlw 0 ------------------------------------------------------------------- -Andy === Andrew Warren - fastfwd@ix.netcom.com === Fast Forward Engineering - Vista, California === === Custodian of the PICLIST Fund -- For more info, see: === http://www.geocities.com/SiliconValley/2499/fund.html