Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!apple!agate!ucbvax!mvs.draper.COM!SEB1525 From: SEB1525@mvs.draper.COM Newsgroups: comp.lang.asm370 Subject: Re: Need string handling macros Message-ID: <9011091740.AA29220@ucbvax.Berkeley.EDU> Date: 9 Nov 90 13:42:00 GMT Sender: daemon@ucbvax.BERKELEY.EDU Reply-To: IBM 370 Assembly Programming Discussion List Distribution: inet Organization: The Internet Lines: 99 Here's a macro that you might find useful for using TRT on strings that may be longer than 256 characters: ------------------- cut here ------------------------------------------- MACRO &SYM XTRT &DATR,&TABLE,&LENR=,&F256=0 .* .* Author: Steve Bacher (c) 1989 Charles Stark Draper Laboratory, Inc. .* .* This 370 assembler macro is provided as is. No warranty implied. .* .* DATR is the register pointing to the (sub)string to scan .* TABLE is the address of the TRT table .* LENR is the register containing the (remaining) length to scan .* F256 is the register the macro uses to hold =F'256' (default=R0) .* LCLC &LBLA,&LBLB,&LBLC,&LBLX &LBLA SETC 'XTRA&SYSNDX' &LBLB SETC 'XTRB&SYSNDX' &LBLC SETC 'XTRC&SYSNDX' &LBLX SETC 'XTRX&SYSNDX' &SYM LA &F256,256 Set up constant 256 &LBLC CR &LENR,&F256 If length greater than 256 BNH &LBLA then... TRT 0(256,&DATR),&TABLE scan for desired characters BNZ &LBLB If we found something, exit AR &DATR,&F256 Else increment text pointer by 256 SR &LENR,&F256 Decrement length by 256 B &LBLC Continue scanning. &LBLX TRT 0(*-*,&DATR),&TABLE (Executed instruction) &LBLA DS 0H Else... BCTR &LENR,0 Reduce length for execute EX &LENR,&LBLX Scan for desired characters &LBLB DS 0H MEND ------------------- cut here ------------------------------------------- Sample usage: *********************************************************************** * * * Scan quoted string, once a quote has been seen. * * * * string_pointer contains the address of beginning of the string * * string_length contains the total length of the string * * * * It is assumed in this code fragment that register 1 has been * * set to point to a quote mark by a previous {X}TRT invocation. * * * *********************************************************************** LR R6,R1 Save address of first quote S R6,string_pointer Convert to offset within string LA R3,1(,R6) Next character is first to scan QLOOP DS 0H L R15,string_length Compute length remaining to scan SR R15,R3 BNP ERROR If not positive, missing end quote LR R14,R3 Compute address in string to scan A R14,string_pointer XR R2,R2 Clear TRT register XTRT R14,TRTQUOTE,LENR=R15 Scan quoted string B QBRANCH(R2) Branch depending on what found QBRANCH B NOQUOTE B YESQUOTE * NOQUOTE DS 0H Non-quote character found ... ... do something with the non-quote mark... ... LA R3,1(,R3) Bump to next character B QLOOP Continue scanning * YESQUOTE DS 0H Quote character found CLI 1(R1),C'''' If quote mark is doubled BNE ENDQUOTE then... ... ... do something with the quote mark... ... LA R3,2(,R3) Bump past quote to next character B QLOOP Continue scanning * ENDQUOTE DS 0H End of quoted string found ... ... do something with the end of the quoted string. ... LA R3,1(,R3) Bump to next character B QLOOP Continue scanning ... TRTQUOTE DC 256YL1(0) Table to scan for quotes ORG TRTQUOTE+C'''' DC YL1(4) ORG , Hope this is useful to some of you. - Steve Bacher - Draper Lab