The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: DaGoN on March 10, 2005, 12:45:36 PM

Title: Problem with a String To Dword
Post by: DaGoN on March 10, 2005, 12:45:36 PM
Im using this code to covert string to dword:


szName      CHAR 10h dup(?) ;
[.....]
szName = "acbde";

   mov edx,offset szName
   mov al,[edx+3]
   mov cl,[edx+2]
   mov ah,[edx+1]
   mov ch,[edx+0]
   shl eax,16
   push ebx
   shl ecx,16
   mov al,[edx+7]
   mov cl,[edx+6]
   mov ah,[edx+5]
   mov ch,[edx+4]
   and eax,not 00110000001100000011000000110000b
   and ecx,not 00110000001100000011000000110000b
   mov ebx,eax
   mov edx,ecx
   and eax,01000000010000000100000001000000b
   and ecx,01000000010000000100000001000000b
   and ebx,not 01000000010000000100000001000000b
   shr eax,6
   and edx,not 01000000010000000100000001000000b
   shr ecx,6
   add ebx,eax
   add edx,ecx
   lea eax,[eax*8+ebx]
   lea ecx,[ecx*8+edx]
   pop ebx
   shl ecx,4
   or eax,ecx; eax = dword in eax

eax = ab.cd.e0.00

There is a method to make eax eguals to 00.0a.bc.de ?
Thx in adv,
DaGoN
Title: Re: Problem with a String To Dword
Post by: AeroASM on March 10, 2005, 02:06:44 PM
Each hexadecimal represents only half of a byte, not a full byte.
However the smallest amount of memory you can access is one byte.
Therefore, with your mov al,[edx], you have the first byte, which represents the first two hexadecimal digits.
You can get just the first digit with: shr al,4
you can get just the second digit with: and al,01111b         or         and al,0Fh

I hope these hints help you!
Title: Re: Problem with a String To Dword
Post by: DaGoN on March 10, 2005, 06:12:14 PM
Hi AeroASM,
very nice solution but it doesnt resolve my problem...
Do u know a valid solution to read a hex string form an editbox and convert it in dword as in this example?
from 
string a = "abcde"
to
eax = 00.0a.bc.de

i dont find nothing about it...
Thanx in adv ,
DaGoN
Title: Re: Problem with a String To Dword
Post by: pbrennick on March 10, 2005, 06:35:56 PM
How about something like this:


        mov     cx,5
        mov     dl, "a"
        xor     eax, eax
again:  or      al, dl
        shl     al, 4
        add     dl,1
        loop    again


Paul
Title: Re: Problem with a String To Dword
Post by: AeroASM on March 10, 2005, 08:15:28 PM
I didn't realise you wanted a full algorithm. I will work one out and post it in the next 22 hours.
Title: Re: Problem with a String To Dword
Post by: DaGoN on March 10, 2005, 09:09:34 PM
QuoteI didn't realise you wanted a full algorithm. I will work one out and post it in the next 10 hours.

Thanx AeroASM,
i very appreciate your help, ill try your solution plus Pbrennick's solution...

Thanx so much,
DaGoN

Title: Re: Problem with a String To Dword
Post by: AeroASM on March 11, 2005, 08:02:38 AM
Just remembered something...  The proc in the masm32 lib called htodw does exactly what you need.
Title: Re: Problem with a String To Dword
Post by: DaGoN on March 11, 2005, 12:01:57 PM
Thanx AeroASM, it works like a charm! :U 

Byez,
DaGoN