Conditional compilation
Preprocessor can change source code that will be sent to the compiler inserting new lines (when including external source file), as well as deleting existing lines. You can manage the source code by conditionally allowing compilation of lines.
Instructions below will be compiled only if the MY_DEBUG
macro is defined before. Indentations are written only for code clarity.
IFDEF MY_DEBUG MOV1u 1 A1 MOV1u 5 A2 MOV4u 1000 BX MOV4u 200 BY OUT ENDIF
There is also ELSE directive that allow to pass lines
when the macro isn't defined. For example:
IFDEF HI_RES MOV4i 1024 BX ELSE MOV4i 640 BX ENDIF
You can also use IFNDEF instead of IFDEF.
In this case, lines under this directive will be allowed to compilation
only if given macro isn't defined and lines under ELSE
directive will be allowed if it is. Conditional compilation directives
can be nested. Example:
; This line is compiled always
IFDEF macro1
; This line is compiled when macro1 defined
IFNDEF macro2
; This line is compiled when macro1 defined and macro2 not
ELSE
; This line is compiled when macro1 and macro2 defined
ENDIF
; This line is compiled when macro1 defined
ELSE
; This line is compiled when macro1 not defined
IFNDEF macro2
; This line is compiled when macro1 and macro2 not defined
ELSE
; This line is compiled when macro1 not defined and macro2 defined
ENDIF
; This line is compiled when macro1 not defined
ENDIF
; This line is compiled always
ERROR directive is related to conditional compilation.
It allows to generate compilation error with given message. If it is
processed, compiler will write error and it will not generate output file,
however compilation will be continued.
IFDEF OLD_AND_DEPRECATED ERROR "You shouldn't define it!" ENDIF