On Tue, 28 Apr 1998 08:22:44 +0500 Sujay Sirur writes: >PS. It might be possible to get a binary to BCD converter using the >same logic. >Am trying to work it out. The routine originally posted is indeed a BCD to binary converter. A binary to BCD converter would be based on dividing by 10, rather than multiplying. For single byte numbers, it is practical to repeatedly subtract 10, counting the number of subtractions needed to reduce the number to less than 10. The number of subtractions required is the tens digit, and the remaining number is the ones digit. The routine attached below is some not too elegant code from one of my recent projects. It converts a number from 0 to 99 to two BCD digits using a repeated subtraction method. The repeated subtraction method becomes unweildy for numbers larger than 999. Either long division by 10 or the "BCD multiply by 2" routine should lead to smaller and faster code. ;------------- cvdec ; Converts the 1-byte number in bin to decimal. Number must be less than 100 ; for correct result of course. Result returned as packed BCD in tmp. ; Number in bin is destroyed. (On exit, bin contains the ones digit with the ; high 4 bits zero) ; clrf tmp ;Start with result = 0. movlw .10 ;Constant to use cvdecl incf tmp,f ;Inc. the tens digit. subwf bin,f ;Subtract 10 skpnc ;Skip if bin was less than 10. goto cvdecl ;Subtract again. ; Here with tens digit + 1 in low bits of bcd, and ones digit - 10 (negative) ; in bin. addwf bin,f ;Restore ones digit (know now 0 to 9). decf tmp,f ;Fix tens digit. swapf tmp,w ;Get tens digit to high bits. iorwf bin,w ;OR in the ones digit. movwf tmp ;Put result back. return ;---------------- _____________________________________________________________________ You don't need to buy Internet access to use free Internet e-mail. Get completely free e-mail from Juno at http://www.juno.com Or call Juno at (800) 654-JUNO [654-5866]