Scan with Control (SCANWC)


Op Code (Hex) Extender Operand 1 Operand 2 Operand 3 Operand 4 Operand [5-8]
SCANWC 10E4
Base locator Controls Options Escape target or null


SCANWCB 1CE4 Branch options Base locator Controls Options Escape target or null Branch targets


SCANWCI 18E4 Indicator options Base locator Controls Options Escape target or null Indicator targets
Operand 1: Space pointer.

Operand 2: Character(8) variable scalar.

Operand 3: Character(4) constant scalar.

Operand 4: Instruction number, relative instruction number, branch point, instruction pointer, instruction definition list element, or null.

Operand 5-8:

Description

The base string to be scanned is specified by the base locator and controls operands. The base locator addresses the first character of the base string. The controls specifies the length of the base string in the base length field.

The scan operation begins at the left end of the base string and continues character by character, left-to-right. The scan operation can be performed on a base string which contains all simple (1-byte) or all extended (2-byte) character codes or a mixture of the two. When the base string is being interpreted in simple character mode, the operation moves through the base string one byte at a time. When the base string is being interpreted in extended character mode, the operation moves through the base string 2 bytes at a time. The character string value of the base locator operand is scanned for occurrences of a character value satisfying the criteria specified in the controls and options operands.

The scan is completed by updating the base locator and controls operands with scan status when a character value being scanned for is found, the end of the base string is encountered, or an escape code is encountered when the escape target operand is specified. The base locator is set with addressability to the character (simple or extended) which caused the instruction to complete execution. The controls operand is set with information which identifies the mode (simple or extended) of the base string character addressed by the base locator and which provides for resumption of the scan operation with minimal overhead.

The controls and options operands specify the modes to be used in interpreting characters during the scan operation. Characters can be interpreted in one of two character modes: simple (1-byte) and extended (2-byte). Additionally, the base string can be scanned in one of two scan modes, mixed (base string may contain a mixture of both character modes) and nonmixed (base string contains one mode of characters).

When the mixed scan mode is specified in the options operand, the base string is interpreted as containing a mixture of simple and extended character codes. The mode, simple or extended, with which the string is to be interpreted, is controlled initially by the base mode indicator in the controls operand and thereafter by mode control characters imbedded in the base string. The mode control characters are as follows:

Hex 0E =

Shift out (SO) of simple character mode to extended mode.

Hex 0F =

Shift in (SI) to simple character mode from extended mode. This is only recognized if it occurs in the first byte position of an extended character code.

When the nonmixed scan mode is specified in the options operand, the base string is interpreted using only the character mode specified by the base mode indicator in the controls operand. Character mode shifting can not occur because no mode control characters are recognized when scanning in nonmixed mode.

The base locator operand is a space pointer which is both input to and output from the instruction. On input, it locates the first character of the base string to be processed. On output, it locates the character of the base string which caused the instruction to complete.

The controls operand must be a character scalar which specifies additional information to be used to control the scan operation. It must be at least 8 bytes long and have the following format:

Offset
Dec Hex
Field Name
Data Type and Length
0 0
Controls operand
Char(8)
0 0
Control indicators
Char(1)
0 0
Base mode
Bit 0



0 = Simple
1 = Extended


0 0
Comparison character mode
Bit 1



0 = Simple
1 = Extended


0 0
Reserved (must be 0)
Bits 2-6
0 0
Scan state
Bit 7



0 = Resume scan
1 = Start scan


1 1
Reserved
Char(1)
2 2
Comparison characters
Char(2)
4 4
Reserved
Char(1)
5 5
Base end
Char(3)
5 5
Instruction work area
Char(1)
6 6
Base length
Char(2)
8 8
--- End ---

Only the first 8 bytes of the controls operand are used. Any excess bytes are ignored. Reserved fields must contain binary 0s.

The base mode is both input to and output from the instruction. In either case, it specifies the mode of the character in the base string currently addressed by the base locator.

The comparison character mode is not changed by the instruction. It specifies the mode of the comparison character contained in the controls operand.

The scan state is both input to and output from the instruction. As input, it indicates whether the scan operation for the base string is being started or resumed. If it is being started, the instruction assumes that the base length value in the base end field of the controls operand specifies the length of the base string, and the instruction work area value is ignored. If it is being resumed, the instruction assumes the base end field has been set by a prior start scan execution of the instruction with an internal machine value identifying the end of the base string.

For a start scan execution of the instruction, the scan state field is reset to indicate resume scan to provide for subsequent resumption of the scan operation. Additionally, for a start scan execution of the instruction, the base end field is set with an internally optimized value which identifies the end of the base string being scanned. This value then overlays the values which were in the instruction work area and base length fields on input to the instruction. Predictable operation of the instruction on a resume scan execution depends upon this base end field being left intact with the value set by the start scan execution.

For a resume scan execution of the instruction, the scan state and base end fields are unchanged. For a resume scan execution of the instruction, base locator must not contain a teraspace address or an unsupported space use  (hex 0607) exception is signaled.

The comparison character is input to the instruction. It specifies a character code to be used in the comparisons performed during the scanning of the base string. The comparison character mode in the control indicators specifies the mode (simple or extended) of the comparison character. If it is a simple character, the first byte of the comparison character field is ignored and the comparison character is assumed to be specified in the second byte. If it is an extended character, the comparison character is specified as a 2-byte value in the comparison character field.

The base end field is both input to and output from the instruction. It contains data which identifies the end of the base string. Initially, for a start scan execution of the instruction, it contains the length of the base string in the base length field. Additionally, the base end field is used to retain information over multiple instruction executions which provides for minimizing the overhead required to resume the scan operation for a particular base string. This information is set on the initial start scan execution of the instruction and is used during subsequent resume scan executions of the instruction to determine the end of the base string to be scanned. If the end of the base string being scanned must be altered during iterative usage of this instruction, a start scan execution of the instruction must be performed to provide for correctly resetting the internally optimized value to be stored in the base end from the values specified in the base locator operand and base length field.

For the special case of a start scan execution where a length value of zero (no characters to scan) is specified in the base length field, the instruction results in a not found resultant condition. In this case, the base string is not verified and the scan state indicator, the base end field, and the base locator are not changed.

The options operand must be a character scalar which specifies the options to be used to control the scan operation. It must be at least 4 bytes in length and has the following format:

Offset
Dec Hex
Field Name
Data Type and Length
0 0
Options operand
Char(4)
0 0
Options indicators
Char(1)
1 1
Reserved
Char(3)
4 4
--- End ---

The options operand must be specified as a constant character scalar.

Only the first 4 bytes of the options operand are used. Any excess bytes are ignored. Reserved fields must contain binary 0s. The option indicators field has the following format:

Offset
Dec Hex
Field Name
Data Type and Length
0 0
Option indicators
Char(1)
0 0
Reserved
Bit 0
0 0
Scan mode
Bit 1



0 = Mixed
1 = Nonmixed


0 0
Reserved
Bits 2-3
0 0
Comparison relation
Bits 4-6
0 0
Equal, (=) relation
Bit 4
0 0
Less than, (<) relation
Bit 5
0 0
Greater than, (>) relation
Bit 6



0 = No match on relation
1 = Match on relation


0 0
Reserved
Bit 7
1 1
--- End ---

The scan mode specifies whether the base string contains a mixture of character modes, or contains all one mode of characters; that is, whether or not mode control characters should be recognized in the base string. Mixed specifies that there is a mixture of character modes and, therefore, mode control characters should be recognized. Nonmixed specifies that there is not a mixture of character modes and, therefore, mode control characters should not be recognized. Note that the base mode indicator in the controls operand specifies the character mode of the base string character addressed by the base locator.

The comparison relation specifies the relation or relations of the comparison character to characters of the base string which will satisfy the scan operation and cause completion of the instruction with one of the high, low, or equal resultant conditions. Multiple relations may be specified in conjunction with one another. Specifying all relations insures a match against any character in the base string which is of the same mode as the comparison character. Specifying no relation insures a not found resultant condition, in the absence of an escape due to verification, regardless of the values of the characters in the base string which match the mode of the comparison character.

An example of comparison scanning is a scan of simple mode characters for a value less than hex 40. This could be done by specifying a comparison character of hex 40 and a comparison relation of greater than in conjunction with a branch option for the resultant condition of high. This could also be done by specifying a comparison character of hex 3F and comparison relations of equal and greater than in conjunction with branch options for equal and high. The target of the branch options in either case would be the instructions to process the character less than hex 40 in value.

The escape target operand controls the verification of bytes of the base string for values less than hex 40. Verification, if requested, is always performed in conjunction with whatever comparison processing has been requested. That is, verification is performed even if no comparison relation is specified. This operand is discussed in more detail in the following material.

During the scan operation, the characters of the base string which are not of the same mode as the comparison character are skipped over until the mode of the characters being processed is the same as the mode of the comparison character. The operation then proceeds by comparing the comparison character with each of the characters of the base string. These comparisons behave as if the characters were being compared in the Compare Bytes Left Adjusted (CMPBLA) instruction.

If a base string character satisfying the criteria specified in the controls and options operands is found, the base locator is set to address the first byte of it, the base mode indicator is set to indicate the mode of the base string as of that character, and the instruction is completed with the appropriate resultant condition based on the comparison relation (high, low, or equal) of the comparison character to the base string character.

If a matching base string character is not found prior to encountering a mode change, the characters of the base string are again skipped over until the mode of the characters being processed is the same as the mode of the comparison character before comparisons are resumed.

If a matching base string character is not found prior to encountering the end of the base string, the base location is set to address the first byte of the character encountered at the end of the base string, the base mode indicator is set to indicate the mode of the base string as of that character, and the instruction is completed with the not found resultant condition. A mode control string results in the changing of the base string mode, but the base locator is left addressing the mode control character.

If the escape target operand is specified (operand 4 is not null), verifications are performed on the characters of the base string prior to their being skipped or compared with the comparison character. Each byte of the base string is checked for a value less than hex 40. Additionally, for a mixed scan mode, when such a value is encountered, it is then determined if it is a valid mode control character.

If a byte value of less than hex 40 is not a valid mode control character, it is considered to be an escape code. The base locator is set to address the first byte of the base string character (simple or extended) which contains the escape code, the base mode indicator is set to indicate the mode of the base string as of that character, and a branch is taken to the target specified by the escape target operand. When the escape target branch is performed, the value of any optional indicator operands is meaningless.

If the escape target operand is not specified (operand 4 is null), verifications of the character codes in the base string are not performed. However, for a mixed scan mode, mode control values are always processed as described previously under the discussion of the mixed scan mode.

If possible, use a space pointer machine object for the base locator, operand 1. Appreciably less overhead is incurred in accessing and storing the value of the base locator if this is done.

If possible, specify through its ODT definition, the controls operand on an 8-byte multiple (doubleword) boundary relative to the start of the space containing it. Appreciably less overhead is incurred in accessing and storing the value of the controls if this is done.

For the case where a base string is to be just scanned for byte values less than hex 40, two techniques can be used.

The following diagram defines the various conditions which can be encountered at the end of the base string and what the base locator addressability is in each case. The solid vertical line represents the end of the base string. The dashes represent the bytes before and after the base string end. The V is positioned over the byte addressed by the base locator in each case. These are the conditions which can be encountered when the base locator input to the instruction addresses a byte prior to the base string end. When the base length field specifies a value of zero for a start scan execution of the instruction, or the input base locator addresses a point beyond the end of the instruction, no processing is performed and the instruction is immediately completed with the not found resultant condition.


Scan diagram

An analysis of the diagram shows that normally, after appropriate processing for the particular found, not found, or escape condition, the scan can be restarted at the byte of data which would follow the base string end in the data stream being scanned. Any mode shift required by an ending mode control character will have been performed.

However, one ending condition may require subsequent resumption of the scan at the character encountered at the end of the base string. This is the case where the instruction completes with the not found resultant condition and the base string ends with an extended character split across string end. That is, the base mode indicator specifies extended mode, the base locator addresses the last byte of the base string, and that byte value is not a shift out, hex 0E character. In this case, complete verification of the extended character and relation comparison could not be performed. If this extended character is to be processed, it must be done through another execution of the Scan instruction where both bytes of the character can be input to the instruction within the confines of the base string.

Resultant Conditions

Authorization Required

Lock Enforcement

Exceptions

06 Addressing

08 Argument/Parameter

10 Damage Encountered

1C Machine-Dependent

20 Machine Support

22 Object Access

24 Pointer Specification

2C Program Execution

2E Resource Control Limit

32 Scalar Specification

36 Space Management

44 Protection Violation