Fast asm conversion of string of hex chars into binary
- From: "James Harris" <james.harris.1@xxxxxxxxxxxxxx>
- Date: 25 Nov 2006 03:40:18 -0800
Is there an obvious way to make this 386+ code faster? It is a
top-of-the-head first sketch for illustration only, not meant to be
working code but I think I have allowed for AGIs and instruction
pairing (for cpus where they apply). I make it circa 6 cycles per loop.
The code should convert up to eight ascii hexadecimal characters to a
number, e.g. "2f4ba7" to 0x002f4ba7.
;setup
mov esi, <address>
mov ecx, <num chars> ;number of characters to convert, up to 8
;
xor eax, eax ;to collect the result
xor ebx, ebx ;workspace; prezero all bits
:loop
mov bl, [esi] ;fetch char
mov bl, convtab[bl] ;convert to (0 to 15)
cmp bl, 15
ja error
inc esi ;point at next char
shl eax, 4 ;move up a nibble
or eax, ebx ;add in new value
dec ecx ;one less to do
jnz loop ;done?
The code uses a table to map a character (0 to 255) into a value in the
range 0 to 15 (for 0 to 9 and A to F). The table is constructed as
shown below allowing values in the range 0 to 36 but the code needs to
reject anything above 15.
The table it is meant to work with would be something like this:
value xtab (layout (256) of octet)
(char 255) for 48 ;positions 0 to 47
(0 upto 9) ;digits 0 to 9 (pos 48-57)
(char 255) for 7 ;positions 58 to 64
(10 upto 25) ;upper case A to Z (pos 64-90)
(char 255) for 6 ;positions 91 to 96
(10 upto 25) ;lower case A to Z (pos 97-122)
(char 255) for (6 + 128) ;positions 123 to 255
endvalue
.
- Follow-Ups:
- Re: Fast asm conversion of string of hex chars into binary
- From: Herbert Kleebauer
- Re: Fast asm conversion of string of hex chars into binary
- From: vid512@xxxxxxxxx
- Re: Fast asm conversion of string of hex chars into binary
- Prev by Date: Re: hard disk I/O
- Next by Date: Re: Fast asm conversion of string of hex chars into binary
- Previous by thread: hard disk I/O
- Next by thread: Re: Fast asm conversion of string of hex chars into binary
- Index(es):
Relevant Pages
|