Miscellaneous > 16 bit DOS Programming
MASM / JWASM - Combining Conditional Assembly statements with logical operator
bugthis:
I have the following macro code:
--- Code: --- IF (Reg EQ AL) OR (Reg EQ AH)
...
ELSE
...
ENDIF
--- End code ---
and this assembles in MASM <= version 5.1, but not in MASM >= 6 or JWASM.
Read here for more information and proof that it assembles in MASM 5:
http://masm32.com/board/index.php?topic=4791.msg115112#msg115112
Now i need a replacement for the above code in a MASM v6 conform syntax.
A working command directive replacement for EQ
--- Code: ---If (argument1 EQ argument2)
--- End code ---
is
--- Code: ---IFIDNI textItem , textItem
--- End code ---
but it only works on one singular item.
In this case, i could test for AL register
--- Code: ---IFIDNI <Reg>,<AL>
....
ELSE
...
ENDIF
--- End code ---
But how do i combine IFIDNI with the logical OR of the old previous code to test also on AH register?
I tried the following combinations (each line, one combination, when doing so, the others were commented)
--- Code: ---; IF (Reg EQ AL) OR (Reg EQ AH) ; this was the old syntax working only in MASM <= 5.1
IF (IFIDNI <Reg>, <BL>) OR (IFIDNI <Reg>, <BH>) ; JWASM throws Error A2064: Expression expected: IFIDNI <BH>, <BL>) OR (IFIDNI <BH>, <BH>)
IF [IFIDNI <Reg>, <BL>] OR [IFIDNI <Reg>, <BH>] ; JWASM throws Error A2064: Expression expected: IFIDNI <BH>, <BL>] OR [IFIDNI <BH>, <BH>)
IFIDNI (<Reg>,<BL>) OR (<Reg>,<BH>) ; JWASM throws Error A2144: Text item required
IFIDNI <Reg>, <BL> OR <Reg>,<BH> ; JWASM throws Error A2209: Syntax error OR
IFIDNI <Reg>, <BL> OR IFIDNI <Reg>, <BL> ; JWASM throws Error A2209: Syntax error OR
--- End code ---
But none of them worked.
Can you tell my, how do i combine several conditional assembly IFIDNI statements with a logical operator like OR?
The only solution i found so far is repeating the code block part after an ELSEIFIDNI, but this is not a very elegant
and clean solution and it is error prone.
--- Code: ---IFIDNI <Reg>, <BL>
... ; Code A
ELSEIFIDNI <Reg>, <BH>
... ; Code A, same Code A as before
ELSE
... ; Code B
ENDIF
--- End code ---
_japheth:
--- Quote from: bugthis on October 27, 2022, 01:15:23 PM ---But how do i combine IFIDNI with the logical OR of the old previous code to test also on AH register?
--- End quote ---
That's the problem: OR doesn't operate "logical", it's working bitwise and hence accepts numeric arguments only.
Register names are socalled keywords and don't have a numeric value assigned to them since Masm v6.
--- Quote ---The only solution i found so far is repeating the code block part after an ELSEIFIDNI, but this is not a very elegant
and clean solution and it is error prone.
--- Code: ---IFIDNI <Reg>, <BL>
... ; Code A
ELSEIFIDNI <Reg>, <BH>
... ; Code A, same Code A as before
ELSE
... ; Code B
ENDIF
--- End code ---
--- End quote ---
I agree. You can instead use the FOR loop operator:
--- Code: ---m1 macro arg
for x,<al,bl,cl>
ifidni <arg>,<x>
echo found arg
endif
endm
endm
--- End code ---
jj2007:
--- Code: ---testme macro arg
Local yes
yes=0
ifidni <arg>, <al>
yes=1
endif
ifidni <arg>, <cl>
yes=1
endif
if yes
dosomething
endif
endm
--- End code ---
bugthis:
--- Quote from: _japheth on October 27, 2022, 03:28:13 PM ---
--- Quote from: bugthis on October 27, 2022, 01:15:23 PM ---But how do i combine IFIDNI with the logical OR of the old previous code to test also on AH register?
--- End quote ---
That's the problem: OR doesn't operate "logical", it's working bitwise and hence accepts numeric arguments only.
Register names are socalled keywords and don't have a numeric value assigned to them since Masm v6.
--- End quote ---
Thank you for the information.
--- Quote ---I agree. You can instead use the FOR loop operator:
--- Code: ---m1 macro arg
for x,<al,bl,cl>
ifidni <arg>,<x>
echo found arg
endif
endm
endm
--- End code ---
--- End quote ---
But with "for" i can't implement the "else".
That brings me to another question. I know it's not very good to use a GOTO, but is there a GOTO for MASM's preprocessor?
bugthis:
--- Quote from: jj2007 on October 27, 2022, 09:14:04 PM ---
--- Code: ---testme macro arg
Local yes
yes=0
ifidni <arg>, <al>
yes=1
endif
ifidni <arg>, <cl>
yes=1
endif
if yes
dosomething
endif
endm
--- End code ---
--- End quote ---
Thank you. That seems to be the best solution so far.
Navigation
[0] Message Index
[#] Next page
Go to full version