News:

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

IsConstant?

Started by Nordwind64, June 26, 2009, 05:31:03 PM

Previous topic - Next topic

dedndave

it is an equate
when the assembler sees it, it simply replaces it with the constant numeric value (or string, in the case of text)
the linker (and, thus, the exe) know nothing of the equate, unless you somehow force it to

qWord

mhh..
you want to know this at runtime (? that is also what you ask in your first post). This can only be done, if you record the EQU's names (this is makeable with macros) and save them as strings.

PS: I'm also not an native English speaker  :8)
FPU in a trice: SmplMath
It's that simple!

Nordwind64

Hey cool, that seems to work...

IFDEF WM_PAINT
 PrintDec 1
ELSE
 PrintDec 0
ENDIF


I will test this extensively!
Greetings, Nordwind.
Windows 7 (64Bit), JWASM/PoLink

Nordwind64

Wow, that works fine! It is possible.  :U

  IFDEF WM_PAINT
   PrintDec 1
  ELSE
   PrintDec 0
  ENDIF
 
  IFDEF TDX_JWCZIGRE
   PrintDec 1
  ELSE
   PrintDec 0
  ENDIF
 
  IFDEF LVM_APPROXIMATEVIEWRECT
   PrintDec 1
  ELSE
   PrintDec 0
  ENDIF


Gives me:

1
0
1

But I could not geht it working as macro. How must I change it to work as macro? Macros are not my strength.  :P
Greetings, Nordwind.
Windows 7 (64Bit), JWASM/PoLink

qWord


MacroName macro txt:=<>
IFDEF txt
PrintDec 1
ELSE
PrintDec 0
ENDIF
endm
FPU in a trice: SmplMath
It's that simple!

Nordwind64

Thank you to everybody which have helped me. Particularly to qWord!  :U
I would not have thought that an easy solution is possible.  :thumbu

Quoteedit > But if you mean to detect if constant is defined in include files
& tell that at run time :} wow  .. there is no easy way | unless you wanna make a parser :}

I need this for writing a parser.  :lol
Greetings, Nordwind.
Windows 7 (64Bit), JWASM/PoLink

Nordwind64

Ok, the macro works perfekt with plaint texts like:

IsConst macro txt:=<>
  IFDEF txt
    mov eax,1
  ELSE
    xor eax,eax
  ENDIF
endm

...

IsConst WM_PAINT


Is it possible to get it working with an address of a string?

lea ecx,text
IsConst ecx
Greetings, Nordwind.
Windows 7 (64Bit), JWASM/PoLink

dedndave

i don't know about that one
in the old days, equates had to be resolved on the first pass of the assembler
the addresses are not resolved until the second pass
the newer assemblers may be different

jj2007

Quote from: Nordwind64 on June 27, 2009, 10:39:16 PM

Is it possible to get it working with an address of a string?

lea ecx,text
IsConst ecx


No. You test for ecx, a register. Its content is known only at runtime, and may correspond to an immediate like offset MyString, but that immediate will always "exist", since it's part of your address space.

If, however, you want to check whether MyString has been defined, it can be done:

ChkIsValidAddress MACRO arg
ifndef <arg>
  EXITM <1>
else
  EXITM <0>
endif
ENDM


EDIT: However, this still does not allow you to use an undefined MyString in your code. To achieve that, some more effort is needed:

include \masm32\include\masm32rt.inc

ChkIsValidAddress MACRO arg
  xor ecx, ecx
  ifdef arg
dec ecx
  else
.data
tmp$ CATSTR <arg>, < db "Hello everybody!", 13, 10, 0>
% echo tmp$
tmp$
.code
  endif
  mov eax, offset &arg&
  EXITM <ecx>
ENDM

.data
MyString db "Good morning, I am a defined string", 0

.code
start:
.if ChkIsValidAddress(MyString)
print eax, 13, 10
.else
print "No MyString", 13, 10
.endif

.if ChkIsValidAddress(MyUndefinedString)
print eax, 13, 10
.else
push eax
print "There was no MyUndefinedString", 13, 10, "but now there is one: "
pop eax
print eax
.endif

getkey
exit

end start

Nordwind64

#24
 :'(

Ok, seems that cannot work. So I will go parsing the include-files.  ::)
Thank you to everybody which wanted to help me!  :U
Greetings, Nordwind.
Windows 7 (64Bit), JWASM/PoLink