Bob Fehrenbach wrote: > > Malone wrote: > >Does anyone know how to convert 32 bits binary to BCD format? > > There probably faster routines but this should do the job. > > ;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. > > ;Handles full range: ff ff ff ff -> 4,294,967,296 Errm, I think that should have been 4294967295... > ;Also uses temp_f and count. > > ;2940 cycles including call and return. Here's mine: ; Binary to BCD conversion (32-bit). ; ; In: value3,value2,value1,value0 : 32-bit integer ; Act: Converts a 32 bit binary number to packed BCD ; Out: bcd4,bcd3,bcd2,bcd1,bcd0 : BCD result (must be contiguous) ; Regs: tmp, Count ; Note: Uses one stack level internally. ; Execution time is 2785 cycles (1948 cycles using in-line code ; for B2B_Adjust). bin2bcd_32 movlw 32 str Count clr bcd4 clr bcd3 clr bcd2 clr bcd1 clr bcd0 clc jp B2B_Enter B2B_Loop movlw bcd0 str fsr call B2B_Adjust call B2B_Adjust call B2B_Adjust call B2B_Adjust call B2B_Adjust B2B_Enter rl value0 rl value1 rl value2 rl value3 rl bcd0 rl bcd1 rl bcd2 rl bcd3 rl bcd4 loop Count,B2B_Loop retlw 0 B2B_Adjust movlw 0x33 addwf ind,w btfsc ind,3 andlw 0xf0 btfsc ind,7 andlw 0x0f subwf ind,f if bcd1>bcd0 inc fsr ; bcd0 at lowest address else dec fsr ; bcd0 at highest address endif retlw 0 ------------------------------------------------------------------------ Frank A. Vorstenbosch Mobile: +44-976-430 569 Wimbledon, London SW19 Home: +44-181-544 1865 frank@falstaff.demon.co.uk Office: +44-181-636 3391