News:

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

how to make if statement in MASM32v10?

Started by FritzGamaliel, March 28, 2010, 06:59:35 AM

Previous topic - Next topic

FritzGamaliel

I have a problem:
I can't do this

;===========================================
LOCAL a:DWORD

.if a="mystring"
invoke MessageBox,hWin,ADDR TextMsg,ADDR TextMsg,MB_OK
.endif
;===========================================


But, I can do this:
;===========================================
LOCAL a:DWORD

switch$ ADDR a
case$ "mystring"
invoke MessageBox,hWin,ADDR TextMsg,ADDR TextMsg,MB_OK
endsw$
;===========================================
can we modify if statement like case statement?

How to do it?
Thank you
Fritz

ragdog

Hi

Your "a" is a dword  and is 4 bytes
and you sting is more as 4 bytes

     lea eax ,a
    ;the first 4 bytes
    .if DWORD PTR [eax]=="tsym"      ;the 4 bytes of a dword and backward "myst"
       .if DWORD PTR [eax+4]=="gnir";the next 4 bytes of a dword backward "ring"
         
        ;mystring if correct

       .endif
    .endif

Byte == 1 byte
Word == 2 byte
Dword== 4 bytes long
...
.

see in the masm32 package for mor help


Or your compare with lstrcmp api

Greets

hutch--

Fritz,

The .IF notation in MASM is for comparing integers, not string characters. The macros in "switch$" actually call a string comparison algorithm that compares the two strings.

If you wanted to use .IF notation you would need to run a string compare algo then feed its result through an .IF block.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

ragdog

Hi Hutch

This compare a string or not only backward or not?
.if DWORD PTR [eax]=="tsym"  ;myst

hutch--

ragdog,

You are actually doing an integer compare in your example as you can fit 4 ascii/ansi characters in a DWORD. MASM reads the characters backwards like their real memory order.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php