it just keeps on looping:mad:

mov ecx,0

mov eax,3
.while ecx != eax
invoke MessageBox,0,0,0,0
inc ecx
.endw
Posted on 2002-01-23 01:10:20 by smurf
Hi smurf !

because the MessageBox API does modify the registers... just try with some others (esi, edi, for example), but be aware that some of them MUST be preserved.
Posted on 2002-01-23 01:20:39 by JCP
Well thats an odd program...

But anyways... MessageBox needs to have a "text" to place in the message box, so the second "0" (NULL) must be the offset/address to some null terminated string.. It will at least work at this point.

Your uses of the while loop confuses me tho. And furthermore, the MessageBox API has not promises that the ECX and EAX will not be altered from the call. So its quite possible your incrementing a different number after every loop.

However, i actually compiled this, and it does exit after the first message box (so eax == ecx after this API).

But the while structure is correct. ?
NaN
Posted on 2002-01-23 01:27:35 by NaN
ok thank you it works now. but what i dont understand what you mean by the MessageBox not being able to modify the registers. i actually just put that there as a placeholder because the contents i originally had is much longer.
Posted on 2002-01-23 01:28:34 by smurf
My butter fingers (a bit), the word "promises" should be "promised"...

But anyways, ALL WINDOWS API CAN AND FREELY WILL alter EAX, ECX, EDX when it feels it wants to! :grin:

This lack of preservation in the API's is (i guess) a M$ form of speeding up the bloat. It can be DAMN annoying at times when your debugging, because its easy to assume that "ecx" didnt change after invoking GetDC or something. But surprise! M$ gotcha there, and your punishment is 4 hours of your life in return!! :rolleyes:

heheheh... think everyone has seen that scenario at least once...

NaN
Posted on 2002-01-23 01:45:03 by NaN
ok here's a different verson:



invoke SendMessage,hRichEdit,EM_GETLINECOUNT,0,0 ;get the total amout of lines of text in a richedit
mov edi,eax ;mov the total into edi (for my testing the count is 3)
mov esi,0 ;zero out the counter
.while esi != edi
invoke MessageBox,0,0,0,0
inc esi
.endw


now what i would like to do is have my Message Box diplay a number. the first one should display a 1 then the next a 2 and the 3rd a 3. the reason for this is because i have 3 lines of text in my richedit control and i want to count each line. can someone help me out with the code. im been adding and trying different ways but it got really messy so i just posted the code without all the extra testing.
Posted on 2002-01-23 02:02:07 by smurf
NaN,

heheheh... think everyone has seen that scenario at least once...


Oh, yeah. :tongue:

Smurf,

now what i would like to do is have my Message Box diplay a number. the first one should display a 1 then the next a 2 and the 3rd a 3. the reason for this is because i have 3 lines of text in my richedit control and i want to count each line. can someone help me out with the code. im been adding and trying different ways but it got really messy so i just posted the code without all the extra testing.


Use wsprintf (using "%d" conversion format) or an optimized conversion snippet from the m32lib (dtoa, or something like that, I suppose).
Posted on 2002-01-23 02:08:50 by JCP
thanks guys i really appreciate the help. been working on this for a long time today.

here's what my final code looks like
invoke SendMessage,hRichEdit,EM_GETLINECOUNT,0,0

mov edi,eax
mov esi,0
mov edx,0
.while esi != edi
inc edx
push edx
invoke wsprintf,addr StoreCount,addr fmtGetCount,edx
invoke lstrcat,addr StoreCount,addr EndOfLine
invoke SendMessage,hRichEdit1,EM_REPLACESEL,FALSE,addr StoreCount
pop edx
inc esi
.endw
Posted on 2002-01-23 02:12:57 by smurf
You can use less code than that... less registers, and less incs...
Use "xor register, register" to set a register to zero instead of "mov register, 0"... nowadays it is not much better but If I remember well there is still some avantages to doing it this way (better pairing, and less bytes taken... but I'm not 100% sure of what I say... and I don't have my debugger right now to check) and it is somewhat a "convention".

I'm not talking about "optimizations", I just see some useless code here...

I let you search a bit... ;)
Posted on 2002-01-23 02:28:07 by JCP
EBX is preserved as well. Eliminate the push/pop by using EBX.

The preservation/nonpreservation policy is a compiler convention. By preserving some, and not others, the compiler can potentially use registers better than with all-saved or none-saved policies.
Posted on 2002-01-24 21:23:22 by tank