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

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

155

 

 

Invoking a Macro

Once a macro has been defined, it can be called many times in the program. A macro call consists of the macro name plus any parameters that are to be passed to the macro.

In the invocation of a macro, the position of the actual parameters corresponds to the position of the parameter names specified in the macro definition. Ax51 performs parameter substitution in the macro starting with the first parameter. The first parameter passed in the invocation replaces each occurrence of the first formal parameter in the macro definition, the second parameter that is passed replaces the second formal parameter in the macro definition, and so on.

If more parameters are specified in the macro invocation than are actually declared in the macro definition, Ax51 ignores the additional parameters. If fewer parameters are specified than declared, Ax51 replaces the missing parameters with a NULL character.

To invoke a macro in your assembly programs, you must first define the macro. For example, the following definition:

 

 

 

 

 

5

.

 

 

 

 

.

 

 

 

 

.

 

 

 

 

DELAY

MACRO

CNT

;macro definition

 

 

REPT

CNT

;insert CNT NOP instructions

 

 

 

NOP

 

 

 

 

 

 

 

 

 

 

ENDM

 

;end REPT block

 

 

 

ENDM

 

;end macro definition

 

 

.

 

 

 

 

 

.

 

 

 

 

 

.

 

 

 

 

 

defines a macro called DELAY that accepts one argument CNT. This macro will generate CNT NOP instructions. So, if CNT is equal to 3, the emitted code will be:

NOP

NOP

NOP

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