Motorola dsp assembler Reference Manual



Yüklə 4,8 Kb.
Pdf görüntüsü
səhifə26/91
tarix08.10.2017
ölçüsü4,8 Kb.
#3546
1   ...   22   23   24   25   26   27   28   29   ...   91

Macro Operations And Conditional Assembly
Macro Definition
MOTOROLA
DSP ASSEMBLER REFERENCE MANUAL
5-3
The required label is the symbol by which the macro will be called.  The dummy argument
list has the form:
[[,,...,]]
The dummy arguments are symbolic names that the macro processor will replace with ar-
guments when the macro is expanded (called).  Each dummy argument must obey the
same rules as global symbol names.  Dummy argument names that are preceded by an
underscore are not allowed.  Dummy arguments are separated by commas.
For example, consider the following macro definition:
N_R_MUL
MACRO
NMUL,AVEC,BVEC,RESULT
header
;
;This macro implements N real multiplies
;RESULT(I) = AVEC(I) * BVEC(I) I=1..NMUL
;where
;
NMUL
= number of multiplications
;
AVEC
= base address of array AVEC(I)
;
BVEC
= base address of array BVEC(I)
;
RESULT
= base address of array RESULT(I)
;
MOVE
#AVEC,R0
body
MOVE
#BVEC,R4
MOVE
#RESULT,R1
MOVE
X:(R0)+,D4.S
Y:(R4)+,D7.S
DO
#NMUL,_ENDLOOP
FMPY.S
D4,D7,D0
X:(R0)+,D4.SY:(R4)+,D7.S
MOVE
D0.S,X:(R1)+
_ENDLOOP
ENDM
terminator
When a macro call is executed, the dummy arguments within the macro definition
(NMUL,AVEC,BVEC,RESULT in the example above) are replaced with the correspond-
ing argument as defined by the macro call.
All local labels within a macro are considered distinct for the currently active level of macro
expansion (unless the macro local label override is used, see below). These local labels
are valid for the entire macro expansion and are not considered bounded by non-local la-
bels. Therefore, all local labels within a macro must be unique. This mechanism allows
the programmer to freely use local labels within a macro definition without regard to the
number of times that the macro is expanded. Non-local labels within a macro expansion
are considered to be normal labels and thus cannot occur more than once unless used
with the SET directive (see Chapter 6).


Macro Operations And Conditional Assembly
Macro Calls
5-4
DSP ASSEMBLER REFERENCE MANUAL
MOTOROLA
When specifying a local label within the body of a macro, the programmer must be aware
that the label symbol is valid for the entire body of the current level of macro expansion.
It is not valid for any nested macros within the current level of expansion.  The example
above shows why the local label feature is useful.  If the macro N_R_MUL were called
several times, there would be several _ENDLOOP labels resulting from the macro expan-
sions.  This is acceptable because each _ENDLOOP label is considered private to a par-
ticular instance of macro expansion.
It is sometimes desirable to pass local labels as macro arguments to be used within the
macro as address references (e.g. MOVE  #_LABEL,R0).  The Assembler effectively dis-
allows this, however, since underscore label references within a macro invocation are re-
garded as labels local to that expansion of the macro.  A macro local label override is
provided which causes local symbol lookup to have normal scope rather than macro call
scope.  If a circumflex (^) precedes an expression containing an underscore label, at ex-
pansion the associated term will be evaluated using the normal local label list rather than
the macro local label list.  The operator has no effect on normal labels or outside a macro
expansion.
5.4
  MACRO CALLS
When a macro is invoked the statement causing the action is termed a macro call.  The
syntax of a macro call consists of the following fields:
[


Macro Operations And Conditional Assembly
Dummy Argument Operators
MOTOROLA
DSP ASSEMBLER REFERENCE MANUAL
5-5
argument can be declared null when calling a macro.  However, it must be declared ex-
plicitly null.  Null arguments can be specified in four ways: by writing the delimiting com-
mas in succession with no intervening spaces, by terminating the argument list with a
comma and omitting the rest of the argument list, by declaring the argument as a null
string, or by simply omitting some or all of the arguments.  A null argument will cause no
character to be substituted in the generated statements that reference the argument.  If
more arguments are supplied in the macro call than appear in the macro definition, a
warning will be output by the Assembler.
5.5
  DUMMY ARGUMENT OPERATORS
The Assembler macro processor provides for text substitution of arguments during macro
expansion.  In order to make the argument substitution facility more flexible, the Assem-
bler also recognizes certain text operators within macro definitions which allow for trans-
formations of the argument text.  These operators can be used for text concatenation,
numeric conversion, and string handling.
5.5.1
  Dummy argument concatenation operator - \
Dummy arguments that are intended to be concatenated with other characters must be
preceded by the concatenation operator, '\' to separate them from the rest of the charac-
ters. The argument may precede or follow the adjoining text, but there must be no inter-
vening blanks between the concatenation operator and the rest of the characters. To
position an argument between two alphanumeric characters, place a backslash both be-
fore and after the argument name. For example, consider the following macro definition:
SWAP_REG
MACRO REG1,REG2
;swap REG1,REG2 using X0 as temp
MOVE
R\REG1,X0
MOVE
R\REG2,R\REG1
MOVE
X0,R\REG2
ENDM
If this macro were called with the following statement,
SWAP_REG
0,1
then for the macro expansion, the macro processor would substitute the character 0 for
the dummy argument REG1, and the character 1 for the dummy argument REG2.  The
concatenation operator (\) indicates to the macro processor that the substitution charac-
ters for the dummy arguments are to be concatenated in both cases with the character R.
The resulting expansion of this macro call would be:
MOVE R0,X0
MOVE R1,R0
MOVE X0,R1


Yüklə 4,8 Kb.

Dostları ilə paylaş:
1   ...   22   23   24   25   26   27   28   29   ...   91




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©genderi.org 2024
rəhbərliyinə müraciət

    Ana səhifə