bdfs1m1g | Structured Programming Macros |
Use this macro group to define code process specific code based on a set of
conditions. The IF macro group includes the following macros:
Format
- IF
- specifies the start of the IF structure based on a conditional
expression.
- ccmask
- is any value that can be used as the mask in a branch on condition
instruction. The SPMEQ equate macro defines some of these condition
code masks.
- booleanop
- is one of the following Boolean connectors:
- arithval
- is a number represented directly in numeric form or in symbolic
form. This value can be one of the following:
- Variable
- Constant
- Result of an arithmetic expression.
- operator
- is one of the following relational operators:
- Operator
- Description
- =
- Equal
- EQ
- Equal
- ¬=
- Not equal
- NE
- Not equal
- <
- Less than
- LT
- Less than
- >
- Greater than
- GT
- Greater than
- <=
- Less than or equal
- LE
- Less than or equal
- >=
- Greater than or equal
- GE
- Greater than or equal.
- strcon
- is a string constant, which can be one of the following:
- Character (C'HELLO')
- Hexadecimal (X'4040404040')
- Binary (B'10101010').
- strsymbl
- is a symbol that represents a character string. This symbol must be
defined with a CHARACTER attribute. See DCL-Declare for more information about defining the attribute for a
symbol.
- OFFSET,byteoff
- specifies a substring, where byteoff is the distance (starting
from zero) from the leftmost byte of the string. For example,
C'12345',OFFSET,3
resolves to a substring of C'45'.
See the restrictions listed in the programming considerations.
- LENGTH,bytelen
- specifies a substring, where bytelen is the length of the string
starting from the leftmost byte. For example,
C'12345',LENGTH,4
resolves to a substring of C'1234'.
See the restrictions listed in the programming considerations.
- PAD,padval
- concatenates a character, padval, on the end of a string to fill
out the string to the end of the declared length.
See the restrictions listed in the programming considerations.
- bitsymbl
- is a symbol that represents a value for the bit mask comparison.
This symbol can be defined with any attribute, but only the leftmost byte is
used in the comparison. See DCL-Declare for more information about defining the attribute for a
symbol.
- L'bitsymbl
- specifies the length of bitsymbl and resolves to the number of
bytes of storage that bitsymbl represents.
- MASK,bitmsk
- specifies a bit mask, where bitmsk is a value that can be used as
immediate data for a test under mask (TM) instruction. See ESA/370 Principles of Operation or ESA/390 Principles of Operation for more information
about the TM instruction.
- THEN
- specifies the start of the code to process when the conditional expression
is true.
- code1
- is the code to process when the conditional expression is true.
- ELSE
- specifies the start of the code to process when the conditional expression
is false.
- code2
- is the code to process when the conditional expression is false.
- ENDIF
- ends the IF structure.
Entry Requirements
None.
Return Conditions
- Control is returned to the next sequential instruction after the ENDIF
macro statement unless another assembler instruction or macro passes control
outside of the IF structure.
- Any combination (or none) of the four work registers (default R0-R1,
R14-R15) can be used by the IF macro. A message is generated for
each work register used. The contents of each work register used are
unknown. The work registers can be changed by coding the WORK0 and
WORK2 parameters of the DCL macro. Each of these parameters must be the
even register of an even-odd pair. The contents of all other registers
are preserved across this macro call.
- If the expression is true, control is returned to the next sequential
instruction (the THEN macro). Otherwise, control is given to the
matching ELSE macro. If the ELSE macro is not used, control is passed
to the matching ENDIF macro.
Programming Considerations
- The IF, THEN, ELSE, and ENDIF macros can only be used with the IF macro
group.
- Each macro statement and assembler instruction must begin on a new
line in the application.
- Note:
- You can code the THEN macro on the same line as the IF expression, but you
must separate the expression and the THEN macro with a comma (,).
- A section of code (represented by code1, and so on) can consist
of any number of standard assembler instructions, including other SPMs or
assembler macros.
- Because the SPMs are assembler language macros, all symbols used with
the macros must be previously defined to the assembler. In addition,
for the TPF SPMs, you must declare the attributes of the symbols using the DCL
macro.
- All operations are performed left to right except when a sublist (items in
parentheses) is encountered. All items within a sublist are evaluated
before applying the preceding operator to the sublist.
- If you specify both the OFFSET and LENGTH parameters, you must code the
OFFSET parameter first.
- If you specify the OFFSET and PAD parameters with the second operand, you
must specify the LENGTH parameter on the second operand as well.
- The conditional expression is evaluated as follows:
- If you code only one operand, or if the first operand is not a
sublist but is followed by THEN, AND, or OR, the first operand is treated as a
condition code mask. The hardware condition code is tested against the
mask. If a branch on condition instruction with this mask would have
branched, the condition is evaluated as true. Otherwise, it is
evaluated as false (see step 6).
- If the first (next) item is a sublist, the key parameter
following the sublist is checked. If it is THEN, AND, or OR, the
sublist is evaluated as a conditional expression as in step 3 through step 6. Otherwise it is evaluated as an
arithmetic expression and is used as the left side of an arithmetic
comparison. Note that the arithmetic expression cannot contain
sublists.
- A conditional expression is treated as a bit mask comparison if
the MASK key parameter appears. The bits specified by the mask are
tested for 0 or 1 as indicated by the right side value.
- A conditional expression is treated as an arithmetic comparison
if the left side does not have the CHARACTER attribute. (See DCL-Declare for information about defining the attribute for a
symbol.) The left and right side values are first converted to a 32-bit
binary number. Symbols with the UNSIGNED attribute are extended on the
left with zeros. Otherwise, the high-order bit is propagated and used
as the sign of the number.
If either side is a sublist (enclosed in parentheses), it is first
evaluated as an arithmetic expression and the result is placed in one of the
work registers so that the comparison can be performed.
The comparison is then performed. The comparison is logical if the
left side symbol is UNSIGNED and not enclosed in parentheses.
Otherwise, the comparison is algebraic; that is, the high-order bit is
treated as the sign of each number.
- A string comparison is performed when the left side symbol has
the CHARACTER attribute. The right side must be a string constant or a
symbol with the CHARACTER attribute. The comparison is performed left
to right using the length of the shortest field unless the PAD key parameter
is used. In this case, the shorter string is extended conceptually with
bytes containing the pad value to the length of the longer string.
- If the comparison results match the relational operator the
conditional expression is true. Otherwise it is false. If the
conditional expression is true and is followed by OR, the rest of the IF
expression is skipped and the entire expression is evaluated as true.
(If the conditional expression is in a sublist, the rest of the sublist is
skipped and the sublist is evaluated as true).
If the conditional expression is false and is followed by AND, the
remainder of the expression (or sublist) is skipped and evaluated as
false.
Otherwise, the next expression is evaluated as in item 2.
If and when the last (or only) relational expression is evaluated, it
determines the evaluation of the whole expression (or sublist).
- The end of the IF expression is indicated by a null operand or
the THEN key parameter in an operator position. The THEN key parameter
causes the THEN macro to be processed. Otherwise, the IF macro must be
immediately followed by a THEN macro.
Examples
The following examples assume that the attributes for the referenced
symbols have been defined with following DCL macro statements:
DCL EOFSW,UNSIGNED,1
DCL I,SIGNED,4
DCL X,SIGNED,4
DCL Y,SIGNED,4
DCL Z,SIGNED,2
DCL AMOTXT,CHARACTER,99
DCL ARG,CHARACTER,4
DCL R3,REGISTER,3
IF EOFSW,=,0
- In the following example, a specific section of code is processed if the
expression ((EOFSW=1) OR (I>(X+Y))) AND (Z<3) is true.
IF EOFSW,=,1,OR,I,GT,(X,+,Y),AND,Z,LT,3
THEN
:
* Code to process
:
ENDIF
- In the following example, a specific section of code is processed if
AM0TXT=C'ZLXXX'. If AM0TXT does not equal
C'ZLXXX', the section of code following the ELSE macro is
processed.
IF AMOTXT,=,C'ZLXXX'
THEN
:
* Code to process
:
ELSE
:
* Code to process
:
ENDIF
- In the following example, the expression is evaluated with the OFFSET,
LENGTH, and PAD parameters.
IF AMOTXT,=,ARG,OFFSET,(X,+,Y),LENGTH,3,PAD,C' '
THEN
:
* Code to process
:
ENDIF
- The following example shows a bit mask comparison. If the bits set
on in mask byte SLSTRCPL do not match those in test byte SLSTLC3, the test is
true and the code following the THEN macro is processed. If any bits in
SLSTRCPL and SLSTLC3 do match, the test is false and the code following the
ELSE macro is processed.
IF SLSTLC3,MASK,SLSTRCPL,=,0
THEN
:
* Code to process
:
ELSE
:
* Code to process
:
ENDIF
- The following example shows a test that uses a number.
BUSY EQU 2
IF BUSY,THEN
:
* Code to process
:
ENDIF
- The following example shows the use of the length attribute in a bit mask
comparison.
OPTION_1 DS 0XL1
OPTION_2 DS 0XL2
FLAG_BYTE DS XL1
* Code to process
IF FLAG_BYTE,MASK,L'OPTION_1,EQ,1
THEN
:
* Code to process
:
ENDIF
:
* Code to process
:
IF FLAG_BYTE,MASK,L'OPTION_2,EQ,1
THEN
:
* Code to process
:
ENDIF
Related Macros