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

148

Chapter 5. Assembler Macros

 

 

Recursive Macros

Macros can call themselves directly or indirectly (via another macro). However, the total number of levels of recursion may not exceed nine. A fatal error will be generated if the total nesting level is greater than nine. The following example shows a recursive macro that is invoked by a non–recursive macro.

RECURSE

MACRO

X

; recursive macro

IF X<>0

 

 

 

 

RECURSE

%X–1

 

 

ADD

A,#X

; gen add a,#?

ENDIF

 

 

 

 

ENDM

 

 

SUMM

MACRO

X

; macro to sum numbers

 

MOV

A,#0

; start with zero

IF NUL X

 

 

; exit if null argument

 

EXITM

 

 

ENDIF

 

 

 

IF X=0

 

 

; exit if 0 argument

 

EXITM

 

 

ENDIF

 

 

 

 

RECURSE X

 

; sum to 0

 

ENDM

 

 

5

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