$MACRO LEN string ?? 2 mov #@{1},r0 #@2=. tstb (r0)+ bne #@2 sub #@{1},r0 dec r0 $ENDM ;+ ; String routines - these are taken from basic-11 string functions. ; These are of course C callable too. ; ; FUNCTION eq[a,b,n] ; ; compares string at a to string at b, compares n chars, ; returns 0 if not equal, 1 if equal ; ; FUNCTION pos[in,of,st] ; ; finds position in 'in' of 'of' starting the search at the 'st'-th ; character position in 'in'. returns 0 if not found else position. ; e.g. pos["in-here","he",#1] returns 4 ; ; FUNCTION val[s,base] ; ; returns the binary value of the ascii string in s. Base may be 2-10. ; may have a '-' sign for two's compliment of resultant value. ; ; FUNCTION SEG[s,in,from,too] ; ; extracts segment in 'in' positions 'from' to 'to'. Result into s ; returns length of s ; / ;buf: .blkb 100. PROGRAM STR FUNCTION SEG[s,in,from,too] LEN in IF too GT r0 mov r0,too(r5) FI IF from LE #0 mov #1,from(r5) FI IF too LT from OR r0 LT from OR r0 LE #0 5$: clrb @s(r5) clr r0 RET FI IF too GT r0 mov r0,too(r5) FI LET r0 = in + from - #1 mov s(r5),r1 LET r2 = too - from + #1 mov r2,r3 IF GT 10$: movb (r0)+,(r1)+ sob r2,10$ ELSE jmp 5$ FI clrb (r1) RET r3 ; AUTO a b c from too s[100.] ; FUNCTION main[argc,argv] ; LET a = argv + #2 ; PRINTF #buf "value is %d %o" val[@a(r5),#10.] val[@a(r5),#8.] ; RET ; LET b = argv + #4 ; LET c = argv + #6 ; LET r3 = pos[@a(r5),@b(r5),val[@c(r5),#10.]] ; PRINTF #buf "pos is %d" r3 ; RET AUTO sign FUNCTION val[s,base] mov #1,sign(r5) mov s(r5),r0 clr r3 DO FOREVER IFB (r0) = #0 RET r3 * sign FI IFB (r0) = #'- neg sign(r5) inc r0 ;next char ELSEIFB (r0) = #'+ inc r0 ELSE movb (r0)+,r2 BIC #177400,r2 LET r3 = r3 * base + r2 - #'0 FI OD AUTO lin lof ncmp i FUNCTION pos[in,of,st] LEN in mov r0,lin(r5) LEN of mov r0,lof(r5) IF lin LT st OR lof GT lin OR lof LE #0 RET #0 FI LET ncmp = lin - lof + #1 LOOP for i = #1 TO ncmp IF i GE st . eq[in,of,lof] IF r0 NE #0 RET i FI FI inc in(r5) NEXT i RET #0 .end