Hi I want a macro to be able to test a constant and depending on the constant passed I want it to assemble different code, how do I go about this?
Posted on 2003-12-21 21:32:02 by x86asm
The IF/ELSE/ENDIF (note there is no leading dot) are used for conditional assembly:

IF MyConstant
; assemble this code
ELSE
; assemble this code
ENDIF
Posted on 2003-12-21 21:49:14 by donkey
I should note that the IF block for conditional assembly does not take an "=" so I usually do it this way if there are alot of conditions. There's probably a better way to do this but it's what I found that works and I just sort of stuck with it. It will assemble the code if the expression evaluates to zero.
IFE MyConstant - 10

; assemble this code for MyConstant = 10
ELSEIFE MyConstant - 20
; assemble this code for MyConstant = 20
ELSEIFE MyConstant - 30
; assemble this code for MyConstant = 30
ELSE
; assemble this code for all others
ENDIF
Posted on 2003-12-21 21:58:23 by donkey
x86asm,

That is a trivial problem. Ratch



Microsoft (R) Macro Assembler Version 6.14.8444 12/22/03 10:53:13
TEST.ASM Page 1 - 1


.686
;.MMX
;.K3D
;.XMM
.MODEL FLAT,STDCALL
option casemap :none ; case sensitive
= OFFSET @ EQU OFFSET

; #########################################################################
.NOLIST
.LIST
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\gdi32.lib

IFFY MACRO MyConstant
IF MyConstant EQ 10
DWORD 10
ELSEIF MyConstant EQ 20
DWORD 20
ELSEIF MyConstant EQ 30
DWORD 30
ELSE
DWORD 1000
ENDIF
ENDM

00000000 .DATA
00000000 .CODE

IFFY 10
00000000 0000000A 1 DWORD 10
IFFY 20
00000004 00000014 1 DWORD 20
IFFY 30
00000008 0000001E 1 DWORD 30
IFFY 40
0000000C 000003E8 1 DWORD 1000

END
Posted on 2003-12-22 10:58:19 by Ratch