On Mon, 4 Feb 2002 11:18:56 -0800, Andrew Warren wrote: >Royce Simmons wrote: > >> I am looking for a ASCII to HEX conversion assembler routine. I need >> to convert 2 ASCII characters to a single hex digit. > >Royce: > >Enter with your two ASCII characters in CHAR1 (tens' digit) and CHAR2 >(ones' digit). Exits with CHAR1 and the CHAR2 modified, and the hex >value in W. > > LIST R =3D DEC > > MOVLW '0' > BTFSC CHAR1,6 > MOVLW 'A'-10 > SUBWF CHAR1 > > MOVLW '0' > BTFSC CHAR2,6 > MOVLW 'A'-10 > SUBWF CHAR2 > > SWAPF CHAR1,W > ADDWF CHAR2,W > Royce, Andy's code here will work if you need the value expressed in BCD and not its actual hex value. I'm not entirely clear on which one you want. If you need its true hex value, you'll need to multiply the msb digit's numeric value by 10 (decimal) before adding it to the lsb's numeric value. (The SWAPF of CHAR1 actually multiplies it by 16.) In either case, you can remove the BTFSC's and the MOVLW's following them since the BTFSC will always skip the MOVLW. Bit 6 of your digit's ASCII will always be clear for decimal digits '0' through '9'. Regards, Bob -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body