Re: Fast asm conversion of string of hex chars into binary



James,

Vid has shown you the basics of getting your code up to speed, what I
have to offer you is a basic algo design that is fast.

Create two tables, the first that is driven by your first hex
character, the second table by the second hex character. The values in
the first table are multiples of 16, the second is 0 to 15.

Read the value from the first table then add the value from the second
table and you have the binary value as a BYTE. This is the nominal code
to do it.

; ascii hex values loaded into ESI

movzx eax, BYTE PTR [esi] ; zero extend 1st byte
movzx edx, BYTE PTR [esi+1] ; zero extend 2nd byte

movzx ecx, BYTE PTR [tbl1+eax] ; zero extend 1st value in table
add cl, [tbl2+edx] ; add 2nd value to it

; byte value from ascii hex now in CL

To check if you have valid characters 0 - 9, A - F, a - f you probably
do that faster from another character lookup table. The tables make the
algo larger but reduce the calculations to get the speed you are after.

Regards,

hutch at movsd dot com

.