Hi, > > If you are looking > > for a compact 32bit divide by 10 routine, mail me and I'll send it to > you. > > > > Niki > > > Would it be possible to take a look? > Here is the routine I use: ;========================================================================= ;Divide the 32 bit number in N_3:N_2:N_1:N_0 by 10 and store the result ;in N_3:N_2:N_1:N_0 and the remainder in Rem. If the quotient and the ;remainder is 0, the Z flag is set. This is useful for leading zero ;suppression. ;Additional register used: C1 ;========================================================================= Div10: movlw 32 movwf C1 ;Repeat for 32 bits clrf Rem Div10Loop: rlf N_0,W rlf N_1,F rlf N_2,F rlf N_3,F rlf Rem,F ;Move MSB of Number into Temp movlw 10 subwf Rem,W ;Does 10 go in? btfsc STATUS,C movwf Rem ;If so, update remainder rlf N_0,F ;If 10 went in, shift in a 1, if not ;shift in a 0 decfsz C1,F goto Div10Loop ;Repeat for all bits movf N_0,W ;Test if Quotient is 0 iorwf N_1,W ;Test if Quotient is 0 iorwf N_2,W ;Test if Quotient is 0 iorwf N_3,W ;Test if Quotient is 0 iorwf Temp,W ;Test if Remainder is also 0 return 16 words without the leading zero detection, 21 with it. Each consecutive call to the divide routine will return the next digit in the number. If the Z flag is set, then the digit returned is a leading zero. Main advantage of the divide approach against the subtract approach is that it is more compact. Niki