Anyone has a source code that can Convert SIGNED decimal string into SIGNED dword value without using "wsprintf"?

I found one, but it seems to only work with UNSIGNED NUMBERS.

Can anybody give me a advice how to modify the code below and make it work on SIGNED value?
I has spent hours on this code, but I got more confused when I spent more time on it. I really need a new direction to work on this code. Thank you.


a2dw proc uses ecx edi edx esi String:DWORD

;----------------------------------------
; Convert decimal string into dword value
; return value in eax
;----------------------------------------

xor ecx, ecx
mov edi, String
invoke lstrlen, String

.while eax != 0
xor edx, edx
mov dl, byte ptr
sub dl, "0" ; subtrack each digit with "0" to convert it to hex value
mov esi, eax
dec esi
push eax
mov eax, edx
push ebx
mov ebx, 10
.while esi > 0
mul ebx
dec esi
.endw
pop ebx
add ecx, eax
pop eax
inc edi
dec eax
.endw

mov eax, ecx
ret

a2dw endp
Posted on 2002-06-28 01:17:01 by ssa
i had the same problem some time ago.... i just pasted this code at the end of my source:



OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE
atodw proc FORCENOFRAME
;----------------------------------------
; Convert decimal string into dword value
; return value in eax
;----------------------------------------
; String EQU [esp+4]
mov edx, [esp+4]
xor eax, eax
cmp BYTE PTR [edx], 2Eh
sbb [esp+4], edx
adc edx, eax
jmp @F
again:
lea eax, [eax+4*eax]
inc edx
lea eax, [ecx+2*eax-30h]
@@: movzx ecx, BYTE PTR [edx]
cmp BYTE PTR [edx], 30h
jns again
add eax, [esp+4]
xor eax, [esp+4]
retn 4
atodw ENDP
OPTION PROLOGUE:DefaultOption
OPTION EPILOGUE:DefaultOption

end start


call it like this:



invoke atodw,addr yourtextnumber


cya,
-NOP-
Posted on 2002-06-28 07:56:59 by NOP-erator
NOP-erator.Thank you for reply.
I have tried to put the code in my program, but a error occured unfortunately. It crashed immediately after I input the textnumber and hit return. I wonder if the problem is my O.S.;I am using Windows98 second edition.
I am still working on it right now. I try to figure out what did I do wrong. after all, I may make some stupid mistakes since I am new on WIN32ASM programming.

CODE==>
atodw PROTO :DWORD
..
invoke GetDlgItemText,hWnd,IDC_EDTText,addr textnumber,4
invoke atodw,addr textnumber
...
atodw proc FORCENOFRAME
;----------------------------------------
; Convert decimal string into dword value
; return value in eax
;----------------------------------------
; String EQU
mov edx,
xor eax, eax
cmp BYTE PTR , 2Eh
sbb , edx
adc edx, eax
jmp @F
again:
lea eax,
inc edx
lea eax,
@@:
movzx ecx, BYTE PTR
cmp BYTE PTR , 30h
jns again
add eax,
xor eax,
retn 4
atodw endp
Posted on 2002-06-28 15:55:09 by ssa
it seems that you left out this "OPTION" commands, sorry, but i even don't know what they're for. if you paste the code with the OPTION commands then you don't need to set a PROTO on that function.

but in your case try this:



atodw PROTO :DWORD
..
invoke GetDlgItemText,hWnd,IDC_EDTText,addr textnumber,4
invoke atodw,addr textnumber
...
atodw proc txtptr:DWORD
;----------------------------------------
; Convert decimal string into dword value
; return value in eax
;----------------------------------------
; String EQU [esp+4]
mov edx, [esp+4]
xor eax, eax
cmp BYTE PTR [edx], 2Eh
sbb [esp+4], edx
adc edx, eax
jmp @F
again:
lea eax, [eax+4*eax]
inc edx
lea eax, [ecx+2*eax-30h]
@@:
movzx ecx, BYTE PTR [edx]
cmp BYTE PTR [edx], 30h
jns again
add eax, [esp+4]
xor eax, [esp+4]
retn 4
atodw endp


i don't know what this "retn 4" is for, i always use "ret". perhaps you could change that, too, if this doesn't work.

bye
Posted on 2002-06-29 04:31:23 by NOP-erator
NOP-erator, thank you for your help.
It works now.
I include all the "OPTION" into the code and add a PROTO in the include file.
what did I do wrong is I didn't put the code at the end of the program.
Thank you! and have a nice day!
Posted on 2002-06-30 22:46:28 by ssa