The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: ecube on October 31, 2006, 01:03:37 AM

Title: macro question
Post by: ecube on October 31, 2006, 01:03:37 AM
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?
Title: Re: macro question
Post by: gwapo on October 31, 2006, 01:42:20 AM
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
Title: Re: macro question
Post by: jdoe on October 31, 2006, 01:44:40 AM
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
Title: Re: macro question
Post by: ecube on October 31, 2006, 02:44:26 AM
Thankyou guys.
Title: Re: macro question
Post by: 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.
Title: Re: macro question
Post by: jdoe on October 31, 2006, 05:05:59 AM
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

Title: Re: macro question
Post by: TNick on October 31, 2006, 10:12:56 AM
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
Title: Re: macro question
Post by: Rainstorm on October 31, 2006, 02:04:14 PM
thanks for explaining that Tnick :)

Title: Re: macro question
Post by: TNick on October 31, 2006, 02:10:38 PM
 :U
Title: Re: macro question
Post by: u on October 31, 2006, 05:20:10 PM
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
Title: Re: macro question
Post by: Jimg on November 01, 2006, 01:01:56 AM
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