> Guys: > > ; Jump to BAD if value in W is not an ASCII character > ; from "0" to "9", otherwise fall thru with the 0-9 > ; value in W. No file registers required. > > ADDLW 255-"9" > ADDLW ("9"-"0") + 1 > BNC BAD > > -Andy It's a very useful test. I put this 18F routine together as part of a module to sort commands and parameters in received text strings. (it also needs a routine to detect and convert lower case to upper case. And there's a pre-test for special characters - it looks for @ ? * - that has to be worked in with ch_skip), but as it is it will sort uppercase and ASCII numbers It makes use of the 18F's 3 FSRs - other PICs could use FSR and two RAM indices sort movlw 0x00 ;source RAM address, received text movwf fsr0l movlw 0x20 ;destination RAM address, UC letters movwf fsr1l movlw 0x40 ;destination RAM address, numbers movwf fsr2l clrf fsr0h clrf fsr1h clrf fsr2h loop movf indf0,w ;get char from source addlw .255-"A"+1 ;test if UC letter addlw ("Z"-"A")+1 bc number ;not letter, try number movff indf0,indf1 ;copy char to letter store incf fsr0l ;increment source index incf fsr1l ;increment letter index btfsc fsr0l,5 ;test for fsr0l=32 bra done ;yes bra loop ;no number movf indf0,w ;get char from source addlw .255-"9" ;test if number addlw ("9"-"0")+1 bnc ch_skip ;not letter or number movff indf0,indf2 ;copy char to number store incf fsr0l ;increment source index incf fsr2l ;increment number index btfsc fsr0l,5 bra done bra loop ch_skip incf fsr0l ;not UC letter or number btfss fsr0l,5 ;done bra loop done ............ -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu