Just about done with a job but I need a routine to check that a HEX digit is valid, and if so convert it to binary, and if not.... here comes the tricky part... retain the original value. And... (what am I going to say next?) I'm totally out of registers and the client just dropped the "retain the value" thing on me. I'm also really pressed for space. This is for a 16C54 (well, actually, an SX) and the best I can do is very SX specific: mov w, #':' mov w, temp-w ;'9' and lower sets the carry inc WReg ;Make 'A'-':' = 8. ;Yes, on an SX W is a file register (replacing the counter) if OPTIONX ; is specified and you clear the RTW bit in the OPTION register (which ; I always do) sc ;Skip if Carry setb WReg.3 ;If it was '9' or lower, avoid this next test sb WReg.3 ;Skip if Bit 3. If the difference + 1 isn't 8 or jmp :Bad ; more then it was between '9' and 'A' mov w, #'0' snc ;skip no carry mov w, #'A'-10 mov w, temp-w ;w = temp - w sb WReg.4 ;Skip if Bit 4. No good if we overflow 16 values sc ; or if we underflow '0' jmp :Bad which in MChip speak is something like: MOVLW ':' SUBWF temp,w ;'9' and lower sets the carry movwf WReg INCF WReg ;Make 'A'-':' = 8. BTFSS status,c BSF WReg,d'3' ;If it was '9' or lower, avoid this next test BTFSS WReg,d'3' ;If the difference + 1 isn't 8 or more then GOTO Bad ; it was between '9' and 'A' MOVLW '0' BTFSC status,c MOVLW 'A'-10 SUBWF temp,w ;w = temp - w movwf WReg BTFSS WReg,d'4' ;No good if we overflow 16 values BTFSS status,c ; or if we underflow '0' GOTO Bad where we had to use a second file register called WReg. Any other ideas? Remember... no second register, but if you like, you can use W as a file register. --- James Newton (PICList Admin #3) mailto:jamesnewton@piclist.com 1-619-652-0593 PIC/PICList FAQ: http://www.piclist.com or .org -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.