is there a more efficient way to get HI WORD and LO WORD?

Started by joemc, January 20, 2010, 06:30:15 AM

Previous topic - Next topic

joemc

I am brand new to MASM or any type of ASM.  i have done a decent amount of programing in C / C++
and more recently been learning the win32 API.

My first application i wrote it is just a button that automatically resizes to the size of
the parent window.  This is all done in response to a WM_SIZE message which is below.

I was trying to decide how to get the low and high word of lParam because that is how it is sent.  Since
I am not using wParam anywhere in the handling of this message i decided to use it to store the height
and put the width back in lParam.  Would it be better to just push SWP_NOZORDER or SWP_NOMOVE first
than push the registers as i figure them out and use a call instead of invoke?
is there a way to get hi/lo inside of invoke?
if i used a local variable would it be pushing it on the stack twice? once when i make the variable and once
when it is getting pushed by invoke?
sorry for such basic questions.  very steep learning curve.


     
      .IF uMsg==WM_SIZE
      ; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««
      ; «« LOWORD of lParam is width, HIWORD of lParam is height
      ; «« Move width to wParam and height in lParam
      mov eax,lParam
      shl eax,16
      shr eax,16
      mov wParam,eax
      mov eax,lParam
      shr eax,16
      mov lParam,eax
      ; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««
      ; ««     Call windows API SetWindowPos()
      invoke SetWindowPos,
      hButton,NULL,NULL,NULL,
      wParam,lParam,
      SWP_NOZORDER or SWP_NOMOVE

sinsi


movzx eax,word ptr lParam   ;loword
movzx edx,word ptr lParam+2 ;hiword

Maybe movsx if it is signed
Light travels faster than sound, that's why some people seem bright until you hear them.

joemc

Quote from: sinsi on January 20, 2010, 06:38:14 AM

movzx eax,word ptr lParam   ;loword
movzx edx,word ptr lParam+2 ;hiword

Maybe movsx if it is signed


thanks for such a quick reply.  that defiantly is shorter.  is there a list somewhere to tell which opcodes take longer? i suppose it would depend on your actual processor.  or do people generally just run it and time it?

hutch--

For doing a split like this Sinsi's code is probably the fastest way it can be done and you end up with 32 bit values that are faster to deal with than 16 bit values.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

dedndave

this is a very useful reference link
it is an HTML version of Randy Hyde's AOA, with some of the pieces left out

http://www.arl.wustl.edu/~lockwood/class/cs306/books/artofasm/toc.html

at the very end of the page is Appendix D: Instruction Set Reference, a PDF download (APNDXD.pdf)
it is hard to say precisely how long an instruction takes because of all the speed enhancement mechanisms of modern processors
but, the reference can give you a general idea of instruction timings