Chapter
4.
Assembler
Directives
Subdividing data
as
shown
in
the example simplifies data access and provides useful documentation
throughout
your program. Notice
that
these EQU directives can
be
inserted anywhere within the program as you need them,
but
coding them
as
shown
in
the example provides a more useful record description.
CONDITIONAL
ASSEMBLY
The IF, ELSE, and ENDIF directives enable you to assemble portions of your program conditionally,
that
is,
only if certain cond itions th,lt you specify are
sa
tisfied.
Conditional assembly
is
especially useful when your application requires custom programs for a number of com-
mon options.
As
an example, assume
that
a basic control program requires customizing
to
accept input from
one
of
six different sensing devices and
to
drive one of five different control devices. Rather than code some
thirty separate programs
to
account for
all
the possibilities, you can code a single program. The code for the
in-
dividual sensors and drivers must
be
enclosed by the conditional directives. When you need
to
generate a custom
program,
you
can insert SET directives near the beginning
of
the source program to select the desired sensor and
driver routines.
IF,
!ELSE, ENDIF Directives
4-8
Because these directives are used
in
conjunction, they are described together here.
Label Opcode
Operand
optional:
IF
expression
optional:
ELSE
optional:
ENDIF
The assembler evaluates the expression
in
the operand field
of
the
IF
directive.
If
bit 0
of
the resulting value
is
one (TRUE),
all
instruction'; between the
IF
directive and the next ELSE or ENDIF directive are assembled.
When bit
0
is
zero (FALSE) these instructions are ignored.
(A
TRUE expression evaluates
to
OFFFFH and
FALSE to
OH;
only bit zero need
be
tested.)
All
statements
included between an
IF
directive and its required associated ENDIF directive are defined
as
an
IF·ENDIF block. The ELSE directive
is
optional, and only one ELSE directive may appear
in
an IF-ENDIF
block. When included, ELSE
is
the converse
of
IF. When bit 0 of the expression
in
the
IF
directive
is
zero,
all
statements
between ELSE and the next ENDIF are assembled.
If
bit 0
is
one, these statements are ignored.
Operands are not allowed with the ELSE and ENDIF directives.
An
IF-ENDIF block may appear within
another
IF·ENDIF block. These blocks can be nested to eight levels.
Macro definitions (explained
in
the next chapter) may appear within an IF·ENDIF block. Conversely, IF-ENDIF
blocks may appear within macro definitions.
In
either case, you must
be
certain to terminate the macro definition