News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Problem with a String To Dword

Started by DaGoN, March 10, 2005, 12:45:36 PM

Previous topic - Next topic

DaGoN

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

AeroASM

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!

DaGoN

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

pbrennick

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

AeroASM

#4
I didn't realise you wanted a full algorithm. I will work one out and post it in the next 22 hours.

DaGoN

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


AeroASM

Just remembered something...  The proc in the masm32 lib called htodw does exactly what you need.

DaGoN

Thanx AeroASM, it works like a charm! :U 

Byez,
DaGoN