SPRUI03E June 2015 – January 2023
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.
storex .macro x
.var tmp
.asg :x(1):, tmp
.if $symcmp(tmp,"A") == 0
STW x,*A15--(4)
.elseif $symcmp(tmp,"B") == 0
STW x,*A15--(4)
.elseif $iscons(x)
MVK x,A0
STW A0,*A15--(4)
.else
.emsg "Bad Macro Parameter"
.endif
.endm
storex 10h
storex A15
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