SNSTR@TTUVM1.BITNET (Steve Strickland) (11/07/90)
Hello, Has anyone got any string handling macros they would be willing to share... like substr, index, verify Thanks in advance Steve Strickland
A01MES1@NIU.BITNET (Michael Stack) (11/09/90)
> If you're coding in 370 Assembler, then simply use the equivalent > machine instructions. SUBSTR ends up being either an EX (Execute) of > an MVC (Move) instruction for "short" strings ... Better, use MVCK. The length is expected to be in a register so you don't need to EXecute, and it is a true length so you don't need to worry about decrementing by one (and it can be zero if that's useful). The only drawback is that it requires an R3 operand containing the storage key of the source location. See POO for an example. Michael Stack Northern Illinois University Bitnet: A01MES1@NIU
eric@sejnet.sunet.se (Eric Thomas, SUNET) (11/09/90)
In article <9011081730.AA21056@ucbvax.Berkeley.EDU>, A01MES1@NIU.BITNET (Michael Stack) writes... >Better, use MVCK. The length is expected to be in a register so you >don't need to EXecute, and it is a true length so you don't need to >worry about decrementing by one (and it can be zero if that's useful). MVCK? What is MVCK? Oh, one of these instructions which don't work on all 370 hardware and are not known to the F assembler. I certainly wouldn't recommend them... :-) MVCK was designed in order to make life easier for operating systems like, say version 1 of your typical intruder, which need to fetch data from user storage but need to check for storage protection to make sure the user is not going to access any data belonging to someone else through a system call. The data is to be moved to "more" protected storage, though, so you really can't just load the user's protection key and do an MVCL. You have to play with ISK's and handle the case where the data spans several pages, etc. MVCK can also be much slower than MVC or MVCL, so you don't want to use it unless you have a good reason to. This of course assumes both user and system data are in the same address space. If that is not the case (like, for instance, in version 2 of your favourite intruder), you can use MVCP and MVCS instead which work with 2 address spaces. Neither work on all 370 hardware, and neither should be used in CMS programs. Eric
eric@NYU.EDU ("Eric Thomas, SUNET") (11/09/90)
In article <9011081730.AA21056@ucbvax.Berkeley.EDU>, A01MES1@NIU.BITNET (Michael Stack) writes... >Better, use MVCK. The length is expected to be in a register so you >don't need to EXecute, and it is a true length so you don't need to >worry about decrementing by one (and it can be zero if that's useful). MVCK? What is MVCK? Oh, one of these instructions which don't work on all 370 hardware and are not known to the F assembler. I certainly wouldn't recommend them... :-) MVCK was designed in order to make life easier for operating systems like, say version 1 of your typical intruder, which need to fetch data from user storage but need to check for storage protection to make sure the user is not going to access any data belonging to someone else through a system call. The data is to be moved to "more" protected storage, though, so you really can't just load the user's protection key and do an MVCL. You have to play with ISK's and handle the case where the data spans several pages, etc. MVCK can also be much slower than MVC or MVCL, so you don't want to use it unless you have a good reason to. This of course assumes both user and system data are in the same address space. If that is not the case (like, for instance, in version 2 of your favourite intruder), you can use MVCP and MVCS instead which work with 2 address spaces. Neither work on all 370 hardware, and neither should be used in CMS programs. Eric
SEB1525@mvs.draper.COM (11/09/90)
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
terry@uts.amdahl.com (Lewis T. Flynn) (11/10/90)
In article <9011081730.AA21056@ucbvax.Berkeley.EDU> IBM 370 Assembly Programming Discussion List <ASM370@OHSTVMA.BITNET> writes: >> If you're coding in 370 Assembler, then simply use the equivalent >> machine instructions. SUBSTR ends up being either an EX (Execute) of >> an MVC (Move) instruction for "short" strings ... > >Better, use MVCK. The length is expected to be in a register so you Uhhh, I don't think so. On most machines, this instruction should be slower than MVCL and has the side effect of needing to know the correct key (using the wrong one will generate a privileged operation exception in problem state). Plus this will only work for for lengths of 256 or less. The suggested EX of an MVC will be substantially faster on nearly all machines for this case and a pure MVC will be faster yet. Terry
terry@APPLE.COM ("Lewis T. Flynn") (11/10/90)
In article <9011081730.AA21056@ucbvax.Berkeley.EDU> IBM 370 Assembly Programming Discussion List <ASM370@OHSTVMA.BITNET> writes: >> If you're coding in 370 Assembler, then simply use the equivalent >> machine instructions. SUBSTR ends up being either an EX (Execute) of >> an MVC (Move) instruction for "short" strings ... > >Better, use MVCK. The length is expected to be in a register so you Uhhh, I don't think so. On most machines, this instruction should be slower than MVCL and has the side effect of needing to know the correct key (using the wrong one will generate a privileged operation exception in problem state). Plus this will only work for for lengths of 256 or less. The suggested EX of an MVC will be substantially faster on nearly all machines for this case and a pure MVC will be faster yet. Terry