IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Inspect in Assemebler


IBM Mainframe Forums -> PL/I & Assembler
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
yuvan

New User


Joined: 10 Jan 2006
Posts: 23
Location: India

PostPosted: Thu Dec 27, 2018 8:28 pm
Reply with quote

Hi Team,

I would like to search a string and set an indicator based on the results. it is similar like COBOL inspect verb, is there a way to do it.

Thanks
Raj
Back to top
View user's profile Send private message
steve-myers

Active Member


Joined: 30 Nov 2013
Posts: 917
Location: The Universe

PostPosted: Thu Dec 27, 2018 9:17 pm
Reply with quote

I'm not really a Cobol person, so I don't really know what INSPECT does.

There are two instructions you might think about.
  1. TRT (Translate and Test) - TRT is relatively easy to use, but it's probably the slower and most expensive in terms of storage, and in the general case its setup cost is quite high. On the other hand TRT can search for several different characters in one execution of the instruction, something SRST cannot do.
  2. SRST (Search string) - SRST is somewhat harder to use compared to TRT, but it should be faster as it does not use a storage intensive table like TRT.
    On the other hand, it does not have the high setup cost like TRT, which makes it much more appealing.

    The similar SRSTU (Search string unicode) might be useful to search for two paired bytes.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2022
Location: USA

PostPosted: Sun Dec 30, 2018 5:17 pm
Reply with quote

yuvan wrote:
I would like to search a string and set an indicator based on the results. it is similar like COBOL inspect verb, is there a way to do it.

Since the statement INSPECT is translated from COBOL to machine instructions equivalent to some Assembler code, and this code really works, hence the straightforward answer to this question is: yes, there is definitely a way to do it.

So far, the existing instructions in Assembler do operate with strings being searched for, or being replaced, of single character each. That's why the most of INSPECT equivalents in Assembler would require some loops, or subroutines in their Assembler versions, with rare exceptions.

INSPECT TALLYING can be implemented using a simple loop on instruction TRT (for counting a single character within a string up to 256 characters long), or loop on instruction SRST (within a string of any length).

INSPECT REPLACING for single character(s) can be done using single TR instruction (within a string up to 256 characters long), or some loop of TR/TRT/SRST insructions combination within longer strings.

For any INSPECT dealing with words longer than one character, a more complex subroutine is needed to operate with those full words after its first character has been detected by TRT/SRST.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2022
Location: USA

PostPosted: Mon Dec 31, 2018 12:37 am
Reply with quote

P.S.

In 64-bit addressing mode, some extra machine instructions are available, to simplify many string parsing solutions, such as instruction TRTE as extended and improved instruction TRT.
Often it can replace some loop code organised around regular TRT.
Back to top
View user's profile Send private message
steve-myers

Active Member


Joined: 30 Nov 2013
Posts: 917
Location: The Universe

PostPosted: Mon Dec 31, 2018 2:51 am
Reply with quote

sergeyken wrote:
P.S.

In 64-bit addressing mode, some extra machine instructions are available, to simplify many string parsing solutions, such as instruction TRTE as extended and improved instruction TRT.
Often it can replace some loop code organised around regular TRT.
Not true. TRTE requires the feature - one of the last enhanced instructions to be added to z/Architecture. It operates in all AMODEs, though the feature to use 128K function tables is probably pretty useless in AMODE 24. Reading through the Principles of Operation, the only loop control aide I see is the ability to specify a long string to test, though, as with MVCL, the machine can quit in the middle of the instruction and your program must execute the TRTE instruction again. This code should be simpler than the corresponding code with TRT.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2022
Location: USA

PostPosted: Mon Dec 31, 2018 4:16 pm
Reply with quote

steve-myers wrote:
sergeyken wrote:
P.S.

In 64-bit addressing mode, some extra machine instructions are available, to simplify many string parsing solutions, such as instruction TRTE as extended and improved instruction TRT.
Often it can replace some loop code organised around regular TRT.
Not true. TRTE requires the feature - one of the last enhanced instructions to be added to z/Architecture. It operates in all AMODEs, though the feature to use 128K function tables is probably pretty useless in AMODE 24. Reading through the Principles of Operation, the only loop control aide I see is the ability to specify a long string to test, though, as with MVCL, the machine can quit in the middle of the instruction and your program must execute the TRTE instruction again. This code should be simpler than the corresponding code with TRT.

Yes, agree.

Let the TS himself write simple examples of INSPECT in Assembler, at least with only TR, TRT, and SRST. I doubt this topic would ever reach any need of TRTE.
Back to top
View user's profile Send private message
steve-myers

Active Member


Joined: 30 Nov 2013
Posts: 917
Location: The Universe

PostPosted: Mon Dec 31, 2018 6:32 pm
Reply with quote

John Ehrman's Assembler language book has an extended discussion of TRTE, with an example. By the way, this is quite a large file. Rather than depend on your browser's PDF file viewer, you may find it more convenient to actually download the file and use regular PDF file viewers such as Adobe Acrobat to work with the file.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2022
Location: USA

PostPosted: Mon Dec 31, 2018 6:55 pm
Reply with quote

The most simple implementation for INSPECT REPLACING (one character)

COBOL
Code:
01 WS-DATA PIC X(10) VALUE 'DD-MM-YYYY'.

      INSPECT WS-DATA REPLACING ALL '-' BY '/'.

Assembler
Code:


         TR WSDATA,REPLTAB        INSPECT itself
. . . . . . . . . . . . . . . . . . .
WSDATA   DC CL10'DD-MM-YYYY'     data field
*
REPLTAB  DC X'000102030405060708090A0B0C0D0E0F'
         DC X'101112131415161718191A1B1C1D1E1F'
         DC X'202122232425262728292A2B2C2D2E2F'
         DC X'303132333435363738393A3B3C3D3E3F'
         DC X'404142434445464748494A4B4CRD4E4F'
         DC X'505152535455565758595A5B5C5D5E5F'
         DC X'606162636465666768696A6B6C6D6E6F'
         DC X'707172737475767778797A7B7C7D7E7F'
. . . . . . . . . etc . . . . . . . . . . .
         DC X'F0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF'
         ORG REPLTAB+C'-'    position of '-'
         DC C'/'                  to replace with '/'
         ORG ,               end of the full table
Back to top
View user's profile Send private message
steve-myers

Active Member


Joined: 30 Nov 2013
Posts: 917
Location: The Universe

PostPosted: Mon Dec 31, 2018 7:56 pm
Reply with quote

Sergeyken's example is good, but the translate table is rather indigestible. Here are two somewhat more digestible ways to prepare the table.
Code:
TRTAB    CSECT
TRTAB1   DC    0XL256'0',256AL1(*-TRTAB1)
         ORG   TRTAB1+C'-'
         DC    C'/'
         ORG   ,
TRTAB2   DC    0XL256'0'
TR2      DC    0XL256'0',(C'-')AL1(*-TR2),C'/',(256-(*-TR2))AL1(*-TR2)
         END

There are three issues here.
  • The Assist Assembler can't handle the AL1(*-origin) "trick."
  • Some assembler programs can't handle constructions like (256-(*-origin)). High level Assembler has no trouble with this.
  • My TRTAB1 echoes Sergeyken's table, but condensed to one line. The issue is with the ORG with no operands we both use. Not all programmers know this is a way to reset the Assembler's location counter to the high value for the section.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2022
Location: USA

PostPosted: Tue Jan 01, 2019 4:06 pm
Reply with quote

1. After reviewing multiple possible options of INSPECT in COBOL, now I'm pretty sure that in most practical cases an implementation of some loops around simple CLI/CLC/CLCL instructions would be the best approach, especially for typical data strings of 10-133 characters.

2. If I personally needed what the TS wants, I would code the required INSPECT statements with specific options in a test COBOL program, and then analyzed the compilation listing for the resulting Assembler equivalent generated by COBOL compiler.

3. It looks like the TS is the person who is the least interested in getting answer to his own question (unless the answer is a ready-to-copy-and-paste code example doing his own job).
Back to top
View user's profile Send private message
steve-myers

Active Member


Joined: 30 Nov 2013
Posts: 917
Location: The Universe

PostPosted: Wed Jan 02, 2019 9:59 am
Reply with quote

sergeyken wrote:
... 3. It looks like the TS is the person who is the least interested in getting answer to his own question (unless the answer is a ready-to-copy-and-paste code example doing his own job).

I suspect sergeyken is correct.

I had worked up both an SRST and TRT example, but never posted either one because I was not happy with the code quality. Of course if the TS (Topic Starter) wants to follow through with my proposal to use SRST or TRT - I'd be surprised if that happens - we can try to assist.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> PL/I & Assembler

 


Similar Topics
Topic Forum Replies
No new posts Help needed with INSPECT COBOL Programming 3
No new posts Inspect statement COBOL Programming 5
No new posts Using Inspect in cobol COBOL Programming 8
No new posts EQUIVALENT OF COBOL INSPECT IN REXX CLIST & REXX 2
No new posts Find the occurrence of keywords using... COBOL Programming 15
Search our Forums:

Back to Top