Hi Satrukaan,

1) You seem to call dispatchMessage once without a GetMessage. This seems like a felony to me, how do you get away with it.

Its simple, the function call fails the first time its called but works on every other time its called. I used this technique to get a shorter message loop in terms of instruction count.

2) In your first example the pointer you send to RegisterClassEx was in the stack, and you restored the part it was in right after. Does this mean that RegisterClassEx makes a copy of the WNDCLASSEX structure. If so then couldn't you have one copy of the structure and modify it for each call to RegisterClassEx you need to make?

Using the seperate function in the first example is not a problem, all the components of the WNDCLASSEX structure are parameters for the RegisterClassEx function so they only have to be passed once. The operating system already stores the starting address so the class gets registered without any problems at all.

I agree with Maverick's view on C, its just a language that has no particular divine right, even if some see it that way, I see it as too old and too inflexible by modern standards.

BuliaNaza is right on the original subject being discussed here, "TO PRESERVE REGISTERS OR NOT".

I have argued by example that the authodox method of constructing a program has size speed and reliability going for it and this includes preserving registers by the authodox published method.

Its not that I deny anyone the capacity to use original ideas or do things differently but I differ as to prescribing it as a method that other people should use over proven documented technology.

I am of the view that there must be some advantage in using a different technique from authodox and unless there is, you risk unreliable code for no purpose.

Regards,

hutch@movsd.com
Posted on 2002-06-08 23:25:09 by hutch--
lol, thanks for the answers, I think that clears up a lot.

But as regards to C and what not, I didn't mean to imply that C was the best. I just ment that if it didn't matter whether you right fast assembly code around ExitProcess or slow assembly code, then it shouldn't matter if you write it in assembly or C.

buliaNaza, I agree with you in the fact that all this is a is a matter of style, but you also seem to imply that optimizing code that a lot of people are saying doesn't need optimizing is intrical to your line of work. I'm just curious as to what you do that requires such tuned assembly programs?
Posted on 2002-06-09 00:45:10 by Satrukaan
buliaNaza: you've serious attitude-problems:
You just don't know what you are talking about..
I don't have time to mess with kids, so I'll stop here. Also, other than respect for my precious time, I have respect for your precious time.. otherwise how will you optimize the code around ExitProcess? :grin:

And since you think you're a God but you're just 1.0/God, take this easy advice and improve on your long source posted on the 1st of June on this same thread (no, not the one for newbees, but the one for 37337 wannabes like you), and optimize for example your code:



;Register the Main window class ;
...
mov dword ptr [esp-(5+0)*4], 0 ;
...
mov dword ptr [esp-(8+0)*4], 0 ;
...
;Create the main window ;
mov dword ptr [esp-(1+0)*4], 0 ;
mov [esp-(2+0)*4], esi ; esi->hInstance
mov dword ptr [esp-(3+0)*4], 0 ;
mov dword ptr [esp-(4+0)*4], 0 ;
...
mov dword ptr [esp-(12+0)*4], 0 ;
...
WinMainWait: ;
lea ecx, [esp- (4+0)*4] ; loading auto stack
mov [esp-(5+0)*4], offset WndProc ; last return -> WndProc
mov dword ptr [esp-(6+0)*4], 0 ; 3 zeros are parameters
mov dword ptr [esp-(7+0)*4], 0 ; of GetMessage
mov dword ptr [esp-(8+0)*4], 0 ;
to:


xor edx,edx ; HORROR!!! what?????? a k00l 37337 c0der like you doesn't know this?????
... ; what happened??? you didn't feel like Registering the Main window class
... ; required that much of optimization effort? Or you just weren't capable? ;D
mov dword ptr [esp-(5+0)*4], edx ;
...
mov dword ptr [esp-(8+0)*4], edx ;
...
;Create the main window ;
mov dword ptr [esp-(1+0)*4], edx ;
mov [esp-(2+0)*4], esi ; esi->hInstance
mov dword ptr [esp-(3+0)*4], edx ;
mov dword ptr [esp-(4+0)*4], edx ;
...
mov dword ptr [esp-(12+0)*4], edx ;
...
WinMainWait: ;
lea ecx, [esp- (4+0)*4] ; loading auto stack
mov [esp-(5+0)*4], offset WndProc ; last return -> WndProc
mov dword ptr [esp-(6+0)*4], edx ; 3 zeros are parameters
mov dword ptr [esp-(7+0)*4], edx ; of GetMessage
mov dword ptr [esp-(8+0)*4], edx ;
that would fit your wannabe-37337 "coding style"..
So much for your not wanting to preserve one register (but if you were smart, and you aren't, you would avoid also that xor edx,edx and track down a register with 0 value.. I even saw a xor edx,edx after your WinMain label!), make the code faster for a number of reasons, and will also save a lot of bytes.. hey, I hope you don't use a linker, but have your own PE generator, otherwise code will be anyway FILEALIGNED, and all will be useless.. don't you know?

But the real size problem here is that you got a big Posted on 2002-06-09 04:58:34 by Maverick
Sorry Maverick that i brought your name up but it's always good to hear you speak and no one can do it better...Your are not known to be a very nice guy when you get piss either.

buliaNaza, you are great but us little people want to learn too. My only friends are Dead Presidents and i don't have enought of them.

I am out of here, i will never stand between true Code Warrior as you guys are.

Posted on 2002-06-09 05:50:26 by cmax

Sorry Maverick that i brought your name up but it's always good to hear you speak and no one can do it better...Your are not known to be a very nice guy when you get piss either.
hehe.. yep, I'm hot blooded.. but I learnt that one has to give respect to the others.. so I do, unless I see that somebody doesn't do it, and I like to pay the same coin back in that case.
Perhaps I could have avoided my post to buliaNaza, but I hope he understands that his attitude is very wrong, and that he should be more friendly to others, instead of looking like that 37337 crap.
At the end he will be a better person if he is constructive instead of being destructive, given that nobody had treated him bad before.
Posted on 2002-06-09 06:46:58 by Maverick
Cmax,
Do you remember:;)
"Hello buliaNaza ,
Can you post a small example with some comments please?"

" Hi, cmax
Of course, I can post an example but the question is WHY?"

Now you can see what happens...I'm guilty for my answer...




Satrukaan,
"..I'm just curious as to what you do that requires such tuned
assembly programs?"
you can take a look here: h**p://ati.com/




Hutch,
"Its not that I deny anyone the capacity to use original ideas or
do things differently but I differ as to prescribing it as a method
that other people should use over proven documented
technology."

"..method that other people should use..."
Why do you think so? I never wrote such things and don't care
about other's programming styles, languages and methods,
because it is not my business...
I am not a teacher or "guru"...

"... proven documented technology..."
Ha, ha.. just read Matt Pietrek's book and articles.



Maverik,
this is a FAST and UNOPTIMIZED example and its goal was
just to prove the original subject being discussed here,
"TO PRESERVE REGISTERS OR NOT".
I created it using copy and paste of different parts of
UNOPTIMIZED code because it is just an example NOT a
program...
I want to thank you for your impressive answer of my question
"...how you appreciate unknown people from different cultures..."
because I learned a bit more who is who here...

;)
Posted on 2002-06-09 09:27:48 by buliaNaza
buliaNaza again:
this is a FAST and UNOPTIMIZED example
Do not make even more a fool of yourself.. such trivial optimizations do not need to be made on a second phase.. you just didn't make them, period, but you bothered those that push/pop a couple of registers they use around a call to a slow Win32 API function, using your 37337 attitude against them. Those are the simple facts. Otherwise I would have never bothered to write that reply.

I do respect other peoples and other cultures, I just can't respect who doesn't know the meaning of this word.

Goodbye.
Posted on 2002-06-09 15:45:18 by Maverick
"I do respect other peoples and other cultures, I just can't respect who doesn't know the meaning of this word."


bitRAKE to Maverick:
"I am just curious of how you reach your conclusions?"



The_Svin to Maverik:

"You have a talant man to turn any sientific discussion into personal things Meveric, when somebody tries to analyze(or
critisize) my method (or thoughts) or beat my code I take it as
sign of respect, 'cause it is ferm fact that he wasted his time
(found worthy to waste it) to follow and study my things.
Why almost any negative comments about your things you take
as a personal insults?"


Maverik to The_Svin:

Are you blind or what? That's what I did.. I compared all methods
on 64 iterations, not 256. So what are you trying to say now? "


bitRAKE to Maverick:

"No, I'm speaking of the method that buliaNaza has posted
BT/JNC. It is the only two instruction method posted above - I
could call you 'blind' here, but it would only serve to admit my
extreme dis-like for your words to Svin - he can take care of
himself."



Maverik to The_Svin:

"Dammit, you must be stupid.. 64 iterations test for all 64
possible bits in the bitmap.
Hello? Is anybody home? "



bitRAKE to Maverik:
"Solve this problem for me: How can both of my comments be
correct? I am not in the habit of contradicting myself. You make
broad assumptions of Svin and myself. Not that I am not guilty of
the same. I would hope that we can learn to communicate well,
for there is much that we should learn from each other. There is
nothing more important for me!"


will be continued...;)
Posted on 2002-06-09 17:11:37 by buliaNaza
Putting phrases out of their context to prove that you're even more a lamer is what fills my today's daily laugh. :grin:
Posted on 2002-06-09 17:16:32 by Maverick
"wannabe elitish stupidity"

"Also, often that kind of coders are also lame at the end,"

"Wannabe 37337 EGO sucks."

"buliaNaza: you've serious attitude-problems:"

"I don't have time to mess with kids, so I'll stop here.
Also, other than respect for my precious time, I have
respect for your precious time.. otherwise how will you optimize
the code around ExitProcess? "

"And since you think you're a God but you're just 1.0/God"

"the one for newbees, but the one for 37337 wannabes like you"

"that would fit your wannabe-37337 "coding style".."

"but if you were smart, and you aren't,"

"here is that you got a big EGO. "

"F*ck, you must be really a pityful lamer with a big and ineducated mouth"

"and leave the 37337ism to the lamers,"

"hehe.. yep, I'm hot blooded.."

"but I hope he understands that his attitude is very wrong, and that he should be more friendly to others, instead of looking like that 37337 crap."

"Do not make even more a fool of yourself"

"using your 37337 attitude against them."

"to prove that you're even more a lamer"
Posted on 2002-06-09 17:39:25 by buliaNaza
Yes, and you deserved all of them, because you started it.

Now please go code something, and don't forget the basic optimization rules. :grin:
Posted on 2002-06-09 18:21:31 by Maverick
Yes, sir!:grin: :grin: :grin:
(don't bother him because he is seriously sick)
Posted on 2002-06-09 19:00:10 by buliaNaza
You are right buliaNaza, but i am glad that you replied. It is of great interest as it is. A whole lots of people used to be big headed with there source samples and you are not the only one that had said things that may hurt other people feeling.... But people did also come in saying things that may hurt your feeling also. You guys are too HEAVY for this to continue. i wish ya would stop and get back to the business of optimization. It would be like WoW if two minds of you guys caluber were to work together they have to re-write the art of programming for the betterment of ALL... No one man is always right. But no more match making for me.

I am out of here and thanks again buliaNaza.
Posted on 2002-06-09 20:42:48 by cmax
Thanks cmax,
You are welcome...;)
Posted on 2002-06-09 20:59:56 by buliaNaza
buliaNaza, I value the example you have posted and it has given me much to think about. Do you design with these severe optimizations in mind at the start, or does the code evolve into this state, or both? I would need many notes on what is going on to make changes easier, but maybe with this being your style, you have become accustom to the level of convolution.

buliaNaza, you can see when I say, "In the world all the matters is what gets the job done", this applies to your code - because you believe your job does require this level of optimization. I still have not found why your first example loads so slow.
Posted on 2002-06-09 21:42:22 by bitRAKE
Hi bitRAKE,;)

"Do you design with these severe optimizations in mind at the start, or does the code evolve into this state, or both?"

The original subject being discussed here is
"TO PRESERVE REGISTERS OR NOT".
So, I expected questions like this:
"Why you can write
mov edi, 12345678h
mov esi, 12345678h
mov ebx, 12345678h
mov ebp, 12345678h
and Hutch can't?"
For me that is the main question here rather optimization, styles, bla, bla, etc.

Please allow me to answer you with question:
Did anyone understand why?;)
Posted on 2002-06-09 22:22:44 by buliaNaza
buliaNaza, I sorry, but I don't understand to which question you are referring. I did not ask the question in your reply!? "TO PRESERVE REGISTERS OR NOT" - I think you have answered. :)
Posted on 2002-06-09 22:35:32 by bitRAKE
What a hot discussion!.. :)
The first question was not "TO PRESERVE REGISTERS OR NOT". Nobody can deny the necessity to preserve registers before calling api functions. Look at this code:


.data
dwValue dword 10

.code
main:
mov edx, offset dwValue
invoke MessageBox, NULL, CTEXT("Message"), CTEXT("Caption"), MB_OK
mov eax, dword ptr [edx]
ret
end main

Is eax 10 after calling MessageBox? No! MessageBox corrupts edx register. So you have to preserve edx before this function. Sometimes you don't know which registers will be corrupted by function. So you have to disasm the function to get this information or preserve all registers with pushad/popad.
Posted on 2002-06-09 23:04:02 by vkim
Just change edx with edi or esi or ebx or ebp
and you are in the game..;)
Posted on 2002-06-09 23:10:01 by buliaNaza
Grin,

Thats because the API call observes the convention of preserving EBX ESI & EDI.

Regards,

hutch@movsd.com
Posted on 2002-06-09 23:16:03 by hutch--