how would i convert a string(number), into a 64bit varable stored in eax and ebx?
Posted on 2004-09-19 19:58:38 by Qages
As you probably know, there may be 1001 ways to achieve that in assembler. One of them could be with the FPU as follows (you should add error checking for unacceptable characters and/or overflow if intended for use by others than yourself):
str2qw proc public lpsrc:DWORD

LOCAL units :DWORD
LOCAL ten :DWORD
LOCAL answer :QWORD
mov ten,10
finit
fldz ;initialize top FPU register
push esi
mov esi,lpsrc
xor eax,eax
loop1:
lodsb
or al,al
jz finish ;reached end of string
sub al,30h ;convert from ASCII to binary
mov units,eax
fimul ten
fiadd units
jmp loop1
finish:
fistp answer ;store answer in memory
lea esi,answer
mov eax,[esi] ;LS dword in EAX
mov ebx,[esi+4] ;MS dword in EBX
pop esi
ret
srt2qw endp

Raymond
Posted on 2004-09-19 22:06:00 by Raymond
Hi...

It is not bad your code...You wrote it to show how to use FPU instructions...it is true that not a lot of persons use them...

For my own I find your code too long in time...

and the better way to multiply by 10 is...



mov ebx,eax
shl ebx,1 ; x 2
shl eax,3 ; x 8
add eax,ecx ; 2+8 =10


And like that you can confim your adage...

Gerard...
-----------
Posted on 2004-09-20 00:40:31 by gerard
You meant



mov ebx,eax
shl ebx,1 ; x 2
shl eax,3 ; x 8
add eax,ebx ; 2+8 =10

I guess..
Posted on 2004-09-20 07:24:09 by roticv
gerard

An even better way to multiply by 10 is:
shl  eax,1

lea eax,[eax+eax*4]
However, this thread is to convert a string to a qword. At some point, the partial sum may exceed 32 bits and reside in 2 registers if the FPU is not used. Although multiplying it by 10 is still possible, it would be somewhat more complicated than the above code or yours.

Raymond
Posted on 2004-09-20 10:13:36 by Raymond