E.6. Recursive Macros

Macros may redefine themselves. In recursive instances, the macro must contain a conditional directive that will terminate the recursion. When a macro is redefined (or when it redefines itself), the previous definition is supplanted by the current one.

Macros may invoke themselves recursively. Consider the factorial function, implemented as a recursive macro:

.macro   factorial INT
 .if \INT
   factorial (\INT-1)
   F = F * \INT
 .else
   F = 1
 .endc
.endm

We encourage you to trace the effect of invoking this macro with a small value of INT, such as 4. The final value of the symbol F could be shown by using it in a mov instruction:

.auto
factorial 4
mov     r14 = F
.default

In this case, the mov instruction will assemble with an immediate ...

Get Itanium® Architecture for Programmers: Understanding 64-Bit Processors and EPIC Principles now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.