Conditional Assembly

With conditional assembly you can easily include or exclude specific blocks of instructions. The syntax is very similar to BASIC IF statements. There are three versions of IF: IF,IFDEF and IFNDEF.

For example IFDEF checks whether a symbol is already defined:

            DEBUG EQU 1
...
            ifdef DEBUG
            ld hl,buffer
            ld de,buffer+1
            ld bc,1023
            ld (hl),#aa
            ldir
            endif

In the above example if DEBUG has been defined then some code is inserted that will place #AA into each byte of a buffer. IFNDEF does the opposite test and the code would be inserted if the symbol wasn't defined. The symbol must already have been defined for the test to work.

IF allows for general expressions and ELSE can also be used:

            if $<#4000
            ld hl,0
            else
            ld hl,#8000
            endif

In the above example hl is loaded with different values depending on where the code is being assembled to. You can use the predefined symbol __ASTRUM__ to include code or directives specifically when being assembled with Astrum:

            ifdef __ASTRUM__
            LIST
            end