News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

About and eax,0FFFFh

Started by Force, March 01, 2012, 06:17:31 PM

Previous topic - Next topic

Force

I usally see in some dialogbox codes

elseif eax==WM_COMMAND
mov eax,wParam
and eax,0FFFFh
.if eax==IDM_FILE_EXIT
invoke SendMessage,hWin,WM_CLOSE,0,0
.elseif eax==IDM_HELP_ABOUT
invoke ShellAbout,hWin,addr AppName,addr AboutMsg,NULL
.endif

or

mov eax, uMsg
.if eax==WM_CHAR
mov eax,wParam
and eax,0FFFFh

Can you explain it to  me What it means
Never Stop Until You Are Better Than The Best

jj2007

The API documentation often says "the ID is in the loword of wParam" or similar. A dword like wParam or lParam contains two words called hiword and loword. You can load the loword with
mov eax, wParam
and eax, 0ffffh
; and eax, 00000000000000001111111111111111b ; same in binary notation - mask out the lower 16 bits
or, more elegant and shorter:
movzx eax, word ptr wParam

The hiword can be loaded with
mov eax, wParam
shr eax, 16
or, more elegant and shorter:
movzx eax, word ptr wParam+2

dedndave

sometimes, the loword or hiword are signed values
if so, you can use MOVSX to get a sign-extended dword   :U
mouse movement is one example that comes to mind

jj2007

Quote from: dedndave on March 01, 2012, 06:59:08 PM
sometimes, the loword or hiword are signed values
if so, you can use MOVSX to get a sign-extended dword   :U
mouse movement is one example that comes to mind

Negative mouse positions? Sure?

dedndave

mouse wheel   :P

WM_MOUSEWHEEL
WM_MOUSEHWHEEL

wParam
The high-order word indicates the distance the wheel is rotated, expressed in multiples or divisions
of WHEEL_DELTA, which is 120. A positive value indicates that the wheel was rotated forward, away
from the user; a negative value indicates that the wheel was rotated backward, toward the user.



Force

if I understand true

value is in loword of wParam that means that value is 16 bits
after transfering it to eax we need to fill other 16 bits with zeros
its important for mouse movement

when i change it "movzx eax word ptr wParam"
it works same again

and

i erased and eax,0FFFFh

it works without problem   also :toothy
Never Stop Until You Are Better Than The Best

dedndave

#6
MOVZX Zero eXtends the source into the destination register
so...
        movzx     eax,word ptr wParam
takes the low word of wParam and places it in AX
the high word of EAX is set to 0

it can also be used to zero extend a byte
        movzx     eax,byte ptr [esi]
takes the byte pointed to by ESI and places it in AL
the upper 3 bytes of EAX are set to 0

MOVSX is similar, except that it Sign eXtends
        movsx     eax,word ptr wParam
if the low word of wParam is positive (i.e., bit 15 is 0), it will clear all the upper bits in EAX to 0
if the low word of wParam is negative (i.e., bit 15 is 1), it will set all the upper bits in EAX to 1

Force

Thanks Dave

You told it clearly I understand now
Never Stop Until You Are Better Than The Best