S P Ms Notes
S P Ms Notes
S P Ms Notes
IN T ERN AT I O N A L
INTRODUCTION TO
STRUCTURED PROGRAMMING
MACROS (SPMs)
Structured Programming Macros Galileo Technical Training Department
Table of Contents
Introduction To SPM's
.................................................................................................. ...........
1
Some Basic Conventions
.................................................................................................. ...........
2
The #IF Macro
.................................................................................................. ...........
3
Instruction Set for the #IF Macro
..................................................................................................... .................
3
Rules for the #IF Macro
..................................................................................................... .................
3
The #IF MACRO - Basic Structures
..................................................................................................... .................
4
The Conditional Expression
.................................................................................................. ...........
8
Instructions that must have a Conditional Expression:
..................................................................................................... .................
8
Instructions that can have a Conditional Expression:
..................................................................................................... .................
8
Rules for the Conditional Expression:
..................................................................................................... .................
8
Valid Condition Code Mnemonics
..................................................................................................... .................
9
Examples Of Conditional Expressions
..................................................................................................... .................
10
Special Conditional Instructions
..................................................................................................... .................
13
Continuation and Boolean Connectors
.................................................................................................. ...........
16
Instruction Set for Boolean Connectors
..................................................................................................... .................
16
Rules for Boolean Connectors
..................................................................................................... .................
16
Rules for Continuation
..................................................................................................... .................
17
The #DO Macro
.................................................................................................. ...........
20
..................................................................................................... .................
34
The #PERF Macro - Basic Structures
..................................................................................................... .................
35
The #PERF Macro - CODING GUIDELINES
..................................................................................................... .................
36
Subroutines....................................................................................... ........................36
The #GOTO Macro
.................................................................................................. ...........
37
Instruction Set for the #GOTO Macro
..................................................................................................... .................
37
Rules for the #GOTO Macro
..................................................................................................... .................
37
#LOCA label
..................................................................................................... .................
37
The #EXEC Macro
.................................................................................................. ...........
38
Instruction Set for the #EXEC Macro
..................................................................................................... .................
38
Rules for the #EXEC Macro
..................................................................................................... .................
38
The #UEXEC Macro
.................................................................................................. ...........
39
Instruction Set for the #UEXEC Macro
..................................................................................................... .................
39
Rules for the #UEXEC Macro
..................................................................................................... .................
39
The #CASE Macro
.................................................................................................. ...........
40
The 'CASE' Set
..................................................................................................... .................
40
Instruction Set for the #CASE Macro
..................................................................................................... .................
40
#CAST reg or #CAST reg,POWER=n or #CAST reg,POWER=n,MAX=M
..................................................................................................... .................
41
Rules for the #CASE Macro
..................................................................................................... .................
42
#CASE Nx or #CASE Nx,Ny or #CASE ERROR
..................................................................................................... .................
42
#ECAS
22561379.doc 1997 Galileo International Partnership. All Rights Reserved. Page iii
Structured Programming Macros Galileo Technical Training Department
..................................................................................................... .................
42
The #CASE Macro - CODING GUIDELINES
..................................................................................................... .................
45
The Condensed Form
.................................................................................................. ...........
47
Rules for the Condensed Form
..................................................................................................... .................
47
The Condensed TEST UNDER MASK
..................................................................................................... .................
47
The Condensed "COMPARE" Command
..................................................................................................... .................
48
The Condensed Form - CODING GUIDELINES
..................................................................................................... .................
49
Introduction To SPM's
A large portion of TPF programming consists of modifying existing code. The way a program
is written effects how easy it is to understand and therefore, modify.
If code is split up into discrete routines it becomes easier to test and maintain. However, it is
often more convenient to 'straight line' code in Assembler.
• Sequence
• Iteration
• Selection
SPM's (Structured Programming Macros) provide the control of Iteration (looping) and
Selection (branching). The use of SPM's forces the programmer to consider the logical
flow and structure of the program. This results in code where the routines are logically
separate from each other, and produces 'Structured' coding.
The users of SPM's have determined that the time required to write new code with SPM's is
about the same as to write it without. However, there is a considerable saving during
testing and later development as it is easier to find and modify the required code in a
structured program.
SPM's (Structured Programming Macros) originated from IBM. However, they have been
considerably enhanced by British Airways, KLM, and Swiss Air to ensure compatibility with
an ACP/TPF environment, and to provide special facilities for easier programming under
ACP/TPF.
The SPM's presented in this course are the enhanced version of the macros developed by
British Airways, KLM, and Swiss Air.
IBM has stated that all future TPF development work will be done with the aid of SPM's.
To an increasing extent, this is already true.
Labels are no longer necessary in front of instructions: i.e. LABEL EQU * is no longer
required. Therefore, to allow more space for comment statements,
start to code in Column 4.
SPM's allow up to 32 characters for its labels. It is no longer necessary to try to squeeze
a descriptive label (eg. for a routine or function) into 8 characters by eliminating all of the
vowels!
Coding inside SPM macros should be indented: the body of the coding (which is usually
normal BAL) should be indented by three columns. This makes the code much easier to
read.
Although the compiler can handle many nesting levels, it is recommended that no more
than 4 nesting levels be used in any given routine. Any more than that, and it becomes
confusing to the eye.
When practicable, insure that the #IF macro and its corresponding #EIF are on the same
page of the listing. One should be able to see the entire structure at a glance.
The same applies to a #DO and #EDO structure.
The #IF macro is used to handle the Selective element of logic based on conditional
expressions.
#IF
#ELIF
#ELSE
#EIF
• Each #IF and #ELIF must have have at least one Conditional Expression.
#IF
#IF true TRUE
...........
........... FALSE
........... PROCESS
#EIF
#EIF
FALSE
#IF true #IF #ELSE
...........
........... TRUE
...........
#ELSE PROCESS PROCESS
...........
...........
...........
#EIF #EIF
FALSE FALSE
#IF true #IF #ELIF
...........
...........
........... TRUE TRUE
#ELIF true
........... PROCESS PROCESS
...........
...........
#EIF
#EIF
TRUE
#IF true #IF PROCESS
...........
...........
........... FALSE
...........
...........
TRUE
#ELIF true #ELIF PROCESS
...........
...........
........... FALSE
...........
........... TRUE
#ELIF true #ELIF PROCESS
...........
...........
........... FALSE
...........
...........
#ELSE #ELSE
...........
...........
...........
........... PROCESS
...........
#EIF
#EIF
TRUE
#IF true #IF PROCESS
...........
...........
........... FALSE
...........
...........
TRUE TRUE
#ELIF true #ELIF #IF
#IF true
...........
........... FALSE
FALSE PROCESS
...........
...........
........... #ELSE
#ELSE
...........
...........
...........
........... PROCESS
...........
#EIF
#EIF #EIF
#EIF
TRUE
#IF true #IF PROCESS
...........
...........
........... FALSE
...........
...........
TRUE
#ELSE #ELSE #IF
#IF true
...........
........... FALSE
PROCESS
...........
...........
........... #ELSE
#ELSE
...........
...........
...........
........... PROCESS
...........
#EIF
#EIF #EIF
#EIF
The Conditional Expression enables a choice to be made between two or more different
processes to be executed based on a condition.
#IF
#ELIF
#EXIF
#DOEX
#DO
#GOTO
• The entire Conditional Expression can be considered a set of parameters for the macro
with which it has been coded. All portions of the Conditional Expression are separated
by a comma.
• The Conditional Expression for the #IF macro can be coded within parenthesis, however
the parentheses are not necessary. In all examples of the #IF macro presented in this
course, the parentheses will not be used.
PLEASE NOTE:
COMPARE Instructions
C #IF C,R4,EQ,=F'5000'
#IF C,R5,NE,FIELD_B
CR #IF CR,R2,EQ,R3
#IF CR,R5,GT,R6
CH #IF CH,R3,LE,=H'10'
#IF CH,R1,EQ,FIELD_B
ARITHMETIC Instructions
AR #IF AR,R2,R3,ZERO
OC #IF OC,FIELD_A,FIELD_A,NONZERO
PLEASE NOTE: BAL Instructions not listed above which can also be used: O, OI, OR,
NC, N, NI, NR, XC, X, XI, A, AP, AH, ALR, AL, SR, S, SP, SH, SLR,
SL, CS, CDS, ICM, LCR, LNR, LPR, MVCL, SRP, SLDA, SLA,
SRDA, SRA, TRT, ED, EDMK, ZAP
TM #IF TM,FIELD_A,X'01',OFF
#IF TM,FIELD_A,X'80',ON
#IF TM,FIELD_A,#CAR,NONZERO
#IF TM,FIELD_A,BIT0,OFF
#IF TM,FIELD_A,BITS2-4/6,ZERO
#IF TM,FIELD_A,BITS4-7,MIXED
ACP/TPF MACROS
PLEASE NOTE: These macros can be handled by SPM's. Other ACP/TPF macros
with labels might not be recognised by SPM's.
If a condition code has been set by another instruction or another Conditional Expression, it
is possible to code SPM's in a manner that more closely resembles traditional BAL code.
Here are some examples of this more "abbreviated" type of Conditional Expression.
Conditional Expression
#IF 8
#IF EQ
#IF ZERO
#ELIF GT
#ELIF ZERO
TM FIELD_A,X'80'
BO LABEL1
BCTR R5,0
LABEL1 EQU *
LA R6,1(R6)
CLI FIELD_A,C'G'
BE LABEL1
ST R6,FIELD_B
B LABEL2
LABEL1 EQU *
ST R6,FIELD_C
LABEL2 EQU *
SR R6,R6
LTR R2,R2
BZ LABEL3
SR R1,R4
BZ LABEL1
MVC FIELD_A(2),=C'AA'
B LABEL2
LABEL1 EQU *
MVC FIELD_A(2),=C'BB'
LABEL2 EQU *
OC FIELD_B,FIELD_C
LABEL3 EQU *
BACKC
TM FIELD_A,X'40'
BO LABEL1
OI FIELD_A,X'80'
B LABEL3
LABEL1 EQU *
C R1,FIELD_B
BL LABEL2
OI FIELD_A,X'70'
B LABEL3
LABEL2 EQU *
MVI FIELD_A,X'60'
LABEL3 EQU *
ENTNC ABCD
Increment R1 by 10
Decrement R2 by 20
If R2 is greater than 0
Set EBW000 = 'B'
Otherwise
Set EBW000 = 'A'
Set R2 to Zero
If bit 2 of EBW000 = 0
Increment R2 by 1
If bit 2 of EBW000 = 1
Increment R2 by 10
An SPM statement that has been compounded to combine more than one Conditional
Expression is called a Complex Conditional Expression.
Complex Conditional Expressions are linked and/or separated with Boolean Connectors.
AND
OR
ANDIF
ORIF
If space permits, the entire Compound Conditional Expression can be placed on a single
line, as in Example 1 on the next page.
If there is not room for the entire Compound Conditional Expression on one line, or if it is
more "readable" to have the separate Conditional Expressions each on its own line, then the
Conditional Expressions can be continued onto the next line/s by placing a hash sign (#)
followed by a blank, in any column (except column 1). Please see Example 2 below.
* No continuation character has to be specified in column 72 (as with normal BAL). Make
sure that the line ends with a comma.
Examples 1 and 2 below, illustrate how individual Conditonal Expressions are linked and
separated by the AND and OR Boolean Connectors.
Example 1
#IF TM,EBW000,X'80',ZERO,AND,TM,EBW100,X'80',ZERO
SR R1,R1
#EIF
Example 2
#IF TM,EBW000,X'80',ZERO,OR,
# TM,EBW100,X'80',ZERO
SR R1,R1
#EIF
Examples 3 and 4 below, illustrate how groups of Conditional Expressions are linked and
separated by the ANDIF and ORIF Boolean Connectors.
Example 3 Example 4
SR R1,R1 LA R1,1(R1)
#EIF #EIF
Example 5 below, illustrates the same example as seen above in Example 3. In this
illustration however, please note that the ANDIF has been placed on a line by itself. This is
also an acceptable manner to code, using the Boolean Connector.
Example 5
#IF CLI,EBW000,EQ,C'A',OR,
# CLI,EBW000,EQ,C'B',OR,
# CLI,EBW000,EQ,C'C',
# ANDIF,
# CLI,EBW100,EQ,C'1',OR,
# CLI,EBW100,EQ,C'2',OR,
# CLI,EBW100,EQ,C'3'
SR R1,R1
#EIF
Please code the following routines using SPM's with Boolean Connectors:
CLI FIELD_A,C'X'
BE LABEL1
CLI FIELD_A,C'Y'
BNE LABEL2
LABEL1 EQU *
SR R6,R6
LABEL2 EQU *
LA R5,1(R5)
CLI EBW000,X'80'
BH LABEL1
CLI EBW000,X'08'
BL LABEL1
ST R5,FIELD_A
LABEL1 EQU *
BACKC
CLI FIELD_A,C'P'
BE LABEL1
CLI FIELD_A,C'Q'
BE LABEL1
CLI FIELD_A,C'R'
BNE LABEL2
LABEL1 EQU *
CLI FIELD_B,X'FO'
BE LABEL3
CLI FIELD_B,X'F1'
BE LABEL3
CLI FIELD_B,X'F2'
BE LABEL3
LABEL2 EQU *
MVC FIELD_C(3),=C'ERR'
B LABEL4
LABEL3 EQU *
MVC FIELD_C(2),=C'OK'
LABEL4 EQU *
ENTRC ABCD
The #DO Macro is used to handle the Iteration element of Logic, (i.e. Looping).
#DO
#DOEX
#EXIF
#OREL
#ELOP
#EDO
• Perform the code between #DO and #EDO (or #ELOP) as long as the Conditional
Expression(s) is/are true.
Control is at the start of the loop. Control is at the end of the loop.
The process will not be performed The process will always be performed at
if the condition is not met least once.
#DO #DO
UNTIL/
WHILE TIMES
FALSE
CONDITION
INITIALISE
TRUE IF TIMES
PROCESS PROCESS
#EDO CONDITION
FALSE
TRUE
#EDO
#DO WHILE=( )
The Condition is being checked at the top of the loop. (Loop could be executed 0 times).
Examples
#DO WHILE=(TM,FIELDA,BIT1,ON,AND,TM,FIELDB,BIT2,OFF)
#DO WHILE=(LTR,R1,R1,NONZERO)
#DO WHILE=(CH,R1,EQ=H'500',OR,CH,R2,EQ,=H'650')
#DO UNTIL=( )
The Condition is being checked at the bottom of the loop. (Loop will be executed at least
once.)
Examples
#DO UNTIL=(TM,FIELDA,BIT1,OFF)
#DO UNTIL=(TM,FIELDA,BIT1,OFF,AND,TM,FIELDB,BIT2,ON)
#DO UNTIL=(CH,R1,LT=H'500',OR,CH,R2,GT,=H'650')
#DO INF
Creates an infinite loop. Needs at least one #DOEX or #EXIF in order to terminate the loop.
Example
#DO INF
Perform the code between #DO and #EDO (or #ELOP) until the specified register is 0.
The specified register can be loaded before the loop or by specifying an intialization value
(n) as the second paratmeter.
Examples
Note:-
#EDO
End of Loop.
#ELOP
• End of iteration
#ELOP Example
FALSE
#DO
#DO
................
................ TRUE
................
................ PROCESS
#ELOP
................
................
................ #ELOP
................
#EDO
PROCESS
#EDO
#DOEX
• #DOEX can only be coded in conjunction with a #DO loop. It can never be used in
conjunction with an #IF macro.
#DOEX/#ELOP Example
#DO
#DO WHILE WHILE
................
................ FALSE
................ CONDITION
................
#DOEX TRUE
................
................ PROCESS
................
................
TRUE
#EDO #DOEX
PROCESS
#EDO
#EXIF
• The code between #EXIF and #OREL is performed once, if the Conditional Expression is
true, and after that, control is given to #EDO (never to #ELOP).
#EXIF/#OREL Example 1
#DO
WHILE
#DO WHILE
................ FALSE
CONDITION
................
................
................ TRUE
#EXIF
PROCESS
................
................
................
................ #EXIF FALSE
#EXIF
#OREL
................
#EXIF TRUE
................
................
................ PROCESS
#EDO
#OREL
PROCESS
#EDO
#EXIF/#OREL Example 2
#DO
WHILE
#DO WHILE
................
................ FALSE
CONDITION
................
................
TRUE
#EXIF PROCESS
................
PROCESS
................
................
................
#EXIF FALSE
#OREL #EXIF #OREL
................
................
................ #EXIF TRUE
................
#ELOP
................ PROCESS
#ELOP
................
................
................
#EDO
PROCESS
#EDO
#OREL
Continuation of the main inline code of the #DO loop, in case the Conditional Expression in
the previous #EXIF was not true.
Will be generated automatically (after a previous #EXIF) when a #DOEX, #ELOP, #EDO,
or a next #EXIF is coded.
#DO true
.................
.................
#EDO
#DO true
.................
#DO true
.................
.................
#EDO
.................
.................
#EDO
#DO true
.................
.................
.................
#ELOP
.................
.................
#EDO
#DO true
.................
#DOEX true
.................
#DOEX true
.................
#ELOP
.................
.................
#EDO
All combinations of a #DO WHILE, a #DO UNTIL, and a #DO TIMES are valid in a #DO
macro (only one of each).
If a "DO UNTIL" is combined with a "DO TIMES" (both tests will be performed at the
bottom of the loop), the "BCT" of the "#DO TIMES" will be the last generated instruction.
Example
#DO TIMES=(R1,10),
# WHILE=(OC,FIELD_A,FIELD_A,ZERO),
# UNTIL=(LTR,R4,R4,NOTNEGATIVE)
.............................
.............................
.............................
#EDO
The Complex Conditional Expression must be specified within one set of parentheses, and
continuation must be done through column 72, starting the next line in column 16. Any
character can be used for continuation, but in keeping with the standard continuation
character, it is advised that an asterisk (*) be used.
Example
COL 16 COL 72
↓ ↓
#DO WHILE=(CLC,FIELD_A,EQ,FIELD_B,AND, *
TM,EBSW01,X'80',OFF,AND, *
CLI,EBW100,EQ,C'Y')
.............................
.............................
#EDO
All forms of the #DO macro are taught on this course, as students may have to maintain
code which contains these forms: however, Galileo Guidelines (TPF Assembler/Program
Design/Structured Programming/SPMs and Subroutines) discourages the use of certain
parameters.
#EXIF
#DOEX
#ELOP
#OREL
except where completely unavoidable, as these unstructure the code: there should only be
one exit point from a loop. Instead of using #DOEX or #EXIF, use #DO UNTIL or #DO
WHILE to test for exit conditions, and/or #DO TIMES to limit the loop count.
You should also avoid the use of #DO INF - if you have set a #DOEX or #EXIF condition
in your loop to use as an exit point, and the condition or conditions are not met, then the
program will loop until the time limit allowed is reached and a dump is produced.
L R1,CE1CR1
L R2,CE1CR2
SR R4,R4
LA R3,15
LABEL1 EQU *
CLC 0(5,R1),0(R2)
BE LABEL2
LA R4,1(R4)
LABEL2 EQU *
LA R1,5(R1)
BCT R3,LABEL1
L R1,CE1CR0
SR R3,R3
SR R4,R4
LABEL1 EQU *
CLI 0(R1),#EOM
BE LABEL3
CLI 0(R1),C'A'
BNE LABEL2
LA R3,1(R3)
LA R1,1(R1)
B LABEL1
LABEL2 EQU *
LA R4,1(R4)
LA R1,1(R1)
B LABEL1
LABEL3 EQU *
BACKC
L R1,CE1CR0
LA R2,100
LABEL1 EQU *
CLI 0(R1),X'4E'
BE LABEL3
CLI 0(R1),X'F0'
BL LABEL2
CLI 0(R1),X'F9'
BH LABEL2
LA R1,1(R1)
BCT R2,LABEL1
B LABEL3
LABEL2 EQU *
MVC EBW000(3),=C'ERR'
LABEL3 EQU *
BACKC
1) Edit the 20 characters that can be found in EBW000 through EBW019. If either an
#EOM or a #CAR character are found:
If all 20 characters are edited successfully, (with-out encountering either the #EOM or #CAR
characters), then move the characters "OK" into EBX000 - EBX001.
2) Edit the 14 hex numbers to be found in EBW000 through EBW013. For each number
over 5, increment R1 by one. For each number equal to or less than 5, decrement R1 by one.
#PERF
#SUBR
#ESUB
• A register save area may be added to the #PERF macro as an optional parameter. The
register save area must be defined as a Fullword of storage. If the #PERF macro has a
register save area specified, the generated BAL instructions are as follows:
N.B:- The Register Save Area cannot be defined in the program; if defined in the program
it will give a Re-entrant Check Failure upon assembly: it must either be an area in
the ECB or a core block DSECT.
#SUBR
• Each #SUBR macro must have one (and only one) #ESUB.
• The linkage register specified in the #SUBR macro must be the same register as
specified in the corresponding #PERF macro(s).
• A register save area may be added to the #SUBR macro as an optional parameter. The
register save area must be defined as a Fullword of storage. If the #SUBR macro has a
register save area specified, the generated BAL instructions are as follows:
N.B:- The Register Save Area cannot be defined in the program; if defined in the program
it will give a Re-entrant Check Failure upon assembly: it must either be an area in
the ECB or a core block DSECT.
#ESUB
• The #ESUB will generate an unconditional "BR" using the linkage register specified in
the corresponding #SUBR macro(s).
• If the #SUBR macro had a register save area specified, the following BAL code will be
generated:
#ESUB L R3,REG_SAVE1
BR R3
#PERF REG,SUBROUTINE_1
................
................
#PERF REG,SUBROUTINE_1
................
................
#SUBR SUBROUTINE_1,REG
................
................
................
#ESUB
#PERF REG,SUBROUTINE_1,REG_SAVE
................
................
................
#SUBR SUBROUTINE_1,REG
................
................
................
#ESUB
#PERF REG,SUBROUTINE_1
................
................
................
#SUBR SUBROUTINE_1,REG,REG_SAVE
................
................
................
#ESUB
Subroutines
.........................
.........................
#ESUB
The #GOTO macro handles the processing of unusual exit conditions from the normal
structure flow. It is a "hard branch", and should only be used for Error processing, and/or
to move "down" the code to Error label(s).
#GOTO
#LOCA
#LOCA label
The following examples illustrate how the #GOTO macro is coded with a Conditional
Expression and without a Conditional Expression:
Examples:
#GOTO LABEL1,IF,LTR,R1,R1,ZERO
#GOTO LABEL1
#LOCA LABEL1
The #EXEC macro gives the same capability as the BAL "EX" instruction.
#EXEC
• The #EXEC macro will execute against the SPM symbolic representation of a BAL
instruction by altering (in execution) the 2nd byte of that generated instruction. The
value of the low order byte of the specified general register is "OR'd" with the value in
the 2nd byte of the generated instruction.
• Unlike the "EX" instruction in BAL, the #EXEC macro does not require a label.
• The #EXEC macro will generate the assembler instruction to be executed and then will
"EX" (using REG) the previous instruction.
• The #EXEC macro requires the same action as the BAL instruction, i.e. subtract one
from the register before the EXEC instruction, then add one after execution to allow for
the Excess One Principle.
The following examples illustrate how the #EXEC macro is coded as a statement.
The following illustrates how the #EXEC macro is coded as a Conditional Expression.
CLC FIELD_A(0),FIELD_B
#IF #EXEC,R1,CLC,FIELD_A(0),EQ,FIELD_B EX R1,*-6
BNE .....
The #UEXEC macro is a Galileo macro, written in-house, and performs the same function as the
#EXEC macro, except that it will decrement the register by one before executing the EX instruction
and add one again afterwards, thereby removing the need to remember the Excess One Principle
from the programmer.
#UEXEC Rx,instruction,ERROR=label
The rules for the #UEXEC Macro are the same as for the #EXEC macro, with the following
exceptions:
• Unlike the #EXEC macro, the #UEXEC macro decrements one from REG before the EX
instruction is executed and adds one afterwards, to allow for the Excess 1 Principle.
• If the ERROR= parameter is specified, a #LOCA must be specified for the error label (see
example below). If the register holds a non-positive value, the EX instruction will NOT be
executed: instead, a branch will be generated to the error label specified on the ERROR
parameter.
• If the ERROR parameter is omitted, an MNOTE will be generated (RC=04) on assembly: if the
register contains a non-positive value, the EX instruction will NOT be executed, but processing
will continue as if the EX instruction WAS executed, (i.e. processing will branch around the EX
instruction) and no error return code will be set on at execution time, therefore it is strongly
recommended that the register is tested for a non-positive value before executing both the
#EXEC and #UEXEC macros. Obviously, no #LOCA is required if the error parameter is
omitted.
The following example illustrates how the #UEXEC macro is coded as a statement, plus a precis of
the generated BAL instructions.
Each #CAST macro must have one (and only one) #ECAS macro.
The general register specified (which must not be register 0), contains the case number,
which is adjusted to index into the branch table generated by the #ECAS macro.
The POWER=n parameter indicates to what power the case numbers are multiples. Case
numbers must always be in powers of 2 (including the power of 0). The default value of
POWER= is 0 in which case, all case numbers will be multiples of 1.
The MAX=n parameter specifies the maximum case number possible. If not specified, all
case numbers are treated as valid and no checking is performed upon execution. If specified,
then a #CASE ERROR must also be included.
WARNING!! If no MAX=n is specified, a case number in the register which is greater than
the largest specified in a #CASE macro will cause a wild branch into the program!
• The #CASE macro is the start of selected case(s) for specified case numbers.
• The #CASE macro handles multiple selections based on a numeric value contained in a
general register.
• The numeric value of the first case must be a power of 2 (the default is 0), and the other
case numbers within the same set must be multiples of the first.
• Upon request, invalid case numbers will be checked for during execution with the
MAX=n parameter on #CAST combined with #CASE ERROR. Invalid case numbers
are:
3. Negative values
• All valid, but unspecified case numbers (including zero) simply drop through the
structure.
#ECAS
• End of selection.
• The #ECAS macro generates a branch table entry for all case numbers specified.
• For all valid case numbers lower than the highest specified, which do not appear in a
#CASE macro statement, a dummy table entry is generated to bypass the case set.
• Avoid the use of #CASE if a simple #IF / #ELIF structure will do the job.
• Use #CASE only where there is a clear relationship between the value in the register and
the logical paths to be taken.
LTR R1,R1
BZ LABEL5
BM LABEL4
CH R1,=H'1'
BE LABEL1
CH R1,=H'3'
BE LABEL2
CH R1,=H'4'
BE LABEL2
CH R1,=H'6'
BE LABEL3
BH LABEL4
B LABEL5
LABEL1 EQU *
MVC EBW000(5),=C'NBR 1'
B LABEL5
LABEL2 EQU *
MVC EBW000(7),=C'NBR 3/4
B LABEL5
LABEL3 EQU *
MVC EBW000(5),=C'NBR 6'
B LABEL5
LABEL4 EQU *
MVC EBW000(3),=C'ERR'
LABEL5 EQU *
BACKC
In order to make the coding of Conditional Expressions less verbose, a wide variety of
Condensed Forms have been introduced.
• Any two or three character operand starting with the character "R", is assumed to be a
general purpose register.
• Any operand starting with the character "#",is assumed to be a system equate value.
• Any operand starting with the characters "BIT", is assumed to refer to a specific bit
pattern for a TM type of operation.
Where a "TM" is desired, the operation code can be omitted if the second operand begins
with the characters "BIT".
PLEASE NOTE: If more than one "BIT" is to be tested, then the second operand begins
with the characters "BITS".
Where it is obvious from the operand what type of compare instruction should be generated,
the operation code (CR,C, CH, CLC, or CLI) can be omitted.
PLEASE NOTE: Once in a while, the assembly generates something other than the BAL
instruction that was expected, i.e. CLC vs. CLI. This can cause some confusion when
testing! Be sure of the type of compare instruction that will be generated! If you're not
sure...check!
If the first and second operands of a "LTR" or "OC" are the same, then the operation code
and the second operand can be omitted.
Even though the mnemonic for the Op Code in Conditional Expressions is not mandatory, it
should still be included for clarity, i.e.
Code the following routines using SPM's and the Condensed form whenever possible.
CLI FIELD_A,C'G'
BE LABEL1
ST R6,FIELD_B
B LABEL2
LABEL1 EQU *
ST R6,FIELD_C
LABEL2 EQU *
SR R6,R6
LTR R2,R2
BZ LABEL3
SR R1,R4
BZ LABEL1
MVC FIELD_A(2),=C'AA'
B LABEL2
LABEL1 EQU *
MVC FIELD_A(2),=C'BB'
LABEL2 EQU *
OC FIELD_B,FIELD_C
LABEL3 EQU *
BACKC
TM FIELD_A,X'40'
BO LABEL1
OI FIELD_A,X'80'
B LABEL3
LABEL1 EQU *
C R1,FIELD_B
BL LABEL2
OI FIELD_A,X'70'
B LABEL3
LABEL2 EQU *
OI FIELD_A,X'60'
LABLE3 EQU *
ENTNC ABCD