Mike Watson wrote: >I have a need for an unsigned 32 bit binary to bcd routine. > >what would be really nice is a routine that produces the >decimal digits in turn starting from the left. This way they >can be sent to an LCD display or rs232 port without having to >be stored in memory. Mike, A conventional subtract and increment routine will generate the decimal digits one at a time but would be very slow for numbers of this size. Since a 32 bit number can be over 4E10, you would start with subtracting 1E10 and incrementing the 'billions' digit each time the result is still positive. Then move on to the next power of ten. The following is an extension of the approach in the Microchip app note. ;Binary - BCD 32 bits ;Input in buff_4|buff_3|buff_2|buff_1, ; ;Converts to packed bcd in temp_a, temp_b, temp_c, temp_d and temp_e ;with the MSD temp_a. ;Also uses temp_f and count. ;2940 cycles including call and return. bin2bcd: bcf STATUS, C movlw 32 movwf count clrf temp_a clrf temp_b clrf temp_c clrf temp_d clrf temp_e bin2bcd_loop: rlf buff_1, f rlf buff_2, f rlf buff_3, f rlf buff_4, f rlf temp_e, f rlf temp_d, f rlf temp_c, f rlf temp_b, f rlf temp_a, f decfsz count, f goto adj_dec goto done adj_dec: movlw temp_e movwf FSR call adj_bcd movlw temp_d movwf FSR call adj_bcd movlw temp_c movwf FSR call adj_bcd movlw temp_b movwf FSR call adj_bcd movlw temp_a movwf FSR call adj_bcd goto bin2bcd_loop adj_bcd: movlw h'3' addwf INDF, w movwf temp_f btfsc temp_f, 3 movwf INDF movlw h'30' addwf INDF, w movwf temp_f btfsc temp_f, 7 movwf INDF return done: return -- Bob Fehrenbach Wauwatosa, WI bfehrenb@execpc.com