SLAU131Y October 2004 – June 2021
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 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 imm, dst
.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