Section 3: Assembler
275
TI
-
89 / TI
-
92 Plus Sierra C Assembler Reference Manual
Not for Distribution
Beta Version February 2, 2001
The MEXIT directive is typically used in conjunction with conditional assembly
directives to provide a conditional macro termination (see IFcc directive).
3.8.1.7. Macro
Examples
The remainder of this section provides a series of examples that illustrate the
various features of the macro facility. Each example includes a macro definition
and one or more invocations of that macro. The OPT MEX directive is required to
show the macro expansion in the listing file.
The first example presents a macro that can be used to repeat an arbitrary
statement a specified number of times. It can be easily modified to accept any
number of statements, including invocations of other macros. Following the
macro definition is an example invocation and the assembler statements it
generates.
REP
MACRO
IFEQ
\2
MEXIT
ENDC
REP
<\1>,?(\2-1)
\1
ENDM
OPT
MEX
REP
<MOVE.B (A0)+,(A1)+>,8
MOVE.B
(A0)+,(A1)+
MOVE.B
(A0)+,(A1)+
MOVE.B
(A0)+,(A1)+
MOVE.B
(A0)+,(A1)+
MOVE.B
(A0)+,(A1)+
MOVE.B
(A0)+,(A1)+
MOVE.B
(A0)+,(A1)+
MOVE.B
(A0)+,(A1)+
If the parameter evaluation operator ( ? ) is omitted from the above example, the
macro will produce the identical code; however, evaluation of the second
parameter will involve redundant computations (e.g., the second parameter
would be 8-1-1-1-1-1-1-1-1
instead of 0
on the final invocation).
The second example presents a macro that can be used to define sequences of
equate symbols; the value of each symbol is a function of its position in the
specified sequence. The definition of this macro is followed by a pair of example
invocations and their associated expansions.