SPRU513Y August 2001 – June 2022 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:
This method of subscripting evaluates to a character string with one character.
In this method, expression1 represents the substring's starting position, and expression2 represents the substring's length. You can specify exactly where to begin subscripting and the exact length of the resulting character string. The index of substring characters begins with 1, not 0.
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