yo. i want to format a string so is has a comma "," every three spaces going from RIGHT TO LEFT
ex. ss,sss,sss,sss,sss
how am i to do this?
Posted on 2002-05-12 16:04:55 by Qages
Posted on 2002-05-12 16:10:37 by Thomas
doesnt work too well, comes up as xx,,xxx,xxxxxx
Posted on 2002-05-12 16:25:18 by Qages
Hmm you'll have to ask The Svin about that, it's his algo. It shouldn't be too hard to think of an algo yourself though.

Posted on 2002-05-12 17:13:13 by Thomas
line lea edi,[1] needs to be lea edi,[0] , and a comma isput at the end, but i can fix that
Posted on 2002-05-12 17:18:31 by Qages
it also very slow, any way to speed it up? it makes my program run 2x slower
Posted on 2002-05-12 17:35:32 by Qages
Qages... I get more and more annoyed by your posts. They are just getting more like "do this, do that, I don't want to try it".

IF you have a problem (and it seems like you have a lot of them), please first post YOUR approach how to solve it. The learn-effect is much higher if we fix a bug in code YOU wrote. Not if you use code WE wrote and complain about speed/size/functionality/whatever.


Posted on 2002-05-12 18:07:17 by bazik
ok dude if you dont want me here i wont come.
Posted on 2002-05-12 18:09:55 by Qages
oh and i learn best by what other people do, i wont come to a fourm where prejustice against my ways are so clear.
Posted on 2002-05-12 18:13:07 by Qages

ok dude if you dont want me here i wont come.

I did not say, that I "don't want you".
My simple advice is:
First try to solve a problem by yourself. Then, if you can't do it post your work here... and perhaps we can complete it to let it work as wanted. Writing a simple string formater wich adds a comma every three chars is just a 10min work if you read at least Thomas' and Iczelions tutorials (and perhaps NOP-erators string tutorial). Or to be clear: With a basic knowledge of ASM programming... you wont have a problem to write such simple routines. And remember always what hutch wrote on his homepage:

MASM32 is not intended as a programming beginners package, it is squarely aimed at experienced programmers who are familiar with windows API programming with compilers and have done some work in assembler. The package assumes that the programmer already knows enough to start working in assembler and is designed with this level in mind. Any programmer is welcome to use MASM32 but unless they have the experience level that is assumed in the design of MASM32, concepts like register sizes to data types, register usage, assembler mnemonics, API calls, calling conventions and other similar technical data will be very difficult to grasp. Programming beginners are better served by learning a higher level language first and when they are familiar enough with the technical concepts involved, they can come back to assembler later.
Posted on 2002-05-12 18:19:11 by bazik
in response to the quote: im not a newbie programmer, i can do vb, and im a low expert in it. i also did work in asm too befor masm, but i cant talk about it because its illegal.

also and to be clear, puting a comma every 3 spaces is not a 10 min job to me. I did try to solve it on my own, but i had no luck on it. and ok ill post fragments of my code that i tryed.
Posted on 2002-05-12 18:36:43 by Qages

There is no plot against you here, just a comment that if you want to write assembler effectively, you will have to learn how to do some of these things. String functions and parsing string data can be complicated depending on the task and what you really need is a good grasp of how general purpose string manipulation works, then you can write your own to do what you need.

Most of the older guys here did this the hard way when the internet was not available, write it, test it and see what the function you write does.

If you want to do this type of work in assembler, start looking for information about string manipulation and start writing some test pieces to become practiced at it. This way you will get a lot better at it and you will not need much help at all.


Posted on 2002-05-12 19:11:38 by hutch--
Here is fixed version. (changes made by Qages don't solve the problem it just created another one)

Qages, the only reason it might seemed slow to you it is if
you used it for long string.
An explonation:
the function was aimed to be used for number periods separation,
were length is short (from one to 11 bytes) that's why division was replaced with substruction. With short string it is much faster
for example div 10 by 3 using substruction would take ~ 6-8 clocks. div 2 by 3 ~ 1 clock. While using div it would be upto 40 clocks. But with long numbers sub division might be as slow as value of devident*2,5. Of course in this case (the case that would not occur in situation where the proc was intended to be used) it's better replace it with mul division since constant is known.
If you are not able to code it for long strings, I can do it for you.

As for speed using with numbers this function showed results 10 times faster than closest to it in former contest in algo section.

OK here is fixed proc inside test program:

string1 db '1234567890',0
string2 db 16 dup (0)

InsertComma proc uses esi edi len,lpszStringIn,lpszStringOut
mov esi,lpszStringIn
mov edi,lpszStringOut
mov ecx,-1
mov eax,len
@@: inc ecx ;number of commas
sub eax,3
jnbe @B
test ecx,ecx ;if length less than 4
je @0
mov edx,[esi]
add eax,3 ;reminder
mov [edi],edx
lea esi,[esi][eax][-1]
dec ecx
lea edi,[edi][eax]
je @l4
@@: mov eax,[esi]
add esi,3
mov al,2Ch
dec ecx
mov [edi],eax
lea edi,[edi][4]
jns @B
jmp @r
mov byte ptr [edi],2Ch
mov eax,[esi+1]
mov [edi+1],eax
@r: ret
@0: mov eax,[esi]
mov [edi],eax
jmp @r
InsertComma endp

invoke InsertComma,sizeof string1-1,offset string1,offset string2
invoke MessageBox,0,offset string2,0,0
call ExitProcess
end start
Posted on 2002-05-12 20:03:58 by The Svin
Does this condensed version hamper the speed any?
InsertComma PROC uses esi edi len,lpszStringIn,lpszStringOut

or ecx,-1
mov eax,len
mov esi,lpszStringIn
mov edi,lpszStringOut
@@: inc ecx ;number of commas
sub eax,3
jnbe @B
mov edx,[esi]
; remainder & back one for 2Ch in low byte of EAX loop below
lea esi,[esi][eax][3][-1]
mov [edi],edx
dec ecx
; remainder & back four for ADD before MOV in loop below
lea edi,[edi][eax][3][-4]
js @r ; if length less than four we are done
jne @F
mov byte ptr [edi][4],2Ch
mov eax,[esi+1]
mov [edi+1][4],eax
jmp @r
@@: mov eax,[esi]
add esi,3
mov al,2Ch
add edi,4
dec ecx
mov [edi],eax
jns @B
@r: ret
InsertComma ENDP
Also, how do you ensure zero termination for string after the multi-comma loop?
Posted on 2002-05-12 21:27:07 by bitRAKE
Why ask me :)
Rickey, you are always progressing very fast when writing test.
So do it.
There is help from our mind (when we think) and additional help from our eyes to our mind (when we test).
Posted on 2002-05-12 21:33:08 by The Svin

Why ask me :)
Tests for you are not the same as for me. How do you ensure zero termination for string after the multi-comma loop?
Posted on 2002-05-12 21:39:15 by bitRAKE
If sourse string is zeroterminated the zero is aoutomaticaly passed with last dword (it sends last 3 bytes + 1 and this one is zero by terms)
oops I'm wrong :) it's only for <= 3 and <= 6 case.
lets write it before ret.
mov byte ptr ,0
Posted on 2002-05-12 21:42:17 by The Svin
Svin & BitRAKE,
Sometimes I feel like a 5 year old listening to my parents talk :)

Don't often understand the conversation, but I figure if I listen long enough I'm sure to learn something :) Well, it never happened from my parents, but I still listen every now and again :)

One day I hope to be able to post something someone finds interesting in the Algo. and Source sections -- until then keep up the good work, both of you...

Anyway, Got to get back to work :) Hope this conversation continues (hence why I replied)

If not I'll wait for the next one...

Posted on 2002-05-13 23:09:00 by Sliver
No Sh*t Sliver,

This is the board i know.

The Warriors are Back ... Again ...

I love the way they light the Fire :) :) :)

Posted on 2002-05-14 00:25:19 by cmax
Am I the only one wich is always suprised about what cmax get's in mind the last days? :eek:

Posted on 2002-05-14 08:38:12 by bazik