-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Labels
Description
Hello asMSX team!
I am developing a routine that I would like to work with in the asMSX, Sjasm and tniASM cross-assemblers, but the peculiarities of defining constants and variables do not allow it, so I have gone to try to use conditional assembly.
While in Sjasm and tniASM they are compatible to a minimum, which allow the use of conditional assembly with this objective, in asMSX this is not fulfilled.
I would like to propose that this problem be discussed, thinking of facilitating the development of routines for common use without having to create and maintain several code files.
References:
- Sjasm 0.42 manual - Conditional assembly
- tniASM Guide Book:
2.6 Conditional Assembly
Sometimes it's useful to have a certain piece of code assemble only
when certain conditions are met. For instance when writing code for
multiple platforms at the same time (Z80 and R800 for example), or
for including/excluding debug code.
tniASM provides this functionality through the IF-construct. Its
basic form is:
IF {operand} [{...}] [ELSE [{...}]] ENDIF
Note that due to the multi-pass nature of tniASM, it's allowed to
use forward references in IF-constructs. They may also be used
accross source file boundaries. Ofcourse IF's can be nested with a
practically infinite depth.
2.6.1 IF {expression}
The expression is evaluated and is considered 'false' when zero,
while any non-zero result is considered 'true'.
loop: {...}
IF $-loop < 128
djnz loop
ELSE
dec b
jp nz,loop
ENDIF
2.6.2 IFDEF {label}
Check if a label was previously declared this pass.
R800: ; comment away for Z80 version
IFDEF R800 mulub a,b ELSE call mulub_a_b ENDIF
IFDEF R800 ELSE
mulub_a_b: {...}
ret
ENDIF
2.6.3 IFEXIST {string}
Check if a file exists. Look at the second example for a nice
trick, which works with any IF-instruction.
IFEXIST "test" {...} ENDIF ; do {...} if "test" exists
IFEXIST "test" ELSE {...} ENDIF ; do {...} if "test" does not exist
2.6.4 IFEXIST {label}
Similar to IFDEF, but checks if a label exists regardless of where
or when it is declared. You can use this to check if a label is
declared further on in the source code.