Using Recursive and Nested Macros
5-23
Macro Language
Example 5–16 shows recursive macros. The fact macro produces assembly
code necessary to calculate the factorial of n where n is an immediate value.
The result is placed in data memory address loc. The fact macro accomplishes
this by calling fact1, which calls itself recursively.
Example 5–16. Using Recursive Macros
(a) Mnemonic example
fact
.macro N, loc
; n is an integer constant
; loc memory address = n!
.if
N < 2
; 0! = 1! = 1
ST
#1, loc
.else
ST
#N, loc
; n >= 2 so, store n at loc
; decrement n, and do the
.eval
N – 1, N
;
factorial of n – 1
fact1
; call fact with current
; environment
.endif
.endm
fact1
.macro
.if
N > 1
LD
loc, T
; multiply present factorial
MPY
#N, A
;
by present position
STL
A, loc
; save result
.eval
N – 1, N
; decrement position
fact1
; recursive call
.endif
.endm
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: ......