Attn Scott, Dmitriy and Nikolai I've added some lines and comments to the 16-bit to ASCII routine to make it a stand-alone module. Would you object if I asked for it to replace the original page ? (it is quite tidy in fixed font) ============================================= list P = 16F877 ;select your intended device include "P16f877.inc" cblock 0x20 temp ;working register lo ;binary LSB hi ;binary MSB known_zero ;working register dg1 ;string digits dg2 dg3 dg4 dg5 endc radix dec ;base 10 ascii16 clrf known_zero clrf temp movlw dg1 ;RAM storage start address for ASCII movwf fsr ;============================= ;example - input with h3039, exit with ASCII string '12345' movlw 0x39 ;binary number LSB movwf lo movlw 0x30 ;binary number MSB movwf hi ;============================= goto $+2 ;[NG] was: skip sub10k incf temp,f movlw 10000 & 255 subwf LO,f ;Scott Dattalo says: ;If you have a ram location that's known to be zero, then ;the following [the IF] can be replaced with [the ELSE] IFNDEF known_zero movlw 10000 >> 8 skpc movlw (10000>>8)+1 ;[NG] was: addlw 1 ; this sucks subwf HI,f ELSE rlf known_zero,W sublw (10000>>8)+1 ;bugfix by Dmitry Kiryashov and Nikolai Golovchenko subwf Hi,F ENDIF bc sub10k ;9*7=63/8*7=56 inst in loop for 60900 (worst) call out_temp movlw 10 movwf temp add1K decf temp,f movlw 1000 & 255 addwf LO,f ;Scott Dattalo says: ;If you have a ram location that's known to be zero, then ;the following [the IF] can be replaced with [the ELSE] IFNDEF known_zero movlw 1000 >> 8 skpnc movlw (1000>>8)+1 ;[NG] was: addlw 1 addwf HI,f ELSE rlf known_zero,w addlw 1000 >> 8 addwf HI,f ENDIF bnc add1k ;9*10=90/8*10=80 inst in loop for 60900 call out_temp ;Scott takes over here clrf temp movlw 100 goto $+2 ;[NG] was: skip sub100 incf temp,f subwf LO,f skpnc ;[NG] was: skpc goto sub100 decf HI,f btfss HI,7 ;Check msb instead of carry for underflow. goto sub100 ;4 inst per loop to 200 then 7 per loop to 900. ;Total 64(?) in loop for worst case ;at this point, HI = 0xff, and 0 <= LO <= 99 call out_temp movlw 10 movwf temp add10 decf temp,f addwf LO,f bnc add10 ;40 inst in loop for worst case. call out_temp call out_lo break goto break ;break here for testing - replace with ;RETURN or GOTO to re-enter main program ;convert to ASCII - optionally store, but the ASCII could be ;sent on to another routine to eg display or transmit out_temp movf temp,w addlw 48 ;add 0x30 to convert to ASCII movwf indf incf fsr,f ;store in RAM return out_lo movf lo,w addlw 48 movwf indf return end -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu