Discussion about a more efficient way to get HI WORD and LO WORD?

Started by Slugsnack, January 20, 2010, 10:43:43 AM

Previous topic - Next topic

jj2007

Quote from: Ghandi on January 21, 2010, 07:06:40 PM
i actually disagree with you on that comment. It depends on the actual usage, because i know for a fact that a lot of experienced assembler programmers will unroll a loop for speed at the expense of size.
That would certainly be a nice topic for the Lab. But here we are in the Campus, trying to teach noobs the rules for writing compact and/or fast assembler code.

So what are, in your opinion, the advantages of using in a slow message pump 4 lines instead of 2, 13 bytes instead of 8?

  mov eax, dword ptr [wParam]
  mov ecx,eax
  and eax,0FFFFh
  shr ecx,16



  movzx eax, word ptr wParam
  movzx ecx, word ptr wParam+2

akane

There is another way to create a switch block for WM_COMMAND, without splitting wParam: compare wParam with 32-bit value created from controlID and notification code:
switch wParam
   case MAKELONG(IDC_COMBO1, CBN_CLOSEUP) ; or IDC_COMBO1 | (CBN_CLOSEUP<<16)
...

jj2007

Quote from: akane on January 22, 2010, 12:44:53 AM
There is another way to create a switch block for WM_COMMAND, without splitting wParam: compare wParam with 32-bit value created from controlID and notification code:
switch wParam
   case MAKELONG(IDC_COMBO1, CBN_CLOSEUP) ; or IDC_COMBO1 | (CBN_CLOSEUP<<16)
...


MAKELONG looks good. Can you show us a working example?

Just in case you can't find MAKELONG in the Masm32 package:

MAKELONG MACRO Lw:REQ, Hw:REQ
EXITM %Lw+65536*Hw
ENDM

Ghandi

Quote
Im must be bad and inefficient, im quite happy to use:


Code:
mov eax, dword ptr [wParam]
mov ecx,eax
and eax,0FFFFh
shr ecx,16

For the benefit of anyone who doesnt know, it simply loads the whole dword into EAX, copies it to ECX and then 'extracts' the HIWORD and LOWORD values for use.

HR,
Ghandi

I thought i made it abundantly clear in my first post that it wasn't optimal code, but just to make sure, i also said it again here.


Quote
Im not out to prove anything to anyone, so im not going to try and optimize the hell out of a message pump which i once again iterate, doesnt need to be lightening fast or super-small. You've taken my comment out of context jj2007, quoting the code i already said is not optimal.

I'm going to just leave this as it is now, because obviously im not able to make myself clear. I have said not once, but twice that the code example wasnt optimal for either size nor speed. Not everything has to perform like a Ferrari for me, especially something as trivial as a dialog pump. I am not trying to start an argument with anybody, but i've obviously said something wrong or committed a faux pas, my apologies.

HR,
Ghandi

dedndave

nawwwwww Ghandi - lol
it's all good - we love to hash things over, is all   :P

hutch--

Folks, I have split the discussion from the original question and answers in accordance with the intent of the Campus so that the extended discussion does not make understanding the answer more compliucated for the original asker or other people who use this topic as reference for things that they have searched for.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php