160/317
6 - STMicroelectronics Programming Tools
67
67 0019 3C00 inc CounterLo
67 001B R 2602 jrne LOC1
67 001D 3C01 inc CounterHi
67 LOC1:
We can see that the label NoIncHigh has been replaced in the first expansion by LOC0 and in
thesecondby
LOC1. The multiple definition problem is now avoided.
6.1.7.3 Conditional statements in macros
You can have the macro expand a different way according to the value of the arguments. This
provides for completely optimized code, since only the expanded lines will produce code; un-
like a subroutine call that must perform tests during execution and thus consume time and
memory. Of course, conditional macro expansions only apply for conditions that can be deter-
mined at assembly time; if you need to wait until the execution has started to know the values
of the conditions, only a subroutine can do it then.
Conditional statements are a powerful way of making flexible macros, that can produce dif-
ferent code depending on their argument values. We have already seen the #IFDEF condition.
Here are some other conditions that can be tested.
#IFB Conditional.
This conditional tests whether an argument is blank. This may be used to mean something
special. For example, let us look again at the Addition macro. This macro requires three argu-
ments: two values to add, and a variable to receive the result. Let us improve this macro by
saying that if the third argument is missing, the result is to be written to the second argument,
to compute the total of several values for example. Here is the modified macro:
Addition MACRO VarA, VarB, Result
ld A, VarA
add A, VarB
#IFB Result
ld VarB, A ; result in second argument
#ELSE
ld Result, A ; result in third argument
#ENDIF
MEND
here are two expansions of the macro, the first one with three arguments, the second one with
two arguments. Please pay attention to the lines that actually produce code. These lines have
something in the third column, that is the generated code. The unselected option has its
source line shown, but no code in the third column.
95 Addition NbOfApples, NbOfPears, NbOfFruit