News:

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

Why doesn't this .if statement work?

Started by iaNac, September 08, 2006, 02:06:40 AM

Previous topic - Next topic

iaNac

In the following procedure, I could only make the .if statement work by first moving Rmargin into eax then checking if pt.x==eax.  Seems like .if pt.x==Rmargin would work but compiling gives me an error (A2070: invalid instruction operands).   Both are DWORD.  What don't I understand?  I'd leave the code as is but I don't want to do the mov every time my timer trips.

Thanks in advance!

*****************************

.486 
.model flat, stdcall
option casemap :none

.data?
sWid    DWORD ?   ; Screen Width
Rmargin   DWORD ?   ; Screen Width minus 1

.code
; get width of screen
mov sWid,  FUNC(GetSystemMetrics,SM_CXSCREEN)

; calc Rmargin (example: sWid = 1024 = "0 to 1023" so Rmargin = 1023)
invoke MemCopy, ADDR sWid, ADDR Rmargin,9   ; 9 bytes is max len of WinTitle
;mov eax, sWid
;mov Rmargin, eax             ; same effect as MemCopy?
sub Rmargin, 1            ; decrement Rmargin by 1

WndProc proc hWin:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
   Switch uMsg
      Case WM_PAINT
         ; skipped code
      Case WM_TIMER
         invoke GetCursorPos,ADDR pt    ; Get mouse position (pt.x , pt.y as DWORD) 
         invoke UpdateWinTitle,pt.x                   ; Display cursor x/screen margin (9 bytes)
         mov eax, Rmargin                  ;>> ??????? <<
         .if pt.x == eax         ; if pt.x = rt screen margin                   ;>> ??????? <<
   invoke GetForegroundWindow   ; locate topmost handle
   mov hWndTop, eax      ; and save it
   invoke CloseWindow, hWndTop   ; shrink topmost window
   invoke KillTimer,hWnd,TimerID   ; exit program
   invoke ExitProcess,eax
         .endif
      Case WM_DESTROY
         invoke PostQuitMessage,NULL
         return 0
   Endsw
   invoke DefWindowProc,hWin,uMsg,wParam,lParam
   ret
WndProc endp

raneti

Because the .if will get translated into 1 assembly mnemonic such as cmp or test and a subsequent jump according to the conditional logic therein.

The error occurs because those mnemonics don't accept both operands to be memory operands thus you get a "(A2070: invalid instruction operands)"

*DEAD*

ive had this answered for me as well. :red

expanding on what raneti said, the if statement will convert the parameters into a cmp statement.
so
if pt.x = rt screen margin
will look like this
cmp pt.x, rt screen margin
this wont work, because theres no way for the processor to comapre two variables. It can compare two numbers, a variable and a number, a variable and a register, a number and a register, two registers, but not two variables.
to fix this, put one of the variables into a registry, then cmp, so
mov eax, rt screen margin
cmp pt.x, eax

that should do it for you

iaNac

raneti, *DEAD* - Thanks.  I understand now.