SPNU118Z September 1995 – March 2023 66AK2E05 , 66AK2H06 , 66AK2H12 , 66AK2H14 , AM1705 , AM1707 , AM1802 , AM1806 , AM1808 , AM1810 , AM5K2E04 , OMAP-L132 , OMAP-L137 , OMAP-L138 , SM470R1B1M-HT , TMS470R1A288 , TMS470R1A384 , TMS470R1A64 , TMS470R1B1M , TMS470R1B512 , TMS470R1B768
In a macro, you can access individual characters (substrings) of a substitution symbol by using subscripts with the forced substitution operator (colons around symbol and subscripts). You can access substrings in two ways:
The following examples show substitution symbol functions with subscripts. In the first example, subscripted substitution symbols redefine the ADD instruction so that it handles short immediate values. In the second example, the subscripted substitution symbol is used to find a substring strg1 beginning at position start in the string strg2. The position of the substring strg1 is assigned to the substitution symbol pos.
ADDX .macro dst, imm
.var TMP
.asg :imm(1):, TMP
.if $$symcmp(TMP,"#") = 0
ADD dst, dst, imm
.else
.emsg "Bad Macro Parameter"
.endif
.endm
ADDX R9, #100 ; macro call
ADDX R9, R8 ; macro call
substr .macro start,strg1,strg2,pos
.var LEN1,LEN2,I,TMP
.if $$symlen(start) = 0
.eval 1,start
.endif
.eval 0,pos
.eval 1,i
.eval $$symlen(strg1),LEN1
.eval $$symlen(strg2),LEN2
.loop
.break I = (LEN2 - LEN1 + 1)
.asg ":strg2(I,LEN1):",TMP
.eval i,pos
.break
.else
.eval I + 1,i
.endif
.endloop
.endm
.asg 0,pos
.asg "ar1 ar2 ar3 ar4",regs
substr 1,"ar2",regs,pos
.word pos