Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Inspect in Assemebler

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> PL/I & Assembler
View previous topic :: :: View next topic  
Author Message
yuvan

New User


Joined: 10 Jan 2006
Posts: 6
Location: India

PostPosted: Thu Dec 27, 2018 8:28 pm    Post subject: Inspect in Assemebler
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: 721
Location: The Universe

PostPosted: Thu Dec 27, 2018 9:17 pm    Post subject: Reply to: Inspect in Assemebler
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

Active User


Joined: 29 Apr 2008
Posts: 408
Location: Maryland

PostPosted: Sun Dec 30, 2018 5:17 pm    Post subject: Re: Inspect in Assemebler
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

Active User


Joined: 29 Apr 2008
Posts: 408
Location: Maryland

PostPosted: Mon Dec 31, 2018 12:37 am    Post subject:
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: 721
Location: The Universe

PostPosted: Mon Dec 31, 2018 2:51 am    Post subject:
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

Active User


Joined: 29 Apr 2008
Posts: 408
Location: Maryland

PostPosted: Mon Dec 31, 2018 4:16 pm    Post subject:
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: 721
Location: The Universe

PostPosted: Mon Dec 31, 2018 6:32 pm    Post subject:
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

Active User


Joined: 29 Apr 2008
Posts: 408
Location: Maryland

PostPosted: Mon Dec 31, 2018 6:55 pm    Post subject:
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: 721
Location: The Universe

PostPosted: Mon Dec 31, 2018 7:56 pm    Post subject:
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

Active User


Joined: 29 Apr 2008
Posts: 408
Location: Maryland

PostPosted: Tue Jan 01, 2019 4:06 pm    Post subject:
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: 721
Location: The Universe

PostPosted: Wed Jan 02, 2019 9:59 am    Post subject:
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    IBMMAINFRAMES.com Support Forums -> PL/I & Assembler All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Help needed with INSPECT yvalhe COBOL Programming 3 Thu May 31, 2018 1:10 am
No new posts Inspect statement spoorni COBOL Programming 5 Mon Jun 06, 2016 9:53 pm
No new posts Using Inspect in cobol Ajay Dwivedi COBOL Programming 8 Sat Sep 26, 2015 11:33 pm
No new posts EQUIVALENT OF COBOL INSPECT IN REXX pshongal CLIST & REXX 2 Fri Nov 22, 2013 10:44 am
No new posts Find the occurrence of keywords using... suraaj COBOL Programming 15 Fri Aug 30, 2013 8:27 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us