News:

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

macro question

Started by ecube, October 31, 2006, 01:03:37 AM

Previous topic - Next topic

ecube

How do I something like

.386
.model flat, stdcall
option casemap:none  ; Case sensitive

include  \Masm32\include\windows.inc
include  \Masm32\include\kernel32.inc

testvalue bool TRUE

.if testvalue==TRUE
   include anotherfile.asm
.endif

.code
etc...

How can I do that via macros or other means?

gwapo

Probably something like this:


testvalue EQU 1


ifdef testvalue

include anotherfile.asm

endif


For more information about IFDEF, refer here:
http://msdn2.microsoft.com/en-us/library/7249def9.aspx

-chris

jdoe

E^cube,

Maybe conditional compiling is what you need. You can, at command line, use the /D switch like this...

ML.EXE /c /coff /D"testvalue=1" PROGRAM.ASM


.386
.model flat, stdcall
option casemap:none  ; Case sensitive

include  \Masm32\include\windows.inc
include  \Masm32\include\kernel32.inc

IF testvalue
  include anotherfile.asm
ENDIF

.code
etc...


Be carefull, it is IF and not .IF

I hope this help


EDIT: gwapo, you are faster then me and maybe better on this one but it does the same thing at the end   :U

ecube


Rainstorm

jdoe wrote
QuoteBe carefull, it is IF and not .IF

what's the diff between an IF & an .IF command.

jdoe

Quote from: Rainstorm on October 31, 2006, 03:32:55 AM
jdoe wrote
QuoteBe carefull, it is IF and not .IF

what's the diff between an IF & an .IF command.

Rainstorm,

IF is an assembly directive passed to ml.exe to know what to assemble and .IF create code conditions at runtime.

I'm not sure to say it the right way but it should be clear.  :P


TNick

You are right, jdoe. This is an example:

.586
.MODEL FLAT, STDCALL
OPTION CASEMAP:NONE

App_In_Debug_Mode       EQU           1

.data
   VarToOutput    BYTE     "a string or another",0
 
.code
.
.
.
IFDEF  App_In_Debug_Mode
     invoke OutputDebugString, ADDR VarToOutput
ENDIF

.IF   eax==1
       mov   edx,    0FFh
.ENDIF
mov  eax, 100


If you will assamble and link the exe in this form, the exe/dll will output a string to debuger. There WILL be opcodes for i<nvoke OutputDebugString, ADDR VarToOutput>
If you will comment this line
;App_In_Debug_Mode       EQU           1
then the exe/dll will not output a string to debuger. There WILL BE NO opcodes for <invoke OutputDebugString, ADDR VarToOutput>


.IF   eax==1
       mov   edx,    0FFh
.ENDIF
mov  eax, 100

this will allways be turned in something like this:

cmp eax,   1
jne  Label1
   mov   edx,    0FFh
Label1:
mov  eax, 100


So, as a conclusion, .IF  .ELSEIF  .ELSE  .ENDIF will have inpact at run time
IF(cond) ELSE ENDIF  wil have impact at assamble time.

Regards,
Nick

Rainstorm

thanks for explaining that Tnick :)


TNick


u

Just note that if you put
App_In_Debug_Mode       EQU           0
then even if it's 0, the symbol is defined!
So,

ifdef App_In_Debug_Mode
    DebugPring "This is always compiled!"
endif


Instead of "equ 0", you'll have to comment the whole line:
;App_In_Debug_Mode       EQU           1
or
;App_In_Debug_Mode       EQU           0
Please use a smaller graphic in your signature.

Jimg

Or just use IF rather than IFDEF

App_In_Debug_Mode  EQU   0    ;  zero if false, anything else if true

if App_In_Debug_Mode
    DebugPrint "In debug mode"
else
    DebugPrint "NOT In debug mode"
endif