bdfs1m1b | Structured Programming Macros |
Use this macro group to select between several alternatives without using
complex If-Then-Else logic. This macro group is used when the choice
between a number of different code paths can be controlled by an arithmetic
variable.
The CASE macro group includes the following macros:
Format
- CASE
- starts a group of subcases based on an arithmetic expression.
If the arithmetic expression resolves to 0, the first subcase is
processed; if the arithmetic expression resolves to 1, the second subcase
is processed, and so on. There is no default subcase.
- 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.
- arithop
- is one of the following arithmetic operators:
- Operator
- Description
- +
- Addition
- -
- Subtraction
- *
- Multiplication
- /
- Integer division
- //
- Remainder.
- SCASE
- specifies the start of a subcase.
- code1
- is the code to process for the associated subcase.
- ENDSC
- specifies the end of a subcase.
- ENDC
- specifies the end of the group of subcases.
Entry Requirements
None.
Return Conditions
- Control is returned to the next sequential instruction after the ENDC
macro statement unless another assembler instruction or macro passes control
outside the CASE structure.
- Any combination (or none) of the four work registers (default R0-R1,
R14-R15) can be used by the CASE 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.
Programming Considerations
- The CASE, SCASE, ENDSC, and ENDC macros can only be used with the CASE
macro group.
- Each macro statement and assembler instruction must begin on a new
line in the application.
- 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.
- If you do not code all the possible subcases, the results cannot be
predicted.
Examples
- In the following example, the subcase is selected based on the result of
1+1; therefore, the subcase with LA R1,3 is always
selected.
CASE 1,+,1
SCASE
LA R1,1
ENDSC
SCASE
LA R1,2
ENDSC
SCASE
LA R1,3
ENDSC
ENDC
- The following example shows the use of variables in the arithmetic
expression.
NUM1 EQU EBW012,4 Reentrant for NUM1 DS A
NUM2 EQU EBW024,4 Reentrant for NUM2 DS A
DCL NUM1,UNSIGNED
DCL NUM2,UNSIGNED
:
:
* Code that assigns values to NUM1 and NUM2
:
:
*
CASE NUM1,-,NUM2
SCASE
* WHEN NUM1-NUM2 = 0
:
ENDSC
SCASE
* WHEN NUM1-NUM2 = 1
:
ENDSC
ENDC
Related Macros