hossa

i found 2 routines for string converting.
here they are:

;*******************************************
.code
Dword2String proc
;ENTREE: eax=Nombre a convertir, edi= Pointer vers resultats
;SORTIE:edi=pointer vers resultat
XOR ECX,ECX ; conversation hexa -> ascii (d?cimale)
XOR EBX,EBX
MOV ebx, 10
MOV ECX,0AH

BOUCLE:
XOR EDX,EDX
DIV ECX
ADD DL,30H
CMP DL,3AH
JL POST
ADD DL,7

POST:
DEC ebx
MOV byte ptr ,DL
OR EAX,EAX
JNZ BOUCLE
dec edi
Vire_Zero :
inc edi
cmp byte ptr , 0
je Vire_Zero
ret
endp
;*******************************************
.data
String dd 0
Result dd 0
.code
String2Dword proc uses ecx edi edx esi
mov Result,0
mov edi,String
call lstrlen,String
.while eax!=0
xor edx,edx
mov dl,byte ptr
sub dl,"0"
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 Result,eax
pop eax
inc edi
dec eax
.endw
mov eax,Result
ret
String2Dword endp
;*******************************************
Posted on 2001-12-21 04:23:54 by Max
They are both as slow as hell.
Check the M32lib from Masm32.
Posted on 2001-12-23 23:33:42 by The Svin
the svin and me coded a reasonnably fast h2dw routine, you can find it on my website (http://www.effervescence.com)
Posted on 2001-12-24 10:23:30 by roy
A little thought about that rutin.
It can be done without branching if only capital hex simbols
alowed(ABCDEF).
than to get a value from simbol this code may do it without jcc
assume hex simbol is in al

cmp al,'A'
sbb cl,cl
sub al,'A'-0Ah
and cl,7
add al,cl
it altogether 4 clocks
and not predicted jcc will cost from 9 to 16 clocks
so in average case it shuld be faster.
Posted on 2001-12-24 10:38:15 by The Svin
This will be even faster:



CMP EAX,'A'
SBB EBX,EBX
AND EBX,'A'-'9'-1
LEA EAX,[EAX+EBX-'A'+10]
Posted on 2002-03-28 18:06:52 by Maverick
Speed the same - 4 clocks.
But yours 1 byte longer (12 bytes against my 11)
Posted on 2002-03-29 12:56:04 by The Svin
You forgot to mention that it's 1 instruction shorter: which in almost all CPU's (but the outdated and obsolete old Pentium) will result in faster execution.

Also, even being same speed (I didn't test so I can't say), having less instructions means one can possibly have more extra free slots to pair with something, to improve overall performance even of those old Pentiums (that at least here in Italy are so rare to see that sometimes you even doubt they ever existed).

But anyway, we can modify this:


CMP EAX,'A'
SBB EBX,EBX
AND EBX,'A'-'9'-1
LEA EAX,[EAX+EBX-'A'+10]

To this:


CMP AL,'A'
SBB EBX,EBX
AND EBX,'A'-'9'-1
LEA EAX,[EAX+EBX-'A'+10]


Which saves 3 bytes of precious hard disk space. ;)

You use the 5 instruction version though, fine.
I know where the problem really is, anyway. :)
Posted on 2002-03-29 17:53:48 by Maverick
Now it is the same size and speed.
Number of instructions means nothing but number of lines in source code (if no macros involved).
You know that better than me.
Posted on 2002-03-29 18:16:42 by The Svin
Ok, let's talk serious.. anyway, on Athlons the 5 instructions one is 3 cycles, the 4 instruction one is 2 cycles.
Posted on 2002-03-29 18:33:53 by Maverick
It's true IF(and only IF) they are executed in parallel.
To do so they need to be independant.
That's why both of codes here takes 4 clocks.
Cause in 5 instruction code there are pare of independent instructions. While in 4 instruction code all instructions are dependant.
So IF in real code you get a chance to insert four independent instructions, wich are no harm to flags you need, processor will be
able to execute 8 instructions (four to conv. hex and four additional) for 4 clocks.
In my code IF I find a chance to insert 3(!) independant instructions they will be able to be executed also for 4 clocks.
So actually you have a little chance to make use of the fact that
you have 4 instructions instead of 5 - and the chance is not to make this very code faster, but to insert one more independent instruction to be executed in parallel.
With 5 instruct code:
cmp al,'A' ;1
nop ;0 1st additional inst
sbb cl,cl ; 1
sub al,'A'-0Ah ;0
and cl,7 ;1
nop ;0 2nd additional inst
add al,cl ;1
nop ;0 3rd additional inst
;alltogether original code + 3 additional inst for 4 clocks
and your code you can insert nop after each original instr
so it would be
alltogether original code + 4 additional inst for 4 clocks

1 more additional instruction in your favor to be executed in parallel with the original code for the same 4 clocks.
But first you need find 4! additional instructions with no harm for
flags and sence that they need to be executed in this part of code
anyway.
Posted on 2002-03-30 05:14:33 by The Svin
It's true IF(and only IF) they are executed in parallel.
To do so they need to be independant.
That's why both of codes here takes 4 clocks.
Cause in 5 instruction code there are pare of independent instructions. While in 4 instruction code all instructions are dependant.
I see it as "greater density" which gives a potential advantage. It still do not understand if you consider your 5 instructions version superior in some regard to my 4 instructions version, or vice versa.
1 more additional instruction in your favor to be executed in parallel with the original code for the same 4 clocks.
Finally you admit it wasn't just a source-length advantage.. we're making progresses.
But first you need find 4! additional instructions with no harm for
flags and sence that they need to be executed in this part of code
anyway.
So in plain English my code has an 4 vs 3 extra slots advantage (which clever coders will have no big problems to exploit, and will surely appreciate more than ignore) but you will keep on using your 5 instructions one because the 4 instructions ones was written by me? :)

Also, for you there seem to exist only Pentium CPU's. It seems of no importance for you that on Athlons (a very clever CPU) my 4-instrs code is 50% faster when inserted into a real world application. It seems irrelevant to you, why?
Posted on 2002-03-30 05:41:44 by Maverick
There is an old rule from motor racing, "When the flag drops, the bullshit stops."

Benchmark them on different boxes and see which is going the fastest.

Regards,

hutch@movsd.com
Posted on 2002-03-30 08:09:51 by hutch--
.Steve,
There is nothing to benchmark.
In another thread were already found better ways to convert hexstring to value in much more effective way than both versions of code here.
Meveric just has a talant to turn any discussion regarding size and clocks to discussion "WHOM is better", making clouns of himself and the person who he is talking to. This always ends to forgetting subject of discussion and starting descussion of personality.

If you care to reread last 8 posts it would become clear to your.
Here is 4 Meveric statements and 4 my replyes. And last Meveric post(9th) is wich trying to make those 8 posts something else than they are.

1.He posted code of bigger size and called his code shorter
2.I just named size and clocks for both code. No a word more.
3.He changing his code so that now it has the same size
4. I confirmed : "Yes now it is the same size" No a word more.
5. He stated that I forget about number of instructions.
6. I explained that size and speed is matter not instructions.
Code couldn't be measured by instructions, only by clocks and size
(for sure anybody would prefer 2 movs instead of 1 div)
7. Now he went unexplicitly on way that instruction execution in parallel and 4 is less than 5.
8. I just felt sorry for him, explain how he can count it, and helped
to find some vage possibility to advantage of his code.

What I got in his replied post just shocked me.
Sorry man, may be he is just pure sick man who is suffering dislexia and halluciantions but it's annoying.
Maveric,
Good luck and good bye. You are in my ignore list, so don't bother anymore.

I hope you are happy now, that such abrivated piece of nothing
as I am won't bother you anymore
;)
Posted on 2002-03-30 11:36:48 by The Svin
It's useless to read your attempted-to-be-constructed-at-art wannabe virtual quotes, and funny to hear such hypocrit statements from you who's the one that in a (in)famous thread intentionally removed "think" at the end of "I'm less ignorant than you" .. "think". Which changes the meaning completely.. you naughty guilty Svin. ;) There are better ways to show that oneself is right, and when one is not, it's better to shut up instead of trying to false things, my friend.

You now nag on me because after all the stupid polemic you made against me (just because of a personal problem you have against me), I served you well exactly as you deserved.. and YOU make a clown of yourself, first throwing out "technical" pedantic notes (code length), then not accepting them on the same ground (instructions count, pairing possibilities, performance on anything but a crap old obsolete Pentium).

Try..
I hope you are happy now

Catch..
that such abrivated piece of nothing as I am won't bother you anymore

Finally.. ;)

But more than that kind of self-pity I would have appreciated some simple honesty.

ExitProcess 0
Posted on 2002-03-30 16:57:33 by Maverick