>I know this must be the worst bin to bcd routine in C >How would be the best? Its in ASM (sorry), but John Payson wrote the quickest version I've seen so far. ;Takes hex number in NumH:NumL Returns decimal in ;TenK:Thou:Hund:Tens:Ones ;written by John Payson NumH EQU AD3M ;input NumL EQU AD3L TenK EQU LOOPER ;share variables Thou EQU D2 Hund EQU D1 Tens EQU R2 Ones EQU R1 swapf NumH,w iorlw b'11110000' movwf Thou addwf Thou,f addlw .226 movwf Hund addlw .50 movwf Ones movfw NumH andlw b'00001111' addwf Hund,f addwf Hund,f addwf Ones,f addlw .233 movwf Tens addwf Tens,f addwf Tens,f swapf NumL,w andlw b'00001111' addwf Tens,f addwf Ones,f rlf Tens,f rlf Ones,f comf Ones,f rlf Ones,f movfw NumL andlw b'00001111' addwf Ones,f rlf Thou,f movlw 7 movwf TenK ; At this point, the original # == 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 normalized, ; but this can all be done with simple byte arithmetic. movlw .10 Lb1: addwf Ones,f decf Tens,f skpc goto Lb1 Lb2: addwf Tens,f decf Hund,f skpc goto Lb2 Lb3: addwf Hund,f decf Thou,f skpc goto Lb3 Lb4: addwf Thou,f decf TenK,f skpc goto Lb4 Dwayne Reid Trinity Electronics Systems Ltd Edmonton, AB, CANADA (780) 489-3199 voice (780) 487-6397 fax Celebrating 15 years of Engineering Innovation (1984 - 1999) * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Do NOT send unsolicited commercial email to this email address. My posting messages to Usenet neither grants consent to receive unsolicited commercial email nor is intended to solicit commercial email.