Главная Manuals High Level Assembler for z/OS & z/VM & z/VSE. Language Reference (Version 1 Release 6)
|
|
|
Null argument strings return zero.
The result of the D2A function is the same as
&value SETA decstring
except that SETA does not allow leading plus or minus signs.
Examples
D2A(’’)
indicates an error condition
D2A(’000’)
has value 0
D2A(’10’)
has value 10
D2A(’+100’)
has value 100
D2A(’-5’)
has value -5
DCLEN
Format: Function-invocation
Operands: Character
Output: DCLEN(’cexpr’) returns the length of its argument string after
pairs of apostrophes and ampersands have been internally replaced by
single occurrences. No change is made to the argument. Such pairing
occurs only once; that is, three successive occurrences of an apostrophe or
ampersand result in two occurrences, not one.
Examples
DCLEN(’’)
has value 0 (null string)
DCLEN(’’’’)
has value 1 (argument is a single apostrophe)
DCLEN(’’’’’’)
has value 1 (argument is two apostrophes)
DCLEN(’&&’)
has value 1 (argument is two ampersands)
DCLEN(’a’’’’b’)
has value 3 (DCVAL string is "a’b")
DCLEN(’a’’’’b&&c’) has value 5 (DCVAL string is "a’b&c")
DCLEN(’&&&&’.’’’’’’’’) has value 4 (DCVAL string is "&&''")
Note: DCLEN is like DCVAL, except that DCLEN returns only the length
of the result, not the paired string.
FIND
Format: Logical-expression, function-invocation
Operands: Character
Output: (’string1’ FIND ’string2’) or FIND(’string1’,’string2’) finds
the first match of any character from operand2 within operand1. The value
returned by FIND indicates the position where the match occurs. FIND
returns 0 if no match occurs or if either operand is a null string.
Examples
After the following statements &VAR contains the arithmetic value 3.
Name
Operation
Operand
&OP1
SETC
’abcdef’
&OP2
SETC
’cde’
&VAR
SETA
(’&OP1’ FIND ’&OP2’)
In the above example the character c in &OP2 is the first character found in
&OP1. Consider the following example where the character c, in &OP1, has
been replaced with the character g.
Chapter 9. How to write conditional assembly instructions
361
Name
Operation
Operand
&OP1
SETC
’abcdef’
&OP2
SETC
’gde’
&VAR
SETA
(’&OP1’ FIND ’&OP2’)
&VAR contains the arithmetic value 4. The character d in &OP2 is the first
character found in &OP1.
In the following example, the ordering of the characters in the second
operand is changed to egd.
Name
Operation
Operand
&OP1
SETC
’abcdef’
&OP2
SETC
’egd’
&VAR
SETA
FIND(’&OP1’,’&OP2’)
&VAR still contains the arithmetic value 4. Because FIND is looking for a
single character from the character string, the order of the characters in the
second operand string is irrelevant.
INDEX
Format: Logical-expression, function-invocation
Operands: Character
Output: INDEX(’cexpr1’,’cexpr2’) or (’cexpr1’ INDEX ’cexpr2’) locates
the first occurrence of the second argument within the first argument, and
returns the position of the match. A zero value is returned if:
v Either argument is null
v No match is found
v The second argument is longer than the first
Examples
INDEX(’ABC’,’B’)
has value 2
INDEX(’ABC’,’D’)
has value 0
ISBIN
Format: Function-invocation
Operands: Character
Output: ISBIN(’cexpr’) determines the validity of cexpr, a string of 1 to
32 characters, as the nominal value of a binary self-defining term usable in
a SETA expression. If valid, ISBIN returns 1; otherwise, it returns zero. The
argument string must not be null.
Example
ISBIN(’10101’)
returns 1
ISBIN(’101010101010101010101010101010101’) returns 0 (excess digits)
ISBIN(’12121’)
returns 0 (non-binary digits)
ISBIN(’’)
indicates an error condition
ISDEC
Format: Function-invocation
Operands: Character
362
HLASM V1R6 Language Reference
Output: ISDEC(’cexpr’) determines the validity of cexpr, a string of 1 to
10 characters, as the nominal value of a decimal self-defining term usable
in a SETA expression. If valid, ISDEC returns 1; otherwise, it returns zero.
The argument string must be null.
Example
ISDEC(’12345678’)
returns 1
ISDEC(’+25’)
returns 0 (non-decimal character)
ISDEC(’2147483648’)
returns 0 (value too large)
ISDEC(’00000000005’)
returns 0 (too many characters)
ISDEC(’’)
indicates an error condition
ISHEX
Format: Function-invocation
Operands: Character
Output: ISHEX(’cexpr’) determines the validity of cexpr, a string of 1-8
characters, as the nominal value of a hexadecimal self-defining term usable
in a SETA expression. If valid, ISHEX returns 1; otherwise, it returns zero.
The argument string mmust not be null.
Example
ISHEX(’ab34CD9F’)
returns 1
ISHEX(’abcdEFGH’)
returns 0 (non-hexadecimal digits)
ISHEX(’123456789’)
returns 0 (too many characters)
ISHEX(’’)
indicates an error condition
ISSYM
Format: Function-invocation
Operands: Character
Output: ISSYM(’cexpr’) determines the validity of cexpr, a string of 1 to
63 characters, for use as an ordinary symbol. If valid, ISSYM returns 1;
otherwise, it returns zero. The argument string must not be null.
Examples
ISSYM(’Abcd_1234’)
returns 1
ISSYM(’_Abcd1234’)
returns 1
ISSYM(’##@$_’)
returns 1
ISSYM(’1234_Abcd’)
returns 0 (invalid initial character)
ISSYM(’’)
indicates an error condition
NOT
Format: Logical-expression
Operands: Arithmetic
Output: (NOT aexp) provides the ones complement of the value contained
or evaluated in the operand.
Example
After the following statements &VAR contains the arithmetic value -11.
Name
Operation
Operand
&OP1
SETA
10
&VAR
SETA
(NOT &OP1)
Chapter 9. How to write conditional assembly instructions
363
OR
Format: Logical-expression
Operands: Arithmetic
Output: Each bit position in the result is set to 1 if the corresponding bit
positions in one or both operands contains a 1, otherwise the result bit is
set to 0.
Example
After the following statements &VAR contains the arithmetic value +10.
Name
Operation
Operand
&OP1
SETA
10
&OP2
SETA
2
&VAR
SETA
(&OP1 OR &OP2)
SLA
Format: Logical-expression
Operands: Arithmetic
Output: The 31 bit numeric part of the signed first operand is shifted left
the number of bits specified in the rightmost six bits of the second
operand. The sign of the first operand remains unchanged. Zeros are used
to fill the vacated bit positions on the right.
Example
After the following statements &VAR contains the arithmetic value +8.
Name
Operation
Operand
&OP1
SETA
2
&OP2
SETA
2
&VAR
SETA
(&OP1 SLA &OP2)
SLL
Format: Logical-expression
Operands: Arithmetic
Output: (aexp1 SLL aexp2) shifts the 32 bit first operand left the number
of bits specified in the rightmost six bits of the second operand. Bits shifted
out of bit position 0 are lost. Zeros are used to fill the vacated bit positions
on the right.
Example
After the following statements &VAR contains the arithmetic value +40.
Name
Operation
Operand
&OP1
SETA
10
&OP2
SETA
2
&VAR
SETA
(&OP1 SLL &OP2)
SRA
Format: Logical-expression
Operands: Arithmetic
364
HLASM V1R6 Language Reference
Output: The 31 bit numeric part of the signed first operand is shifted right
the number of bits specified in the rightmost six bits of the second
operand. The sign of the first operand remains unchanged. Bits shifted out
of bit position 31 are lost. Bits equal to the sign are used to fill the vacated
bit positions on the left.
Examples
After the following statements &VAR contains the arithmetic value +2.
Name
Operation
Operand
&OP1
SETA
10
&OP2
SETA
2
&VAR
SETA
(&OP1 SRA &OP2)
After the following statements &VAR contains the arithmetic value -1.
Name
Operation
Operand
&OP1
SETA
-344
&OP2
SETA
40
&VAR
SETA
(&OP1 SRA &OP2)
Compare this result with the result in the second example under SRL
below.
SRL
Format: Logical-expression
Operands: Arithmetic
Output: The 32 bit first operand is shifted right the number of bits
specified in the rightmost six bits of the second operand. Bits shifted out of
bit position 31 are lost. Zeros are used to fill the vacated bit positions on
the left.
Examples
After the following statements &VAR contains the arithmetic value +2.
Name
Operation
Operand
&OP1
SETA
10
&OP2
SETA
2
&VAR
SETA
(&OP1 SRL &OP2)
After the following statements &VAR contains the arithmetic value 0.
Name
Operation
Operand
&OP1
SETA
-344
&OP2
SETA
40
&VAR
SETA
(&OP1 SRL &OP2)
X2A
Format: Function-invocation
Operands: Character
Output: X2A(’hexstring’) converts a character string argument containing
hexadecimal digits to an arithmetic value.
v If the character string contains fewer than eight characters, it is padded
internally on the left with ’0’ characters.
Chapter 9. How to write conditional assembly instructions
365
v Error conditions are detected if the argument contains invalid characters,
or if the argument length exceeds eight characters, generating the
message ASMA214E.
v Null argument strings return zero.
The result of the X2A function is the same as
&value SETA X’hexstring’
except that null strings are allowed by X2A but not by SETA.
Examples
X2A(’00000101’)
has value 257
X2A(’C1’)
has value 193
X2A(’’)
has value 0
X2A(’FFFFFFF0’)
has value -16
XOR
Format: Logical-expression
Operands: Arithmetic
Output: Each bit position in the result is set to 1 if the corresponding bit
positions in the two operands are unlike, otherwise the result bit is set to 0.
Example After the following statements &VAR contains the arithmetic value
+8.
Name
Operation
Operand
&OP1
SETA
10
&OP2
SETA
2
&VAR
SETA
(&OP1 XOR &OP2)
Rules for coding arithmetic expressions: Here is a summary of coding rules for
arithmetic expressions:
1. Unary (operating on one value) operators and binary (operating on two
values) operators are allowed in arithmetic expressions.
2. An arithmetic expression can have one or more unary operators preceding any
term in the expression or at the beginning of the expression. The unary
operators are + (positive) and - (negative).
3. The binary operators that can be used to combine the terms of an expression
are + (addition), - (subtraction), * (multiplication), and / (division).
4. An arithmetic expression must not begin with a binary operator, and it must
not contain two binary operators in succession.
5. An arithmetic-valued function is a term.
6. An arithmetic expression must not contain two terms in succession.
7. An arithmetic expression must not contain a decimal point. For example,
123.456 is not a valid arithmetic term, but 123 is.
8. An arithmetic expression must not contain spaces between an operator and a
term, nor between two successive operators except for built-in functions using
the “logical-expression format” described at “Logical (SETB) expressions” on
page 372.
9. Ordinary symbols specified in arithmetic expressions must be defined before
the arithmetic expression is encountered, and must have an absolute value.
366
HLASM V1R6 Language Reference
10. An arithmetic expression can contain up to 24 unary and binary operators,
and is limited to 255 levels of parentheses. The parentheses required for
sublist notation, substring notation, and subscript notation count toward this
limit.
An arithmetic expression must not contain two terms in succession; however,
any term can be preceded by up to 24 unary operators. +&A*-&B is a valid
operand for a SETA instruction. The expression &FIELD+- is invalid because it
has no final term.
Evaluation of arithmetic expressions: The assembler evaluates arithmetic
expressions during conditional assembly processing as follows:
1. It evaluates each arithmetic term.
2. It carries out arithmetic operations from left to right. However,
a. It carries out unary operations before binary operations.
b. It carries out the binary operations of multiplication and division before the
binary operations of addition and subtraction.
c. It carries out the binary operations of addition and subtraction before the
bitwise logical operations.
d. It carries out the bitwise logical operations before shift operations.
3. In division, it gives an integer result; any fractional portion is dropped.
Division by zero gives a 0 result.
4. In parenthesized arithmetic expressions, the assembler evaluates the innermost
expressions first, and then considers them as arithmetic terms in the next outer
level of expressions. It continues this process until the outermost expression is
evaluated.
5. The computed result, including intermediate values, must lie in the range -231
through +231-1. (If the value -231 is substituted in a SETC expression, its
magnitude, 2147483648, is invalid if substituted in a SETA expression.)
SETC variables in arithmetic expressions: The assembler permits a SETC
variable to be used as a term in an arithmetic expression if the character string
value of the variable is a self-defining term. The value represented by the string is
assigned to the arithmetic term. A null string is treated as zero.
Examples:
LCLC
&C(5)
&C(1)
SETC
’B’’101’’’
&C(2)
SETC
’C’’A’’’
&C(3)
SETC
’23’
&A
SETA
&C(1)+&C(2)-&C(3)
In evaluating the arithmetic expression in the fifth statement, the first term, &C(1),
is assigned the binary value 101 (decimal 5). To that is added the value represented
by the EBCDIC character A (hexadecimal C1, which corresponds to decimal 193).
Then the value represented by the third term &C(3) is subtracted, and the value of
&A becomes 5+193-23=175.
This feature lets you associate numeric values with EBCDIC or hexadecimal
characters to be used in such applications as indexing, code conversion, translation,
and sorting.
Assume that &X is a character string with the value ABC.
&I
SETC
’C’’’.’&X’(1,1).’’’’
&VAL
SETA
&TRANS(&I)
Chapter 9. How to write conditional assembly instructions
367
The first statement sets &I to C’A’. The second statement extracts the 193rd element
of &TRANS (C’A’ = X’C1’ = 193).
The following code converts a hexadecimal value in &H into a decimal value in
&VAL:
&X
SETC
’X’’&H’’’
&VAL
SETA
&X
The following code converts the double-byte character Da into a decimal value in
&VAL. &VAL can then be used to find an alternative code in a subscripted SETC
variable:
&DA
SETC
’G’’<Da>’’’
&VAL
SETA
&DA
Although you can use a predefined absolute symbol as an operand in a SETA
expression, you cannot substitute a SETC variable whose value is the same as the
symbol. For example:
ABS
EQU
5
&ABS
SETA
ABS
&ABS has value 5
&CABS
SETC
’ABS’
&CABS has value ’ABS’
&ABS
SETA
&CABS
invalid usage
DBCS assembler option: The G-type self-defining term is valid only if the DBCS
assembler option is specified.
Using SETA symbols
The arithmetic value assigned to a SETA symbol is substituted for the SETA
symbol when it is used in an arithmetic expression. If the SETA symbol is not used
in an arithmetic expression, the arithmetic value is converted to a character string
containing its absolute value, with leading zeros removed. If the value is 0, it is
converted to a single 0.
Example:
MACRO
&NAME
MOVE
&TO,&FROM
LCLA
&A,&B,&C,&D
&A
SETA
10
Statement 1
&B
SETA
12
Statement 2
&C
SETA
&A-&B
Statement 3
&D
SETA
&A+&C
Statement 4
&NAME
ST
2,SAVEAREA
L
2,&FROM&C
Statement 5
ST
2,&TO&D
Statement 6
L
2,SAVEAREA
MEND
-------------------------------------------------------------------
HERE
MOVE
FIELDA,FIELDB
-------------------------------------------------------------------
+HERE ST
2,SAVEAREA
+
L
2,FIELDB2
+
ST
2,FIELDA8
+
L
2,SAVEAREA
Statements 1 and 2 assign the arithmetic values +10 and +12 to the SETA symbols
&A and &B. Therefore, statement 3 assigns the SETA symbol &C the arithmetic value
-2. When &C is used in statement 5, the arithmetic value -2 is converted to the
character 2. When &C is used in statement 4, however, the arithmetic value -2 is
used. Therefore, &D is assigned the arithmetic value +8. When &D is used in
statement 6, the arithmetic value +8 is converted to the character 8.
368
HLASM V1R6 Language Reference
The following example shows how the value assigned to a SETA symbol can be
changed in a macro definition.
MACRO
&NAME
MOVE
&TO,&FROM
LCLA
&A
&A
SETA
5
Statement 1
&NAME
ST
2,SAVEAREA
L
2,&FROM&A
Statement 2
&A
SETA
8
Statement 3
ST
2,&TO&A
Statement 4
L
2,SAVEAREA
MEND
-------------------------------------------------------------------
HERE
MOVE
FIELDA,FIELDB
-------------------------------------------------------------------
+HERE ST
2,SAVEAREA
+
L
2,FIELDB5
+
ST
2,FIELDA8
+
L
2,SAVEAREA
Statement 1 assigns the arithmetic value +5 to SETA symbol &A. In statement 2, &A
is converted to the character 5. Statement 3 assigns the arithmetic value +8 to &A. In
statement 4, therefore, &A is converted to the character 8, instead of 5.
A SETA symbol can be used with a symbolic parameter to refer to an operand in
an operand sublist. If a SETA symbol is used for this purpose, it must have been
assigned a positive value.
Any expression that can be used in the operand field of a SETA instruction can be
used to refer to an operand in an operand sublist. Sublists are described in
“Sublists in operands” on page 304.
The following macro definition adds the last operand in an operand sublist to the
first operand in an operand sublist and stores the result at the first operand. A
sample macro instruction and generated statements follow the macro definition.
MACRO
ADDX
&NUMBER,®
Statement 1
LCLA
&LAST
&LAST
SETA
N’&NUMBER
Statement 2
L
®,&NUMBER(1)
A
®,&NUMBER(&LAST) Statement 3
ST
®,&NUMBER(1)
MEND
-------------------------------------------------------------------
ADDX
(A,B,C,D,E),3
Statement 4
-------------------------------------------------------------------
+
L
3,A
+
A
3,E
+
ST
3,A
&NUMBER is the first symbolic parameter in the operand field of the prototype
statement (statement 1). The corresponding characters (A,B,C,D,E) of the macro
instruction (statement 4) are a sublist. Statement 2 assigns to &LAST the arithmetic
value +5, which is equal to the number of operands in the sublist. Therefore, in
statement 3, &NUMBER(&LAST) is replaced by the fifth operand of the sublist.
SETB instruction
Use the SETB instruction to assign a bit value to a SETB symbol. You can assign
the bit values, 0 or 1, to a SETB symbol directly and use it as a switch.
Chapter 9. How to write conditional assembly instructions
369
If you specify a logical (Boolean) expression in the operand field, the assembler
evaluates this expression to determine whether it is true or false, and then assigns
the value 1 or 0 to the SETB symbol. You can use this computed value in condition
tests or for substitution.
►► variable_symbol SETB binary_value
►◄
variable_symbol
Is a variable symbol.
A global variable symbol in the name field must have been previously declared
as a SETB symbol in a GBLB instruction. Local SETB symbols need not be
declared in an LCLB instruction. The assembler considers any undeclared
variable symbol found in the name field of a SETB instruction as a local SET
symbol. The variable symbol is assigned a type attribute value of N.
binary_value
Is a binary bit value specified as:
v A binary digit (0 or 1)
v A binary value enclosed in parentheses
An arithmetic value enclosed in parentheses is allowed. This value can be
represented by:
- An unsigned self-defining term
- A SETA symbol
- A previously defined ordinary symbol with an absolute value
- An attribute reference other than the type attribute reference.
If the value is 0, the assembler assigns a value of 0 to the symbol in the
name field. If the value is not 0, the assembler assigns a value of 1.
v A logical expression enclosed in parentheses
A logical expression is evaluated to determine if it is true or false; the SETB
symbol in the name field is then assigned the binary value 1 or 0,
corresponding to true (1) or false (0). The assembler assigns the explicitly
specified binary value (0 or 1) or the computed logical value (0 or 1) to the
SETB symbol in the name field.
370
HLASM V1R6 Language Reference
┌───────────┐
│
│
│Logical¹
│
│Expression │
│
│
!─────┬─────┘
│
⌂ Can be any of
├─────────────┬─────────────────────────────────────────────────┐
Logical Operators Allowed
⌂
⌂
⌂
┌─────┴─────┐ ┌─────┴─────┬───────────┬───────────┐ ┌───────────┬─────┴─────┐
OR
Intersection
│
│ │
│ OR
│
│ │
│
│
AND
Union
│ Logical² │ │Logical²
│ OR NOT
│ Logical
│ │
NOT
│Logical²
│
NOT
Negation
│ Term
│ │Expression │ AND
│ Term
│ │
│Expression │
XOR
Exclusive OR
│
│ │
│ AND NOT
│
│ │
│
│
│
│ │
│ XOR
│
│ │
│
│
│
│ │
│ XOR NOT
│
│ │
│
│
!─────┬─────┘ !───────────┴───────────┴───────────┘ !───────────┴───────────┘
│
⌂ Can be any of
├─────────────┬─────────────┬─────────────┬─────────────┬─────────────┬─────────────┐
⌂
⌂
⌂
⌂
⌂
⌂
⌂
┌─────┴─────┐ ┌─────┴─────┐ ┌─────┴─────┐ ┌─────┴─────┐ ┌─────┴─────┐ ┌─────┴─────┐ ┌─────┴─────┐
│
│ │ SETB²
│ │
│ │
│ │
│ │ Predefined│ │
│
│ Logical²
│ │ Variable
│ │Arithmetic²│ │
0²
│ │
1²
│ │ Absolute
│ │ Logical²
│
│ Relation
│ │ Symbol
│ │Value
│ │
│ │
│ │ Ordinary
│ │ Function
│
│
│ │
│ │
│ │
│ │
│ │ Symbol
│ │
│
!─────┬─────┘ !───────────┘ !───────────┘ !───────────┘ !───────────┘ !───────────┘ !───────────┘
│
⌂ Can be any of
├─────────────────────────────────────────┐
⌂
⌂
┌─────┴─────┐
┌─────┴─────┐
│
│
│
│
│Arithmetic │
│ Character │
│Relation
│
│ Relation
│
│
│
│
│
!─────┬─────┘
!─────┬─────┘
│
│
Relational Operators Allowed
⌂ Which is
⌂ Which is
┌─────┴─────┬───────────┬───────────┐
┌─────┴─────┬───────────┬───────────┐
EQ
Equal
│
│ EQ, NE
│
│
│
│ EQ, NE
│
│
NE
Not equal
│Arithmetic │ LE, LT
│Arithmetic │
│ Character³│ LE, LT
│ Character³│
LE
Less than or equal
│Comparand
│ GE, GT
│Comparand
│
│ Comparand │ GE, GT
│ Comparand │
LT
Less than
│
│
│
│
│
│
│
│
GE
Greater than or equal
!─────┬─────┴───────────┴───────────┘
!─────┬─────┴───────────┴───────────┘
GT
Greater than
│
│
⌂ Which can be
⌂ Can be any of
│
├─────────────┬─────────────┬──────────────────┐
│
⌂
⌂
⌂
⌂
┌─────┴─────┐
┌─────┴─────┐ ┌─────┴─────┐ ┌─────┴──────────┐ ┌─────┴─────┐
│
│
│
│ │
│ │ Type Attribute │ │Character
│
│Arithmetic │
│Character
│ │ Substring │ │ or Operation
│ │Exp. and
│
│Expression │
│Expression │ │ Notation
│ │ Code
│ │Substring
│
│
│
│
│ │
│ │ Reference⁴
│ │Notation
│
!───────────┘
!───────────┘ !───────────┘ !────────────────┘ !───────────┘
Notes:
1. Outermost expression must be enclosed in parentheses in SETB and AIF instructions.
2. Optional parentheses around terms and expressions at this level.
3. Must be in the range 0 through 1024 characters.
4. Must stand alone and not be enclosed in apostrophes.
Figure 48. Defining logical expressions
Rules for Coding Logical Expressions: The following is a summary of coding rules
for logical expressions:
v A logical expression must not contain two logical terms in succession.
v A logical expression can contain two logical operators in succession; however,
the only allowed combinations are OR NOT, XOR NOT and AND NOT. The two
operators must be separated from each other by one or more spaces.
v Any logical term, relation, or inner logical expression can be optionally enclosed
in parentheses.
Chapter 9. How to write conditional assembly instructions
371
v The relational and logical operators must be immediately preceded and followed
by at least one space, except when written (NOT bexpr).
v A logical expression can begin with the logical unary operator NOT.
v A logical expression can contain up to 18 logical operators. The relational and
other operators used by the arithmetic and character expressions in relations do
not count toward this total.
v Up to 255 levels of nested parentheses are allowed.
v Absolute ordinary symbols specified in logical expressions must be defined
before the logical expression is encountered.
v The assembler determines the type of a logical relation by the first comparand. If
the first comparand is a character expression that begins with an apostrophe,
then the logical relation is a character relation, otherwise the assembler treats it
as an arithmetic relation.
Subscripted SETB symbols
The SETB symbol in the name field can be subscripted. If the same SETB symbol
has not been previously declared in a GBLB or LCLB instruction with an allowable
dimension, and has not been implicitly declared in a SETB instruction as a scalar
(unscripted)variable symbol, then the symbol is implicitly declared as a local SETB
array variable.
The assembler assigns the binary value explicitly specified, or implicit in the
logical expression present in the operand field, to the position in the declared array
given by the value of the subscript. The subscript expression must not be 0 or have
a negative value.
Logical (SETB) expressions
You can use a logical expression to assign a binary value to a SETB symbol. You
can also use a logical expression to represent the condition test in an AIF
instruction. This use lets you code a logical expression whose value (0 or 1) varies
according to the values substituted into the expression and thus determine whether
or not a branch is to be taken.
Figure 48 on page 371 defines a logical expression.
Logical expressions contain unquoted spaces that do not terminate the operand
field. This is called “logical-expression format”, and such expressions are always
enclosed in parentheses.
A logical expression can consist of a logical expression and a logical term separated
by a logical operator delimited by spaces. The logical operators are:
AND
Format: Logical-expression
Operands: Binary
Output: (bexpr1 AND bexpr2) has value 1, if each logical expression
evaluates to 1, otherwise the value is 0.
Example
After the following statements &VAR contains the arithmetic value 0.
372
HLASM V1R6 Language Reference
Name
Operation
Operand
&OP1
SETB
1
&OP2
SETB
0
&VAR
SETB
(&OP1 AND &OP2)
AND NOT
Format: Logical-expression
Operands: Binary
Output: The value of the second logical term is inverted, and the
expression is evaluated as though the AND operator was specified.
Example
(1 AND NOT 0) is equivalent to (1 AND 1).
NOT
Format:
Logical-expression
Operands: Binary
Output: NOT(bexp) inverts the value of the logical expression.
OR
Format: Logical-expression
Operands: Binary
Output: (bexp1 OR bexp2) returns a value of 1, if either of the logical
expressions contain or evaluate to 1. If they both contain or evaluate to 0
then the value is 0.
OR NOT
Format: Logical-expression
Operands: Binary
Output: (bexp1 OR NOT bexp2) inverts the value of the second logical term,
and the expression is evaluated as though the OR operator was specified.
For example, (1 OR NOT 1) is equivalent to (1 OR 0).
XOR
Format: Logical-expression
Operands: Binary
Output: (bexp1 XOR bexp2) evaluates to 1 if the logical expressions contain
or evaluate to opposite bit values. If they both contain or evaluate to the
same bit value, the result is 0.
XOR NOT
Format: Logical-expression
Operands: Binary
Output: (bexp1 XOR NOT bexp2) inverts the second logical term, and the
expression is evaluated as though the XOR operator was specified.
Chapter 9. How to write conditional assembly instructions
373
Example (1 XOR NOT 1) is equivalent to (1 XOR 0).
Relational operators: Relational operators provide the means for comparing two
items. A relational operator plus the items form a relation. An arithmetic relation is
two arithmetic expressions separated by a relational operator, and a character
relation is two character strings (for example, a character expression and a type
attribute reference) separated by a relational operator.
The relational operators are:
EQ Equal
NE Not equal
LE
Less than or equal
LT
Less than
GE
Greater than or equal
GT
Greater than
Evaluation of logical expressions: The assembler evaluates logical expressions as
follows:
1.
It evaluates each logical term, which is given a binary value of 0 or 1.
2.
If the logical term is an arithmetic or character relation, the assembler
evaluates:
a. The arithmetic or character expressions specified as values for comparison
in these relations
b. The arithmetic or character relation
c. The logical term, which is the result of the relation. If the relation is true,
the logical term it represents is given a value of 1; if the relation is false, the
term is given a value of 0.
The two comparands in a character relation are compared, character by
character, according to binary (EBCDIC) representation of the characters. If two
comparands in a relation have character values of unequal length, the
assembler always takes the shorter character value to be less.
Character comparisons are recognized by the presence of an opening
apostrophe in the first operand. For example, if a character comparison
involves a character function and a character constant, the constant must be
written first, as in
AIF
(’A’ eq UPPER(’a’)).Okay
3.
The assembler carries out logical operations from left to right. However,
a. It carries out logical NOTs before logical ANDs, ORs, and XORs
b. It carries out logical ANDs before logical ORs and XORs
c. It carries out logical ORs before logical XORs
4.
In parenthesized logical expressions, the assembler evaluates the innermost
expressions first, and then considers them as logical terms in the next outer
level of expressions. It continues this process until it evaluates the outermost
expression.
Using SETB symbols: The logical value assigned to a SETB symbol is used for
the SETB symbol appearing in the operand field of an AIF instruction or another
SETB instruction.
If a SETB symbol is used in the operand field of a SETA instruction, or in
arithmetic relations in the operand fields of AIF and SETB instructions, the binary
values 1 (true) and 0 (false) are converted to the arithmetic values 1 and 0.
374
HLASM V1R6 Language Reference
If a SETB symbol is used in the operand field of a SETC instruction, in character
relations in the operand fields of AIF and SETB instructions, or in any other
statement, the binary values 1 (true) and 0 (false), are converted to the character
values ’1’ and ’0’.
The following example illustrates these rules. It assumes that (L’&TO EQ 4) is true,
and (S’&TO EQ 0) is false.
MACRO
&NAME
MOVE
&TO,&FROM
LCLA
&A1
LCLB
&B1,&B2
LCLC
&C1
&B1
SETB
(L’&TO EQ 4)
Statement 1
&B2
SETB
(S’&TO EQ 0)
Statement 2
&A1
SETA
&B1
Statement 3
&C1
SETC
’&B2’
Statement 4
ST
2,SAVEAREA
L
2,&FROM&A1
ST
2,&TO&C1
L
2,SAVEAREA
MEND
-------------------------------------------------------------------
HERE
MOVE
FIELDA,FIELDB
-------------------------------------------------------------------
+HERE ST
2,SAVEAREA
+
L
2,FIELDB1
+
ST
2,FIELDA0
+
L
2,SAVEAREA
Because the operand field of statement 1 is true, &B1 is assigned the binary value 1.
Therefore, the arithmetic value +1 is substituted for &B1 in statement 3. Because the
operand field of statement 2 is false, &B2 is assigned the binary value 0. Therefore,
the character value 0 is substituted for &B2 in statement 4.
SETC instruction
The SETC instruction assigns a character value to a SETC symbol. You can assign
whole character strings, or concatenate several smaller strings together. The
assembler assigns the composite string to your SETC symbol. You can also assign
parts of a character string to a SETC symbol by using the substring notation; see
“Substring notation” on page 378.
A character string consists of any combination of characters enclosed in
apostrophes. Variable symbols are allowed. The assembler substitutes the
representation of their values as character strings into the character expression
before evaluating the expression. Up to 4064 characters are allowed in a character
expression.
You can change the character value assigned to a SETC symbol. This lets you use
the same SETC symbol with different values for character comparisons in several
places, or for substituting different values into the same model statement.
►► variable_symbol SETC character_value
►◄
variable symbol
Is a variable symbol.
Chapter 9. How to write conditional assembly instructions
375
A global variable symbol in the name field must have been previously declared
as a SETC symbol in a GBLC instruction. Local SETC symbols need not be
declared in an LCLC instruction. The assembler considers any undeclared
variable symbol found in the name field of a SETC instruction as a local SET
symbol. The variable symbol is assigned a type attribute value of U.
character_value
Is a character value specified by:
v An operation code attribute reference
v A type attribute reference
v A character expression
The assembler assigns the character string value represented in the operand field
to the SETC symbol in the name field. The string length must be in the range 0
(null character string) through 4064 characters.
When a SETA or SETB symbol is specified in a character expression, the unsigned
decimal value of the symbol (with leading zeros removed) is the character value
given to the symbol.
A duplication factor can precede a character expression or substring notation. The
duplication factor can be any non-negative arithmetic expression allowed in the
operand of a SETA instruction. For example:
&C1
SETC
(3)’ABC’
assigns the value ’ABCABCABC’ to &C1.
A zero duplication factor results in a null (zero-length) string.
Notes:
1.
The assembler evaluates the represented character string (in particular, the
substring; see “Substring notation” on page 378) before applying the
duplication factor. The resulting character string is then assigned to the SETC
symbol in the name field. For example:
&C2
SETC
’ABC’.(3)’ABCDEF’(4,3)
assigns the value ’ABCDEFDEFDEF’ to &C2.
2.
If the character string contains double-byte data, then redundant SI/SO pairs
are not removed on duplication. For example:
&C3
SETC
(3)’<.A.B>’
assigns the value ’<.A.B><.A.B><.A.B>’ to &C3.
3.
To duplicate double-byte data, without including redundant SI/SO pairs, use
the substring notation. For example:
&C4
SETC
(3)’<.A.B>’(2,4)
assigns the value ’.A.B.A.B.A.B’ to &C4.
4.
To duplicate the arithmetic value of a previously defined ordinary symbol with
an absolute value, first assign the arithmetic value to a SETA symbol. For
example:
A
EQU
123
&A1
SETA
A
&C5
SETC
(3)’&A1’
assigns the value ’123123123’ to &C5.
376
HLASM V1R6 Language Reference
┌───────────┐
│
│
│Character
│
│Expression │
│
│
!─────┬─────┘
│
⌂ Can be any of
├─────────────┬─────────────┬──────────────────────┐
⌂
⌂
⌂
⌂
┌─────┴─────┐ ┌─────┴──────┐ ┌────┴──────────────┐ ┌─────┴────────┬────────────┐
│
│ │
│ │
│ │
│
│
│ Character │ │ CharExpr
│ │ Character-Valued
│ │ (Duplication │ CharExpr
│
│ Value
│ │
. ◄──┐ │ │ Built-In Function │ │ Factor)
│
│
│
│ │ CharExpr │ │ │
│ │
│
│
!─────┬─────┘ !──────────┼─┘ !───────────────────┘ !──────────────┴────────────┘
│
│
│
!── Period (.) = Concatenation Character
⌂ Can be any of
├─────────────┬─────────────┬─────────────┐
⌂
⌂
⌂
⌂
┌─────┴─────┐ ┌─────┴─────┐ ┌─────┴─────┐ ┌─────┴─────┐
│ Substring │ │ Variable
│ │ Self-
│ │ Attribute¹│
│
│ │ Symbol
│ │ Defining
│ │ Reference │
│
│ │
│ │ Term
│ │
│
│
│ │
│ │
│ │ T’ or O’
│
!───────────┘ !───────────┘ !───────────┘ !───────────┘
Figure 49. Defining character (SETC) expressions
Note:
1. The attribute reference term must not be preceded by a duplication factor.
Subscripted SETC symbols
The SETC symbol (see ▌1▐ in Figure 50 on page 378) in the name field can be
subscripted. If the same SETC symbol has not been previously declared in a GBLC
or LCLC instruction with an allowable dimension (see ▌2▐ in Figure 50 on page
378), or has been implicitly declared in a SETC instruction as a scalar (unscripted)
variable symbol, then the symbol is implicitly declared as a local SETC array
variable.
The assembler assigns the character value represented in the operand field to the
position in the declared array (see ▌3▐ in Figure 50 on page 378) given by the value
of the subscript. The subscript expression must not be 0 or have a negative value.
Chapter 9. How to write conditional assembly instructions
377
LCLC
&C1,&C2
LCLC
&SUBSCRC(20)
&D(4)
SETC
’XYZ’
⌂
┌─── ▌1▐
└─── ▌2▐⌂
&SUBSCRC(10) SETC
’ABCDE’
│
│
│
────────────────────────┼──────────────────────────────────────────────
▌3▐─────┐
&SUBSCRC Array:
│
⌂
┌─────┬─────┬─────┬────/ /────┬─────┬─────┬─────┬────/ /────┬─────┐
│
│
│
│
│ABCDE│
│
│
│
│
└─────┴─────┴─────┴────/ /────┴─────┴─────┴─────┴────/ /────┴─────┘⌂
⌂
⌂
⌂
⌂
⌂
⌂
⌂
⌂
1
2
3
4
10
11
12
13
20
Figure 50. Subscripted SETC symbols
Character (SETC) expressions
The main purpose of a character expression is to assign a character value to a
SETC symbol. You can then use the SETC symbol to substitute the character string
into a model statement.
You can also use a character expression as a value for comparison in condition
tests and logical expressions. Also, a character expression provides the string from
which characters can be selected by the substring notation.
Substitution of one or more character values into a character expression lets you
use the character expression wherever you need to vary values for substitution or
to control loops.
An attribute reference must be the only term in a character expression.
Substring notation: The substring notation lets you refer to one or more
characters within a character string. You can, therefore, either select characters from
the string and use them for substitution or testing, or scan through a complete
string, inspecting each character. By concatenating substrings with other substrings
or character strings, you can rearrange and build your own strings.
The substring notation can be used only in conditional assembly instructions.
Table 60 shows how to use the substring notation.
Table 60. Substring notation in conditional assembly instructions
Value
assigned to
Used in
Used as
Example
SETC Symbol
SETC
&C1
SETC
’ABC’(1,3)
instruction
Operand
ABC
operand
&C2
SETC ’&C1’(1,2).’DEF’
Part of
ABDEF
operand
378
HLASM V1R6 Language Reference
Table 60. Substring notation in conditional assembly instructions (continued)
Value
assigned to
Used in
Used as
Example
SETC Symbol
AIF or SETB
Character
---
AIF
(’&STRING’(1,4) EQ ’AREA’).SEQ
instruction
value in
&B SETB
(’&STRING’(1,4).’9’ EQ ’FULL9’)
operand
comparand
(logical
of character
expression)
relation
The substring notation must be specified as follows:
’CHARACTER STRING’(e1,e2)
where the CHARACTER STRING is a character expression from which the substring is
to be extracted. The first subscript (e1) shows the position of the first character that
is to be extracted from the character string. The second subscript (e2) shows the
number of characters to be extracted from the character string, starting with the
character indicated by the first subscript. Thus, the second subscript specifies the
length of the resulting substring.
The second subscript value of the substring notation can be specified as an asterisk
(*), to indicate that all the characters beginning at the position of the first
expression are used. The extracted string is equal to the length of the character
expression, less the number of characters before the starting character.
The character string must be a valid character expression with a length, n, in the
range 1 through 4064 characters. The length of the resulting substring must be in
the range 0 through 4064.
The subscripts, e1 and e2, must be arithmetic expressions.
When you use subscripted variable symbols in combination with substring
notation, take care to distinguish variable subscripts from substring-operation
subscripts.
LCLC &DVAR(10),&SVAR,&C(10)
&C(1) SETC
’&DVAR(5)’
Select 5th element of &DVAR
&C(2) SETC
’&SVAR’(1,3)
Select substring of &SVAR
&C(3) SETC
’&DVAR(5)’(1,3)
Select substring of &DVAR(5)
&C(4) SETC
’&SYSLIST(1,3)’(1,3)
Select substring of &SYSLIST(1,3)
Evaluation of substrings: The following examples show how the assembler
processes substrings depending on the value of the elements n, e1, and e2.
v In the usual case, the assembler generates a correct substring of the specified
length:
Value of Variable Character Value
Notation
Symbol
of Substring
’ABCDE’(1,5)
ABCDE
’ABCDE’(2,3)
BCD
’ABCDE’(2,*)
BCDE
’ABCDE’(4,*)
DE
’&C’(3,3)
ABCDE
CDE
’&PARAM’(3,3)
((A+3)*10)
A+3
v When e1 has a zero or negative value, the assembler generates a null string and
issues error message ASMA093E.
Chapter 9. How to write conditional assembly instructions
379
Character Value
Notation
of Substring
’ABCDE’(0,5)
null character string
’ABCDE’(0,*)
null character string
v
When the value of e1 exceeds n, the assembler generates a null string and issues
error message ASMA092E.
Value of Variable Character Value
Notation
Symbol
of Substring
’ABCDE’(7,3)
null character string
’ABCDE’(6,*)
null character string
v
When e2 has a value less than one, the assembler generates the null character
string. If e2 is negative, the assembler also issues error message ASMA095W.
Value of Variable Character Value
Notation
Symbol
of Substring
’ABCDE’(4,0)
null character string
’ABCDE’(3,-2)
null character string
v
When e2 indexes past the end of the character expression (that is, e1+e2 is
greater than n+1), the assembler issues warning message ASMA094I, and
generates a substring that includes only the characters up to the end of the
character expression specified.
Value of Variable Character Value
Notation
Symbol
of Substring
’ABCDE’(3,5)
CDE
Figure 51 shows the results of an assembly of SETC instructions with different
substring notations.
Sample Program
-
LRSAMP02 - HLASM
Page
3
Active
Usings: None
Loc
Object Code
Addr1
Addr2
Stmt Source Statement
HLASM R6.0
2015/02/23 09.41
2 ***********************************************************************
3 *
4 * Licensed Materials - Property of IBM
5 *
6 *
5696-234
7 *
8 * Copyright IBM Corporation 2008, 2015 All Rights Reserved.
9 *
10 * US Government Users Restricted Rights - Use, duplication
11 * or disclosure restricted by GSA ADP Schedule Contract
12 * with IBM Corp.
13 *
14 ***********************************************************************
00000000
00000000 00000000
15 LPSAMP02 CSECT
16 &STRING SETC
’STRING’
17 &SUBSTR1 SETC
’&STRING’(0,4)
** ASMA093E Substring expression 1 less than 1; default=null - OPENC
** ASMA435I Record 17 in SMORSA.BOOK.SAMPLE.ASM(LRSAMP02) on volume: 37P003
18 &SUBSTR2 SETC
’&STRING’(7,4)
** ASMA092E Substring expression 1 points past string end; default=null - OPENC
** ASMA435I Record 18 in SMORSA.BOOK.SAMPLE.ASM(LRSAMP02) on volume: 37P003
19 &SUBSTR3 SETC
’&STRING’(3,0)
20 &SUBSTR4 SETC
’&STRING’(3,-2)
** ASMA095W Substring expression 2 less than 0; default=null - OPENC
** ASMA435I Record 20 in SMORSA.BOOK.SAMPLE.ASM(LRSAMP02) on volume: 37P003
21 &SUBSTR5 SETC
’&STRING’(3,4)
22 &SUBSTR6 SETC
’&STRING’(3,5)
23
END
Figure 51. Sample assembly using substring notation
380
HLASM V1R6 Language Reference
|
|