SPRU513Z August 2001 – October 2023 SM320F28335-EP
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 STW instruction so that it handles immediates. 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 ABC
.var TMP
.asg :ABC(1): , TMP
.if $symcmp(TMP, "#") = 0
ADD ACC, ABC
.else
.emsg "Bad Macro Parameter"
.endif
.endm
ADDX #100 ;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 start,i
.eval $symlen(strg1),len1
.eval $symlen(strg2),len2
.loop
.break i = (len2 - len1 + 1)
.asg ":strg2(i,len1):",tmp
.if $symcmp(strg1,tmp) = 0
.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