News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

hexidecimal input

Started by shankle, May 01, 2016, 08:38:09 PM

Previous topic - Next topic

nidud

#15
deleted

jj2007

Quote from: habran on May 02, 2016, 07:52:21 PMI did not expect such advantage in the speed :shock:

The crt_sscanf is surprisingly slow ::)

Intel(R) Core(TM) i7-4700MQ CPU @ 2.40GHz (SSE4)
Assembled with HJWasm
5837    cycles for 100 * xtol2   QWORD size, accepts 123aBcD with or without trailing h
16475   cycles for 100 * MovVal  QWORD size, accepts almost everything*) (decimal, 1010b, 0xAb12, $abc, 0abch)
63942   cycles for 100 * a2uqJ   QWORD size, CRT, accepts only hex with the given format string
5376    cycles for 100 * Masm32 hval (dword)
3120    cycles for 100 * hex2num (Habran, dword)


*)
include \masm32\MasmBasic\MasmBasic.inc
  Init
  Print Str$("\n%i", Val("2748"))
  Print Str$("\n%i", Val("101010111100b"))
  Print Str$("\n%i", Val("101010111100y"))
  Print Str$("\n%i", Val("0xaBc"))
  Print Str$("\n%i", Val("$aBc"))
  Print Str$("\n%i (bad format)", Val("aBc"))
  Print Str$("\n%i", Val("aBch"))
  Print Str$("\n%i", Val("aBcH"))
EndOfCode

habran

Hi shankle,
Here is 64 bit in a plain asm:
Quotehex2dec   PROC  src:QWORD
   movsx   eax, BYTE PTR [rcx]
   xor   edx, edx
   mov   r9, rcx
   test   eax, eax
   je   LN16
LL2:
   shl   edx, 4
   lea   r8d, DWORD PTR [rax-48]
   cmp   r8d, 9
   ja   LN6
   mov   eax, r8d
   jmp   LN8
LN6:
   or   eax, 32
   lea   ecx, DWORD PTR [rax-97]
   cmp   ecx, 5
   ja   LN8
   add   eax, -87
LN8:
   inc   r9
   add   edx, eax
   movsx   eax, BYTE PTR [r9]
   test   eax, eax
   jne   LL2
LN16:
   mov   eax, edx
   ret   
hex2dec   ENDP
it is created from this C source:
Quoteuint_32  hex2dec(const char *src)
{
  uint_32 a;
  uint_32 b = 0;
  for ( ;; )
  {
    a = *src;
    if (!a) break;
    b = (b << 4);
    if (a >= '0' && a <= '9') a -= '0';
    else {
      a |= 0x20;
      if (a >= 'a' && a <= 'f') a -= 'a' - 10;
    }
    b = b + a;
    src++;
  }
  return (b);
}
Cod-Father

shankle

Thanks everyone for your help.  I think I have solved my problem.
It might not be the best but its works.