HLASM Language Reference
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


Arithmetic (SETA) expressions

HLASM Language Reference
SC26-4940-06

Table 1 shows how arithmetic expressions can be used.

Table 1. Use of arithmetic expressions
Used in Used as Example
SETA instruction Operand &A1 SETA &A1+2
AIF or SETB instruction Term in arithmetic relation AIF (&A*10 GT 30).A
Subscripted SET symbols Subscript &ASYM(&A+10-&C)
Substring notation Subscript 'STRING'(&A*2,&A-1)
Sublist notation Subscript

Given sublist (A,B,C,D)
named &PARAM,
if &A=1 then &PARAM(&A+1)=B

&SYSLIST Subscript
&SYSLIST(&M+1,&N-2)
&SYSLIST(N'&SYSLIST)
SETC instruction Character string in operand

Given &C  SETC  '5-10*&A'  1 
if &A=10 then
&C=5-10*10  2 
Given &D  SETC  '5-10*&A'  1 
if &A=-10 then
&D=5-10*10 3 

Built-in functions Operand &VAR SETA (NOT &OP1) &VAR SETA BYTE(64)

When an arithmetic expression is used in the operand field of a SETC instruction (see  1  in Table 1), the assembler assigns the character value representing the arithmetic expression to the SETC symbol, after substituting values (see  2  in Table 1) into any variable symbols. It does not evaluate the arithmetic expression. The mathematical sign (+ or -) is not included in the substituted value of a variable symbol (see  3  in Table 1), and any insignificant leading zeros are removed.

Here are the built-in functions for arithmetic (SETA) expressions:
AND

Format: Logical-expression
Operands: Arithmetic

Output: (aexpr1 AND aexpr2) provides an arithmetic result where each bit position in the result is set to 1 if the corresponding bit positions in both operands contain 1, otherwise, the result bit is set to 0.

Example

After the following statements &VAR contains the arithmetic value +2.
Name      Operation      Operand

&OP1      SETA           10
&OP2      SETA           2
&VAR      SETA           (&OP1 AND &OP2)
B2A

Format: Function-invocation
Operands: Character

Output: B2A('bitstring') converts a character string argument containing '0' and '1' characters to an arithmetic value.
  • Fewer than 32 characters are padded internally on the left with '0' characters to a length of 32 characters.
  • Error conditions are detected if the argument contains invalid characters, or if the argument length exceeds 32 characters, generating the message ASMA214E.
  • Null argument strings return zero.
The result of the B2A function is the same as
&value  SETA  B'bitstring'
except that null strings are allowed by B2A but not by SETA.
Examples
B2A('')              has value 0
B2A('0000000101')    has value 5
B2A('11111111111111111111111111111110')    has value -2
C2A

Format: Function-invocation
Operands: Character

Output: C2A('charstring') converts a character string of zero to four characters to a binary arithmetic value having the same bit pattern.
  • Fewer than four characters are padded internally on the left with EBCDIC null characters to a length of four characters.
  • An error condition is detected if the argument length exceeds 4 characters, generating the message ASMA214E.
  • Null argument strings return zero.
The result of C2A is the same as is obtained from
&value  SETA C'charstring'
except that C2A gives a zero result for null strings, and does not pair apostrophes or ampersands before conversion.
Example
C2A('')              has value 0
C2A('+')             has value 78
C2A('1')             has value 241
C2A('0000')          has value -252645136
D2A

Format: Function-invocation
Operands: Character

Output: D2A('decstring') converts a character string argument containing an optional leading plus or minus sign followed by decimal digits to an arithmetic value. Error conditions are detected if:
  • The argument contains invalid characters.
  • No digits are present following a sign.
  • The argument length exceeds 11 characters.
  • The resulting value is too large.

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.
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:
  • Either argument is null
  • No match is found
  • 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

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)
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

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.
  • If the character string contains fewer than eight characters, it is padded internally on the left with '0' characters.
  • Error conditions are detected if the argument contains invalid characters, or if the argument length exceeds eight characters, generating the message ASMA214E.
  • 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)

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014