gnupic: nibble<->hex conversions
Subject:
nibble<->hex conversions
From:
Samuel Tardieu ####@####.####
Date:
26 Sep 2002 14:44:02 -0000
Message-Id: <2002-09-26-16-41-52+trackit+sam@rfc1149.net>
In my Forth compiler for 16f87x (see http://www.rfc1149.net/devel/picforth),
I have a nibble>hex and hex>nibble conversion routines.
I would like to know if faster ones do exist. The goal of nibble>hex is to
convert a character (present in INDF) into the corresponding hexadecimal
value, stored at the same place. The character can be in the range 0-9, A-Z
or a-z. hex>nibble converts the value at INDF into the corresponding ASCII
character (0-9 and A-Z), result goes to the same place.
Here are my routines. I want to make them as fast as possible; only the
interface cannot change, except that the nibble or character to convert from
can come in W rather than INDF (but the result must be stored in INDF).
Also, I do not want to use more room, so using tables is not an option.
nibble>hex:
| movlw 0x30
| addwf 0x00,f
| movf 0x00,w
| addlw 0xC6
| andlw 0x80
| btfss 0x03,2
| return
| movlw 0x07
| addwf 0x00,f
| return
hex>nibble:
| bcf 0x00,5
| movlw 0xC9
| addwf 0x00,f
| btfss 0x00,7
| return
| movlw 0x27
| addwf 0x00,f
| return
Thanks in advance for your suggestions.
Sam