Search String – SRST

Anubha Agarwal wrote and asked for a video covering Search String (SRST). I don’t have a video quite yet, but here are my notes on this instruction. It’s an interesting one that can be used to search for the first occurrence of a single character in a given area of storage. It was probably added to the instruction set to help compiler writers who needed to search for C strings which are terminated with X’00’.

The interesting feature of the instruction is that it can be interrupted by the CPU for efficiency reasons when searching large areas of storage. The programmer can then decide whether to continue searching or not.

I stumbled over the examples given in the Principles of Operation, until I realized the code is flawed. A BC 1,LOOP instruction should be BC 3,LOOP, so pay close attention to those two examples.

Now that I’ve written down my thoughts, I’ll put together a video soon and provide some program examples you can experiment with. This instruction is definitely worth a look.

2 Comments

Filed under Fans of IBM z, IBM Mainframe Assembler

2 responses to “Search String – SRST

  1. brian_westerman@syzygyinc.com

    The comments on your second set of samples is incorrect, the first time you do search for x’FF’, but the second time you are searching for x’00’, while the comments still say x‘FF’, probably a cut/paste error.

    SR R0,R0 SEARCH FOR X’00’

    LA R5,SRCHAREA R5 POINTS AT THE SEARCH AREA

    LOOP SRST R0,R5 SEARCH FOR X’00’,STOP AT BYTE 0

    BO LOOP CONTINUE IF SEARCH INTERRUPTED

    BH NOTFND CC = 2 – BYTE NOT FOUND

    … X’FF’ WAS FOUND, R7 HAS THE ADDRESS

    NOTFND EQU * X’FF’ WAS NOT FOUND

    Brian

    ________________________________________________

    Brian Westerman, PhD | Sr. Technical Specialist and Director of Research and Development | Syzygy Incorporated PO Box 119 | Pismo Beach, CA 93448 |☎ 800.767.2244 |📠 800.366.4082 |✉ Email Brian_Westerman@SyzygyInc.com

Leave a Reply