Fast asm conversion of string of hex chars into binary



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

.



Relevant Pages

  • Re: Fast asm conversion of string of hex chars into binary
    ... top-of-the-head first sketch for illustration only, ... I make it circa 6 cycles per loop. ... mov ecx,;number of characters to convert, up to 8 ...
    (alt.lang.asm)
  • Re: malloc + 4??
    ... >the screen or to a file, there aren addition 4 characters. ... This loop tries to count the size of the file by calling getc ... until getcreturns EOF. ... yet also return the special marker value EOF. ...
    (comp.lang.c)
  • [SUMMARY] Word Loop (#149)
    ... cheater is a wonderful label for a programmer to have. ... the first priority is to find a possible loop. ... puts before+letter+looplets.shift ...
    (comp.lang.ruby)
  • Re: StrReverse() function - infinite loop
    ... also be a sequence of space characters at the beginning of a document, ... right-click aWord and choose Add to Watch. ... 'reverses' that space again and again in an infinite loop. ... Dim myRange As Range ...
    (microsoft.public.word.vba.beginners)
  • Re: Get the path and namefile in run time
    ... function Get_Path_Only return String; ... -- This returns the first N characters of the program name. ... end loop; ...
    (comp.lang.ada)