'Cause Mirno started on stack frames,
I post new version in frameless format
though it is actually stdcall procedure and will
work correctly with standard proto.
I post it inside test prog so you can see how it should be
done with Mirno macros to produce correct result.
Apart of this stack frame stuff, the prolog of the
proc has been changed, it reduce branching on start while
checking if there is "-" sign before number characters.
Actually, there is not segnificant speed improvment -
I reduce 9 instructions to five but not in the loop, and also
avoid flashing on first time jcc ('cause now here is no jcc at all
in prolog).
Yet I think the tecnique itself might be interesting for those who seriously interested in implementation of some algos in ASM.
In different case it might lead to more segnificant results.
No here it a new version:


;#########################################################################
.586
.model flat,stdcall
option casemap:none
include C:\masm32\include\windows.inc
include C:\masm32\include\kernel32.inc
includelib kernel32.lib

NO_PRO MACRO
OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE
ENDM

DEF_PRO MACRO
OPTION PROLOGUE:PrologueDef
OPTION EPILOGUE:EpilogueDef
ENDM

atodw PROTO :DWORD
.data
numb db '-2',0 ;try here different pos and neg numbers
.data?
.code
start: invoke atodw,offset numb
call ExitProcess

; #########################################################################
NO_PRO
atodw proc FORCENOFRAME
;----------------------------------------
; Convert decimal string into dword value ; return value in eax
;----------------------------------------
String equ [esp+12]
push esi
push edi
xor eax, eax
mov esi, String
xor ecx, ecx
; xor edx, edx ;here is old code commanted
; mov al, [esi] ;so you can compare it with new one
; inc esi
; cmp al, 2Dh
; jne proceed
; mov al, byte ptr [esi]
; not edx
; inc esi
; jmp proceed
cmp byte ptr [esi],2Eh ;if it's not number
sbb edx,edx ;edx=0 if it was number and FFFFFFFFh if it was not
adc esi,1 ;esi+1 if edx = 0 and first chr was number ; esi+2 if first chr was not number
mov al,[esi-1] ;mov al first symb. if first was number and second if it was not number
jmp proceed
again:
lea ecx, dword ptr [ecx+4*ecx] ;ecx=ecx*5
lea ecx, dword ptr [eax+2*ecx] ; ecx = ecx*2+eax or privious ecx*10 + eax
mov al, byte ptr [esi]
inc esi
proceed:
sub al, 30h
jns again
lea eax, dword ptr [edx+ecx]
xor eax, edx ;if edx -1 it will negate result
pop edi
pop esi
ret 4
atodw endp
DEF_PRO
; #########################################################################

end start


Well, I think, I should say for the beginners that 'cause the app
doesn't have any output you should look in a debugger how it works.
And if you still never used debbuger - you're moving in the wrong
direction.
Posted on 2001-08-13 02:14:18 by The Svin
The Svin, vot tak..


push esi
mov eax, String
mov dl, [eax]
xor ecx, ecx
cmp dl, 2Eh
lea esi, [eax-1]
sbb edx, edx
mov eax, ecx
again:
adc esi, 1
lea eax, [eax+4*eax]
lea eax, [ecx+2*eax]
mov cl, [esi]
sub ecx, 30h
jns again

add eax, edx
pop esi
xor eax, edx
ret
Posted on 2001-08-14 01:14:52 by buliaNaza
That's better.
It was pleasure to analyze the improvements.
I hope to see you again
Posted on 2001-08-14 02:49:39 by The Svin
Well, your code looks nice,
that's why I hate to say it that this one runs
~20% faster for some reason :)
Yet some solution you preposed is stylish and
effective, I left those of them that make positive effect
in the very proc.



mov eax, String
push esi
mov dl, [eax]
xor ecx, ecx
cmp dl, 2Eh
mov esi, eax
sbb edx, edx
mov eax, ecx
adc esi,0
jmp @F
again2:

lea eax, [eax+4*eax]
lea eax, [ecx+2*eax]
@@:
mov cl, [esi]
inc esi
sub ecx, 30h
jns again2

add eax, edx
pop esi
xor eax, edx
Posted on 2001-08-15 00:53:57 by The Svin