Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
71
Добавлен:
14.04.2015
Размер:
2.03 Mб
Скачать

Keil Software — A51/AX51/A251 Macro Assembler and Utilities

137

 

 

Chapter 5. Assembler Macros

A macro is a name that you assign to one or more assembly statements. For maximum flexibility the Ax51 macro assembler provides three different macro languages:

Standard Assembler Macros: are known from many other macro assemblers and allow you to define macros that look like standard assemblers instructions. Refer to “Standard Macro Directives” on page 139 for a detailed description.

C Macros: are known from ANSI C compilers and allow you to use common header files with constant definitions that can be used on the Ax51 macro assembler as well as on the Cx51 compiler. Refer to “C Macros” on page 156 for more information.

MPL Macros: are compatible with the Intel ASM-51 and allow you to retranslate existing source files that initially written for this macro assembler. The assembler control MPL enables this macro processor. If you enable MPL macros the C Macros are disabled. Refer to “Chapter 6. Macro Processing Language” on page 163 for a detailed description.

A macro processor enables you to define and to use macros in your x51 assembly

5

programs. This section describes some of the features and advantages of using

macros, lists the directives and operators that are used in macro definitions, and provides a number of example macros.

When you define a macro, you provide text (usually assembly code) that you want to associate with a macro name. Then, when you want to include the macro text in your assembly program, you provide the name of the macro. The Ax51 assembler will replace the macro name with the text specified in the macro definition.

138

Chapter 5. Assembler Macros

 

 

Macros provide a number of advantages when writing assembly programs.

The frequent use of macros can reduce programmer induced errors. A macro allows you to define instruction sequences that are used repetitively throughout your program. Subsequent use of the macro will faithfully provide the same results each time. A macro can help reduce the likelihood of errors introduced in repetitive programming sequences. Of course, introduction of an error into a macro definition will cause that error to be duplicated where the macro is used.

The scope of symbols used in a macro is limited to that macro. You do not need to be concerned about utilizing a previously used symbol name.

Macros are well suited for the creation of simple code tables. Production of these tables by hand is both tedious and error prone.

A macro can be thought of as a subroutine call with the exception that the code that would be contained in the subroutine is included in–line at the point of the macro call. However, macros should not be used to replace subroutines. Each invocation of a subroutine only adds code to call the subroutine. Each invocation of a macro causes the assembly code associated with the macro to be included in–line in the assembly program. This can cause a program to grow rapidly if a large macro is used frequently. In a static environment, a subroutine

5 is the better choice, since program size can be considerably reduced. But in time critical, dynamic programs, macros will speed the execution of algorithms or other frequently called statements without the penalty of the procedure calling overhead.

Use the following guidelines when deciding between macros or subroutines:

Subroutines are best used when certain procedures are frequently executed or when memory space usage must be kept to a minimum.

Macros should be used when maximum processor speed is required and when memory space used is of less importance.

Macros can also be used to make repetitive, short assembly blocks more convenient to enter.

Keil Software — A51/AX51/A251 Macro Assembler and Utilities

139

 

 

Standard Macro Directives

Ax51 provides a number of directives that are used specifically for defining macros. These directives are listed in the following table:

Directive

Description

ENDM

Ends a macro definition.

EXITM

Causes the macro expansion to immediately terminate.

IRP

Specifies a list of arguments to be substituted, one at a time, for a specified

 

parameter in subsequent lines.

IRPC

Specifies an argument to be substituted, one character at a time, for a

 

specified parameter in subsequent lines.

LOCAL

Specifies up to 16 local symbols used within the macro.

MACRO

Begins a macro definition and specifies the name of the macro and any

 

parameters that may be passed to the macro.

REPT

Specifies a repetition factor for subsequent lines in the macro.

Refer to “Assembler Controls” on page 197 as well as the following sections for more information on these and other directives.

5

Соседние файлы в папке HLP