![background image](http://html.mh-extra.com/html/texas-instruments/tms320c54x/tms320c54x_user-manual_1097113182.webp)
Using Macros
5-2
5.1
Using Macros
Programs often contain routines that are executed several times. Instead of
repeating the source statements for a routine, you can define the routine as
a macro, then call the macro in the places where you would normally repeat
the routine. This simplifies and shortens your source program.
If you want to call a macro several times, but with different data each time, you
can assign parameters within a macro. This enables you to pass different
information to the macro each time you call it. The macro language supports
a special symbol called a
substitution symbol, which is used for macro
parameters. In this chapter, we use the terms
macro parameters and
substitution symbols interchangeably.
Using a macro is a three-step process.
Step 1: Define the macro. You must define macros before you can use them
in your program. There are two methods for defining macros:
-
Macros can be defined at the beginning of a source file or in a
.copy/.include file. See Section 5.2,
Defining Macros, for more
information.
-
Macros can be defined in a macro library. A macro library is a
collection of files in archive format created by the archiver. Each
member of the archive file (macro library) contains one macro
definition corresponding to the member name. You can access
a macro library by using the .mlib directive. See Section 5.4,
Macro Libraries, on page 5-14 for more information.
Step 2: Call the macro. After defining a macro, you call it by using the macro
name as an opcode in the source program. This is referred to as a
macro call.
Step 3: Expand the macro. The assembler expands your macros when the
source program calls them. During expansion, the assembler
passes arguments by variable to the macro parameters, replaces
the macro call statement with the macro definition, and assembles
the source code. By default, the macro expansions are printed in the
listing file. You can turn off expansion listing by using the .mnolist
directive. See Section 5.8,
Formatting the Output Listing, on page
5-21 for more information.
When the assembler encounters a macro definition, it places the macro name
in the opcode table. This redefines any previously defined macro, library entry,
directive, or instruction mnemonic that has the same name as the macro.
Summary of Contents for TMS320C54x
Page 38: ......
Page 39: ......
Page 40: ......
Page 41: ......
Page 42: ......
Page 43: ......
Page 44: ......
Page 45: ......
Page 46: ......
Page 47: ......
Page 48: ......
Page 49: ......
Page 50: ......
Page 51: ......
Page 52: ......
Page 53: ......
Page 54: ......
Page 55: ......
Page 56: ......
Page 57: ......
Page 58: ......
Page 59: ......
Page 60: ......
Page 61: ......
Page 62: ......
Page 276: ......
Page 277: ......
Page 278: ......
Page 279: ......
Page 280: ......
Page 281: ......
Page 282: ......
Page 283: ......
Page 284: ......
Page 285: ......
Page 286: ......
Page 287: ......
Page 288: ......
Page 289: ......
Page 290: ......
Page 291: ......
Page 292: ......
Page 293: ......
Page 294: ......
Page 295: ......
Page 296: ......
Page 297: ......
Page 298: ......
Page 299: ......
Page 300: ......
Page 301: ......
Page 302: ......