dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
See if this is of any use. . . .
Quote: |
The CUSE (COMPARE UNTIL SUBSTRING EQUAL) instruction is given both the address and the length of the two storage locations to be compared. It is also given a pad byte that is logically appended to the shorter of the two storage locations. Finally it is also provided the length of the substring. It will search for equal substrings of specified length at same offsets in both storage locations.
LA R2,STRING1
LA R3,L'STRING1
LA R4,STRING2
LA R5,L'STRING2
LA R0,3
LA R1,C' '
LOOP CUSE R2,R4
BC 1,LOOP
. . .
. . .
STRING1 DC C'Now is the time for all good men to come to the aid'
STRING2 DC C'Suffragettes protested for women and their right to vote'
The above will find the three letter sequence 'men' in both strings at same offset. R2 will point to 'men' in STRING1 and R4 will point to 'men' in STRING2. Somehow this does not seem like a very common programming need, does it?
There are some IBM APARs that specify code fixes concerning CUSE. These were in compression and database modules so apparently there's an esoteric use for CUSE in those areas. Maybe it's in data dictionaries?
I could see code using CLCL to compare two storage areas. Should the CLCL end on an unequal condition, with register addresses updated to point to differing bytes in each storage area, the code could then pick up from there with a CUSE instruction to find the next matching sequence or substring. This might be an efficient, or at least simple, means to isolate changes in a buffer when compared to previous content. Of course, the specification of substring size would require care.
Let's get a little tricky. What if length of one storage area is given as zero, substring size as 3 and pad byte as asterisk ("*")? This could be a very neat (and quick?) way to pick out '***' strings.
LA R2,STRING
LA R3,L'STRING
LA R4,?????? does this address even have to be valid since length = 0?
XR R5,R5 length of zero
LA R0,3
LA R1,C'*'
LOOP CUSE R2,R4
BC 1,LOOP
. . .
. . .
STRING DC C'Now is the time ! *** F L A S H *** ! for all good men'
You could quite readily skip through the buffer from one '***' to the next '***' and so on until end of buffer. Maybe you wish to flutter from ellipse ("...") to ellipse? Easy enough.
|
|
|