Abel Programming Assembler Language 1979
Abel Programming Assembler Language 1979
PRTR
MVC PRINT•BLANK
PAGE HEADI
AP LINEPK,=P»1'
CP LINEPK.-P*10*
BL bioread
'
a A10HEAD
Diagnostics, registers, operations, and much more
in this auth.oritative handhotflc/reference.
PR[]GRF«ME
ASSEMBLER
LANGUAGE
PETER ABEL
ASSEMBLER programmers are always in
great demand because of their expertise in
understanding machine language and intri¬
cate computer operations. While other high-
level languages sometimes mask how com¬
puters accomplish tasks, ASSEMBLER bears
a close relationship with machine language.
ASSEMBLER is often more efficient than
other languages, providing an alternative to
such languages as COBOL or PL/1.
PROGRAMMING ASSEMBLER LANG¬
UAGE is a concise, detailed analysis of this
challenging language. It looks at all the im¬
portant strengths of the language, and high¬
lights the capabilities and usages that pro¬
grammers find so technically interesting.
Each chapter covers a separate area of
ASSEMBLER and includes sample programs,
end-of-chapter exercises, and debugging tips
to help newcomers to ASSEMBLER develop
effective programming strategy. Programming
assignments allow experimentation with the
language, and technical notes clarify details.
After completing the first three chapters,
the user can study the more advanced topics
in any sequence. This flexible design makes
PROGRAMMING ASSEMBLER LANG¬
UAGE valuable both as an introduction to the
language and as a technical reference later
on. The advanced topics include writing
macros, subprograms and overlays, operating
systems, and floating-point operations, all
extremely important considerations for the
technically ambitious programmer. This ad¬
vanced section presents these challenging
areas in clear, easy-to-understand terms that
promote fast learning.
https://archive.org/details/programmingassemOOOOabel
PROGRAMMING
ASSEMBLER
LANGUAGE
Peter Abel
British Columbia Institute of Technology
Abel, Peter
Programming assembler language.
Includes index.
1. Assembler language (Computer program language)
2. IBM 360 (Computer)—Programming. 3. IBM 370
(Computer)—Programming. I. Title.
QA76.73.A8A23 001.6'424 79-255
ISBN 0-8359-5658-X
© 1979 by
Reston Publishing Company, Inc.
A Prentice-Hall Company
Reston, Virginia 22090
10 98765432
PREFACE
ACKNOWLEDGMENT
1 THE ASSEMBLER 17
Languages, 1 7
The Assembler, 18
The Assembler Coding Sheet, 21
Assembler Instruction Statements, 24
The Assembler Card, 26
Coding Conventions, 26
The Assembled Program Listing, 29
Assembler Diagnostic Messages, 30
Problems, 32
2 PROGRAM EXECUTION 34
Program Execution Statements, 34
Condition Code, 38
VI CONTENTS
Input Data, 40
Flowchart Logic, 44
Job Control, 47
Problems, 47
5 DECIMAL ARITHMETIC II
Editing—ED, 101
Multiply Packed—MP, 106
Move With Offset—MVO, 108
Divide Packed—DP, 110
Sample Program—Inventory Update, 113
ORG—Set Location Counter, 119
PDUMP—Partial Dump of Main Storage, 121
Debugging Tips, 123
Problems, 123
VII CONTENTS
APPENDICES
A HEXADECIMAL AND DECIMAL
CONVERSION 377
INDEX 392
PREFACE
Assembler language is the fundamental "low-level” language of the IBM 360 and
370 computers. As such, it is directly translatable into machine language; thus, one
Assembler instruction typically generates one machine code instruction. "High-
level languages like COBOL and PL/I are easier to learn. Why then an emphasis on
learning Assembler language? An understanding of Assembler language can help the
programmer in a number of ways:
Although the material in this text has been used successfully as an introduction
to programming, most educational institutes would not teach Assembler as an intro¬
ductory language. Generally, the concepts of logic and programming style are easier
to learn when there is less need for concern with rigorous rules and field sizes. The
text does not, however, assume that the reader has had much, if any, programming
experience. The approach of the text is to introduce simple processing using card
xi
XII PREFACE
input and printer output, first with character data only, and then with simple decimal
arithmetic, all by Chapter 4. In this way, packed (decimal) data and editing are
introduced early, and the user is soon writing quite realistic programs.
The book should provide both a practical guide for the Assembler student and
also may act subsequently as a useful reference. These two objectives are accom¬
plished by:
6, 7
c =5= zn
8 9, 10, 11,17 12, 13 14 16
Chapters 9, 10, and 11 develop related material on processing binary data. Chapter
12 on Magnetic Tape introduces basic material required for an understanding of Disk
Storage in Chapter 13. To complete Chapter 14 (Macro Writing) would require some
familiarity with the material in Chapter 9. Anyone interested in linking separately
assembled programs could attempt Chapter 15 directly after Chapter 7, perhaps
referencing Chapter 9 for some basic binary operations. Chapter 16 on Operating
Systems is presented for general useful information, although not entirely related to
Assembler programming as such.
XIII PREFACE
Among the users of earlier versions of this text, many have worked ahead of the
course, experimenting with binary operations, macro writing, and subprogram link¬
age. Such motivation is certainly commendable and should be encouraged.
The IBM manuals concerned with the material in this text require a bookshelf
about five feet wide. Readers should not expect, therefore, that this or any other
single book will provide all there is to know about the Assembler language and
related topics. Eventually the IBM manuals have to be referenced for current detailed
information. The following IBM manuals or their equivalent are especially recom¬
mended:
Other useful manuals include those on Job Control, disk file organization, tape
labels, disk labels, and the operating system.
Peter Abel
.
ACKNOWLEDGMENT
The author is grateful for the assistance from all those who contributed typing,
reviews, and suggestions, and to IBM for permission to reproduce some of their
copyrighted materials. The following materials are printed with permission, and with
modifications from publications copyrighted in 1966, 1970, 1972, 1973, and 1974
by International Business Machines Corporation as IBM form numbers GA22-7000,
GX20-1 850 and GC20-1 649: Figures 2-2, 1 3-2, 1 6-3, Appendix A, and Appendix C.
xv
PART I
INTRODUCTION TO
THE COMPUTER AND
THE ASSEMBLER
CHAPTER 0
BASIC COMPUTER
CONCEPTS
INTRODUCTION
This chapter discusses computer concepts and systems in general terms, then intro¬
duces basic technical detail concerned specifically with the 360 and 370 computers.
The three main areas are general computer systems, binary number system, and
360/370 organization.
The first generation of computers was introduced in the early 1950s. These
computers were characterized by many vacuum tubes and relatively slow processing
speed. The second generation, introduced in 1957-1958, used transistorized cir¬
cuitry that permitted smaller size, higher speed storage, and lower costs. Finally, the
third generation computers, introduced in the early 1960s, replaced the tran¬
sistorized computers with integrated circuits. These computers featured higher
speeds, greater storage capacity, and more facilities.
IBM introduced System/360, a third generation computer, in 1964 to replace
and to improve upon a variety of then existing IBM computers. Some had been
specialized for business applications, others for scientific purposes. The 360 pro¬
vided a single computer designed to serve effectively in both fields. The 360 (and
computers of other manufacturers) provided many other advantages over the second
3
4 BASIC COMPUTER CONCEPTS
generation computers. First, its performance was considerably faster. Second, it had a
greater size and capacity for performing more functions. These characteristics ena¬
bled the computer to handle larger and more complex applications. Finally, the 360
had the ability to expand. IBM adopted a building block concept to enable the user to
increase the size of computer storage without always requiring a different computer.
Similarly, because the programming languages were standardized for 360 models,
little reprogramming was required when transferring to a larger system.
An important feature of the 360 (and of many other computers) was its super¬
visor capability. It contained a control program that permitted error recovery, storing
of programs and data on disk storage or magnetic tape for subsequent processing,
continuous job processing with limited operator intervention, and multiprogramming
(concurrent processing of several data processing jobs).
In 1970 IBM introduced System/370 with significant improvement in comput¬
ing performance over the 360. Although the 370 has some additional instructions
and capabilities, it was designed for compatibility with the 360, with the same
languages and control programs. This text cavers differences where applicable.
In 1977, the 370 was further extended into a more complex processor system:
the 3031, 3032, and 3033. In 1979, IBM announced the 4300 series. Through all
the various improvements, the basic Assembler language remains the same.
Although computers have evolved radically since the 1940s, and although there are
many manufacturers and models, their basic structure remains the same. Figure 0-1
illustrates the four main components: input/output, storage, arithmetic/logic, and
control. Arithmetic/logic and control together form what is called the Central Pro¬
cessing Unit (CPU).
INPUT/OUTPUT. The computer must be able to access new data. The computer
reads data into its storage from such input devices as card readers and magnetic
tape. Also, because the computer must communicate its results to the user, it
writes” data from storage onto such devices as printers and tape.
Instructions
T-
Unused
1 2 5 0 0 5
storage location: 1263 f 1 265 1338f 1340
1264 1339
Assume that an add operation is the letter 'A'. The instruction to add the contents of
locations 1338-1340 to the contents of locations 1263-1265 could be:
A 1 2 6 3 1 3 3 8 . (The 360/370 work similarly to this.) Locations
1263-1265 now contain '1 30'. Locations 1338-1340 still contain '005', unchanged
by the add operation. This instruction would itself require nine storage locations
consisting of three parts. A is the operation, telling the computer what function
6 BASIC COMPUTER CONCEPTS
to perform; '1263' and '1338' are respectively operand-1 and operand-2 that
specify which storage positions to process.
ARITHMETIC. Computers add and subtract, and most can multiply and divide.
With these basic functions, the computer can be programmed to perform, for exam¬
ple, square roots, trigonometric functions, and calculus.
LOGIC. A program generally must make tests and comparisons. For example, does
a divisor have a zero value? If so, then a division cannot be performed. Is a value
negative? If so, we cannot calculate its square root. Similarly, we may have to check
if a value is greater than, less than, or equal to another. The ability to make such
decisions is the computer logic.
CONTROL. The computer requires a component to control its actions. The control
device that performs this function does the following:
— Causes the computer to execute each instruction in the stored program, step-by-
step. Typically, each instruction is stored and executed one after another, such as
"Read”, "Add", "Move", "Print".
— Involves control of the input/output devices.
— Handles the transfer of data between storage positions.
— Handles the transfer of data between storage and arithmetic/logic.
The time required to transfer data is known as access time. Access time is measured
in thousandths of a second, millionths (microseconds), or even billionths
(nanoseconds). The number and type of input/output devices, the size of storage, the
type and complexity of arithmetic/logic circuitry, and the access time vary consider¬
ably by computer model.
INPUT/OUTPUT DEVICES
There are many types of input/output devices, of various capacities and speeds. This
section discusses the two basic common ones, the card reader and the printer. Later
chapters cover magnetic tape and disk storage devices.
THE PUNCHED CARD. A common source of input data is the punched card. The
card represents data by means of small rectangular holes punched by a keypunch
machine. The holes in the card, when read by a card reader, are translated into
electrical impulses and transferred into storage.
7 Input/Output Devices
22|22222222|22222222|2222222|222222222222222|22|22222|22222222222222222222222222
I 333|33333333|33333333|3333333|333333||||3333333333333333333333333333333333333333
CD
4444|44444444|44444444|4444444|444444444444444444444444 ■ III 444444444444444444444
o 5 5 5 5 5 | 5 5 5 5 5 5 5 5 1 5 5 5 5 5 5 5 5 | 5 5 5 5 5 5 5 1 5 5 5 5 5 5 5 5 5 5 || 5 5 5 5 5 1 5 5 5 5 1 5 5 5 5 5 5 S 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
o'
666666|66666666|6666G666|6666666|666G6666|6666|6|6B6|66666GS6C36S6G6G66S666GGSB6
/777777|77777777|77777777|7777777|777?777777777777||7777777777777/7777777777777?
x88g8888|888868B8|88888888|8888888|8||||8||||8|||||||||||||888388383388888S88888
999999999|99999339|99999999|9999999|999999999999999999999993399999S9939999993999
7 J « 5 K I » 0 '0 II ’’ •' ‘ ■« ’• •« >9 7C ?' 22 23 7* 75 26 27 78 29 30 31 32 33 34 35 36 37 3B 39 «0 *1 42 43'',M5 46 4/ 48 4'J SO 51 52 53 54 55 56 57 58 OS 60 61 6; C3 64 60 6bGi 13 G9 70 I) U 73 74 75 75 77 78 79 HO
A field is one or more related columns. A record consists of one or more fields.
The card itself is a record of data, and may be subdivided into fields. Some fields
contain alphabetic data, such as customer name. Other fields contain numeric data,
such as an invoice amount. (A field such as address may contain alphameric data,
mixed alphabetic and numeric.) Not all card columns need be defined or punched.
Fields may contain subfields: a date field could contain subfields month, day, and
year.
A minus sign indicates that a field has a negative value. In data processing, the
minus sign is usually an 11 -zone punch over the units position of the amount field.
For example, if an amount field in columns 63-67 is minus, we punch an 11 -zone in
column 67.
The punched card serves two main purposes:
1. To record programs.
2. To record data. Information for data processing is supplied to the keypunch
department on source documents. Examples are customer payments, sales, and
employee hours worked. These data are punched according to a predesigned
card format. The cards are then submitted as input to the computer department for
processing.
8 BASIC COMPUTER CONCEPTS
THE PRINTER. There are many different types of printers, but all have certain
common features. They print at speeds ranging from a few hundred to several
thousand lines per minute. Many can print 60 or more different characters, including
the numbers 0 through 9, letters A through Z, and various characters such as $, #, *,
and + . Typical printers print 10 characters to the inch, and 1 20, 1 32, or 160 charac¬
ters on a line.
The paper used for printing is called continuous forms. The forms are perfo¬
rated horizontally so that each sheet may be separated after printing. Manufacturers
supply the forms in various widths, such as 11" and 15", and lengths such as 8V2".
This length at six lines per inch permits up to 60 lines of print per page. It is available
in single-part, or, with carbon inserts, two or more parts. The forms may be pre¬
printed according to the user's design (e.g., customer bills), or they may contain only
horizontal lines or bars {"stock tab" forms or "continuous printout").
Binary numbers provide the basic numbering system of computers. Whereas a dec¬
imal (base 10) number has ten digits, a binary (base 2) number has two: 0 and 1. For
both decimal and binary, the position of the digit determines the value. Consider the
decimal number 1111:
decimal 1111
-1000 +100 + 10 + 1
Whereas a decimal number uses the base of ten, a binary number uses the base of
two. Consider the same number, 1111, this time expressed as binary:
binary 1111
= 8 + 4 + 2 + 1 = 15 (or 24-1)
As another example, the value of the decimal number 1010 is determined as:
decimal 1010
A decimal digit zero as shown has no value, nor has a binary digit zero. The number
1010 expressed in binary is:
binary 1010
= 8 + 0+2+0 = 10 (decimal)
Through the use of digits 0 and 1, binary numbers can represent any decimal value.
For example, the binary number 101101 equals:
25 + 04 + 23 + 22 + 01 + 2°
= decimal 32 + 0 + 8 + 4 + 0+1 =45
A binary value may also have a binary point, equivalent to the decimal point. We
calculate a binary number with a point such as 101.1101 as:
22 + 01 + °+
2 2'1 + 2-2 + O-3 + 2~4
= 4 + 0 + 1+ -^+-^ + -^ + y4
= 4 + 1 +| + |+o + ^
= 5 + .5 + .25 + .0625
= 5.8125
In computer terminology, a binary digit is called for short a "bit". A storage location
consists of a specified number of bits, and can be related to binary digits, since a
computer bit can be OFF (zero) or ON (one). The number of bits in a storage location
varies by computer (the 360 and 370 use nine bits). Assume a storage position that
contains five bits. Four bits represent data and the other is a parity bit:
bits:
value: p 8 4 2 1 one storage location
contents: 0 0 0 0 0 with five bits
r
Parity
Data
10 BASIC COMPUTER CONCEPTS
In the diagram, each bit is indicated by a 'O', with the binary value of the bit
above it. Each bit can contain the value 0 or 1, so if the bit numbered 1 on the right is
ON, the contents of the byte are 00001, and the value is 1. If only bit 2 (second from
the right) is ON, the contents are 00010, and the value is 2. Both bits 1 and 2 ON
(00011) represent 3, and combinations of ON bits provide values 1 through 9. All bits
OFF means zero.
The bit on the left is the parity bit. The typical storage location must have "odd
parity"; the number of bits ON must always be an odd number. For example, the
value in a location is 7; bits 4, 2, and 1 are ON. Because this is an odd number of
bits, the computer sets the parity bit OFF:
p 8 4 2 1
0 0 1 1 1 value = 7, odd parity
Assume that the value in a location is 9: bits 8 and 1 are ON. To force odd
parity, the computer sets the parity bit ON:
P 8 4 2 1
1 0 1 value = 9, parity bit ON for odd parity
JL o
Setting bits ON and OFF is entirely an automatic process over which we have
no control. When processing the contents of a location, the computer automatically
checks the parity. If the parity is not odd, the computer circuitry may require servic¬
ing; the computer signals a warning to the operator and may stop processing.
On the 360/370, the configuration in a storage location (a "byte") is eight data
bits and one parity bit. A hardware malfunction such as losing odd parity causes a
"machine interrupt", as explained in Chapter 16.
As Figure 0-1 illustrated, the computer system consists of the following units: the
Central Processing Unit (CPU), which contains the arithmetic/logic unit and the
control section, input and output devices and facilities, and Main Storage or Mem¬
ory. In addition, the 360 and 370 have a special unit called general purpose registers
that serve such purposes as arithmetic and addressing. Most 360s and all 370s have
as well floating-point registers that perform floating-point arithmetic. Another fea¬
ture, Program Status Word (PSW), controls the sequence of instructions executed by
the program and records the current status of the program. The next sections briefly
describe the CPU, Input/Output, Storage, the general registers, and the PSW.
THE CENTRAL PROCESSING UNIT (CPU). The CPU is the control center of the
360/370 computer system. It consists of two sections: control and arithmetic/logic,
and provides facilities for the following features:
11 S/360 and S/370 Organization
INPUT AND OUTPUT (I/O) DEVICES. There are various models of each input/
output device, providing different capabilities and I/O speeds. Disk and magnetic
tape supply external data storage of practically unlimited capacity. Among the I/O
devices that most 360 and 370 models may use are:
MAIN STORAGE. Each 1,024 storage positions is called IK. Addressable storage
varies from a minimum of 8,192 (8K) locations to a maximum of 16,777,216
(16,384K).
BITS. Storage on the 360 is composed of ring-shaped magnetized ferrite cores, each
of which is a bit. The cores may be magnitized clockwise as ON and assigned the
value one, or magnetized counterclockwise as OFF and assigned the value zero.
Combinations of bits represent the various digits and characters used in computer
processing. 370 data is stored in small ''chips” called monolithic circuits.
12 BASIC COMPUTER CONCEPTS
BYTES. The basic building block of main storage is the byte, which represents a
single storage location. Each byte consists of nine bits. Eight bits represent data. The
ninth is the parity bit to ensure odd parity, and is not a programming consideration.
The eight data bits are “split” into two portions of four bits (half-bytes), a zone and a
numeric portion:
value: 4 2 1 8 4 2 1
portion: zone numeric
Character Format. A character field (such as the letters A through Z, the numbers 1
through 9, and special characters as $ or * or &) requires one byte for each
character. The eight bits in a byte can represent 256 (28) possible characters. For
example, the ON bits 1100 0001 represent the letter A. The character code is
called the "extended binary-coded-decimal-interchange code" (EBCDIC).
Decimal, or Packed, Format. For ordinary decimal arithmetic, the digits 0 through 9
are "packed" two digits per byte. For example, the digits 4 and 7 appear in a
byte as the bits 0100 0111. Whereas a character 'V requires a full byte
(11110001), a packed digit 'V uses a half-byte (0001).
Binary Format. For binary arithmetic, addressing, and special features, each bit rep¬
resents a binary 0 or 1. The binary value 01000111 equals the decimal value 71.
Floating-Point Format. Used to represent extremely small or large values.
GENERAL PURPOSE REGISTERS. The 360 and 370 have 16 general purpose reg¬
isters (GPR's), numbered 0 through 1 5. Instead of being part of main storage, they are
special circuitry. Each register consists of 32 bits. The two main uses of registers are:
PROGRAM STATUS WORD (PSW). The Program Status Word (PSW) is a 64-bit
hardware feature in the control section of the CPU. The PSW contains the current
status of the computer and controls the sequence of instructions being executed.
One PSW feature important to the programmer is the 2-bit "condition code"
that indicates the result of an arithmetic test (minus/zero/plus) or a logical compari¬
son (low/equal/high). Another field, the 24-bit "instruction address" contains the
address of the next instruction to be executed.
IBM
supervisor
program
Main
storage
User
program(s)
Both the programmer and the computer operator can request the Supervisor to
perform certain actions. For example, if we want the system to "assemble" a pro-
14 BASIC COMPUTER CONCEPTS
gram, we can enter a job control statement such as //EXEC ASSEMBLY that tells the
Supervisor to arrange for the assembling of the program following.
PROGRAM INTERRUPTION. The Program Status Word contains bits that record
the status of the program. Among these conditions are bits to record “program
interrupts." An interrupt occurs when our program asks the Supervisor to perform
some special task, such as input/output. Basically, our program is "interrupted," and
control is passed to the Supervisor program. An interrupt also occurs, for example,
when a serious processing error occurs—such as invalid data in an arithmetic opera¬
tion. The Supervisor may have to "flush" the interrupted program and resume pro¬
cessing with the next job.
HEXADECIMAL REPRESENTATION
A hexadecimal numbering system uses base-1 6. Hexadecimal (or hex) numbers are 0
tnrough 9 and A through F, for the decimal values 0-15. We use hexadecimal
numbers to represent the contents of storage. Hexadecimal is only a representation of
storage—at no time does the computer actually work in base-16 as such. One hex
digit depicts four bits of a byte, and two hex digits represent all eight bits in a byte.
Figure 0-5 lists the equivalent decimal, binary, and hexadecimal numbers.
Two hex digits can represent the contents of any storage location, regardless of
the data format that it contains. For example, a byte contains the character 'A'. The
binary representation of A in main storage is 1100 0001, and the hex representation
of this is 'Clor as commonly notated, X'CI'. Thus, if an input record contains an 'A'
in a certain position, when read into storage, it appears in a byte as 1100 0001, and
we can represent its contents as either character A or as hex 'Cl'.
Since there are 256 possible bit configurations in a byte, there is no way to
represent each possibility as a single character (there are only about 60 different print
characters). Assume that a byte contains the packed digits 4 and 5. The binary
representation of the byte's contents is 0100 0101. There is no single character that
can represent this 8-bit code, but we can represent it with two hex digits as X'45'.
15 Problems
A byte used for binary data could contain 0101 1011 (which equals decimal
value 91). The hexadecimal representation is X'5B'. In this way, hex format can
represent all 360/370 formats, such as character, packed, and binary, one hex digit
for each half-byte (four bits). The computer Supervisor and the Assembler both use
hex extensively to represent the contents of storage, although only the programmer
knows that the specific contents of bytes and fields are in a particular format. Among
the uses of hexadecimal format are:
1. The Assembler converts source code to object code. It prints the locations of
instructions and their object code entirely in hex format.
2. To facilitate tracing program errors, we can instruct the Supervisor to print a
"storage dump". The dump prints the contents of storage, two hex digits per byte.
3. Some special purpose characters, for example, control the printer carriage (spac¬
ing lines, skipping to a new page), and "edit” data fields with punctuation and
sign (as $1,250.00CR). Many of these special characters are bit configurations that
cannot be printed. We can represent them, however, in our Assembler program
with hex numbers.
Since the Supervisor and the Assembler print storage addresses in hex, a
knowledge of hexadecimalarithmetic is quite useful (and so would be 1 6 fingers for
doing it). Note how X'F' overflows when we add 1:
15 F
+_2 +_L
16 10
Thus, X'l 0' equals the decimal value 1 6. Also, note that X'5' + X'5' = X'A', and X'8'
+ X'8' = X'l O'. The following examples illustrate more hex addition:
PROBLEMS
0-1. What are the basic components of a digital computer? What is the function of
each one?
0-2. Distinguish between instructions and data.
16 BASIC COMPUTER CONCEPTS
0-3. What holes are punched in a card for the letters READ?
0-4. Define the following: (a) Stored program; (b) Access time; (c) Field; (d) Re¬
cord; (e) File, or data set; (f) Alphameric data.
0-5. What is the decimal value of binary (a) 1110; (b) 11001; (c) 101101?
0-6. What is a "bit"? What is a bit's relationship to a "byte"?
0-7. The left four bits of a byte are the_portion; the right four bits are
the-portion. The ninth bit is called_; what is its purpose?
0-8. What are the two main purposes of the general registers?
0-9. What is the purpose of an "operating system"?
0-10. Where is the Supervisor stored? What are its main functions?
0-11. What is a "program interrupt"?
0-12. What action does the system take when a serious processing error occurs?
0-13. What is the purpose of hexadecimal representation?
0-14. Give the hexadecimal representation for the following binary values: (a) 1110'
(b) 01 01 1101; (c) 1011 0011; (d) 11 11 001 0 11 00 111 0.
0-15. Convert the following decimal values to hexadecimal (refer to Appendix Al¬
la) 10; (b) 16; (c) 24; (d) 32; (e) 275; (f) 2048; (g) 4096.
0-16. Convert the following hex values to decimal: (a) F; (b) 10- (c) 2D' (d) 4F- Ip)
80; (f) 800; (g) 1000. ' K [
0-17. Add the following hex values: (a) 24 + 6; (b) 3A +7; (c) AAA + 555- (d) FFF +
1; (e) 437B + 2A4B.
CHAPTER 1
THE ASSEMBLER
The previous chapter examined the computer organization and its "hardware" fea¬
tures. This chapter covers the Assembler program, a "software" feature, and the
requirements for coding and assembling a program in Basic Assembler Language.
This text recommends standard coding practices, such as naming conventions for
fields and files, in order to make computer programs more comprehensible and more
easily maintained.
LANGUAGES
The 360/370 come equipped with a set of executable machine instructions similar
for all models. Instructions include the ability to read input data, move data in
storage, add and subtract the contents of storage locations, compare, and print data
records.
17
18 THE ASSEMBLER
unique numeric address; the "operands” of the machine language instructions refer¬
ence the addresses of storage locations by their number. On the earliest computers,
programmers coded at this basic level. On the 360/370 and most other current
computers, however, coding in machine language is far too complex.
THE ASSEMBLER
Basic Assembler Language (BAL) with which this text deals is the fundamental 360/
370 language. It is reasonably standardized for all models. Although we code pro¬
grams in symbolic Assembler language, the computer cannot execute such instruc¬
tions. The Assembler translator program is required to "assemble” or translate the
symbolic language into computer machine language.
KEYING. These sheets are then keyed onto punched cards, or onto disk via a
terminal.
— Accounts for the amount of storage required for each instruction and each data
area, and assigns storage locations to them in the sequence in which they are
coded.
— Supplies messages for programming errors, such as the invalid use of an instruc¬
tion and spelling errors.
— Includes any required routines that are written in Assembler language and are
catalogued on disk.
19 The Assembler
— Prints the original symbolic coding and the translated machine language on a
printed form. This print-out is necessary to "debug” the program and to make
subsequent changes.
— Writes the machine language object program onto an output device such as a
card punch, disk, or tape, for use when the program is to be executed.
The Assembler uses a location counter to account for the length of each data
field and instruction. If the Assembler has just assigned a 4-byte instruction starting at
location 10,024, the location counter now contains 10,028, the starting address of
the next instruction. The Assembler always assigns the address to the leftmost byte of
a data area or constant.
ERROR CHECKING. We correct any errors that the Assembler signals, reassemble
the program and execute it using test data. The Assembler cannot recognize errors in
our program logic—these errors we must find through testing and "debugging”.
ADDRESSING. The first storage location is numbered zero, with subsequent bytes
numbered consecutively. Therefore, a size of 16,384 has addresses numbered zero
through 1 6,383. (Note that 1 K = 1024 bytes.) Addressing is done by means of the
rightmost 24 bits of a register. These 24 bits provide a capacity of 224 or 16,777,21 6
addressable bytes of storage. Machine language uses a two-address system for ad¬
dressing. It consists of:
1. A base register (any available general purpose register). The base register contains
the beginning address of an area in storage used by the program, and provides a
reference point for the next 4096 bytes. The program requires one base register for
each 4096 bytes used.
2. A displacement, or the number of bytes from zero to 4095, from the first byte of
the area to which the base register points.
PAGECTR
t t t
10516 10517 10518
20 THE ASSEMBLER
80 bytes
t t
CARDIN CARDIN + 79
CARDIN + 1
Length
in bytes Format Typical use
For example, an RR format instruction, AR, can be used to add the contents of
register-8 to register-6. It is coded in Assembler language as:
21 The Assembler Coding Sheet
^AR
operation code 'operand-2
operand-1
The machine language code for AR is XT A'. The Assembler translates the symbolic
instruction to two bytes of object code, in hexadecimal as ITAl68l. The object code
for operands that reference storage-is more complex because the Assembler converts
their addresses to base/displacement format, explained in Chapter 6.
Figure 1-2 depicts the IBM Assembler coding sheet, Form GX09-0010, used for the
coding of Assembler programs. The coding on the form is strictly illustrative, and is
not intended to be understandable at this time. The space at the top of the form for
the program name, programmer name, date, and page number should be completed
on each page. There are 80 columns for punching onto the standard 80-column card.
Some characters that are written alike may be key-punched incorrectly. Al¬
though there is no universal standard, the following conventions may be used to
distinguish among certain easily confused characters:
— Code the digit zero as 0, and the letter O as 0 (some use the opposite conven¬
tion).
— Code the digit one and the letter I clearly.
— Code the letter Z as Z to distinguish it from the digit 2.
— There is often confusion between the digit 5 and the letter S, between the left
parenthesis ('(') and the letter C, and between the letters U and V.
— Where not otherwise clear, indicate a blank position byt>.
The Assembler accepts coding that is "free-form"; that is, although the form has
predefined columns for Name, Operation, and Operand, we do not have to code
these fields in the defined columns. Flowever, there is little need to vary from the
c fN C o Q 0 Q D c C c c) c c c
0 0 V. U 2 vfl T~ 0- o vl r- 6.9 Q
0 0 0 0 o 0 o 0 o T- -n -- •*■ i ■*-j 0 0 c
j . -r-
o o 0 0 0 0 0 0 0 0 0 0 c C 0 ’-
1 e b h
V- h e b e p b b i— b e e b b
| co V] <j] 10 00 (/ to 01 v s VI VI V
H H H H e e P e h H e e e b H p e
a
-J •u - -J -u -J - L -J - -J -J - _
A
A
U
H
-j b
2
bl
b P
0- V
£■ <
J3 O
<v b
A b
-O 00 X
b lu
0- Uj <; >
Uj
O' <t b a
Uj P 'b 2
-J 5? d \r~ Ui
co 5 H UJ 1 a cl oc Uj 1
8 t UJ Uj P l H 1
y LU tU S <1 l •© 1
i •< Pi
< z VI H U) l d P P b 1
5 3
VJ _J O X H 1 H 1
IBM System/360 Assembler Coding Form
<r *U 1 ■< f) . X I
t
H b l ~D 1
z h^bl b
o2 Uj b p 2 l UJ z I
z~ Q
_J H H H Z) l X D 1
0- > \ * V P l -© V l
il
t H 0/1 0- -Rj, 1 S' ffj IS] l
? <sz t 1 1
*< • OsT 1 & 1
X z
X 5 Ijj H t t 1
o i l 1
J- l h 1 \ 0 1
CNJ t l 1
<2 1 H l > _l 1
s; l H P 1 H ■H 1
zi
MJ I V to el l A U. M t
i t/J 1 P U) 1
> H » 4 < l c 5 u_ 1
Uj i A Q l 0 1
vfet -J I P 1 4 Nb 1 l
■iS- i tin Ui 1 r 1
A, ■2 l Uj 3: X 1 > o H u. 1
r t b
~Q
read
-2 3
<N
? o
f v8
5 I
■©
[Alp
p_
O o
O o
* Cu * A *1
22
23 The Assembler Coding Sheet
defined columns, and there is a need for standardized, legible programs. The exam¬
ples in this text use only the defined columns.
1. Instructions, such as add and compare, that provide the program logic for execu¬
tion.
2. Declaratives, such as accumulators and constants, used by instructions.
3. Comments, used as documentation to make the program clearer. They do not
become part of the machine-language code.
COLUMN
oper¬
name ation operand erand_,
column: 1 '0 ^6 operand-2
I
A20ADD AP ACCUM,FIVE
no blanks
24 THE ASSEMBLER
column: 10 16 comments
COLUMN
72 CONTINUATION. Operands and comments may not continue past column
71. If more columns are required, then we must do the following:
— Code any character in column 72. This text uses a plus ( + ) sign.
— Continue coding the statement on the next line beginning in column 1 6.
The first statement in Figure 1-2, TITLE, illustrates continuation. Depend¬
ing on the Assembler version, one or more continuations are permitted.
73-80 IDENTIFICATION SEQUENCE. We may optionally use this field to identify
the program—a recommended practice. A useful identification sequence is
as follows. Columns 73-76 contain the program identification, such as P023
for Payroll program 023. Columns 77-80 contain a card sequence number. If
the sequence numbers are consecutive, then we cannot insert additional
instructions between them. Therefore, a good practice is to number the se¬
quence in intervals of ten, such as 0010, 0020, 0030. Major program sections
may begin with a value such as 1000 or 2000.
We may force the Assembler to check the sequence of card columns
73-80 by coding an Assembler card with the instruction ISEQ (Input Se¬
quence Checking), discussed in the section Assembler Instruction Statements.
TITLE. The purpose of TITLE is to identify the assembly listing and the object card
deck (if any). See Figure 1-2 for an example. The name field may be omitted. If it is
present, the Assembler punches the first four characters into columns 73-76 of the
object program card deck, if any.
The operand field is enclosed in apostrophes to denote the start and end of the
title. It contains any descriptive title that we want printed at the top of each page of
the Assembler listing (see the top line of Figure 1-4). The maximum length is 100
characters. But, if the title exceeds 56 characters, we must code a continuation
character in column 72, and continue the title on the next line in column 16. An
apostrophe or ampersand used in the operand must be coded as two apostrophes or
ampersands. The Assembler stores and prints only one. Example: TITLE 'JEAN &&
SAM"S PROGRAM'.
EJECT. After printing a full page, the Assembler automatically ejects to the top of
the next page. EHowever, we may want to eject the page before it is fully printed, for
example, to print the declaratives or the start of a new major routine. We code EJECT,
causing the Assembler to start a new page for the listing.
SPACE. The SPACE instruction tells the Assembler to space one or more blank lines
on the listing. We code the number of lines to be spaced in the operand. If we leave
the operand blank, the Assembler assumes a space of one line:
Column 10 16
SPACE Space 1 line
SPACE 1 Space 1 line
SPACE 2 Space 2 lines
SPACE 3 Space 3 lines
Note: The Assembler acts on EJECT and SPACE but does not print them.
It does, however, increment the statement (STMT) number on the listing;
see, for example, missing statement number 73 in Figure 1-4.
PRINT. This instruction controls the general format of the program listing. It con¬
tains any or all of the following three operands, in any sequence. The common
requirement is PRINT ON,NOGEN,NODATA.
DATA Print the full hexadecimal contents of constants (on the left side of the
listing, under OBJECT CODE).
NODATA Print only the leftmost 8 bytes, or 16 hex digits. We normally code
NODATA because the full hex printed contents of constants are of little
value.
ISEQ. This instruction causes the Assembler to sequence-check the input source
cards. The operands / and r specify the leftmost and rightmost card columns of the
field being checked. The field is normally the "Identification Sequence" between
columns 73 and 80, and the instruction is coded as ISEQ 73,80, as shown in the
example coding. Since each card checked must contain a higher sequence value
than the previous one, low, equal, or blank fields cause error messages. ISEQ with a
blank operand will terminate sequence-checking.
END. The END instruction must be the last statement of the program. It causes
termination of the program's assembly. We may code the operand with a symbolic
address, such as END PROG02. The operand PROG02 in this case designates an
address in the program to which control is to transfer when the program is loaded for
execution. Thus, the address is that of the program's normal first executable instruc¬
tion.
Remember that these instructions simply tell the Assembler how to handle the
program, and generate no machine code. This section provides the most commonly
required information. The Assembler manual contains more detail on these instruc¬
tions. Later chapters cover other instructions, such as EQU, LTORG ORG and
USING.
Figure 1 -3 shows the IBM Assembler card (one of the cards punched from the coding
sheet in Figure 1-2). The cards are punched column for column, one card for each
line. Since the operators who punch the cards are normally unfamiliar with Assem¬
bler language, we must code clearly and neatly. Unclear printing causes many
programming errors.
CODING CONVENTIONS
This text uses certain clear and meaningful conventions to define the names of fields
and instructions.
(8 8(IS((S 8 I I M I I I 6 8 8 8 8 8 8 6 8 8 8 9 8 8 8 8 8 6 8 8 0 8
DEFINE STORAGE, DS. DS defines an area of storage within the program, such as
an inputyoutput area. When the program first executes, the contents of a DS are
unpredictable, and could contain any “garbage." The instruction CARDIN DS CL80
defines a field called CARDIN, character format, length 80 bytes. Each time a record
reads into this area, it erases the previous contents of CARDIN.
In both cases, CARDIN and HEADING, the name references the leftmost byte of
the defined field. A DS or DC, however, need not have a name.
Declarative names should be unique and descriptive. Since a name (or label)
can be up to eight characters long, it is more meaningful to use, for example, the
name EXPENSE rather than EXP. Also, it is often useful to identify a packed field with
a suffix PK, such as AMOUNTPK, and a binary field with BIN, as AMTBIN. We may
give input/output areas descriptive labels as CARDIN for a card input area, and
PRINT for a print area. (The declarative PRINT in Figure 1-4 is the name of a
1 33-byte field. It should not be confused with the assembler instruction PRINT. This
symbol PRINT illustrates how we can use the same name for both an operation and a
declarative; the Assembler can tell from the use of the symbol whether it references a
declarative or an instruction.)
-j -J -i _J -l -J _i _J J -J -J J -) _l -J -J -J
z 15
M < O
a o a \
a CL **
< a z UJ
o u o J >
x * ** ft* X
H in X x UJ < •
m X < J UJ X o
x UJ • z H ft* cr < UJ
UJ i z z UJ D LL < z X
o i UJ j z a < a •< >-
< i X a a z a UJ X o a -J
a o i z < x UJ M UJ a 3 X UJ CD
z i o X UJ 1 x x < a UJ z Z
3* — UJ 1 a u Z x UJ 1 Q Q z x z O UJ UJ
UJ UJ o i x i a CD a ft* x 3 «■* ID 15 in
N z < Z 1 < Q a o Z 1 < O < cr D o j V in
M HI 1 u x a. x 1 u <3 a a o in <*
J O I < - 1 » z x o ® -i
< H 1 < o •0 x 1 X J UJ UJ *■* UJ z < x o
— X X 1 u >- 1 □ < z z x ft* z a o
K a z 1 u UJ z 1 1 z ft* a z o ft* UJ
© Z
•—
* a
in a
D
O
1
•
1 a z
>
UJ o
<
a.
m
D
O
1
1
1
Q
z
UJ
CL
o
z
x
UJ
a
IL
UJ
o
a:
<
u
ft*
a
a
<
UJ
X *
m
Q
x
►*
J
o
z
UJ
in i
i
UJ I
Jjj
jQ
■3
©
©
£
0 CD
t/i
IS)
Wi o o o O in <
* u
o o U) CM JV
<r a O X
o o —• in *o a.
o
u
<3 o
u o
n
I
E
* o Q Q ro
o O K O n o O X ® < < on
Q o
u
o *o
u u
CM CNJ
3
O
in
CNJ
in
<r
N-
—
®
n
O
n
u 3 u 3 « < < < <
3 3 O' CD CD 3 3 a 3 3 3
o in in O O o 3 3 3
3 3 Pft X X 3 o o 3 3 O
Q in in O o 3 O 3 3
< X X O' ® uu 3 ® 3 3 <T ® u O'
© Q
n
<
u
in
■»
<
a
in vO
c ■if
u u
<
X
«•
< <
X
<r
<
X
11
<
u 3 O
in U)
< * <
O
X
<
3
in
<
D
U
o o o o
a u
3 o
u
o
u
3
a o 3
o 3 3
3
3
o
3 J
28
29 The Assembled Program Listing
the read operation, we "branch back" to read the next record of the read (GET
CARD,CARDIN). In order to reference the GET, we must give it a name—in this case
A1 OREAD. The program uses the instruction B A1 OREAD to branch to A1 OREAD, the
address of the GET instruction.
This text uses a convention that requires that the first character of an address
label be an alphabetic letter, A through Z. The next two or three characters are digits,
for example, A10, D35, P200. In the first main logical section of the program, the
labels begin with A. Address labels, where required, are numbered within this sec¬
tion starting with At 0, then increasing by intervals of ten, such as A20, A30, etc. This
practice facilitates the following:
The next main logical section and all others begin with a letter higher than the
previous, such as B, E, G, and X. Each section uses digits starting with 10 and
increasing by intervals of 10. The first label of a logical section and all other labels to
which we branch from outside the section are given descriptive suffixes, such as
A1 OREAD and XIOEOF. An examination of the sample programs throughout this text
should make clear the advantages of such coding conventions.
Figure 1-4 provides a sample Assembler program that reads cards and lists them in
"80/80" format (the 80 card columns are printed column-for-column in 80 print
positions). This section briefly describes the assembled program listing. Some of the
detail may not be clear until after Chapter 3:
1. The first line lists the contents of the TITLE card (if any) at the top of each page.
The Assembler prints the page number to the right.
2. LOC, for Assembler Location Counter, is the assembled location or address of the
first (leftmost) byte of the object code instruction or declarative, in hexadecimal
format. The first address shown is X'ODAl 32', which is the address of the leftmost
byte of the instruction on that line. (The Supervisor occupies the lower part of
main storage, and this program occupies a following area.)
3. OBJECT CODE lists the hexadecimal object code instruction, or the contents of a
constant, as assembled. The column shows the actual contents of storage. In the
listing, the first executable instruction is the INIT statement. Because INIT is a
macro, and we coded PRINT NOGEN earlier, the Assembler has suppressed
30 THE ASSEMBLER
printing INIT's generated code. The first object code listed is for statement 64,
D24F 336A 3310. The first byte, D2, is the machine-language code for the sym¬
bolic operation MVC (Move Character). The D2 is stored in location X'0DA132'.
The second byte, 4F, gives the hexadecimal length of operand-1, and the other
four bytes are the machine code operands. The actual machine operand ad¬
dresses consist of a “base register" and a “displacement". This section merely
describes the purpose of these columns—do not expect to understand the assem¬
bled object code at this time!
4. ADDR1 ADDR2 shows the "effective" addresses of operand-1 and operand-2.
These addresses do not appear in main storage as part of the machine code; the
Assembler prints them only as a convenience to the programmer. The first line
printed shows DA3E4 DA38A, which refers to the actual storage locations of
operand-1 and operand-2 of the MVC instruction (PRINT+10 and CARDIN re¬
spectively).
5. STMT means Statement Number. The Assembler counts each statement in the
program and prints the assigned statement number in this column. The first in¬
struction, TITLE, and the second, EJECT, are not listed. The first statement number
in this example is 3 for the PRINT ON instruction. Certain other statements are
also not printed. Statement 57, for example, is the instruction SPACE, which the
Assembler counts but does not print. Similarly, because we coded PRINT NO¬
GEN, the printing of instructions generated by macros (such as GET) is sup¬
pressed. (The instruction PRINT GEN will force the Assembler to list generated
macro-code.)
6. SOURCE STATEMENT lists our original source code from Assembler cards,
exactly as coded.
7. DOS/VS ASSEMBLER REL shows the “release" and “version" number, which
varies by computer system.
The declaratives are coded in an area separate from the instructions. The
declarative CARDIN, for example, begins here in location (LOC) X'0DA38A'. The
contents of DC's (but not DS's) are shown in hexadecimal format under OBJECT
CODE. Since PRINT NODATA was specified, the Assembler lists only the first eight
bytes (16 hex digits) of DC contents, as shown by statement 151. Note that the object
code contents of PRINT show eight hexadecimal 40's, the 360/370 blank character.
Coding PRINT DATA would cause the Assembler to print the entire hex constant,
resulting in more printed lines of little value to the programmer.
Figure 1-5 provides the assembled program listing, similar to the previous example,
with a random assortment of coding errors. Immediately following the program is a
list of any errors that the Assembler has identified, along with the statement number
and explanation. (The code numbers under ERROR NO. can help locate further
explanations in the IBM Assembler manual, although this is seldom necessary.)
LOC OEJECT CODE ADORi A0DR2 STMT SOURCE STATEMENT
3 PRINT ON.NODATA.NOGEN
5 4 INITIALIZA T I 0 N
93 444 DECLARATIV E S
Check this section immediately on receiving the assembled program listing. The
Assembler denotes some, but not all, errors to the left of the invalid statement with
*** ERROR ***. Before reading the following explanation, try to locate the cause of
each error message.
Statement 35, indicating that PRTR is undefined, refers to the OPEN statement.
The use of PRINT NOGEN has caused the statements generated by macros not to
print. The printer device is defined in statement 119 as PRINTER.
Statement 61 spells the instruction MVC as MCV; the Assembler generates no
object code, because it does not know if the operation is supposed to be a macro or
normal instruction.
Statement 69 indicates B A20READ instead of A1 OREAD. Statement 144 should
either be a DS or should define a constant for the DC. Statement 151 is supposed to
be a SPACE instruction.
Statement 159 is in the literal pool that the Assembler generates, caused by the
fact that the GET instruction references CARDIN. This is a common case of one error
(144) causing another. Correcting 144 will cause 159 to disappear.
Statement 162 should be coded as END PROG2B, one error which caused the
Assembler to generate two messages.
If the computer attempts to execute this program, it will quickly "bomb out."
Be sure to correct all error diagnostics before reassembling and executing.
PROBLEMS
1-1. What steps are required to assemble a program? Where is the assembled
program stored?
1-2. EHow does the Assembler account for the address of each instruction and
declarative?
1 -3. Indicate which instruction formats are used to move data (a) between registers-
(b) between storage locations; (c) between registers and storage.
1-4. Explain (a) machine language instruction; (b) symbolic instruction; (c) macro
instruction.
1-5. Comment on the validity of the following Assembler program names (labels)■
(a) W25; (b) START-UP; (c) READDEVICE; (d) $AMT; (e) TOT AMT- (f) -TO¬
TAL; (g) 25CENTS.
1 -6. On the coding sheet, what does an asterisk in column 1 indicate? What would
it indicate in column 72?
1-8. What statement causes the assembled program listing to space 3 lines?
1-9. How may the Assembler check the sequence of a deck of program source
cards'
1-10. Does the EJECT statement cause the printer to skip to the top of a page
during
an assembly, during program execution, or both?
1-11. What statement terminates assembly of a program?
33 Problems
1-12. Refer to the IBM Assembler manual. Define in your own words (a) Self¬
defining terms; (b) Absolute and relocatable expressions.
1 -13. This chapter describes an address labelling system used in this text. What are
the advantages of such a system?
1-14. What is a declarative? How do DS and DC differ?
1-15. Distinguish between "source program" and "object program."
1-16. On the assembled program listing, what is meant by (a) LOC; (b) OBJECT
CODE; (c) ADDR1 and ADDR2; (d) STMT?
CHAPTER 2
PROGRAM EXECUTION
Chapter 1 covered the requirements for coding an Assembler program. This chapter
covers the basic instructions for executing an Assembler language program: ini¬
tialization, the defining of files, and the input/output macros. We also examine the
input of a data record and its format in main storage. Now that we are close to coding
a program, we also examine the conventional analytical tool for program design, the
flowchart. The next chapter provides enough information so that we can write pro¬
grams that use character data.
34
35 Program Execution Statements
PUTPR. They handle some complex coding and enable the beginner to get started
quickly. All other macros used in this text are standard IBM macros.
DEFINING CARD & PRINTER FILES. This text begins with the simplest, basic
input/output: punched cards and the printer. The names of the card and printer files
used in the program must be defined. This definition is handled by two special
macros, DEFCD (Define Card) and DEFPR (Define Printer) that generate some com¬
plex Assembler code. (The standard IBM macros, DTFCD and DTFPR (or DCB), are
covered in Chapter 7.) Other macros such as OPEN and GET reference these files by
the defined names.
DEFCD defines the card reader file with any valid unique name. Under DOS,
the last card of our input data must be a job control card containing /* in columns
1 -2. As each data card is read, the system checks the first two positions. If they
contain /*, the system directs the program to our end-of-file address. In the case of
the DEFCD macro, we enter this address in the operand field (with any unique
name). Typically the name begins a routine that may print final totals and terminate
the program execution. Under OS, the /* job card is optional.
-EOF
N
36 PROGRAM EXECUTION
DEFPR defines the name of the printer file with any unique name. The printer is
an output file and has no associated "end-of-file".
OPENING AND CLOSING FILES. Most programming languages require the pro¬
grammer to code statements that "activate” (OPEN) the files at the start of the
program and "deactivate” (CLOSE) them at the end. The normal function of OPEN is
to make the file available to the program (it may be damaged or in use by another
program). At the end of the program execution, CLOSE releases the file for use by
other programs. For both macros, the operands are the card and printer file names
defined by DEFCD and DEFPR. (Under many large systems, the programmer may
omit the OPEN and CLOSE of card and printer files.)
Under Disk Operating System (DOS), OPEN and CLOSE are coded as:
OPEN cardfile,printfile
CLOSE cardfile,printfile
Under Operating System (OS), we code OPEN and CLOSE with the operands in
brackets. Also OPEN must specify if the file is INPUT or OUTPUT; CLOSE may omit
the references.
OPEN (cardfile,(INPUT),printfile(OUTPUT))
CLOSE (cardfile, ,printfile)
-- 11extra -:-
comma denotes omission of
(INPUT)
For either DOS or OS, we may open or close one or more files with one
statement.
READING INPUT RECORDS. The GET macro reads input records. There are two
operands: Operand-1 designates the card file name defined by DEFCD (or by the
IBM macro DCB or DTFCD); Operand-2 is the name of an 80-byte input area in main
storage.
GET cardfile,cardarea
GET causes the card device to read a record and store its contents in the input
area, erasing the previous contents of the area. The card input area may have any
unique name. Prior to storing in the input area, the macro checks the record; if it is
the end-of-file card (/*), the program branches to the end-of-file address defined in
the DEFCD macro. An example:
37 Program Execution Statements
PRINTING LINES. Printing lines during program execution requires special treat¬
ment, because we may want to space on the page without printing, or print and
space one or more lines. To simplify the requirements involved in spacing the print
forms, in the early chapters this text uses a special macro, PUTPR. (Do not confuse
this printing during execute-time with the SPACE or PRINT statements that control
the printing of the program listing during assembly-time.)
For PUTPR, operand-1 is the name of the printer file defined by DEFPR (or by
the IBM macros DCB or DTFPR). Operand-2 is the name of the print area where we
have stored data that is to be printed. The print area may have any unique name, and
there may be more than one print area. Operand-3 specifies the forms control:
Note: PUTPR does not clear the print area. Because unwanted data may
still be in the area from the previous print operation, it is usually desirable
to clear the print area to blanks after printing so that the next printing does
not contain "garbage”. Also, if the print area is a DS, then it may contain
38 PROGRAM EXECUTION
garbage from some previous program. It is useful to define the print area
as a DC, as PRINT DC CL133' to initialize the print area to blanks.
More advanced programs are written to check if the input record contains
invalid data, and we may want to cancel the run if the input is invalid. The CANCEL
macro also terminates processing, but as well it "flushes” any remaining input rec¬
ords. The beginning programmer may want to delay using CANCEL until becoming
more advanced. Under OS, the macro equivalent to CANCEL is ABEND.
END OF ASSEMBLY. EOJ and CANCEL are concerned with terminating the pro¬
gram's execution, and may be coded in any logical place within the program. To
terminate program assembly, the last statement in the program must be END, which
tells the Assembler that there are no more statements.
The operand of the END instruction stipulates the address of the first executable
statement in the program. Through most of this text, this address will be the program
name, as:
The END instruction is not a macro and generates no executable code; it does,
however, provide the starting address for the Supervisor to begin execution of the
program.
Figure 2-1 combines the preceding Assembler macros and declaratives into a
skeleton program, the overall logic required for many programming problems. The
only instruction not covered is B A1 OREAD which causes the executing program to
go to ("branch” to) the instruction labeled A1 OREAD.
CONDITION CODE
Computers must have logic: the ability to compare the contents of one field to that of
another, and to check if a value is positive, negative, or zero. On the 360/370,
39 Condition Code
* INITIALIZATI 0 N
PROGEX INI T INITIALIZE
OPEN CARO,PR INTER ACTIVATE FILES
• MAIN PROCESS I N G
A 10READ GET CARD.CARDIN READ AN INPUT
* END-OF-FIL
810END •
• (PRINT FINAL TOTAL S IF REQUIRED)
•
* DECLARATIV E S
C ARC OEFCC B10END DEFINE CARO FILE 4 EOF ADDRESS
PRINTER DEFPR OEFINE PRINTER FILE
CARCIN OS CL 8 0 CARO INPUT AREA
PRINT cc CL133* • PRINT AREA
END PROGEX
comparing or checking fields sets the condition code, two bits in the Program Status
Word (PSW). Many compare and arithmetic instructions set the condition code
according to the results of the operation:
Equal or zero 0
Low or minus 1
High or plus 2
Arithmetic overflow 3 (arithmetic field is too
small for the calculated answer)
The purpose of the condition code is to facilitate the computer logic. Certain
operations set the condition code. Subsequently we can use other instructions that
can test what condition was set. In this way, we can change the flow of the program
logic.
As an example, a file of Accounts Receivable records must be read into the
computer in sequence by Customer. The program sequence-checks the file by com¬
paring the Customer number on the input record just read against the Customer
number on the record that was previously read and processed. The possibilities are as
follows:
40 PROGRAM EXECUTION
Similarly, the program may check an amount field to determine whether its contents
are zero (0), negative (1), or positive (2).
INPUT DATA
The card constitutes a record of data, such as a Customer Balance record. The record is
divided into fields of data, as customer number, name, and balance owing. A collec¬
tion of related records, such as all the Customer Balance records, comprises a file, or,
in OS terminology, a "data set."
Many records contain a unique code in a specified position to identify the file
to which they belong. Thus, the Customer Balance records could all contain '01' in
the first two positions, and programs that read this file can check each record to
ensure that the correct records are being entered. Also, the records are normally in
ascending sequence by control field, in this case, customer number. If the program
prints reports in sequence, the user can quickly locate any required customer
number. Because the file may be submitted in an incorrect sequence, it is common
practice for the program to "sequence-check" input records by their control fields.
We may define a field that contains character data: the numbers 0 through 9,
the letters A through Z, and other characters as $, *, and @. Character data, like all
other data, use binary representation through the bit on/off condition. One byte (8
bits) represents one character. The combinations of eight bits in a byte provide 256
(28) possible characters. The typical printer, however, can print about 60 different
characters. Figure 2-2 depicts the standard printable characters. As can be seen, in
storage the bits
1100 0010
zone numeric
represent the letter B. On a card, the letter B is punched as a 12-zone and a 2. The
zone portion of the byte, 1100, represents the card 12-zone punch. The numeric
portion of the byte, 0010, represents the card numeric 2-punch. Also, the figure
shows that the letter K, punched with an 11 -zone and a 2, has a binary representation
1101 0010. The letter S, punched with a zero-zone and a 2, has a binary representa¬
tion 1 110 0010. The characters 0 through 9 are represented as 1111 0000 through
1111 1001, and in hexadecimal as F0 through F9.
CODE TRANSLATION TABLE
CODE TRANSLATION TABLE (Contd)
Instruction Graphics and Controls EBCDIC Instruction Graphics and Controls EBCDIC
Dec. Hex 1RR) BCDIC EBCDIC! 11 ASCII Card Code Binary Dec. Hex IRX) BCDIC EBCDICI1I ASCII Card Code Binary
0 00 NUL NUL 12-0-1-8-9 0000 0000 64 40 STH Sp Sp e no punches 01® 00®
1 01 SOH SOH 12-1-9 0000 0001 65 41 LA A 12-0-1-9 01® 0®]
2 02 STX STX 12-2-9 0000 0010 66 42 STC B 12-0-2-9 01MM10
3 03 ETX ETX 12-3-9 0000 0011 67 43 1C C 12-0-3-9 01® ®11
4 M SPM PE EOT 12-4-9 ‘oooooi® 68 44 EX D 12-0-4-9 01® 01®
5 05 BAIR HI ENQ 12-5-9 0000 0101 69 45 BAL E 12-0-5-9 01® 0101
6 06 BCTR LC ACK 12-6-9 0000 0110 70 46 8CT F 12-0-6-9 01® 0110
7 07 BCR on BEL 12-7-9 0000 0111 71 47 BC G 12-0-7-9 01® 0111
8 08 SSK BS 12-8-9 -0000 1000 72 48 LH H 12-0-8-9 01® 10®
9 09 ISK HT 12-1-8-9 0000 1001 49
73 CH i 12-1-8 01® 1®1
10 0A SVC SMM LE 12-2-8-9 0000 1010 74 4A AH t ♦ j 12-2-8 01® 1010
11 0B VT VT 12-3-8-9 0000 1011 75 48 SH K 12-3-8 01® 1011
12 oc FF FF 12-4-8-9 0000 11® 76 4C MH n ) < < L 12-4-8 01® 11®
13 0D CR CR 12-5-8-9 0000 1101 77 4D 1 1
t M 12-5-8 01® 1101
14 OE MVCl SO SO 12-6-8-9 0000 1110 78 4E CVD < ♦ ♦ N 12-6-8 01® 1110
15 Of CICl SI SI 12-7-8-9 oooo mi 79 4F CVB * 1 1 0 12-7-8 oi® nil
16 10 L PR DU DU 12-11-1-8-9 0001 0000 80 50 ST & ♦ & & P 12 010100®
17 11
LNR DC1 0C1 11-1-9 0001 0001 81 51 12-11-1-9
Q 01010®!
18 ITR
12 DC2 DC 2 11-2-9 0001 0010 82 52 R 12-11-2-9 0101 ®10
19 13
LCR TM DC3 11-3-9 0001 0011 83 53 S 12*11-3-9 oioi mn
20 NR14 RES DC4 11-4-9 000 1 01® 84 54 N T 12-11-4-9 010101®
21 15
CLR Nl NAK 11-5-9 0001 0101 85 55 CL- U 12-11-5-9 0101 0101
22 OR 16 BS SYN 11-6-9 0001 0110 86 56 0 V 12-11-6-9 01010110
23 XR17 IL ETB 11-7-9 0001 0111 87 57 X w 12-11-7-9 01010111
24 LR18 CAN CAN 11-8-9 0®1 10® 88 58 L X 12-11-8-9 0101 10®
25 CR19 EM EM 11-1-8-9 0M1 1®1 89 59 c Y 11-1-8 oioi lmi
26 AR1A CC SUB 11-2-8-9 0M1 1010 90 5A A ! 1 Z 11-2-8 0101 1010
27 SRIB CU1 ESC 11-3-8-9 0M1 1011 91 58 s $ $ t 11-3-8 0101 1011
28 MR !C IFS FS 11-4-8-9 0M1 11® 92 5C M • • * \ 11-4-8 0101 11®
29 DRID ICS GS 11-5-8-9 0M1 1101 93 5D D ] 1 1 11-5-8 0101 1101
]
30 ALR
IE IRS RS 11-6-8-9 0®] 1110 94 5£ AL ; “» ~ 11-6-8 0101 1110
31 IF
SLR IUS US 11-7-8-9 0®1 111! 95 5F SL A —9 —« _ 11-7-8 oioi mi
32 20 IP0R DS SP 11-0-1-8-9 0010 00® 96 60 STO - - - ' 11 0110 00®
33 21 LNDR SOS i ! 0-1-9 ®10 0®1 97 61 7 / / a 0-1 0110 0® 1
34 22 LTDR FS " 0-2-9 0010 0010 98 62 b 11-0-2-9 0110® 10
35 23 LCDR # 0-3-9 0010 ®11 99 63 c 11-0-3-9 0110 0011
36 24 HDR BYP $ 0-4-9 M10 01M 1® 64 d 11-0-4-9 0110 01®
37 25 LRDR IF % 0-5-9 M10 0101 101 65 e 11-0-5-9 0110 0101
38 26 MXR ETB & 0-6-9 0010 0110 102 66 i 11-0-6-9 onoono
39 27 MX DR ESC • 0-7-9 ®10 0111 103 67 MXD 9 11-0-7-9 01100111
40 28 LDR t 0-8-9 ®10 10® 104 68 LD h 11-0-8-9 0110 10®
41 29 CDR i 0-1-8-9 ®10 1®1 105 69 CD i 0-1-8 ono lmi
42 2A ADR SM • 1
0-2-8-9 ®10 1010 1® 6A AD i 12-11 0110 1010
43 28 SDR CU2 + 0-3-8-9 M10 1011 107 6B SO k 0-3-8 ono ion
44 2C MDR 0-4-8-9 ®10 11® 108 6C MD %( % % 1 0-4-8 ono n®
45 20 DDR ENO - 0-5-8-9 M10 1101 109 6D DD V _ _ m 0-5-8 onojioi
46 2E AWR ACK 0-6-8-9 ®10 1110 no 6E AW \ > > n 0-6-8 ono mo
47 2F SWR BEL / 0-7-8-9 ®10 1111 in 6F sw #*. ? ? 0 0-7-8 ono nil
48 30 IPER 0 12-11-0-1-8-9 ®1100® 112 70 STE P 12-11-0 011100®
49 31 LNER 1 1-9 ® 11 0®1 113 71 4 12-11-0-1-9 01110M1
50 32 LTER SYN 2 2-9 0011 ®10 114 72 r 12-11-0-2-9 onimio
51 33 LCER 3 3-9 Mil ® 11 115 73 s 12-11-0-3-9 oni mn
52 34 HER PN 4 4-9 ® 11 01® 116 74 t 12-1HM-9 011101®
53 35 LRER RS 5 5-9 ®U 0101 117 75 u 12-11-0-5-9 0111 0101
54 36 AXR UC 6 6-9 ®11 0110 118 76 V 12-11-0-6-9 01110110
55 37 SXR EOT 7 7-9 ® 110111 119 77 w 12-11-0-7-9 01110111
56 38 LER 8 8-9 ®11 10® 120 78 U X 12-11-0-8-9 0111 10®
57 39 CER 9 1-8-9 ®11 1W1 121 79 CE y 1-8 oni lmi
58 3A AER 2-8-9 ®11 1010 122 7A A£ ft Z 2-8 0111 1010
59 ii. SER CU3 3-8-9 ®11 1011 123 7B SE f - # # i 3-8 oni ion
60 3C MER DC4 < 4-8-9 ®1111® 124 7C ME S ' 8 e ! 4-8 0111 11®
61 3D DER NAK ■ 5-8-9 Mil 1101 125 7D DE ' ' ) 5-8 0111 1101
62 3£ AUR > 6-8-9 ®1I 1110 126 7E AU > • - 6-8 0111 1110
63 3F SUR SUB ? 7-8-9 ®n mi 12, 7F SU s " on 7-8 oni nn
1. Two columns of EBCDIC graphics Note the following common Hex representations:
are shown. The first gives standard
bit pattern assignments. The second
shows the T-ll and TN text printing
chains (120 graphics). Hex Hex Hex
40 t5 Blank 50 & Ampersand 61 / Slash
4B . Period 5B $ Dollar 6B ) Comma
4E + Plus 5C * Asterisk 6C % Percent
4F 1 OR symbol 60 - Minus 7D } Apostrophe
41
CODE TRANSLA TION TABLE (Contd )
CODE TRANSLATION TABLE (Contd)
Instruction Craphics and Controls EBCDIC
Instruction Graphics and Controls EBCDIC Binary
Hex (SSI BCDIC EBCDIC! 11 ASCII Card Code
Card Code Binary Dec.
Hex BCDIC EBCDIC! 11 ASCII
12-0 1100 0000
12-0-1-8 1000 0000 192 CO ? {
128 80 SSM -S A 12-1 1100 0001
12-0-1 1000 0001 193 Cl A A
129 81 a a 1100 0010
194 C2 B B B 12-2
b b 12-0-2 1000 0010
130 82 LPSW -S 12-3 1100 0011
1000 0011 195 C3 C C C
12-0-3
D 0 D 124
d 1244 1000 0100 196 C4
132 84 WRD d 1100 0101
SI E E E 12-5
e e 12-0-6 1000 0101 197 C5
133 85 ROD 12-6 1100 0110
12-0-6 1000 0110 198 C6 F F F
134 86 BXH f f
G G G 12-7 1100 0111
q 12-0-7 1000 0111 199 C7
BXL£ 12-8
1000 1000 200 C8 H H H
136 88 SRL h h 12-0-8
1 1 1 12-9 1100 1001
1 12-0-9 1000 1001 201 C9
137 89 SLl 1 1100 1010
202 CA 12-0-2-8-9
SRA 12-0-2-8 1000 1010
138 8A 12-0-3-8-9 1100 1011
12-0-3-8 1000 toil 203 CB
204 J 12-04-8-9 1100 1100
12-0-4-8 1000 1100 CC
140 8C SRM. £ 12-0-5-8-9 1100 1101
( 12-0-5-8 1000 1101 205 CO
141 80 SLDL 12-04-8-9 1100 1110
12-0-6-8 1000 1110 206 CE V
142 8E SRDA
207 Cf 12-0-7-8-9 noo mi
Rf SLDA 12-0-7-8 iooo mi
143
1001 0000 208 DO j 11-0
144 90 STM 12-11-1-8
209 01 MVN J j j 11-1 1101 0001
TM 12-11-1 1001 0001
143 91 ] i
SI 210 02 MVC K K K 11-2 11010010
146 92 MVI k k 12-11-2 1001 0010
211 03 MV 2 L L l 11-3 11010011
93 TS -s 1 l 12-11-3 1001 0011
147
10010100 212 04 NC M M M 11-4 11010100
94 Nl m 12-11-4
1001 0101 213 05 CLC N N N 114 1101 0101
95 CLI n 12-11-5
SI 10010110 214 D6 oc 0 0 0 11“6 11010110
150 96 01 0 12-11-6
10010111 215 07 xc p p p 11-7 1101 0111
151 97 XI p 12-11-7
12-11-8 1001 1000 216 08 0 Q Q 11-8 1101 1000
15? 98 LM -RS q q
12-11-9 1001 1001 217 D9 R R R 11-9 1101 1001
153 99
12-11-2-8 1001 1010 218 OA 12-11-2-8-9 1101 1010
154 9A
12-11-3-8 1001 1011 219 DB 12-11-3-8-9 1101 1011
155 9R i
12-114-8-9 1101 1100
156 9C SIO.SIOF □ 12-11-4-8 1001 1100 220 DC TR
) 12-11-5-8 1001 1101 221 DO TRT 12-114-8-9 1101 1101
157 90 TIO, CLR10
S + 12-11-6-8 1001 1110 222 DC ED 12-114-84 1101 1110
158 9E HIO.HDV
12-11-7-8 iooi lm 223 OF EDMK 12-11-7-84 noi nil
159 9F TCH
AO 11-0-1-8 1010 0000 224 EO ♦ \ 0-2-8 1110 0000
160
« 11-0-1 1010 0001 225 El 11-0-14 1110 0001
161 A1
11-0-2 1010 0010 226 E2 s S s 0-2 1110 0010
162 A2 s s
A3 t t 11-0-3 1010 0011 227 E3 T T T 0-3 1110 0011
163
11-0-4 1010 0100 228 E4 U U U 04 1110 0100
164 A4 u u
V V 11-0-5 1010 0101 229 E5 V V V 04 1110 0101
165 A5
w 11-0-6 1010 0110 230 E6 W w w 04 mo ono
166 A6
167 A7 X X 11-0-7 1010 0111 231 E7 X X X 0~1 11100111
232 Y Y V 0-8 1110 1000
168 A8 y Y 11-0-8 1010 1000 E8
42
43 Input Data
Digits are normally read from cards into storage in character format, and are
printed in this format. (However, to perform arithmetic, we must translate character
data into packed or binary format.) Data is read into storage from such devices as
card readers, disk, and tape. This chapter considers only card input. The card,
punched with alphabetic and numeric data, reads into an 80-byte area, defined
anywhere in available storage. The card is read entirely in character format. The
following lists the contents of a punched card:
Assume that the name of the 80-byte input area is CARDIN, and the name of
the input file is CARD. The relevant instructions to read the record are:
GET CARD,CARDIN
The GET instruction reads the 80-character input record into the 80-byte CAR¬
DIN area in main storage, byte-for-byte, as shown in Figure 2-3.
CARDIN CARDIN + 79
card input area
jL
Char 0 1 1 2 3 J P M C K 1 N N O N 0 1 2 5 0 0 0
LL
LL.
CN
o
Hex F0 FI FI F2 F3 D1 D7 40 D4 C3 D2 C9 D5 D5 D6 D5 40 40 FI F5 F0 F0 F0 40 40 40
Compare the character and the hexadecimal representation, two hex digits for
each character read. Note especially that any blank card position appears in storage
as X'40' (binary 0100 0000). Also, the numbers 0 through 9 become X'FO' through
X'F9'. We may assign symbolic names to each field within the CARDIN area. We
then process the data by referring to each field's symbolic name. For example, we
may check that the card code (01) is correct. We may move the account number
(123) and the name to another storage area in order to print them. Also, we may
44 PROGRAM EXECUTION
convert the balance field (1,250.00) into packed decimal format in order to add it to
an accumulator. In order to perform these tasks, we must be able to do the following:
— Reference areas and fields in storage. For this purpose we use declaratives to tell
the Assembler each field's name, length, and format (e.g. character, binary,
packed).
— Instruct the computer step-by-step what is to be done. We use Assembler sym¬
bolic instructions in order, for example, to move, add, and compare data.
FLOWCHART LOGIC
Programming is more than simply coding instructions for the computer to execute.
Usually there are several steps: analysis, design, flowcharting, and coding.
ANALYSIS. The first step is to analyze the problem. This step may consist of inter¬
viewing people concerned with the problem, studying input data to be processed,
and designing the output required. If other programs use the same input or require
the output, then the new program must integrate with the present system.
FLOWCHARTING. The next step depicts the solution to the problem. Commonly,
we draw a flowchart, a pictorial representation of the program's flow of logic,
showing each step that the program coding is to take. If we can flowchart the
program, we should be able to code it. A flowchart serves the following purposes:
SYMBOL IDENTIFICATION
r
TERMINAL Start or termination of the program.
INPUT/
Depicts all input/output operations, such as read a card,
OUTPUT
BLOCK
or write a line.
o
CONNECTOR
one block to another. One on-page connector is an exit
from the block, and one is an entry to the other block.
Unique letters, such as 'A', in each connector relate
them.
EXAMPLE FLOWCHART. Figure 2-4 illustrates most of the flowchart symbols. The
flowchart depicts a program that reads Customer Balance records. Each record is
identified by a customer number, and contains also customer name and balance
owing. There may be only one record for a customer. The objective is to print the
balance owing for each valid customer. Note the following points:
1. The program compares the customer number on each input record against the
customer number from the previously processed record. If the new one is higher
(Y), the program prints customer number, name and balance, and stores the new
customer number in "previous" number for the next sequence-check. The pro¬
gram then branches back to read the next record and repeats the instructions.
46 PROGRAM EXECUTION
If the customer number is not higher, the program prints an error message
and branches back to read the next record, indicated by a connector (A).
2. Immediately following the read operation is the end-of-file condition. If there are
no more records to be processed, the program closes the files and terminates
processing (END-OF-JOB).
JOB CONTROL
Medium and large sized 360/370 computers run under an operating system. In order
to assemble or execute a program, we must submit "job control" entries that tell the
operating system what action to perform. A "job" may consist of one or more
programs that are to execute with required data. The system recognizes the start of a
job, such as "Payroll", by means of the first job control card which contains an entry
such as // JOB or //jobname JOB. Such entries that specify the job, and the action to
perform comprise the "job control language" (JCL).
The two main IBM operating systems are Disk Operating System (DOS) for
medium size computers, and Operating System (OS) for large ones. Job control
language for these two systems is quite different, and even within a system may vary
considerably between installations. Appendix D gives example job control for some
typical situations. Check the particular JCL requirements for your own installation.
PROBLEMS
2-1. An input file is called "FILEIN" and an output file is called "FILEPR". Provide
for your system: (a) The OPEN statement; (b) a properly defined area for input
records; (c) the GET instruction; (d) a properly defined area for print records; (e)
the write statement necessary to write and space two lines; (f) the CLOSE
statement.
2-2. FHow does your system recognize the end of data for a file of cards?
2-3. A field tested in a program is found to be negative. What will be the condition
code setting?
2-4. Given the Character, Hexadecimal or Binary, complete the representation.
O
CM
CO
salesman number and amount of sales for the week. For each card, calculate
sales commission as follows:
up to $1,000.00 5.0%
$1,000.01 to $3,500.00 7.5%
over $3,500.00 8.5%
Multiply sales amount by the required commission rate and print sales, rate,
and commission. At the end of the file terminate processing.
2-7. Code the job control for your installation for assembly, link-edit, and execution
of a card input program.
2-8. Code, assemble, and test a program that reads cards and prints their contents. If
you call the input area CARDIN and the print area PRINT, then you can move
the contents of each input record to the print area with:
MVC PRINT+20(80),CARDIN
PART II
BASIC ASSEMBLER
CODING
CHAPTER 3
PROGRAMMING FOR
CHARACTER DATA
The chapter introduces character format in which data is normally read and printed.
The first part describes the Assembler declaratives that define character fields: areas
in storage to handle input and output records, and constants such as report headings.
Because programs must manipulate data that is read or defined, the next sections
cover the basic instructions to move and compare data. A sample program illustrates
the use of these instructions and how they may be organized into a working program.
DECLARATIVES
Declaratives are instructions that the Assembler recognizes and assigns storage loca¬
tions. They do not generate an executable instruction. Declaratives provide for the
entry of data to the program in two ways:
1. The declarative Define Storage (DS) defines areas for the program to receive data
that varies in content, such as an input area.
2. The declarative Define Constant (DC) defines constants, such as a title for a report
heading, or the numeric value 'V to count the pages being printed, or an ac¬
cumulator initially set to zero.
57
52 PROGRAMMING FOR CHARACTER DATA
DEFINE STORAGE (DS). The DS statement reserves an area of storage, for exam¬
ple, to define areas for reading cards and for printing. The general format of the DS
statement on the coding sheet is:
Optional: Symbol = the name assigned to the field. If the program needs to refer to
the field by name, then we assign a name in columns 1 -8. The name
refers to the first (leftmost) byte of the field. Chapter 1 gives the require¬
ments of symbolic names.
Optional: d = duplication factor which tells the Assembler how many repetitions
of the same area are required. If we omit the factor, the Assembler
assumes one area. If 2 is specified, the Assembler creates two adjacent
areas; the name (if any) refers to the first area.
Required: T = type of format, such as C for Character, or P for Packed.
Optional: Ln = length of the field in bytes (n), positive values only. For example, L3
designates a 3-byte field. If length and comments are omitted (such as DS
C), the Assembler assumes a length of one byte. The maximum length of
a character DS field is 65,535 bytes.
Optional: 'comments' = a description within apostrophes of the purpose of the
field. If we omit the length (Ln), the Assembler assumes that the length is
the number of bytes within the apostrophes. For example, DS C'LIZ'
defines a 3-byte area, but containing no such value—the contents are
still “garbage”.
Figure 3-1 depicts various DS statements in character format. Note the headings
on the Assembler listing:
7 *
8 * DS CHARACTER FORMAT
Hex address of leftmost 9 *
003600 byte of defined field 10 FIELDA DS 1CL5 RESERVES 5 BYTES CALLED FIELDA
003605 12 FIELDB DS CL 5 RESERVES 5 BYTES CALLED FIELDB
00360A 14 DS CLIO RESERVES 10 BYTES
00361A 16 CARDAREA DS CL 80 RESERVES 80 BYTES FOR CARD AREA
003664 18 DS 80C RESERVES 80 1-BYTE FIELDS
0036B4 20 FIELDS DS 3CL 5 RESERVES 3 5-BYTE FIELDS
22 DATE DS CL 8•DD/MM/YY •
0036C3 RESERVES 8 BYTES. CONTENTS ARE +
DOCUMENTATION ONLY
SOURCE STATEMENT in the center lists our original source symbolic language
code.
STMT, immediately to the left, gives the statement number of each source statement,
as generated by the Assembler. FIELDA, for example, is statement-10. (State¬
ment-1 1 is suppressed; it is a card with the instruction SPACE that causes the
Assembler to space one line.)
LOC at the far left is the contents of the location counter that lists the hexadecimal
address location of each statement. FIELDA is a 5-byte field beginning in location
X'003600'. FIELDB begins immediately following in X'003605'. The Assembler
defines declaratives in the same sequence that they are coded, in locations
directly one after the other.
OBJECT CODE lists the assembled machine code: object code instructions and the
contents of DC's. A DS lists no object code because it merely reserves space.
ADDR1 and ADDR2 refer to instructions, not declaratives. Each declarative is ex¬
plained next. Commentson the rightofeach statement describe the defined area.
Statement-10: FIELDA is a 5-byte DS beginning in location X'003600'. The duplica¬
tion factor 1 may be omitted, as shown in FIELDB.
Statement-12: FIELDB at X'003605' immediately follows FIELDA.
Statement-14: This DS is unnamed. Its address is X'360A' because FIELDB at X'3605'
is five bytes: X'3605' + 5 = X'360A' (5 + 5 = 10 or A in hex).
Statement-16: CARDAREA defines an 80-byte area to be used for card input.
Statement-18: Because there is no length (Ln), the Assembler assumes that each of
the 80 fields is one byte.
Statement-20: FIELDS defines three 5-byte fields. A reference to the name FIELDS is
to the leftmost byte of the first 5-byte field.
Statement-22: DATE illustrates the use of comments. The programmer expects to
store the date in the field in the specified format.
1. Where in storage will the field reside? The Assembler assigns the field's location
and accounts for the length of every instruction, storage area, and constant. For
this task it uses a location counter (see Chapter 1).
2. How does the computer know where the field resides and how long its length is?
The Assembler translates the symbolic addresses into machine object addresses. If
it has assigned, for example, FIELDA with the address X'3600' then any instruc¬
tion's reference to FIELDA is to address X'3600'. For certain instructions, the
Assembler stores the length of the field as part of the instruction.
3. What are the contents of the field? The contents of a DS field are unknown,
because the Assembler merely reserves the defined area. At the start of the pro¬
gram a DS area may contain data from a previous program. Therefore, we may
have to initialize DS fields with valid data. For example, if the print area is defined
as a DS, we should clear it to blanks at the start of the program so that "garbage"
is not printed along with valid data. The only purpose of DS is to define an area of
storage with a specified length. The fact that the field's format is defined as
character, packed, etc., is irrelevant, because at execution-time the field may
54 PROGRAMMING FOR CHARACTER DATA
contain data in any format. The defined format is merely a convenient reminder of
what format we expect the field to contain. A major use of DS is to define input
and output areas, covered next.
INPUT AREAS. In order to define fields within a record, we use a DS with a zero
duplication factor, as DS 0CL80, and define the fields immediately following.
The set of DS's in Figure 3-2 fully defines the input area for the card format
given in Figure 2-3. The DS defines CARDIN as an 80-byte record. However, be¬
cause of the "0” (zero) duplication factor, the Assembler location counter is not
incremented. The Assembler assigns the next field, CODEIN, the same address as
CARDIN (X'4201'). CODEIN, however, is a 2-byte field. Although both fields begin
at X'4201', a reference to CARDIN is to an 80-byte field, whereas a reference to
CODEIN is to a 2-byte field. Each DS following CARDIN defines a field within the
CARDIN area. The sum of their lengths must equal 80, the length of CARDIN, in
order to account for all card columns that read into the program's main storage area.
We may now refer to the entire 80-byte CARDIN record, and to any field defined
within the record.
The GET macro reads an 80-column card into an 80-byte area that we define,
as in GET CARD,CARDIN. On input, card column 1 reads into the leftmost byte
of CARDIN (location X'4201' on the assembled DS statement). Card column 2 reads
into the next byte (X'4202'), and column 80 into the 80th byte (X'4250').
Note: The read operation erases the previous contents of the CARDIN
area.
OUTPUT AREAS. Whereas a read operation erases the previous contents of the
input area, a write operation leaves the contents of the output area unchanged.
Therefore, if a DS defines the output area, we must ensure that the storage positions
do not contain "garbage'' from the previous program. At the beginning of our pro¬
gram, we should clear the output area to blanks (X'40'). An alternative soution is to
use Define Constant (DC) to define the output area with an initial constant containing
b anks It is also often necessary to clear the print area after writing a line, so that it is
blank for the next line to be printed.
Although the number of print positions varies with the printer used, a common
requirement is to define a 1 33-byte print area as PRINT DS CL1 33 or DC CL1 33' '
55 Declaratives
The 360/370 use the leftmost byte of PRINT for a printer forms control character.
This character controls forms movement, such as print and space one line, or skip to
a new page. We may use the other 1 32 positions to store data to be printed. Chapter
2 gives the requirements for the print macro, PUTPR.
We may also define the print area with a zero duplication factor, as PRINT DS
0CL133, with a DS to define each field within the record. Alternatively, we may
reference PRINT by relative addressing. (It is possible to reference any field in main
storage by relative addressing, or to define it with a zero duplication factor and
redefine the fields within it.) Since the leftmost byte (the position labeled PRINT) is
reserved for the control character, we may refer to the first printable position as
PRINT + 1, to the second as PRINT + 2, etc.:
133 bytes
t
PRINT+0 PRINT+2 PRINT+132
reserved for PRINT+1 PRINT+3
control character
DEFINE CONSTANT (DC). The DC statement, like DS, reserves storage of a de¬
fined length. In addition, DC defines a constant (or value) such as a heading to be
printed on a report. A DC may define a constant in any format, such as Character,
Binary, Packed and Hexadecimal, and in various lengths. The general format for a
DC statement is as follows:
FIELDA DC CL5’APRIL’
FIELDB DC CL4’APRIL’
The defined length, 4, overrides the length of the constant. The length of
FIELDB will be four bytes. The Assembler left-adjusts the constant and trun¬
cates rightmost characters that exceed the defined length. APRI is generated.
c. The defined length is greater than the length of the constant.
The length of FIELDC will be six bytes. The Assembler left-adjusts the constant
and pads rightmost bytes with blanks. APRIL# is generated.
5. The apostrophe (') and the ampersand (&) have special meaning to the Assembler.
If we define them within a constant, we must code them as two adjacent charac¬
ters, although the Assembler counts and prints only one.
Figure 3-3 provides various character DC's with explanations. On the Assem¬
bler listing note the OBJECT CODE generated by each statement. LOC gives the hex
address of the first byte of each constant. Under OBJECT CODE is the hex contents
up to the first eight bytes (1 6 hex digits) of the constant. (The entire hex contents for
constants exceeding eight bytes can be printed by means of the Assembler instruction
PRINT DATA.)
The first pair of DC's defines fields containing blanks, or X'40' in object code.
BLANK1 generates a 5-byte field containing five blanks. Its location is X'004301'.
Under OBJECT CODE are the five bytes of blanks (X'40's). BLANK2 defines five
1-byte blank fields; its implicit length is therefore one.
The next section defines fields with zero values. ZEROI generates a 5-byte field
containing five zeros. Note that a character zero is X'FO'. ZER02 is a 5-byte field as
well. But because only one zero is specified, the Assembler left-adjusts the zero and
fills the remaining bytes with blanks, a common coding error. ZER03 generates five
1-byte fields, each containing a zero.
The third section defines numeric values. FIVEA and FIVEB show two ways to
define a 1 -byte field containing the value 5 (X'F5'). FIVEC generates 05, or X'F0F5'.
57 Declaratives
41 *
42 * OC CHARACTER FORMAT
43 *
CONSTANT GENERATED
45 *
004301 4040404040 46 BLANK1 DC CL 5 * •
004306 4040404040 l 2 uL flirlv O
47 BL ANK 2 DC 5CL 11 • 5 1-BYTE BLANKS
49 ♦ DEFINE ZEROS:
00430B F0F0F0F0F0 50 ZER01 OC C•00000'
004310 F040404040 51 ZER02 OC CL 5'0'
004315 F0F0F0F0F0 52 ZER03 DC 5C 1 0 * '0* , 'O' , 'O','O','O'
54 * DEFINE NUMBERS:
00431 A F5 55 FIVEA DC CL 1'5 • '5•
004 3 1B F5 56 FIVES DC C • 5' •5'
00431C F0F5 57 FIVEC DC C '05' •05'
59 * DEFINE ALPHABETIC:
00431E 5BF16BF0F0F04BF0 60 AMT DC C'tl.OOO.OO' ' $ 1,000.00'
004327 C1C2C3C44040 61 PADBLANK DC CL 6'ABCD' •ABCD •
00432D 40D106C540 5040C6 62 AMPERSND DC C' JOE EE FLO''S • ' JOE £ FLO'S •
00433A C1C2C1C2 63 TRUNCATE DC 2CL2'ABCD' 2 CONSTANTS = 1AB' , ’ AB *
00433E F0F701E4D3E8 64 JULY DC C'07' ,C'JULY' 2 CONSTANTS = *07 • ,
65 title DC C' INTERNAT onal businf M A O
004344 404040C940D540E3 H I N E S'
continuation char
67 * DEFINE ERRORS: col 72
68 ERROR A DC CL 3 MISSING 'CONSTANT'
*** ERROR ***
69 ERROR B DC • i
MISSING FORMAT
*** ERROR ***
70 ERRORC DC CL ' 123' MISSING LENGTH N
*** Error ***
71 ERRORD DC CL300 • • LENGTH EXCEEDS 256
* * ERROR ***
The fourth section defines alphabetic fields. AMT generates a field with a dollar
sign (X'5B'), a comma (X'6B'), and a decimal point (X'4B'). PADBLANK left-adjusts
the constant and pads two blanks to the right. AMPERSND illustrates the use of the
ampersand (&) and apostrophe ('), both of which must be defined twice. The gener¬
ated constant in this case is 1 3 bytes long, although the Assembler prints only the first
eight bytes under OBJECT CODE. TRUNCATE defines two constants, each two bytes
long. The Assembler truncates the constant ABCD on the right to two bytes (because
we coded L2) and generates AB twice (see the hex object code). JULY shows one
statement that defines two character constants, separated by a comma. A reference to
the name JULY is to the first 2-byte field. (This feature, providing for definition of
more than one constant with one DC, is not available in every level of Assembler.)
TITLE illustrates the continuation character, in this case a plus sign (+) in
column 72. The constant continues on the next line in column 16. (Even though there
is an Assembler instruction TITLE, we can use TITLE for the name of a field.)
The last section defines some common coding errors. The comments on the
right explain the cause of the error. The Assembler prints ERROR instead of the object
code, and explains the cause at the end of the program listing (not shown). Any
instruction in the program that references one of these invalid constants also causes
an error message for that instruction.
Problems 3-1 and 3-2 should now be attempted.
58 PROGRAMMING FOR CHARACTER DATA
CHARACTER INSTRUCTIONS
This section covers the movement and comparison of fields in character format. The
content of these fields is made available to the program from an input record or
declared as a constant value. There are two instruction formats that process data in
main storage: Storage-to-Storage (SS) and Storage Immediate (SI). SS format pro¬
cesses data between two fields in main storage, whereas SI format processes between
a one-byte constant built into the instruction and one main storage location.
STORAGE-TO-STORAGE FORMAT
Some instructions reference data in main storage only, others process data between
main storage and the registers, and others process in registers only. Storage-to-storage
(SS) format references only storage locations. In an instruction like MVC (Move
Character), the operands are represented as S1,S2 meaning that both operand-1 (SI)
and operand-2 (S2) reference main storage. Another representation in symbolic form
is:
MVC D1(L,B1),D2(B2)
D1 (L,B1) means that the operand-1 address consists of a base register (B1) and a
displacement (D1).
L means that the length of operand-1 controls the number of bytes processed.
D2(B2) means that the operand-2 address consists of a base register (B2) and a
displacement (D2). This feature may be ignored for now; Chapter 6 describes it
in detail.
MOVE CHARACTERS—MVC
Frequently the program must move the contents of one field to another. Fields in the
input area must be moved to other areas in order to save them from erasure by the
next record that the program reads. Also, constants, headings, and calculated values
must be moved to the print area for printing. The following instructions move charac¬
ter fields, bytes, and half-bytes from one storage location to another: Move Character
(MVC), Move Numerics (MVN), Move Zones (MVZ), Move Immediate (MVI), and
Move With Offset (MVO). This chapter describes MVC and MVI. Although MVC may
move data in any format, we normally confine its use to character fields.
1. MVC may move from one to 256 bytes, usually character data, but technically
any format.
2. Data beginning in the byte specified by operand-2 is moved one byte at a time to
the field beginning with the byte specified by operand-1. The move does not
affect the contents of the operand-2 field; the bytes are copied into the operand-1
field. Thus, the instruction MVC FLDA,FLDB copies the contents of FLDB into
FLDA.
3. Each operand specifies the leftmost byte of the field, and movement is from
left to right.
4. The length of the operand-! field determines the number of bytes moved. In the
MVC instruction format there is a length code (L) for operand-1 only. The length
of operand-2 is irrelevant to the operation. If the operand-1 field is five bytes long
and operand-2 is six bytes, MVC moves only the first five bytes of operand-2 (from
left to right one byte at a time) to the operand-1 field. If the operand-1 field is six
bytes and operand-2 is five, MVC moves all five bytes of operand-2, plus one byte
immediately to its right.
FIELD LENGTH. We may specify the number of bytes to be moved in one of two
ways: implicit or explicit length. Assume the following DC's:
FIELD1 DC CJUNE’
FIELD2 DC CAPFUL’
(FIELD1 (FIELD2
before the MVC: JUNEAPR I L
EXPLICIT LENGTH: MVC FIELD1 (3),FIELD2. Assume the same DC's as before.
Operand-1 has an explicit length (3) that overrides the defined length of FIELD1.
Therefore, MVC moves only the first three bytes of FIELD2 (APR) into the first three
bytes of FIELD1. The fourth byte of FIELD! is unaltered:
(FIELD1 (FIELD2
EXPLICIT LENGTH: MVC FIELD! (5),FIELD2 moves 5 bytes. APRI is moved into
FIELD 1. The "L" is moved into the next byte to the right, the first byte of FIELD2,
which immediately follows FIELD1:
(FIELD1 {FIELD2
before the MVC: JUNEAPR I L
RELATIVE ADDRESSING. Any operand that references main storage may use rela¬
tive addressing. If we have to refer to a byte that has no name, we may refer to its
position relative to a byte that has a name. For example, suppose we want to move
the third and fourth bytes of FIELD2 to the second and third bytes of FIELD1 • MVC
FIELD! +1(2), FIELD2 + 2:
(FIELD1 (FIELD2
before the MVC: JUNEAPR I L
SYMBOL LENGTH ATTRIBUTE. The Assembler permits explicit lengths coded ab¬
solutely, as was described, and symbolically:
The symbol length attribute uses L' followed by a symbolic name. In this example wc
want to move five bytes Since the length of FIELD2 is five, the Assembler under
stands the explicit length to be 5.
Figure 3-4 depicts unrelated MVC operations. Note the OBJECT CODE gener¬
ated for each statement. The Assembler lists under ADDR1 and ADDR2 the ad-
resses of operand-1 anc! operand-2 respectively. For example, statement-1 7 is MVC
n^nnl Th 655 ' 3 Yte 6ld' is 03002 and the address of Y' a 5-byte field is
03005. The instruction may be read as: Move the first three bytes of Y starting in
ocation 03005, to the field called X, starting in location 03002. The object code
instruction is six bytes long, beginning in location 003012. Chapter 6 gives the
interpretation of this machine language.
61 Move Characters—MVC
14 *
ACTION OF MOVE: RESULT OF MOVE:
15 *
For illustrative purposes, this text uses examples with declaratives named as X,
Y, and Z, but does not advocate such cryptic names in programs.
It is often necessary to determine if the contents of one field are equal to, greater than,
or less than, the contents of another field. Examples of the need to compare character
fields include:
CONDITION CODE
COMPARISON SETTING
Operand-1 equals operand-2 0 (equal)
Operand-1 is lower 1 (low)
Operand-1 is higher 2 (high)
3. CLC terminates comparison as soon as an u
nequal condition is encountered, or if
none, by the length of operand-1 (explicit or implicit).
63 Compare Logical Character—CLC
28 *
29 *** CLC COMPARE LOGICAL CHARACTER
30 *
003042. C1C2C3C4C5 31 F I EL 01 DC C•ABCDE * THESE FIELDS
003047 C6C7C8 32 FIELD2 DC C 'FGH • ARE ADJACENT
00304 A 5C5C 33 FIELD3 DC c '** • IN STORAGE*
COMP1: The operand-1 field, FIELD2, is shorter. CLC compares the three bytes of
FIELD2 against the first three bytes only of FIELD1. Because the data in FIELD2 is
logically greater than that of FIELD1, the condition code is set to high.
COMP2: The operand-1 field is longer. CLC compares the five bytes of FIELD1 against
the three bytes of FIELD2 plus the next rightmost two bytes of FIELD3 (two
asterisks). Operand-1 is lower.
COMP3: Operand-1 uses relative addressing and explicit length. CLC compares
bytes 3, 4 and 5 of FIELD1 against FIELD2.
COMP4: The instruction is similar to COMP3, with the explicit length omitted. The
implicit length of operand-1 is therefore 5.
COMP5: An asterisk (X'5C') is lower than character 'A' (X'CI'), so the operation
terminates as "low" after comparing only the first byte.
COMP6 illustrates erroneous use of explicit length in operand-2; omitting the length
corrects the error.
BRANCHING. CLC makes the comparison and sets the condition code. To test the
condition code to determine what action to take (for example, was the result of the
test high, low, or equal?), we use the following conditional branch instructions:
CONDITION
CODE CONDITIONAL BRANCHES
NEW DS CL4 Contains the value of the account just read (assume
'1347').
PREV DS CL4 Contains the value of the previous account read
(assume '1208').
CLC NEW,PREV Compare the contents of NEW to PREV.
BH R20HIGH If NEW is higher, branch to R20HIGH (some ad¬
dress of a routine in the program).
The preceding instructions are read as follows: Compare the new account (contain¬
ing 1 347) to the previously read account (1208). NEW's contents being higher than
PREV, the condition code is set to high (2). Next, BH tests if the high condition is set.
Because the code is 'high', the program branches to R20HIGH. If the code was not
"high", the computer would execute the next sequential instruction (NSI) following
the BH.
Two other branch instructions are Unconditional branch (B), and No-operation
(NOP). The unconditional branch tests if any condition (high, low, equal) exists.
Since there is always at least one condition, we use B if a branch is always required.
For example, after processing an input record, we may return to read the next record
by means of an unconditional branch:
COMPARE AND BRANCH. The following examples illustrate the preceding dis¬
cussion. Assume the declaratives X, Y, and Z contain data and are each defined as DS
CL4:
Example: If X is greater than Z, branch to J20HI. Else, if Z does not equal Y branch
to J30NEQ.
Storage-to-Storage (SS) format references two fields in main storage, whereas the
Storage-Immediate (SI) format references only one field. The other data used is a
1-byte constant, built into the instruction itself. The Assembler stores the immediate
constant in the second byte of the object code instruction. The constant is therefore
part of the object instruction.
The rules for MVI and CLI are similar to those for MVC and CLC, with the following
exceptions:
1. Operand-1 references a single main storage location. The operand does not per¬
mit an explicit length code because the number of bytes is always one.
2. Operand-2 contains a 1 -byte immediate constant. The immediate constant value
may be character (C), hexadecimal (X), binary (B), or a decimal digit, but not
zoned (Z) or packed (P).
66 PROGRAMMING FOR CHARACTER DATA
50 ♦
MVI S 51 ** * MVI MOVE IMMEDIATE
xi.
003074 92 3B 406E 03070
52 *
53 MOVIMMI MVI SAVE.C't* SAVE= I5BIF0IF0I
003078 925 B 4 06E 03070 54 MOV I MM2 MVI SAVE,X'5B' X•5B*IS IDENTICAL TO C' $•
00307C 0000 0000 00000 55 MOV IMM3 MVI SAVE!1),C•?• ERROR IF LENGTH IN OP-1.
*** ERROR ***
003080 0000 0000 00000 56 M0VIMM4 MVI SAV E+ 1» =C•$ • ERROR: CANNOT USE LITERAL
*** ERROR
58 *
CLI 5 59 *** CL I COMPARE LOGICAL IMMEDIATE
TT 60 *
003084 95F5 4071 03073 61 C0MIMM1 CL I C0DEIN,C'5' SETS CONDITION CODE EQUAL
003088 0000 0000 00000 62 COM I MM2 CL I C0DEINII),C•5 • ERROR IF LENGTH IN OP-1.
*** ERROR $ $$
00308C 0000 0000 00000 63 COM I MM3 CL I C0DEIN,P'5' ERROR IF PACK OR ZONED
*** ERROR
LITERALS
The use of literals is a short cut way of writing a DC. The literal begins with an equal
(=) sign followed by a character for the type of constant, and the constant contained
with apostrophes ('). The same basic rules that apply to DCs apply as well to literals.
Both operations accomplish the same results. However, the use of the literal, ^IN¬
VENTORY', saves us from writing the line of coding for the DC.
The Assembler recognizes that an operand beginning with an equal sign is a
literal. The Assembler creates the object code constant, assigns an address, and stores
the constant as part of the program in a "literal pool", without a name. Two or more
literals defined identically within a program are usually set up as only one constant in
the literal pool. Literals generated by IOCS (input/output system) macros are also
included in the pool.
Although both operations accomplish identical results, note: (a) MVC requires a
length (I) in operand-1 if PRINT is not defined with a length of one; (b) MVC uses a
literal—the assembled address of operand-2 will contain the location of the constant
($); (c) MVI contains the $ as part of the assembled instruction; (d) MVI is more
efficient coding here because it is only four bytes long. MVC requires six bytes for the
instruction plus one for the constant defined by the literal =C'$'.
THE LITERAL POOL. The Assembler organizes the literal pool into four sections,
and within these sections, stores the literals in order of their appearance in the
program.
SECTION CONTENTS
The Assembler stores the literal pool at the end of the program and prints it
immediately following the END statement. However, the Assembler command
LTORG can cause the Assembler to store literals anywhere in the program.
Wherever we use LTORG, the Assembler stores and prints the literals up to that
point, from either the start of the program or from the previous LTORG. Figure 3-7
depicts various uses of literals. Note that the sequence of the literals in the literal pool
after LTORG is different from the sequence in which they were originally coded. (The
next chapter covers the ZAP and AP instructions.)
71 $
72 *** L ITERALS
73 *
003091 4040404040404040 74 SAVLIT DC CL 81 1
003099 oooooc 75 PAGECT DC PL3’O'
00309C oooc 76 L INECT DC PL2'O'
00 309 F 77 PRINT OS CL 121
0031 1 7 00
0031 IB 02 07 408F 4136 03091 03138 79 MVC SAVLIT,=C'COMPUTER' MOVE CONSTANT
0031 IF F 82 0 4 09 7 4 146 03099 03148 80 ZAP PAGECT,=P'0' clear PAGECT
003174 FA 10 40 9 A M47 0309C 03149 81 AP L INECT,=P'1• ADD ONE TO LI NEC
00312 A 0205 4 OB 0 4 1 3 E 030B2 03140 87 MVC PRINT+20(6),=X'40204B202060' MOVE HEX CONSTAN'
003130 0201 40R6 4144 0303 8 03146 83 MVC PR INT+26(2),=C'**' MOVE ** TO PRINT
00313B 85 LTORG
00*138 C3060407F4F3C509 86 =C'COMPUTER’
003140 407 04B202060 87 = X '40204B202060'
003146 5C 5C 88
f generated by
003148 oc 89 = P '0 •
003149 re 90 =p • i ■
EQUATE SYMBOL—EQU
EQU is used to equate one symbolic address to another. The Assembler only acts on
EQU, and does not generate executable code.
1. We may assign more than one symbolic name to a field, just as a person may have
a full name and a nickname:
After the Assembler processes SAVE, its location counter contains X'3015'. The
address of KEEP is equated to the “address” in the operand, * + 5, meaning the
contents of the location counter plus 5. KEEP is therefore assigned the address
X'3015' plus 5, or X'301 A'. KEEP will have a length attribute of one.
Figure 3-8 depicts a flowchart for a simple program that reads customer records and
prints selected fields, and Figure 3-9 provides the coding.
1 Record code
6-10 Customer number 11-15
1 1 -30 Customer name 18-37
41 -46 Balance owing 40-46 (prints as xxxx.xx)
PROCEDURE
1. A heading prints at the top of the first page (the program does not provide for
printing headings at the top of every page printed).
2. The program checks column 1 of each input record for valid code (3). An invalid
code causes an error message.
3. To ensure that each customer record is in ascending sequence (one record per
customer), the program compares the current customer (CUSTIN) to the pre¬
viously processed customer number (PREVCUST). If the new customer number is
higher, the program stores CUSTIN in PREVCUST for the next input test. An equal
or low customer number causes an error message.
70 PROGRAMMING FOR CHARACTER DATA
4. For valid records, the program moves customer name, number and balance
owing to the print area, and inserts a decimal point in the balance field.
5. Immediately before PRINT is a 1-byte constant called BLANK. After printing, the
program copies the contents of BLANK through the 1 33 bytes of PRINT. The blank
character propagates through PRINT, clearing the entire field. (See MOVE6 in
Figure 3-4 for an explanation.)
71 Sample Program—Read and Print Customer Records
4 4 I N I T I A L I Z A
5 4
6 PR0G03 I N I T INITIALIZE
27 OPEN CARD,PR INTER
36 M VC PRINT,BLANK CLEAR PRINT AREA
6. When the end-of-file is reached, the program branches to D10END, closes the
files, and ends execution.
202 LTORG
203 =C*»*BOPEN •
204 =C*CUSTCNER*
205 — C'* tBCLOSE *
206 = V < PCOCIT)
207 =A(PR INTER)
208 = A C PR INT)
209 =A I CARD >
210 = AIC AROINI
211 =C*BALANCE*
CUSTOMER BALANCE
72
73 Problems
DEBUGGING TIPS
dXTC'T ' SUCh ^ MCV f°r MVC' °r a" °Perand iS n0t sPelled th<- way a is
eftned. Such errors may cause the Assembler to generate a "dummy" instruction of
™ hat will cause an "Operation Exception" if executed. Failure to initialize
IIMIT (or the instruction USING introduced in a later chapter) will cause a large
number of "Addressability" errors. 8
Violating the rules of declaratives is also common, such as defining a DS with a
constant, which ,s treated as a comment, and defining a DC without a constant
Watch for defining a constant length (Ln) that does not agree with the defined
ri^ry01, ^ CL3 DuJuu 11 'S 6aSy f° C°de the wron§ constant; the constant DC
CL5 0 generates 'Obbbb' rather than '00000'.
Coding an explicit length in an MVI or CLI or in operand-2 of an MVC or CLC
will cause Assembler errors. The program, when corrected and reassembled may
cause errors during execution. Be sure that the input definition agrees exactly with
t e actual input record format—any difference will cause incorrect results. Failure to
clear the print area to blanks will cause "garbage" on the printed lines. A common
error is caused by omitting the explicit length from an MVC used with relative
addressing, as:
The computer will move 1 33 bytes, starting from the first byte of the literal 'DATE'_
perhaps a good reason to minimize (or avoid?) use of relative addressing. The areas
following PRINT will be clobbered, with often spectacular results that may not occur
until later in the execution.
An error difficult to detect is caused by incorrect branching—reversing oper¬
ands 1 and 2, or using, for example, BNH instead of BNL.
A disastrous error is caused by coding GET or PUT incorrectly, as, for example,
GET CARDIN,CARD; the computer may end up executing outside of the program
area, perhaps even executing garbage in the Supervisor.
Appendix B contains a list of program checks (interrupts) that can occur during
program execution, along with possible causes of the errors.
PROBLEMS
Example: Move the contents of C to the leftmost two bytes of A: MVC A(2),C.
(a) Move the contents of C to the second and third bytes of B.
(b) Move the rightmost byte of A to the third byte of B.
(c) Move A to the bytes starting at the third byte of B.
(d) Use one MVC to change all the contents of A, B and C to character 1's.
(e) Use one MVC to shift both A and B one byte to the left, as follows:
before: 1 234567
after: 2345677
A B
3-4. COMPARE AND BRANCFT Given the declaratives, code the following:
D DC C’ANN’
E DC C’MOE’
F DC C’SAL’
Output (including/heading):
Procedure:
— Check the record code ('4') to ensure that the program processes only valid
records. By-pass invalid records and print a message 'INVALID RECORD'.
— To ensure that the records are in proper order, sequence-check them on
Stock number. If out of sequence, print an error message 'OUT OF SE¬
QUENCE'.
— Provide input data that tests for invalid record code and out-of-sequence
condition.
— Print the fields as shown, in any suitable print positions. As an optional
extra, code the program to convert the numeric input month into alphabetic
for printing (i.e., '01' should be 'JANUARY').
— Flowchart, code, and test the program. Be sure to use the programming
standards for your installation.
CHAPTER 4
Chapter 3 covered the use of data in character format. Few programs are written
using just this format, because generally we need to perform arithmetic—addition,
multiplication, etc. The most common format for arithmetic is packed decimal. This
chapter introduces three data formats: hexadecimal, zoned, and packed. The instruc¬
tions, MVN and MVZ, although technically character operations, are covered here
because they are mostly used with packed data. This chapter then covers the basic
packed operations for packing, unpacking, addition, subtraction, and comparing.
HEXADECIMAL CONSTANTS
Two hexadecimal digits can represent any of the 256 different characters. They
normally define constants that cannot easily be defined as character packed, zoned,
or binary. A major use is in defining edit word constants (Chapter 5). The following
rules apply to hexadecimal constants:
1. The constant may be defined in length from one byte (two hex digits) to 256 bvtes
(512 hex digits).
76
77 Move Numeric (MVN) and Move Zones (MVZ)
2. They may contain only the hex digits 0 through 9 and A through F.
3. A length (Ln) if defined specifies the number of bytes, one byte for each pair of
hex digits. The Assembler right-adjusts hex constants. Therefore, if the defined
length is less than the constant, the Assembler truncates the constant on the left. If
the defined length is longer, the Assembler pads hex zeros to the left.
See Figure 4-1 for example hex DC's. Compare the defined constant to the
object code:
6 *
7 OC HEXADECIMAL FORMAT
8 *
003002 1 A7 6 9 HEX 1 DC X 1 1A76• 1 1A | 76 1
003004 76 10 HEX2 DC XL 1 ’ 1 A7 6 ’ 176 1 TRUNCATES
003005 001A76 1 1 HEX3 DC XL 311A7 61 1 00 |1 1A |176 1 PADS ZEROS
003008 012C 12 HE X4 DC X'12C • ! 01 12 C 1 PADS ZERO
00300A FFFFFF 13 HEX5 DC 3X1F F' IFF ||FF|IFF | 3 CONSTANTS
Hex constants should not be confused with constants of other formats. Note the
difference between the following:
These move operations are mainly used to manipulate half-bytes for decimal
arithmetic. The rules for both instructions are similar to those for MVC, with the
following exceptions:
MVN moves only the numeric portion of the half-byte, the rightmost four bits,
numbered 4 to 7. From one to 256 numeric portions may be moved from the
operand-2 field to the operand-1 field. The zone portion is undisturbed.
zone numeric
bits: 0 0 0 0 0 0 0 0
position: 0 1 2 3 '4 5 6 7
I
MVZ moves only the zone half of the byte, the leftmost four bits, numbered 0 to
3. From one to 256 zones may be moved. The numeric portion is undisturbed.
Figure 4-2 provides examples of MVN and MVZ operations:
The first MVN moves the numeric portion of each byte of A (1, 2, and 3) to the
numeric portion of each byte of B. The second MVN, illustrating relative addressing
and explicit length, moves two numerics, starting from A to B + 1.
The first MVZ moves zone portions (X'F's). The second MVZ moves one zone
from B + 1 to B + 2.
21 $
22 MVN MOVE NUMERICS
23 *
003013 00
003014 D102 40 0E 400B 03010 0300D 24 MVN B*A B= 141 162 1 83 1
00301 A D10 1 400F 4 00B 03011 0300D 25 MVN 8+1(2),A B= |45l16111 82 |
27 *
28 *** MVZ MOVE ZONES
29 *
003020 D30 2 400E 4 00 B 03010 0300D 30 MVZ B, A B= 1F 51 F 7 1 FCI
003026 D300 4010 400F 03012 0301 1 31 MVZ B+2(1),B+1 B= 1451671! 6C !
Zoned decimal data is similar to character data, but is of limited use. Zoned is
sometimes used, for example, to define a field containing data that will be later
packed, such as an amount read from an input file. The following rules govern zoned
declaratives:
79 Zoned Decimal Data
DC ZL3’25’ /F0/F2/C5/
If the constant is longer than the specified length, the Assembler truncates
the constant on the left:
DC ZL2’1234’ /F3/C4/
35 $
36 * DC ZONED FORMAT
37 $
00302C 38 ZONEO DS ZL5 5-BYTE ZONED AREA
003031 F1F2F3C5 39 ZONE 1 DC Z* 123.5’ 1F1IF2IF3IC5I IGNORES DEC
003035 F5F0F0F0D0 40 Z0NE2 DC Z’-500.00’ 1 F 5|FO1FO|FO|DO 1 MINUS
00303A F OF 1F2C3 41 ZONE 3 DC ZL4*123’ IF0IF1IF2IC3I PADS ZEROS
ZONE3 and ZONE4 use the length indication (Ln). In ZONE3, X'FO' is padded on the
left, and in ZONE4 the constant is truncated.
ZONE5 defines three identical constants. A reference to ZONE5 is to the first 2-byte
constant.
ZONE6 defines three constants, each separated by a comma. The comma is not
stored. A reference to ZONE6 is to the first 3-byte constant.
Note the difference between the generated code for the following character and
zoned DC's:
1. All digit positions (all half-bytes other than the rightmost sign) may contain only
digits 0 through 9 (binary 0000 through 1001).
2. The rightmost half-byte must contain a sign. There are four valid plus signs and
two valid minus signs:
3. Packed fields may be a minimum of one byte long (one digit plus a sign) and a
maximum of 16 bytes (31 digits plus a sign).
PACKED DECIMAL CONSTANTS. Constants are defined as packed for use in dec¬
imal arithmetic. The rules for packed, which are similar to zoned, are as follows:
81 Packed Decimal Data
1. The rightmost half-byte (numeric portion) of the assembled constant contains the
sign, X'C' for plus and X'D' for minus. For example, DC PL3'1234' is converted to
packed as /01/23/4C/.
2. All other half-bytes contain a digit. Other than the rightmost byte which has a digit
and a sign, all bytes contain two digits. A packed constant, therefore, always has
an odd number of digits, one to 31.
PACK1 packs three digits into two bytes. The plus (+) sign is optional.
PACK2 defines a negative constant.
PACK3 packs four digits into three bytes. The Assembler inserts a zero digit in the
leftmost half-byte. Note that a packed constant defined as an even number of
digits results in an odd number of packed digits. Also, the decimal point acts as a
comment, and is not stored.
PACK4 defines the length longer than the constant. The Assembler pads zeros on the
left.
PACK5 defines the length shorter than the constant. The Assembler truncates the
leftmost digit.
PACK6 defines three identical constants containing zeros.
PACK7 defines three constants, each separated by a comma, which is not stored.
A reference to PACK7 is to the first 2-byte field.
49 * -
50 $ DC PACKED FORMAT
51 *
52 PACK1 DC P * + 370' I37I0CI PLUS SIGN
00304C 37 0C
53 PACK2 DC P 1 -500' I50IODI MINUS SIGN
00304E 500 D
54 PACK3 DC P' 12.34' 101I23I4C1 IGNORES DEC
003050 01234C
55 PACK4 DC PL4*12345' 100112134 | 5C 1 PADS ZERO
003053 0012345C
PACK8 defines two constants, the first packed and the second character. A reference
to PACK8 is to the first field, the 2-byte packed constant.
PACKED OPERATIONS
The computer can perform arithmetic only on valid numeric fields (packed decimal
and binary). Since input data from cards is in character format, it is necessary to
convert into packed, using the PACK operation. In packed format, operations such as
AP, SP and ZAP can perform arithmetic, and CP can perform comparisons. The
UNPK operation (and ED in the next chapter) converts the packed data into printable
characters.
1. Read an input record. We may define card amount fields as character or zoned,
but regardless of our definition, the card content is read in character format.
2. Convert (PACK) character amount fields into packed.
3. Perform decimal arithmetic on packed fields.
4. Prepare the output area. Output on tape and disk may be any format. Output on a
printer or card punch is usually in character format; the packed fields must be
either unpacked or "edited" into the print area (the next chapter covers editing).
5. Write the output record.
1. The maximum length of each operand is 16 bytes. Either operand may specify an
explicit length (LI and L2). y H y
2. Bytes referenced by operand-2 are packed one byte at a time from right to left into
the operand-1 field. In the rightmost byte the half-bytes are reversed:
ope rand-2: F 5
operand-1 5 F
zone numeric
83 Packed Operations
In the example, the zone portion of the rightmost byte of operand-2 (XT') is placed
in the numeric portion of the rightmost byte of operand-1. The numeric portion
of operand-2 (X'5') is placed in the zone portion of operand-1. It becomes the
rightmost, or units, digit.
3. Other than the rightmost byte, all other zones of operand-2 are ignored. PACK
extracts numeric portions from operand-2 one at a time from right to left, and
places them adjacent to one another in the operand-1 field. The following instruc¬
tion packs the contents of ZONED into PACKED:
PACKED DS PL3
/12/34/5C/
PACK PACKED,ZONED
Note that the zoned sign C becomes the packed sign. The zoned 5 becomes the
rightmost digit, and each other numeric ZONED digit is extracted and placed in
PACKED. PACKED now contains data on which we may perform arithmetic.
4. PACK terminates when all digits are transmitted. If operand-1 is too short to
receive all the digits, the remaining leftmost digits of operand-2 are ignored. If
operand-1 is longer than necessary to receive all the digits, its leftmost bytes
are filled with zeros (X'O'). In any event, PACK fully erases the previous contents
of the receiving field.
Figure 4-5 gives various unrelated PACK examples which should now be
studied:
64 *
65 PACK
66 *
00306B 67 G DS PL 3
00306E ElF2 F 3F 4C 5 68 H DC Z'12345* H= |F1!F2|F3|F4|C5|
003073 F1F2F3 69 J DC C'123* J= IF1IF2IF3I
003076 ElF2F3F4F5C6 70 K DC Z•123456' K= |F1|F2|F3|F4|F5|C6|
00307C F 224 4069 406C 0306B 0306E 72 PACKA PACK GtH G= 112 1 34|5C|
003082 F222 4069 4071 0306B 03073 73 PACKB PACK G»J G= 10011213F|
003088 F 22 5 4069 4074 0306B 03076 74 PACKC PACK G,K G= 12314516C |
3-byte field, G. PACK proceeds from right to left, terminating before packing all
the digits in G.
PACKD shows the effect of packing a field into itself. Although the operation works
correctly, this practice is not always desirable. First, the field is defined as
zoned, but now contains packed data. Second, the defined length is five bytes,
but the field now contains only three bytes of significant data. It is generally
preferable to pack into a field defined with the correct format and length.
PACKE and PACKF illustrate valid use of relative addressing and explicit lengths. In
the case of PACKF, the second, third, and fourth bytes of H are packed into the
fourth and fifth bytes of K—the other bytes are not affected by the operation. The
example is illustrative, because there are few practical reasons to code in this
way.
UNPACKING FIELDS—UNPK. UNPK performs the reverse of PACK. Its main pur¬
pose is to convert packed data into zoned, in order, for example, to print the zoned
field. However, UNPK may be used to manipulate data in any format; there is no
checking for validity of data. Unpacking data that is not packed may result in "gar¬
bage".
1. The maximum length for each field is 16 bytes. Either operand may specify an
explicit length (LI and L2).
2. Bytes referenced by operand-2 are unpacked one byte at a time from right to left
into the operand-1 field.
3. As done also by PACK, the half-bytes of the rightmost byte of the operand-2 field
are reversed in the operand-1 field.
4. UNPK successively places all other digits in operand-2 from right to left in the
numeric portion of each byte in operand-1. The zone portions are filled with hex
'F'. The following unpacks PACKED into ZONED:
Note that UNPK reverses the PACKED sign C and the digit '5' in the receiving
field, ZONED. All other digits are placed in ZONED with a zone 'F. The data in
ZONED is now in a format that we can print, whereas PACKED contains bytes
that are invalid for printing. (In practice, rather than use UNPK to translate packed
data for printing, we normally use the ED operation covered in the next chapter.)
85 Packed Operations
5. UNPK normally terminates when all digits are transmitted. If the operand-1 field is
too short to receive all the digits, the remaining leftmost bytes of operand-2 are
ignored. If the operand-1 field is longer than necessary to receive all the digits, its
leftmost bytes are filled with character zeros (X'FO').
In Figure 4-6, UNPACK1 illustrates a 3-byte field unpacked into a 5-byte field, the
correct size.
In UNPACK2, operand-1 is one byte longer than necessary. The unpack fills a
character zero (X'FO') to the left.
In UNPACK3, operand-1 is two bytes too short to receive all the unpacked data.
Therefore, the two leftmost digits of the operand-2 field are not unpacked.
UNPACK4 and UNPACK5 depict the use of relative addressing and explicit length,
fancy coding, but dangerous.
UNPACK6 and UNPACK7 unpack fields into themselves. The result is correct only if
the field is one or two bytes long. The danger of this practice is seen by the
results.
UNPACK6 attempts to unpack a 3-byte field called L into itself. Because L contains
five digits which cannot fully unpack into a 3-byte field, the two leftmost digits
(1 and 2) are erased.
UNPACK7 unpacks a 5-byte field called Q into itself, propagating an error. The error
can be best understood if we consider the rule of UNPK: one byte at a time
is extracted and unpacked from right to left:
— The zone and numeric portions of Q+4 are reversed.
— Q + 3 containing 78 is extracted. F8 is stored in Q + 3 and F7 is stored in
Q + 2.
— Q + 2, now containing F7, is extracted. F7 is stored in Q+1 and FF is stored
in Q. The operation having filled all five bytes is now complete, but in¬
correct.
82 *
83 *** UNPK UNPACK
84 $
0030AO 12345C 85 L DC P’12345• L= 1 12 I 34|5C1
0030A3 86 M DS ZL 5
F9F9F9F9F9C9 87 N DC Z * 999999• N= |F9|F9|F9|F9|F9|C9
0030A8
0030AE 88 P DS CL 3
12 34567 89C 89 0 DC P’ 123456789 • Q= 1 1 2 1 34 | 5617819C|
0030B1
We use ZAP, Zero and Add Packed, to transfer packed data, just as MVC is used
to transfer character data. However, if the receiving field is longer than the sending
field, ZAP fills the leftmost bytes with zeros. We use AP, Add Packed, and SP,
Subtract Packed, for addition and subtraction of packed fields. The rules for ZAP, AP,
and SP are as follows:
1. The maximum length of each field is 16 bytes. Either operand may contain an
explicit length (LI and L2), up to 16.
2. The operand-2 sending field must be a packed field with a valid sign (hex 'A' to
hex 'F'). If the field is not valid, a program interrupt "data exception" will occur.
On the 370, if the sign is invalid the operation may be suppressed rather than
terminated.
3. For AP and SP the operand-1 receiving field must be a packed field with a valid
sign. In the case of ZAP, the operand-1 field may be any format.
4. If the operand-1 field is shorter than the operand-2 field, a program interrupt
overflow may occur. Normally an arithmetic field should be defined so that it
can contain the largest answer that could ever occur, plus a byte for insurance.
5. The rules of algebra determine the resulting sign. A positive sum yields a plus (hex
'C) sign, and a negative sum yields a minus (hex 'D') sign. A zero result yields
a positive (hex 'C') sign. X'C' and X'D' are the standard plus and minus signs,
although X'A', X'B', X'E', and X'F' are valid.
6. ZAP, AP, and SP set the condition code, so that we may test the results if neces¬
sary:
87 Packed Operations
0 Zero
1 Minus (less than zero)
2 Plus (greater than zero)
3 Overflow
The following conditional branches may then test for these conditions:
ACCUM DC PL2’0’
TOTAL DC PL30’
AP TOTAL,ACCUM Add and set the condition code.
BM P10NEG (Assume P10NEG is any valid address.)
Assume the contents of ACCUM and TOTAL are unknown. If the result of
adding the contents of ACCUM to TOTAL is negative, the program branches to
PI ONEG. If the result is positive or zero, the program continues with the next instruc¬
tion. Figure 4-7 provides various unrelated ZAP, AP, and SP examples:
ZAP1, ADD1, and SUBTR1 illustrate conventional ZAP, AP, and SP operations.
ZAP2 and ADD2 depict a coding error in which operand-! is shorter than
operand-2. The result at execute-time is an overflow condition.
ZAP3 and ADD3 also are coding errors not recognized by the Assembler. The
explicit length P3(3) causes only the first three bytes to be processed. Since there
is no sign in the explicitly defined field, the instruction will "bomb” with a
"Data Exception."
ZAP4 shows how we may correctly use explicit length and relative addressing.
ZAP5 tests the contents of a packed field. If we ZAP a field into itself the value is
unchanged, but the condition code is set. Since PI contains a positive value, the
condition code is set to high/plus.
ZAP6 and SUBTR2 both clear a field to packed zeros. Subtracting a field from itself,
as in SUBTR2, is more efficient, but requires valid packed data in operand-1.
ZAP requires a constant defined for operand-2, in this case a literal =P'0'.
ADD4 depicts a common coding error caused by an operand-! field that is too short:
20
21 ** £ AP ADD PACKED
22 $
003030 FA 21 4002 4000 23 ADD 1 AP P2 , P 1 P2= | 04|69lOCl
003036 FA12 4000 4002 24 A DD2 AP PI ,P2 ERROR - PI IS TOO SHORT
00303C FA 21 4005 4000 25 ADD3 AP P3(3),P1 ERROR - NO SIGN IN OPERAND-1
003042 FA1 1 4000 4 OB E 26 A DD4 AP P1, = P'999' Pl= I12I2CI ERROR - OVERFLOW
28 $
29 *** SP SUBTRACT PACKED
30 *
003048 FB21 4002 4000 31 SUBTR1 SP P2 PI P2 = I 04 44|4C I
00304E FB 11 4000 4000 32 SUBTR2 SP PI PI Pl = 100 OC I
1. Maximum field lengths are 16 bytes. Either operand may contain an explicit
length (LI and L2).
2. Both operands must contain valid packed data. Invalid data results in a pro¬
gram interrupt ("data exception"); the 370 suppresses the operation.
3. If the fields are not the same length, CP extends the shorter field (not in storage)
with leftmost zeros (the value is not changed algebraically, and the test is still
valid). There can be no overflow.
4. CP compares the contents of operand-1 algebraically to that of operand-2. That
is, the positive value P'-t-OOl' is algebraically greater than P'—001'. (However,
89 Packed Operations
+0 is equal to -0.) CP sets the condition code, which we may then test with
conditional branches, as for CLC.
Example: Contrast between CP and CLC. The following illustrates why we should use
the correct operation for the data format, CLC for Character data and CP for Packed.
AMTCHAR packed into AMTPACK gives the hex value /12/3F/. Using both CP and
CLC, we compare AMTPACK to a literal -P'1 23'. The literal generates a constant
/12/30. For CP, /12/3F/ and /12/30 are algebraically equal (+123); the condition
code is set to equal. For CLC, the two fields do not contain identical bits. Because F is
greater than C, the condition code is set to high. Figure 4-8 depicts various CP
operations:
COMP1 compares A to B. Because A's algebraic value is less, the condition code is
set to low/minus.
37 CP COMPARE PACKED
00305F 00
003060 F911 40 52 40 54 46 C0MP1 CP A,B ' 12+ ' < 1•345+' LOW
003066 F92 1 4056 4052 47 C0MP2 CP CtA '5000+’ > 11 12+ ' HIGH
00306C F911 40 52 4059 48 C0MP3 CP A*D • 12+ ' > ■25-' HIGH
003072 F91 1 4054 4057 49 C0MP4 CP B.C+1< 2) '345+' > 1'000+' HIGH
003078 51 CP
A,E •012+' = 1'012+' EQUAL
00307E F91 1 4052 4 05 B 52 C0MP6 CP
003084 F9 11 40 56 40 54 53 C0MP7 CP C ( 2 ) ,B ERROR - NO SIGN IN OP-1
00308A F91 1 4052 4 0C0 54 C0MP8 CP A f =C ' 12 ' ERROR - NO SIGN IN OP-2
No problem was encountered in the previous chapter printing character data. Packed
fields, however, contain nonprintable characters and must be unpacked for printing.
A small problem arises when we print unpacked data. Assume we read a card field
QTYIN containing the value 1 2345 (FI F2F3F4F5). We pack QTYIN into QTYPACK,
add '50', and unpack QTYPACK into QTYOUT for printing:
QTYPACK DC PL30’
QTYOUT DS CL5
PACK QTYPACK,QTYIN QTYPACK /12/34/5F/ )•
AP QTYPACK , = P‘50’ QTYPACK /12/39/5i
UNPK QTYOUT,QTYPACK QTYOUT: /F1/F2/F3/F9/C5
Note that AP changed the sign in QTYPACK from XT' to X'C'. Now QTYOUT will
print as 1239E. (The printer graphic for X'C5' is an alphabetic E.) But we want to print
12395. Because a character 5 is X'F5', then we need to change X'C5' to X'F5'. We
can, therefore, move one of the other zone positions of QTYOUT into the units zone
position. QTYOUT will now print correctly as 12345:
Another problem arises if the field is negative. Assume that QTYOUT contains /FI/
F2/F3/F9/D5/. Inserting an F-zone to replace the D-zone changes the field's value
from negative to positive. If we want the field to print, if positive as 12395, and if
negative as 12395-, we may use the routine shown in Figure 4-9.
91 Sample Program—Budget Statement
67 * #
68 * #
69 QTYIN DS ZL 5 ZONED INPUT FIELD
70 QTYPK OS PL 3 PACKED FIELD
71 0TY0UT DS ZL 5 ZONED OUTPUT FIELD
PAGE OVERFLOW. The standard 11" form provides for up to 60 lines of printing.
Up to now we have not considered the possibility that the printer would reach the
bottom of the form. Unless action is taken, the program will continue printing lines to
the bottom of the page, over the horizontal perforation, and onto the top of the next
page. Desirably, the program should know when printing has reached near to the
bottom of the page, and the forms should eject to the top of the next page. Then the
routine that printed the heading at the beginning of the program should be repeated,
and normal printing of detail resumed.
The procedure to accommodate page overflow is for the program to count the
lines that have been printed or spaced. The count is compared to some number, such
as 40 or 50, that has been deemed the maximum number of print lines on a page. If
the count exceeds this maximum, the program is directed to repeat the heading
routine. The program at the end of this chapter provides for simple page overflow and
should be carefully studied.
The flowchart in Figure 4-10 depicts a program that reads company cost records
containing Budget expense and Actual expense for the current period. The cards are
sequence-checked by general account number. The program calculates the var¬
iance: Budget less Actual expense. A negative variance means that the Actual ex¬
pense exceeds the Budget. If this variance exceeds $-500.00, the program prints a
message "OVER LIMIT". At the end of the run, the total variance is printed.
92 DECIMAL DATA AND ARITHMETIC I
uuugei jjiugicmi.
For reasons of brevity, the program omits many common procedures such as:
checking for valid record code, printing total budget amount and actual expense, and
providing for the current date on the report. Figure 4-11 gives the assembled and
executed program. The input format is as follows:
2 PR I NT ON,NCGEN.NODATA
4 * INIT IALIZATI N
5 *
6 PROG 04 INIT INITIALIZE
27 OPEN CARD.PRTR
36 MVC PRINT.BLANK CLEAR PRINT AREA
38 * PAGE HEAOING C U T I N E
39 *
40 A10HEAD PUT PR PRT R * PRINT•SKI SKIP TO NEK PAGE
47 UNPK PAGEPR.PAGEPK SET UP
48 MV Z PAGEPR+2I1).PACEPR PAGE NO.
49 PUTPR PRTR.PRHEAD,WSP2 PRINT HEAOING
56 AP PAGEPK,=P*1• AOD TO PAGE NUMBER
57 ZAP L INEPK. = P*0• CLEAR LINE COUNTER
FIGURE 4-11 List of budget, actual expense, and variance. Output record.
94 DECIMAL DATA AND ARITHMETIC I
14 1 * ERROR R 0 1U T I N E
142 *
143 R10SEQER M VC MESSAGOT!17),ME PRINT ERROR MESSAGE
1 44 PUTPR PRTR,PRINT.*SP3
15 1 CLOSE CARD.PRTR
160 CANCEL , ABNORMAL JOB TERMINATION
232 BLANK DC C* •
BLANK FOR CLEARING PRINT AREA
233 PRINT DS OCL133 PRINTER AREA:
234 P DS CL 1 *
235 DS CL 19 *
236 ACCOT DS CL4 * ACCOUNT NO.
237 DS CL 2 *
238 DESCROT DS CL 15 * DESCRIPTION
239 DS CL3 *
240 BUCGOUT OS ZL 6 * BUDGETTEO EXPENSE
24 1 DS CL3 *
242 ACTOUT DS ZL 6 * ACTUAL EXPENSE
243 DS CL 3 *
244 VAROUT DS ZL7 ♦ VARIANCE
245 DS CL 4 *
246 MESSAGOT DS CLIO * OVER BUDGET MESSAGE
247 DS CL5 0 *
251 PAGEPK DC PL 2* 1 • 4
252 VAfiPK OC PL 4 • 0 • *
259 LTORG
260 =C***BOPEN •
26 1 =C*SJBCLCSE*
262 =V(PCOCIT)
263 = A(PRTR >
264 = A I PR I NT)
265 = A< PRHEAD)
266 =A(CARD)
267 =A(CARDIN)
268 =C*OVER LIMIT*
269 =P*10•
270 = P* 1 •
27 1 =P * 0 •
272 = P*-500.00 *
273 =c*final total*
000255456-
F INAL TOTAL
DEBUGGING TIPS
Expect considerably more bugs in both the assembly and execution phases as your
programs become larger and involve arithmetic data. Finding a bug for the first time
is quite often time-consuming, but in time you can become proficient in tracing
errors (especially if you have enough of them!).
New assembly errors that can occur involve, for example, coding packed DC's
with characters other than 0-9, decimal point, and sign. Watch for coding hex
constants: DC XL3'FF' generates '0000FF', not 'FFFFFF'.
More likely, however, are errors during program execution. Packing a field that
contains a blank (X'40') in its rightmost position generates a packed field with an
invalid sign (X'04'); an attempt to perform arithmetic using this field will cause a
"Data Exception". A likely cause of the blank position is a blank input field or an
improperly defined input record. Another popular cause of Data Exceptions is adding
to a field that has not been initialized as a DC, or is defined as Character or Hex so
that it contains invalid packed data.
74ra,^r°DUI alT f°r USing MVC and CLC on packed data ('"correct execution),
or ZAP and CP on character data (Data Exceptions). Improper relative addressing and
missing explicit lengths are always good for a few bugs.
ERRORS UNDER DOS. On a processing error, the DOS Supervisor interrupts the
program and prints the location of the invalid instruction and the type of error, as:
The "hex location" is the address of the instruction in error. If the program's
START instruction specifies the program "load point" (starting storage location for
execution), then we simply have to check the program listing:
LOC
51340 ... AP TOTAL,AMOUNT (Instruction causing the error)
51346 ... ZAP ...
A "Data Exception" means that the instruction has attempted to perform arith¬
metic on invalid packed data. An examination of the two defined operands reveals:
TOTAL is incorrectly defined as a DS. The Supervisor can also print a hexadecimal
dump of the contents of storage, which we can examine. The dump could indicate
for locations 51 783-51786 the hex value 00000000. The cause of the error is
explained—TOTAL does not contain a valid sign because it was defined as a DS
instead of a DC.
//GO.SYSUDUMP DD SYSOUT=A
The system will now supply the load or entry point of the program, the address of the
instruction following the error, and a hex dump of the registers and program storage
area. If the program encounters an error (program check interrupt), check the print¬
out following the program listing and any output. The first diagnostics could appear
as:
"Completion Code" indicates the type of program check. In this case, the code '7' is
for "Data Exception"—see Appendix B for all codes. (Incredibly, the system prints
several hundred lines of diagnostics, but identifies errors only with this crumby code!)
98 DECIMAL DATA AND ARITHMETIC I
The PSW (Program Status Word) indicates the "instruction address" in the
rightmost six hex digits, in this case 051346. This is the address of the instruction
following the one in error. When the program was assembled, we did not know
where it would load for execution, and indicated the START location as zero. We can
determine the load point in the diagnostics under the CDE section. The first statement
there could appear as:
The entry point address (EPA) is therefore 05120, the "relocation factor". Now we
can calculate the address in the program listing:
LOC
130 ... AP TOTAL, AMOUNT
136 ... ZAP . . .
The instruction preceding 136 is the AP at 130. The Data Exception indicates
invalid packed data in one or both operands. The next steps are to check the defi¬
nitions of TOTAL and AMOUNT, and to examine the hex dump of storage, as was
done for the DOS example.
ERROR RECOVERY. Program checks cause the program to terminate, but when
testing, we usually want to push the program through to detect as many errors as
possible. There are special macros that provide for error recovery, STXIT under DOS
and SPIE under OS. The IBM Supervisor and Macros manuals provide details.
PROBLEMS
4-1. MVN and MVZ. Given the following declaratives, code the following unrelated
questions. Give results in hex and character.
HAM DC CHAL’
EGGS DC C’2472’
TOAST DC X’C9E2C4E0’
(a) Move the first 3 numeric %-bytes of TOAST to the numerics of HAM.
(b) Move the zone y2-bytes of TOAST to those of EGGS.
4-2. Complete the hex representation for the following. Except for a and for b
questions are unrelated.
99 Problems
HI LO EQ
(a) CP P,Q
(b) CP Q,P
(c) CP M,Q
(d) CLC M,N
COLUMN COLUMN
Procedure:
— Check for valid record code (3).
— Sequence-check the file according to Store-Customer number. Within a
Store, the Customer numbers are in ascending sequence.
— Check that the current month is the same for all cards. If not, print a suitable
message.
100 DECIMAL DATA AND ARITHMETIC I
DECIMAL ARITHMETIC II
This chapter continues with the additional decimal instructions commonly used in
programming: edit, multiply, and divide. Editing involves sign and punctuation con¬
trol to format packed fields for printing. The sections on multiply and divide provide
practical techniques for handling various field lengths and decimal-point precision
and more realistic programming examples and problems.
EDITING—ED
The purpose of ED is to make packed data suitable for printing. ED converts packed
data into zoned format and provides for punctuation and sign. Once understood, ED
greatly facilitates print formatting.
70 7
102 DECIMAL ARITHMETIC II
The following simple example edits a 2-byte (3-digit) packed field called
COUNT into a print field called COUNPR. (There is no provision for commas or
decimal point.)
THE EDIT WORD. The edit word consists of pairs of hex digits. Each pair represents
one print position. The commonly used edit characters are:
The defined edit word, EDWORD, provides the necessary sign and punctuation
control. Note that there is an X'20' or X'21' for each packed digit. The instructions to
edit are:
MVC moved EDWORD into the required print positions. ED then edits PACKAMT
into the same print positions. The explicit length (8) in the ED operand refers to the
length of the edit word in the print area, not to the length of PACKAMT. Editing
proceeds from left to right, starting at P+90:
At this point the length (8) of operand-1 is exhausted, and the operation
terminates. The edited amount will print as .05 (if EDWORD contained
X'402021204B202060', the result would be 0.05). Figure 5-1 illustrates four exam¬
ple edit operations:
EDWD1 shows simple zero suppression. The packed amount in COUNTER is to print
v/ln'fnm°,St Zer°S suPPressed- The edit word, EDWD1, therefore consists of an
X 40 fill character and an X'20' for each packed digit.
EDWD2 edits and prints a 4-byte packed field. The edit word provides for zero
suppression, comma, decimal point, and minus sign.
EDWD3 depicts use of the CR symbol commonly used in financial statements.
EDWD4 is explained in the next section.
DOLLAR SIGN AND ASTERISK. The dollar sign (X'5B') and the asterisk (X'5C')
when used in the edit word create certain problems. Normally we use the dollar sign
($) to print Supplier and Employee checks and Customer bills, with the $ to the left of
the amount. If X'5B' is coded on the left, ED improperly uses it as the fill character.
105 Editing—Ed
6 * -
7 ED EDIT
8 *
9 * ZERO SUPPRESSION : HEX CONTENTS:
1o
11 P DS CL 1 2 1
12 COUNTER DC P * 0015 * 100101|5C1
13 EDWD1 DC X *402020202020 * 1 4012 0|2 0 1 I20| 20|1201
15 MVC P + 20I6)»EDWD1 1 40 I 20 I 20 I 20 | 20 | 20 I
16 ED P+20(6),COUNTER |40|401401I40| FI ||F5|
Also, many installations print asterisks (*) to the right of the amount field to denote
the level of total:
* Minor total
** Intermediate total
*** Major total
If one or more X'5C's are coded to the right of the edit word, ED leaves the
asterisks undisturbed only if the amount is negative. If positive, ED replaces asterisks
with the fill character, thus erasing them. One solution is to omit both X'5B' and
X'5C' from the edit word and use separate operations to move $ and * to the print
area. Another solution is to use the technique in Figure 5-1, in which $ and * are
defined as part of the edit word but do not participate in the ED operation. MVC
moves the full edit word, starting in P + 70. The ED operation begins in P+71, leaving
the $ intact. Further, ED specifies editing only 8 bytes, although the MVC moved 10.
The operation terminates just prior to the * at P+79, leaving it also intact.
106 DECIMAL ARITHMETIC II
Another instruction, EDMK, providing for floating dollar sign and asterisk is
covered in a later chapter.
MULTIPLY PACKED—MP
We use MP to multiply one packed field (the multiplicand) by another (the multi¬
plier). Common examples are multiplying hours by rate-of-pay in payroll, and quantity
by unit cost in inventory programs.
Since MULTPLD is four bytes and MULTPLR is two, we define PRODUCT as six
bytes (PRODUCT may be defined longer). We ZAP MULTPLD into PRODUCT. After
107 Multiply Packed—MP
the MP, PRODUCT contains a 6-byte product. If PRODUCT were shorter, the MP
would cause a program interrupt.
DECIMAL PRECISION. Neither the Assembler nor the computer handles the dec¬
imal position. With all decimal arithmetic we must provide for the implied decimal
point. The following is a useful rule: the number of decimal positions in the product
equals the number of decimals in the multiplicand plus multiplier. For example, if the
multiplicand has three decimals and the multiplier has two, then the product will
have five decimal positions.
42 * -
43 *** MP MULTIPLY PACKED
44 * -
The second example multiplies a 3-byte field, HRS, by a 2-byte field, RATE. The
product, WAGE, is therefore five bytes long. Since HRS contains one decimal and
RATE two, the product has three decimal positions. Because only two decimals are
required, this example rounds the unwanted rightmost decimal digit. That is, the
rightmost byte of WAGE is added to WAGE. Next, an MVO operation shifts the
product one digit to the right, leaving two decimal positions, as explained in the next
section.
A later chapter covers a 370 instruction, SRP, which greatly facilitates rounding
and shifting.
The MVO operation moves data an odd number of half-bytes to the right. Although
MVO may be used on any format, its most common use is on packed data—to shift
off unwanted decimal positions generated by MP and DP operations. For example
an MVO could shift a field containing 12/34/56/7C three digits to the right yielding
00/01/23/4C. 6 ,y 8
1. The maximum length of each operand is 16 bytes. Either operand may specify an
explicit length (LI and L2).
2. MVO moves the operand-2 data to the operand-1 field and shifts to the right an
odd number of half-bytes. (To shift an even number of half-bytes requires two
MVOs.) The rightmost half-byte of operand-1 (if packed, the sign position) is not
altered.
3. MVO fills leftmost shifted half-bytes with X'O'.
4. The length of operand-2 determines how many bytes MVO moves into the
operand-1 field, and shifts to the rightmost half-byte of operand-1.
68 *
69 *** MVO MOVE WITH OFF SET
70 *
71 X OC P’ 12 3456789• 9
112 1 34 1 561 78 11 C 1
7? Y nc PL5 ’ O' 100 | 00 1 00 1 00 IOC 1
84 7 AP PAY,HOUR 1 on | no|on|20|1 5C 1
85 MP PAY,RATEPY 100106|66|25 IOC 1 MULT I PLY 66.6250
86 MVO PAY,PAY(4) 1 00|00|6616211 5C 1 SHIFT 66.625
87 AP PAY,P A Y + 4( 1 ) 1 no 1 on|661 63 IOC 1 ROUND 66.630
88 MVO PAY,PAY(4) 1 no|no 106166 I3C 1 SHIFT 66.63
MVOI moves the first four (leftmost) bytes of X into Y. The packed digits from X are
right-shifted, one half-byte, to the rightmost half-byte of Y. MV02 moves the first
three bytes of X into Y and right-shifts 3 half-bytes, to the rightmost half-byte of Y.
MV03 moves the first two bytes of X into Y and right-shifts 5 half-bytes, to the
rightmost half-byte of Y..
Figure 5-3 also illustrates a multiply operation that generates four decimal
positions. Because only two are required, two MVO's are used to shift the unwanted
two decimals to the right. The rounding operation, AP, is immediately after the first
MVO. This is because we must round beginning with the first unwanted decimal
position, in this case '5'. In the product, /00/06/66/25/0C/, the '5' is shifted one
position so that it becomes the leftmost digit of the next byte, /00/00/66/62/5C/. We
now round and shift off the unwanted '5'.
110 DECIMAL ARITHMETIC II
DIVIDE PACKED—DP
We use DP to divide one packed field (the dividend) by another (the divisor). Com¬
mon examples include dividing inventory value by number of units to calculate unit
cost, and computing ratios and percentages.
As good programming practice, therefore, we should define the length of the quotient
equal at least to the length of the dividend. Also, the length of the remainder always
equals the length of the divisor. The remainder is generated in the operand-1 field to
the right of the quotient. Both quotient and remainder contain a sign. Technically the
quotient length needs to be only long enough to contain the significant digits de¬
veloped If the quotient field is longer than necessary, DP inserts leftmost zeros. If the
quotient field is too short to contain all the significant digits generated in the quotient,
Ill Divide Packed—DP
an overflow interrupt occurs. The following rule always provides adequate field
lengths: define the operand-1 field equal at least to the length of the dividend plus
divisor:
Since DIVIDEND contains four bytes and DIVISOR one, ANSWER (to be used for the
resulting quotient and remainder) should contain five bytes. (ANSWER may be de¬
fined longer.) We ZAP DIVIDEND into ANSWER. After the DP, the first four bytes of
ANSWER contain the quotient, with a sign. The fifth byte contains the signed re¬
mainder, one byte long, the same length as the divisor.
DECIMAL PRECISION. We must provide for the implied decimal point. The fol¬
lowing rule is always valid: the number of decimal positions in the quotient equals
the number of decimals in the dividend minus divisor. For example, if the dividend
contains four decimals and the divisor one, then the quotient has three decimal
positions. If the dividend does not contain sufficient decimal positions for our divi¬
sion, we may generate the required extra decimal positions by shifting the dividend
to the left, using an MP that multiplies by 100 (1.00). Thus, 12.34 x 1.00 = 12.3400,
a product that is the same algebraic value, provided that we in the program always
account for the new implied decimal point.
It may facilitate programming to mentally "clear” the divisor of decimal posi¬
tions first. For example, the following divisor can be "cleared" of its decimal places
with no added programming steps, by definition:
12.3400 1234.00
1.23 123
246.79
7.96 (may be rounded to 8.0)
31
9? £
93 *** np DIVIDF PACKFD
94 *
95 DIST DC P'2356.5' I 2 3 I 5 6 I 5C I
96 GALS DC P ' 1 50.0 • |01|50|0CI
1 ?3 *
DIVIDE, ROUND TO TWO DFCIMALS:
124 *
125 ANS4 DS OPLR ZFRO DUPLICATION FACTOR
126 QUDT DS PL 5 QUOTIENT AREA
127 RMDR DS PL 3 REMAINDER AREA
In a typical business system, there are two common types of records. Master records
contain data of a relatively permanent nature, such as Customer name and address,
or Stock description and price. Other data can be temporary and subject to periodic
change, such as current Customer balance or current Stock quantity on hand.
Transaction records contain data for the current period that affects the Master
records. For example, a payment or sale must be applied to the balance owing in the
Customer Master record, and a Stock receipt or issue must be applied to the quantity
on hand in the Inventory Master record.
A "control break" occurs when the input records make a significant change
in the control fields. In the example program next, it is necessary to break control and
print totals by changes in Stock number (minor totals), and by Branch number (major
totals). There can be any number of Receipt records for a Stock item, and any number
114 DECIMAL ARITHMETIC II
(DIO)
DIOSTOCK
STOCK YES
QUANITY ^ ~
=°?
jfNO
UNIT-COST =
STOCK COST -F
QUANTITY
.
MOVE TO PRINT:
STOCK COST,
UNIT COST, QTY.
DESCR'N, ETC.
PRINT
DETAIL
LINE
Process
branch
totals
Error routines:
MOVE TO PRINT:
'OUT OF SEQ'
i
MOVE TO PRINT.
'CARD CODE NOT END-OF-JOB
12'
CLOSE
FILES
D
FIGURE 5-5 Flowchart for sample inventory program.
115 Sample Program—Inventory Update
of Stock items in a Branch. The program is organized into logical, separated sections
that perform specific functions.
The flowchart in Figure 5-5 depicts an inventory update program. There are two
types of records, Inventory masters (code 11) and Inventory receipts (12).
— For each Stock number there may be only one master record (code 11) but any
number of receipts (code 12). The master record precedes its receipt records.
— Missing masters, invalid record codes, and out-of-sequence conditions on
Branch-Stock number cause errors.
— For each receipt record that contains the same Stock number as the master
record, the program calculates quantity times unit cost. The calculated cost is
added to total cost on hand for the Stock, and the quantity received is added to
total quantity on hand for the Stock.
— The program checks sequence on Stock number (minor) and on Branch (major).
The program uses a control word composed of Branch-Stock number. If the new
control word is greater than the previous, then the program prints the stored Stock
number data and calculates and prints new unit cost. (This is a "control break"
on the Stock number.) New unit cost is calculated by dividing Stock cost-on-hand
by quantity-on-hand.
— If the input Branch number is also higher than the one in the previous record,
total Branch cost is printed. At the end of the run, the program prints total cost for
all Branches.
— The first record condition is handled by hex zeros in "PREVCTL". On a high
Branch/Stock, if PREVCTL contains hex zeros, the program recognizes a "false
control break" on the first record. End-of-file is handled by storing hex F's in the
input Branch/Stock number to force printing the last stored Stock and Branch.
Figure 5-6 provides the program listing. The program has two new features,
ORG and PDUMP, which the next sections explain. Carefully study the flowchart
and listing and work through all conditions. For purposes of brevity, the program
omits some features that we would normally include, such as printing the current
date and page overflow.
INVENTORY UPCATE AND CALCULATE UNIT COST
4 4 INITIAL I Z A T I 0 N
5 4
59 4 N A I N L 0 G I c
6C 4
ea 4
PROCESS R E C E i PTS RECORD
89 4
90 ClCRECT CLC CODEIN.—C*12* RECEIPT RECORO?
91 BNE R20NCREC * NO - ERROR
92 PACK OTYPK.QTYRECIN
93 AP STOOTYPK.QTYPK AOO QUANTITY RECEIVEO TO STOCK
94 PACK COSTFK.UNCOSTIN QUANTITY X UNIT-COST = COST
95 MP COSTPK.QTYPK j xxjxxj XX]XC| 2 DEC
96 AP STCOSTPK.COSTPK AOO COST OF RECEIPT TO STOCK
97 e AIOREAD
99 4
CALCULATE N E W UNIT COST
00 4
D1CST0CK ZAP UNCOSTPK,=P*o•
CLEAR UNIT-COST FIELD
1 02 ZAP STCOTYPK.STOQTYPK STOCK QUANTITY = 07
103 BZ D20
104 • YES - BYPASS DIVIDE
ZAP UNCOSTPK.STCOSTPK
105 MP I 00 loo|00|00|XX |XX|XX|XC J OEC
UNCOSTPK.=P*10*
106 OP |co|oo!oo|ox|xx|xxlxx|oc| OEC
UNCOSTPK.STOOTYPK 1 00| 00|xxjxxj xc|xx|xx|xc|
107 AP DEC
UNCOSTPK!5> «UNC0STPK44(1) ROUND. THEN SHIFT 1 DIGIT
108 MVO
UNCOSTPK(51.UNCOSTPK(41 100|00|OXJXX|XC I XX1XX|XC1 2
DEC
110 020 M VC COSTPR.EOCOST
111 ED COSTPR.STCOSTPK
EDIT STOCK FIB. DS
* COST
1 13 N VC UNCOSPR.EDUNIT
1 14 ED UNCOSPR.UNCOSTPK+2
UNIT COST
1 19 MVC DESCRIPR.DESCRN
120 MVC STGCKPR tPREVSTK
12 1 MVC BRANPR.PREVBR
139 *
PROCESS BRANC H TOTAL
140 ♦
141 E1CBRAN PUTPR PRTR.PRINT,SP1 SPACE 1 LINE
148 MVC C0STPRIL*£0C0ST+1).EDC0ST
149 EO CCSTPR.BRCOSTPK EOIT TOTAL BRANCH COST
150 MVC DESCR I PR<12), = C•BRANCH TOTAL*
151 PUTPR PRTR.PRINT.MSP2 PRINT BRANCH TOTAL
158 MVC PRINT.BLANK
i e6 CLOSE CARO.PRTR
195 EO J
207 R30N0MAS MVC P + 4 1<L * MASTERR ) .MAS TERR NEM STOCK RECORD. NOT MASTER
233 ♦ DECLARATIVES
234 ♦
117
265 BRCOSTPK DC PL 4 • 0 • P4CKE0 declaratives:
2B6 COST PK DC PL4•0* *
26 7 FINCOSPK DC PL 4 • 0 • *
288 CTYPK CC PL2•0* *
289 STCOSTPK; dc PL 4 • C • *
290 STCQTYPK DC PL3• 0 • *
291 UNCOSTPK OC PL 6 • 0 • *
3 15 ORG CARDIN
3 16 DS CL 6 INVENTORY MASTER:
317 DESCRPIN DS CL I 6 09-24 * DESCRIPTION
3 18 CTY I N OS ZL4 25-28 * QUANTITY
319 COST IN DS ZL7*00000.00* 29-35 * COST
32 1 ORG CARDIN
322 DS CL 10 RECEIPTS :
323 qtyrecin DS ZL3 11-13 * QUANTITY
324 UNCOSTIN DS ZL4 *00.00* 14-17 4 UNIT COST
325 ORG
RESET LOCATION COUNTER
327 BLANK DC C* •
BLANK FOR CLEARING PRINT AREA
328 PRINT OS 0CL133 PRINT area:
329 P OC CL 1 • • 4
330 DC CL 17* • 4
33 l BRANPR OS CL 2
* BRANCH NO.
332 OC CL4 • • •
333 STOCKPR OS CL 4
* STOCK NO.
334 OC CL 2 • • 4
335 DESCRIPR DS CL 16
* DESCRIPTION
336 QT YPR DS ZL 6
* QUANTITY
337 CC CL 4* • *
3 3e UNCOSPB DS ZL 7
* UNIT COST
339 COSTPR DS ZL 12
* COST
340 OC CL 56• • 4
ORG is a command to the Assembler to alter or reoriginate the value of the location
counter during assembly. We generally use ORG to redefine data areas in the pro¬
gram, that is, one on top of the other.
The name is normally used only in macro writing, and is otherwise omitted. The
ooerand if any, is a symbolic address with or without relative addressing (i.e., A30,
or A30 + 1000), or a reference to the location counter itself (as * + 20). The Assembler
sets the location counter to the value of the expression. The operand may not be an
absolute address, such as 8192 or X'2000'. Note: if the operand ,s omitted, the
Assembler sets the location counter to the maximum value that it has been set up to
P[3eware of ORG with no operand, because the Assembler may mistakenly use a
comment for its operand. In the following, the Assembler will use the asterisk in
column 41 as the ORG operand. Instead of setting the location counter to the
previous high setting, it is set incorrectly to the current setting of the location counter:
column 10 16 41
ORG * RESET LOCATION COUNTER
The solution as shown in the program is to insert a comma in column 16, which tells
the Assembler explicitly that there is no operand.
120 DECIMAL ARITHMETIC II
Figure 5-7 provides the object code for declaratives defined in the previous
program. ORG is used to redefine the input area, which starts with column 1 at
X'DA61 D' in statement 308. First, the fields common to both types of records, Master
and Receipts, are defined. Then the other fields for both record formats are uniquely
defined.
223 ♦ DECLARATIVES
234 4 -
STATEMENT EXPLANATION
All fields for both types of records may now be referenced by name, without an
explicit length. In a similar manner, we may use ORG to redefine the print area.
The DOS PDUMP macro is a convenient device for program debugging. (The macro
differs under operating systems.) PDUMP enables us to see the contents of any
storage area during program execution. When the program encounters PDUMP it
transfers control to the Supervisor, which produces a hexadecimal printout of the
contents of the registers and of the specified storage area. At termination of the dump,
control returns to the statement immediately following the PDUMP.
Addressl and address2 reference the start and end positions of the area to be
dumped The addresses may be symbolic (as A10,CARDIN+ 80), or hexadecimal (as
X'301 5' X'3420'). We normally use PDUMP in a program that contains a bug, and
we want to know the contents of certain accumulators and work areas at some
snecific ooint We can insert PDUMPs in the program wherever storage contents are
:ePquiredPWhen the program is corrected and working, we take the PDUMP out
Refer again to the sample program. Statement (STMT) 180 specifies PDUMP
BRCOSTPK P+132 to print hex contents from BRCOSTPK (location X DA55A )
through to P + 132 (location X'DA6F2', hex address not printed). Although the pro¬
gram works correctly, PDUMP is inserted so that it executes after the printing of e
122 DECIMAL ARITHMETIC II
final total. Refer now to the dump itself in Figure 5-8. (Some dump versions may
differ from this one.)
— Lines 1 and 2 print the hex contents of the 16 general registers, GR 0-7 and
GR 8-F, or registers 0-7 and 8-15.
— The next line lists the hex contents of the floating-point registers, FP REG.
The lines following with CR 0-7 and CR 0-F show the contents of the 1 6 "Control
Registers" of the 370 that the operating system uses.
The contents of storage print next. Each line lists 32 bytes, with the hex contents
to the left, and the character contents—if the character is printable—to the right (not
shown in the figure). The vertical spacing between each 4 bytes (8 hex digits) is for
readability, and may be ignored. At the extreme left is the address X'DA540\ of the
first location to be printed on the line. The address of the first byte in each group of 4
bytes after DA540 is DA544, DA548, and DA54C. The address of the first byte at the
center is DA550. Now PDUMP begins printing with the group that contains the first
byte specified, BRCOSTPK at DA55A. Thus, DA558 and DA559 are printed (and
contain '4040'). Next print the contents of BRCOSTPK, a 4-byte field, containing
OOOOOOOC'. The next field defined in the program, COSTPK, is 4 bytes beginning it
DA55E, and contains '0000700C' (spilling onto the next line)
DA558
DA562 ^ DA566^
r DA55E
uaooo ^UOQDO 000O6d00
Check the names and locations to Figure 5-7 to ensure that the dump represents the
storage contents correctly.
Thus, PDUMP provides the starting address on a line, and to locate the contents
of any field, we must count across the line, using each pair of digits as one byte. Note
the line beginning at DA640: All the locations on that line contain the same charac¬
ter X'40'. PDUMP minimizes printing and simply prints —SAME—.
Under Operating System (OS), a partial dump requires the SNAP macro and
other complex coding—see the IBM Supervisor manual.
DEBUGGING TIPS
The ED instruction offers almost unlimited scope for new bugs. Before assembly,
double-check the MVC/ED operations. Allow in the edit word X'20's and X'21's for
each packed digit to be edited (there should be an odd number). Be sure that the print
area field is the same size as the edit word.
The most common error with MP seems to be ignoring the rule that the product
field must be at least the length of the multiplicand plus multiplier in bytes, regardless
of the contents. If too short, then count on a much-deserved Data Exception.
DP suffers from the similar problem of field length: the quotient/remainder area
must be at least as long as the dividend (after the MP left-shift, if any) plus divisor.
Another popular error is attempting to divide by a zero value—check for a zero
divisor first! Both errors cause "Decimal Divide Exceptions".
If the bug cannot be located, rerun the program with a request for a dump of
storage, and trace the hex contents of the concerned storage areas. Almost always the
error is in your program or data, rarely in the operating system, and never is it the
computer.
As well as the technical misuse of instructions, there are the problems with
programming logic—wrong compares, wrong branches, wrong calculations. Perhaps
the worst error is misunderstanding the problem, and coding the incorrect solution.
Analyze the program specifications carefully before flowcharting and coding the
program.
PROBLEMS
5-1. Editing.
(a) What characters other than X'40' may be used as the fill character?
(b) An amount field containing zero is defined as TOTAL DC PL3'0'. Define an
edit word to cause TOTAL to print as all blanks.
(c) Why must the edit word contain an odd number of X'20's and X'21's?
(d) Refer to the IBM Principles of Operation manual and define the purpose of
the "field separator."
5-2. Complete the following Edit words and Edit operations as indicated.
124 DECIMAL ARITHMETIC II
PKFIELD DC P’123456789’
A DC P’82.5’
B DC P’940.5’
C DC P’78.55’
D DC P’92.345’
A DC P’017’
B DC P’127.5’
C DC P’613.57’
D DC P’925.365’
125 Problems
1-2 Record code (25) 11-13 Commission rate (e.g. .155 = 15.5%)
3-4 Store number 14-27 Category description
5-7 Salesman number 28-33 Selling price (xxxx.xx)
8-10 Category (type of sale, 36-41 Cost price (xxxx.xx)
such as TV, furniture, appliance)
Procedure:
— Check for valid record code (25) and that records are in sequence by Sales¬
man (minor) within Store (major).
— For each record, calculate and print:
Gross profit = Selling Price - Cost (Cost can exceed Selling Price).
Percent Gross Profit = Gross Profit -4- Cost.
Commission = Gross Profit x Commission rate.
— For each Salesman, print totals of Sales, Cost, Gross Profit, and Commis¬
sion. Calculate Percent Gross Profit. For each Store and for final total, print
and calculate as for Salesman.
— Provide test data that checks all conditions. Flowchart, code, and test. Take
a hex dump of storage and analyze the contents.
CHAPTER 6
Up to now we have used only instructions that access data in main storage—the
storage-to-storage (SS) and storage immediate (SI) formats. The next step is to use the
registers to perform binary arithmetic and to manipulate addresses. These operations
enable the explicit use of registers in addressing for powerful programming capabil¬
ity, such as table look-up. For these purposes we must learn how to use registers for
arithmetic and for addressing, and what is the machine language object code format
for each instruction.
The 16 general purpose registers are separate from main storage. They are numbered
from 0 through 15, and are referenced by number.* Each register contains 32 bits of
data, numbered from left to right 0 through 31. The registers have two main purposes,
binary arithmetic and addressing.
*We can use EQU to assign a name to a register: e.g., LINKREG EQU 7 tells the
Assembler to substitute the number 7 for each reference to the name LINKREG in the
program. Thus, the instruction BAL LINKREG,HIOHEAD becomes BAL 7,H1 OHEAD.
726
127 Base Register Addressing
1. Binary Arithmetic. The general registers perform all binary arithmetic. For binary
values, bit 0 is the sign bit, and bits 1-31 are data. Chapter 7 covers binary
arithmetic in detail.
As¬
sign Data
bit: 0 I 31
2. Addressing. The general registers perform all the addressing involved in referenc¬
ing main storage. A register used for addressing purposes is called a base register.
Addressing uses only the rightmost 24 bits of the register (bits 8-31), giving a
maximum address of 224-1 , or 16,777,215. Certain instructions of "RX" format
have the facility to modify or "index" an address; a register used for this purpose
is called an "index register".
Unused Address
bit: 0 7 8 31
Some of the registers have special functions, and the following restrictions
apply:
REGISTER RESTRICTIONS
0-1 We may use 0 and 1 freely for temporary calculations, but Supervisor
operations such as CALL and PUT destroy their contents. Also, because
the Supervisor uses register-0 as its own base register, the system does not
permit us to use register-0 as a base register.
2 2 is available as a base register or for binary arithmetic, with one excep¬
tion: the TRT instruction uses register-2 to store a generated value, thus
limiting its use as a base register.
3-12 Registers 3-12 are always available for binary arithmetic or as base reg¬
isters.
13 Control program routines including the input/output system use register-
13. We use it when performing special linkage to a "subprogram," and
otherwise should not use it.
14-15 Control program and subprogram routines also use these. Their use is re¬
stricted as for 0 and 1, for temporary calculations.
direct addressing system is simple, but limits the highest address, in this case to
99999. Modern large computers require considerably more storage because of (a)
more complex input/output facilities, (b) complex operating systems, and (c) the
capability of multiprogramming—the executing of two or more programs in storage
concurrently.
For addressing main storage locations, the 360/370 use the rightmost 24 bits of
a register, providing a maximum address of 16,777,215. Every instruction operand
that references a main storage location consists of more than just a direct reference to
that location; the computer architecture compresses the addresses by splitting them
into two parts, a base address and a displacement:
Each address referenced therefore consists of two parts: the contents of the base
register combined with the displacement provides the effective address. Refer to
Figure 6-1 a. Assume that register-3 is the base register for a small program in main
storage. Register-3 contains the value X'4200', which is the location of the first byte
of the program in main storage. (Do not be concerned for now how X'4200' loads
into register-3 or how the Assembler knows this value.)
Main storage
Register-3:
X'4200'
Every location within the program is relative to the first byte X'4200' For
example, location X'4502' is X'302' bytes from the start, and therefore location
X'4502' has a displacement of X'302' bytes. The computer then references location
X'4502' by adding: base address X'4200' plus displacement X'302' equals the effec¬
tive address X'4502'. Any instruction referencing this location does so by means of
the contents of the base register (X'4200') plus the displacement (X'302').
129 Base Register Addressing
The Assembler calculates the displacement for every instruction and declara¬
tive in the program. For every instruction that references a main storage location, the
Assembler forms an operand in object code comprised of the base register number
and the displacement, and stores this as two bytes within the instruction:
B D D D]
bits: 0-3 4-15
Bits 0-3 provide four bits to reference a base register, as X'l' through X'F', Bits 4-15
provide for a displacement from X'000' through X'FFF' (up to 4095 bytes). Thus, in
Figure 6-1 a an instruction referencing X'4502' would contain as its operand the hex
value I 3J 302\. To reference X'4502' the computer adds the contents of the base
register-3, X'4200', with the displacement, X'302'. An MVC instruction would move
data to the address X'4200' plus X'302'.
Example: Assume that a program defines PRINT + 30 at location X'4502'. The As¬
sembler would translate the instruction MVI PRINT + 30,C'*' into hex object code as:
92 5C 3 | 302
/
machine code for MVI displacement
base register
MORE THAN ONE BASE REGISTER. Since the maximum displacement is X'FFF',
or 4095, the area covered by a base register and its displacement is X'000' through
X'FFF', giving X'1000' or 4096 bytes. Each 4096 (4K) bytes of program being exe¬
cuted requires a base register. A program up to 12K bytes in size requires three base
registers, as shown in Figure 6-1 b.
The first 4K area begins with base address X'4200', and any position defined
within this area is subject to base register-3 and a displacement relative to the base
address. The second 4K area begins at a location X'1000' higher, at X'5200'. In the
example, the base register is register-4 (although it could have been some other
available register), and any position defined within this area is subject to base
register-4 and a displacement. Also, in the example, any position defined within the
third 4K area beginning at X'6200' is subject to base register-5 and a displacement.
There are two advantages to base/displacement addressing:
1. Instruction length is reduced because each address requires only two rather than
three bytes.
130 BASE REGISTERS AND INSTRUCTION FORMAT
Main storage
2. Such a system facilitates program repeatability. The Assembler does not assign
specific locations for each address. Instead, it determines where each address is
relative to a base address. At execute-time the base address may be almost any
location, loaded in a base register. Accordingly, the system may locate a program
almost anywhere in main storage for execution. For example, the program may be
executed beginning in X'4200' today, and next week in X'6840'. The purpose of
relocatability is to facilitate multiprogramming—the executing of two or more
programs in storage concurrently. (Although there are several programs in main
storage, the computer can execute only one instruction at a time, and it "flip-
flops" between programs, as available time permits.)
INSTRUCTION FORMAT
This section examines the instruction format in detail to make clear how the Assem¬
bler converts symbolic to machine language code and how it converts base registers
and displacements. Each format has a specific purpose. RR format processes data
between registers; RS and RX process data between registers and storage; SI and SS
process data between storage positions, as follows:
Registers:
Format:
RS RX
RR Register-to-Register
RS Register-to-Storage
RX Register-to-Indexed-Storage
Main SI Storage Immediate
storage: SS Storage-to-Storage
131 Instruction Format
Figure 6-2 depicts the five formats. The column under Format contains the
general symbolic coding format. For example, RR means that both operand-1 and
operand-2 reference a register. SS means that both operands reference storage ad¬
dresses. The other symbols, explained in the next section, are:
D = displacement
B = base register
X = index register
I = immediate operand
Length
Format in Explicit symbolic Object code format
bytes operands
RR 2 R1, R2 OP R1R2
RS 4 R1, R3, D2 (B2) OP R1R3 B2D2 D2D2
RX 4 R1, D2 (X2, B2) OP R1X2 B2D2 D2D2
SI 4 D1 (B1), 12 OP I I B1D1 D1D1
SS (1) 6 D1 (L, B1), D2 (B2) OP L L B1D1 D1D1 B2D2 D2D2
SS (2) 6 D1 (LI, B1), D2 (L2, B2) OP L1L2 B1D1 D1D1 B2D2 D2D2
Bits 0-7 8-15 16-23 24-31 32-39 40-47
Byte 1 2 3 4 5 6
OP IM B1D1 D1D1
1. Character instructions such as MVC and CLC permit a length up to 256 bytes of
data. These use the length of operand-1 to govern the number of bytes that are
processed. Assume that MVC is used to move a field to the print area:
MVC PRINT + 20(6),=C'RECORD'. Given register-3 as the base register and dis¬
placements of 426 for PRINT+20 and 62A for the literal, the generated object
code is ’
fD2 1 05 | 34 26 1 36 2Al
© ® © @
@ D2 is the machine code for MVC.
® I® length of operand-1 is explicitly coded as 6. However, the Assembler
deducts I from the length when converting to object code. At execute-time
t e computer increments the length by 1. This process permits lengths of 256
rather than 255. If we code a length of 256 in an instruction, the Assembler
deducts 1, giving 255 or X'FF'.
© The^third and fourth bytes contain base/displacement for operand-
1, LBD [ DD]. The Assembler inserts base register-3 and the displacement
426 in these positions.
© The fifth and sixth bytes contain base register-3 and displacement 62A for
operand-2.
OPERAND-! OPERAND-2
Contents of base register X'4200' X'4200'
Displacement X'0426' X'062A'
Effective address X'4626' X'482A'
133 Instruction Format
The instruction says, in effect, Move (D2) for six bytes (05 + 1) the contents
beginning at location X'482A' to the field beginning at X'4626'.
2. Packed operations permit a length code for both operands, but limited to 16
bytes. Assume we use APto add packed fields as: AP PAGEPK, = P'1Given base
register-3 and displacements of 624 for PAGEPK and 94E for the literal, the
generated object code is
FA 10 36 24 39 4E
© ® © @
(a) FA is the machine code for AP.
(b) The lengths of operand-1 and 2 are stored in the second byte. Assume
PAGEPK DC PL2'0'. The Assembler decrements the defined length 2 by 1,
and stores 1 as the length. The literal = P'1' creates a 1-byte constant; the
Assembler decrements and stores the length as 0. For the maximum length,
16, the Assembler decrements the length to 15 and stores X'F'.
(c) The third and fourth bytes contain base/displacement for operand-1. The As¬
sembler inserts base register-3 and displacement 624 in these positions.
(d) The fifth and sixth bytes contain base register-3 and displacement 94E for
operand-2, the literal.
At execute-time the computer increments the two length codes and combines the
contents of the base register with the displacement. The effective addresses are:
OPERAND-1 OPERAND-2
Contents of base register X'4200' X'4200'
Displacement X'0624' X'094E'
Effective address X'4824' X'4B4E'
5,7,FIELDS (load registers 5, 6, and 7 with the three 4-byte fields in storage beginning
at the address of FIELDS). The machine language code for LM is 98. The Assembler
translates symbolic to four bytes of object code as |98 J 57 | BD | DD|. The two
bytes referencing FIELDS in storage, [BD DD[, are filled by the Assembler. Given a
base register to use, it inserts the register number (0 through F) in the specified half
byte. The Assembler calculates and stores the displacement in V/2 bytes.
Some RS instructions, such as shift, use only two operands. For these, we omit
R3 as shown in Figure 6-2, and the Assembler inserts a zero in the machine language
position. (Register-0 is not used as the third operand.)
Operand-2 references a storage location with base and displacement. The operation
determines the length of operand-2. For example, there are two operations that add
binary data in storage to a register. A (Add Fullword) adds four bytes of storage to a
register, and AH (Add Halfword) adds two bytes of storage.
As an example, assume the AH (Add Halfword) instruction, coded as AH
5,~H 7'. The literal, =H'7' defines a binary halfword (2-byte) constant. The opera¬
tion adds the halfword value defined in storage to register-5. There is no length
specification, because the operation AH indicates a 2-byte length for operand-2, and
register length is always four bytes. The machine code for AH is X'4A' and assume
that the base register is 3, containing X'4200'. If the literal =H'7' is stored at X'4704'
then its displacement from the base address is X'504\ The Assembler completes the
machine code as:
M 50 3504
T l\
operation \ base/displacement
code / index register
register
ln this «se, the Assembler sets the 'Index register" position to zero. In many
cases, including this one, a reference to register-0 means no register reference If lhe
mstmcfon is one that can specify an index register or an index register is explicitlv
coded, the Assembler inserts the register number into the machine code position An
index register is simply a specific use of one of the general registers just as is a base
register. Indexing is a feature tha, does no, have too many uses but an exempted
given in a later chapter under the LA (Load Address) instruction.
135 Control Sections
CONTROL SECTIONS
For practical purposes, only eleven registers (2 through 12) are available as base
registers. It would appear that the largest program we can assemble and execute is 11
x 4K, or 44K. But many programs require considerably more storage. We may write
such large programs and, indeed, any program requiring more than 2 or 3 base
registers in separate sections. These control sections (CSECTS) are assembled sepa¬
rately, each with its own set of base registers. They may then be combined (link-
edited) into one object program. We have written programs comprised of one control
section. By definition a control section is “a block of coding that can be relocated
(independent of other coding) without altering the operating logic of the program".
Neither the Assembler nor the Linkage-Editor recognizes a "program"—they process
one or more control sections.
Under Operating System, OS, where multiprogramming is common, there is
often more than one program being executed in storage. On any given day these
programs are located in storage depending on the sequence in which they are first
required. Therefore, under such a system when we code a program we do not know
where it will be located for execution. Under smaller systems where generally single
programs are run, programs are normally loaded following the Supervisor area,
beginning in an available location that is evenly divisible by eight, a "doubleword"
address.
The first or only control section of a program is identified by either the START or
CSECT instruction. Subsequent control sections, if any, are identified by CSECT.
Because we are still concerned with small programs we may code them in one
section using START. Chapter 15 covers program sectioning and CSECT.
The START instruction specifies the beginning of the first or only control section
(CSECT may also be used for this purpose). The Assembler treats the name, if any, as
the name of the control section. If we know where the program will be loaded, we
may code an initial value (evenly divisible by eight) for the Assembler location
counter. If the value is omitted the location counter is set to zero. The following three
examples illustrate various uses of START:
136 BASE REGISTERS AND INSTRUCTION FORMAT
1. PROGA START X’4800' The name of the control section is PROGA. The
location counter is set to X'4800' or 18,432,
where we expect the program to be loaded.
2. START 18432 The control section is unnamed. The location
counter is set to 18,432 or X'4800'.
3. PROGB START The name is PROGB. Because the operand is
blank the location counter is set to zero. This
coding practice is common under OS, where it
is generally not known in advance where the
program will reside during execution.
Up to this point, the IN IT macro has performed the START statement functions, as
well as the BALR/USING, covered in the next section.
The Assembler location counter assigns storage addresses to program state¬
ments. These are relative addresses that are printed under the LOC column. The
content of the location counter has no effect on program execution. Displacements
are all relative to the contents of a base register. We may, for example, omit the
operand in the START statement so that the location counter is set to zero. But at
execute-time the program may be loaded at X'4200'. The first statement shown on
the listing at X'OOOO' is actually at X'4200'. When debugging the program we have to
reconcile the listing with the storage dump—a statement listed under LOC at X'0048'
is in storage at X'4200' + X'0048', or X'4248'.
It is our responsibility to notify the Assembler which registers are available as a base
register. For this purpose we code the USING instruction. Subject to the restrictions
discussed earlier, we may assign any registers (generally 2 through 12)_but the
program should not use them for any other purpose. The USING instruction simply
tells the Assembler which register(s) to use for base addressing. No executable code
is generated.
SI in the operand field designates the address from which the Assembler calcu¬
lates displacements. R2,... , Rn specifes the base registers (1 through 15) and their
sequence. When coding the program we can only guess how much storage is re¬
quired. Assume about 25 coding sheets for each 4K of storage, excluding any large
declaratives. Consider the following three examples:
1. USING \3 The asterisk in the operand references the current value in the
Assembler location counter. The statement tells the Assembler
137 Loading the Base Register
that from this point on (for the next 4096 bytes) to use register-3 as the base
register. In effect, the Assembler inserts a '3' as the base register into any address
that references this region. The Assembler also calculates the displacement from
this beginning address and inserts the displacement into the object code instruction.
2. USING A10.5
A 10 MVC P+30(10),NAME At assembly-time the current value of the
location counter is the address of A10.
Here, register-5 becomes the assigned base register. The exact same effect is
achieved by USING *,5.
3. USING *,3,9,4 Each 4096 bytes of storage referenced by the program requires
one base register. In this case we expect to require between
8K and 12K of storage. We designate three base registers, and the Assembler
uses them as required in the sequence coded. Suppose that the current value
in the location counter is X'3802'. Then base register-3 is to apply to all locations
from X'3802' through the next 4095 bytes. Since 4096 equals X'l 000', when the
location counter reaches X'4802', the Assembler assigns base register-9 for the
next 4K region. At X'5802' and for the next region, register-4 becomes the base
register.
USING merely notifies the Assembler which base registers to use. It is our responsi¬
bility to code the program to load the register with a base address. For this purpose
we use the BALR instruction, Branch and Link Register.
X‘4000’ BALR 6,9 Load the address of the next instruction, X'4002', into
X‘4002’ MVC . .. register-6, and branch to the address in register-9.
138 BASE REGISTERS AND INSTRUCTION FORMAT
4. For certain instructions like BALR and BCTR, register-0 has special properties.
When operand-2 specifies register-O, the computer assumes that there is no reg¬
ister reference. For BALR, if operand-2 is register-O, no branch is taken. The
program continues with the next sequential instruction:
X‘5800' BALR 3,0 Load the address of the next instruction, X'5802', into
X‘5802’ MVC ... register-3, and execute the next instruction, the MVC in
X'5802'. This is the most common use of BALR. (0 in
operand-2 means no register.)
Figure 6-3 shows how BALR and USING are combined at the beginning of a
program to initialize and assign a base register. This is a skeleton program for
illustrative purposes—we would not normally move such a constant into the first
position of PRINT, which is reserved for the printer forms control character. Carefully
distinguish in the example between assembly and execute operations.
003808 10 PRINT DS CL 12 1
003881 C9D5E5D6C9C3C540 11 HEADING DC CL 151 INVOICE LISTING'
003800
Ivafin©?" f° 38°u' US'NG °e><t tel'S the Assemb|er from this point
(X 3802 ) to use register-3 as the base register. USING generates no object code The
next instruction, MVC, is assigned to X'3802'. The generated MVC instruction is
D2 | 0B 1 30 06 30 7F
© ® © (d)
139 OS INITIALIZATION
These effective addresses agree with those shown under ADDR1 and ADDR2, and
for the location of PRINT and HEADING. The computer adds 1 to the length (14 + 1
= 15), and moves 15 bytes beginning at X'3881' to X'3808'.
Note: We must reserve a base register and ensure that it is loaded with
the correct value. The Assembler cannot check that the base register is
correctly initialized. It is possible to get an error-free assembly, but one
that at execute-time references the wrong locations! One way to cause
such an execute error is to code the USING before the BALR. The Assem¬
bler sets the location counter to X'3800' instead of X'3802', and calcu¬
lates displacements from X'3800'. But at execute-time BALR loads the
base register with X'3802', causing all displacements to be incorrect by
two bytes.
OS INITIALIZATION
Both DOS and OS require the BALR/USING initialization instructions, used identi¬
cally. But OS is a more complex system, and its Supervisor treats all users' programs
140 BASE REGISTERS AND INSTRUCTION FORMAT
like subprograms". There is added code to supply a linkage between the Supervisor
and our program, as Figure 6-4 illustrates.
1 START
2 SAVE < 14,121 STORE SUPERVISOR'S REGISTERS
3 8 ALR ...
4 USING ...
o cn
e CLOSE ...
9
L 13.SAVEAREA+4 RE-LOAD REGISTER 13
1 0
RETURN (14,12) RE-LOAO REGS. RETURN TO SPVR
11 SAVEAREA DS 18F
SAVE AREA. 18 FULLMORDS
00 0 Equal/Zero
01 1 Low/Minus
10 2 H igh/Plus
1 1 3 Overflow
Figure 6-5 provides the four-bit mask for the nine common branch conditions.
We can test for Equal/Zero with either BE addr or BC 8,addr. The Assembler trans¬
lates the 8 to binary 1000 in the object code mask position. Note that bits are
numbered from left to right, beginning with zero for the leftmost bit, as 0, 1, 2, 3. On
execution, the computer checks the mask—binary 1000 asks if bit 0 is on, meaning:
does the condition code value equal zero?
The 4-bit Mask
For Not Equal, we could code either BNE addr or BC 7,addr. The Assembler
translates the 7 to binary 0111 in the mask. On execution, the computer checks the
mask:
If any one of these conditions exists, then the condition is not equal. The Assembler
provides the extended mnemonics to save us coding and memorizing the mask. But
whichever way we code, for example BNE addr or BC 7,addr, the Assembler gener¬
ates the identical object code.
In the interests of clarity and reducing program bugs, this text recommends
using the extended mnemonics. An understanding of the mask and the condition is
useful, however, to aid in deciphering machine language code.
DEBUGGING TIPS
-Except for the special OS initialization, the only new instructions introduced in this
chapter are BALR and USING. Typical errors are:
USING *,3
BALR 3,0
BCTR 3,0 Decrement register-3 by 1
BCTR 3,0 Decrement register-3 by 1
PROBLEMS
6-1. What are the two main purposes of the general registers?
6-2. What are the two main advantages of base/displacement addressing?
6-3. Why is explicit length indication permitted only for SS format?
6-4. Give the machine language code generated for the following Assume base
register-2 contains X'4800'. 6 Se
(a) BALR 9,10
(b) LM 3,15,SAVE Assume SAVE is at location 4920.
(c) CLI CODE.C X Assume CODE is at location 4A26.
143 Problems
6-9. Revise any previous program for base register initialization. Replace the INIT
macro (or whatever macro you used for initialization). If under OS, code the
linkage carefully.
6-10. The first base register is loaded using BALR, and additional ones with L, LA, or
LM. Assign and load registers 6, 7, and 8 as base registers, and define any
required declaratives. (Hint: Look ahead in the book.)
(a) Use one LM instruction to load registers 7 and 8.
(b) Use LA instructions to load registers 7 and 8.
6-11. Give the extended mnemonics for the following: (a) BC 8,C90; (b) BC 2,D90;
(c) BC 11,E90; (d) BC 15,F90.
6-12. Code the following in machine language (assuming base register-3 contains
X'5200' and B30 is at X'5C38'): (a) B B30; (b) BNL B30; (c) BAL 5,B30;
(d) BR 5.
6-13. What would BC 9,addr mean?
CHAPTER 7
Input/output on the 360 and 370 is significantly complex and for this reason its
discussion has been delayed until now. This chapter covers only a fraction of the
technical material available. (See especially the IBM Supervisor manuals.)
Earlier computers transmitted data directly between storage and I/O devices.
Such computers used to read records directly into storage in a specified area and
wrote out of an area. Indeed many small computers still function this way. During the
I/O operation, all other processing was suspended until transmission was completed.
Such a system considerably delays processing, especially when many devices are
attached. I/O processing has been improved by:
At the software (programming) level, buffers are used (covered in a later section).
The I/O devices now generally are faster.
CPU processing and data transmission are designed to overlap. For example
while a print operation transmits data to the printer, the CPU continues executing
instructions This advantage is achieved by the use of a hardware feature chan
riels, covered in the chapter on Operating Systems.
Many more I/O devices are available, requiring more powerful I/O capability.
144
145 Input/Output Control System
A 360/370 program always executes in one of two states—the Problem and the
Supervisor state. At any given time, the computer is either in the problem state
executing a user's ("problem") program, or in the Supervisor state, executing the
Supervisor program. The Supervisor program handles the transition between jobs and
all interrupts, which include program and machine checks and all input/output
operations. The problem program cannot actually issue I/O operations—these are
privileged instructions that only the Supervisor can execute. The PSW indication is in
bit 15 : 0 means supervisor and 1 means the problem program is being executed.
Privileged instructions execute only when the program is in the supervisor state (PSW
bit 15 = 0). For all I/O, the problem program interrupts and transfers control to the
Supervisor.
For its I/O operations, the Supervisor uses the privileged instructions: Start I/O,
Test I/O, FHalt I/O, and Test Channel. We can (but usually do not) code I/O operations
for the channel program by linking to the Supervisor with SVC (Supervisor Call) and
CCW (Channel Command Word). This detailed level requires that we synchronize
I/O operations with the program and provide for channel scheduling and interrupts.
Few programmers code at this level. Instead, there is available a generalized Input/
Output Control System, IOCS (called Data Management Services under OS). We can
simplify I/O programming considerably by coding IOCS macro instructions. There
are two main forms of IOCS: physical IOCS (PIOCS) and logical IOCS (LIOCS).
PHYSICAL IOCS. This level is still close to the actual machine operation, and
coding is similar to that already discussed. We code the channel program using the
macros EXCP (Execute Channel Program), WAIT, and CCB (Command Control
Block). This level initiates execution of channel commands, and handles I/O inter¬
rupts and channel scheduling, but we must still synchronize I/O operations with our
program. Chapter 16 provides more information on Physical IOCS.
LOGICAL IOCS. This level uses the capabilities of physical IOCS, but provides
many more features. On input, LIOCS locates the required record and delivers it to
the program as a logical record. On output, LIOCS delivers the logical record to the
channel program. LIOCS handles end-of-file conditions and many more functions
not yet discussed, including:
— Switching ("flip-flopping") between I/O areas ("buffers") if more than one buffer
is designated.
— "Blocking" and "unblocking" tape and disk records.
— Checking and writing tape and disk "labels."
To obtain a record using logical IOCS we simply code the GET macro, and to
write a record we code the PUT macro (sometimes READ and WRITE in special
146 INPUT AND OUTPUT
cases). IOCS saves us from coding the complex but repetitious input/output routines.
The rest of this chapter covers programming using logical IOCS. We have already
used Logical IOCS for OPEN, CLOSE, and GET. This chapter explains these and other
macros in detail.
As can be seen, reading and processing are overlapped. The input records are read
into areas in our program called buffers or I/O areas. We can extend this facility by
increasing the number of buffers (up to 2 for DOS and 256 for OS). Similarly, writing
can be overlapped with processing. Under DOS the programmer must designate the
buffer areas, but OS automatically supplies them.
There are two types of IOCS macros: file definition macros and imperative
macros.
IMPERATIVE MACROS
These initiate the input/output operation and include OPEN CLOSE GET and PUT
These macros relate to the generalized DTF's channel commands'and link to the
Supervisor to issue the data transmission.
147 Imperative Macros
THE OPEN MACRO. OPEN makes a file available to the program. Control is passed
to the Supervisor which checks that the file exists and that the device is ready. (IOCS
does considerably more when opening disk and tape.) One OPEN may open from
one to 16 files. For example, assume the following statements:
THE CLOSE MACRO. CLOSE deactivates all files previously opened and no longer
required. We may close a file any time, and should close all files before terminating
the program. A file closed in a program may be reopened and further processed.
(IOCS does considerably more when closing disk and tape.)
Many systems now provide for automatic self-relocating programs. If the sys¬
tem does not have this capability, then to facilitate program self-relocatabiIity under
DOS, the macros should be coded OPENR and CLOSER. The IBM Supervisor manual
provides the details.
THE GET MACRO. GET makes available the next record from a sequential input
file. The input record erases the previous contents of the input area.
OPERATION OPERAND
GET filename,workarea
or GET (1),(0)
The file name is that of the DTF for the file. IOCS delivers the record to the
workarea specified in operand-2. For instance:
In this example, the filename is CARD and the workarea is CARDIN. The
80-character card record is transmitted to CARDIN. We may also load the DTF or
DCB address and the workarea address into registers 1 and 0, as follows:
Figure 7-1 a depicts the relationship of the GET statement with two buffers. The
first GET issued in the program reads record-1 into the first buffer, I/O areal. Record-1
is transferred to CARDIN, available for processing. Then while the program processes
the record in CARDIN, IOCS reads record-2 into the second buffer, I/O area2:
FIGURE 7-1 a
In Figure 7-1 b the second GET issued in the program transfers record-2 to
CARDIN, and while the program processes CARDIN, IOCS reads record-3 into the
first buffer:
workarea
FIGURE 7-1 b
We must inform IOCS where to branch when it encounters the end-of-file (the
/ trailer card). We designate the address where the system is to branch in the DCB or
DTF statement. IOCS reads the /* record directly into a buffer. When a GET attempts
to transfer the /* record to our workarea, the system instead will automatically direct
the program to our end-of-file address.
THE PUT MACRO. PUT writes or punches our record from our output (work) area.
The rules for coding PUT are similar to those for GET.
OPERATION OPERAND
PUT filename,workarea
or PUT (1),(0)
For example:
The PUT macro causes the contents of the workarea PRINT to write onto the device
called PRINTER. Note: The contents of the workarea and the buffers are not erased. If
we move data into the print area, we should clear the area after writing.
Before printing, we must insert a special forms control character into the first
byte of the print workarea. (An alternative method is to use the CNTRL macro—see
the IBM Supervisor Macro manuals.) The character informs the channel what action
to take, such as print, space, eject. Punching cards may also require a special control
character before the punch area. The common forms control characters in hex are:
NO WRITE WRITE
Space 1 line OB 09
Space 2 lines 13 11 Note also: X'01' is Write, space
Space 3 lines IB 19 0 lines.
Skip to new page 8B 89
If we use X'l 3' as the control character, the printer spaces two lines, without print¬
ing, regardless of the contents of PRINT. "Skip to a new page" is actually "skip to
channel 1". The printer is equipped with a carriage control tape punched with a hole
in "channel 1". The hole usually aligns with the printer forms at the top of the page
as shown in Figure 7-2. Punches and control channels are available for channels 1
through 12 to permit skipping to various lines on the page. Most tapes are punched
with channel 1, but not necessarily with the other channels.
Channel 12 ... 2 1
r
Channel 1 hole_
Channel 2 hole-
Channel 1 2 hole_
V
The next two example programs both illustrate the same program, using DOS
and OS imperative and file definition macros. The programs simply read and write
card records. They load register-3 as the base register and open the files; this ini¬
tialization need be performed only once, at the start of the program execution.
At A10HEAD the program skips to a new page to print the heading. Note that
CTLCHAR is defined as the first byte of the print area. At A20READ a card is read into
CARDIN. This field is moved to the print area and printed. The line counter is
incremented and checked for page overflow as in previous programs.
When all the input records have been read, IOCS recognizes the end-of-file (/*
trailer record under DOS), and directs the program to the end-file address, Z10END,
where the files are closed and execution terminates. Both file definition macros, DTF
and DCB, are keyword macros. That is, the entries are recognized by specific
names, and may be coded in any sequence. The keyword is followed by an equal
sign (=) and a 'parameter', such as EOFADDR=Zl OEND. One entry is coded per
line, followed immediately by a comma to separate the entries. We punch a continu¬
ation character in column 72 to indicate that the macro continues on the next line, in
column 16. (It is possible to code several entries per line, but this practice makes the
listing difficult to read and to change.) The last entry has no comma or continuation
character. Some entries may be omitted; in these cases the Assembler assumes an
entry—such assumptions are called "default valuesPrecise entries and defaults
vary by version of operating system, so that it is necessary to refer to the appropriate
IBM Supervisor manual.
Figure 7-3 provides the requirements for a program written under DOS The soecifi
cations for DTFCD and DTFPR follow: M
?IpnDrDEF1NE ™E CARD FILE- The n‘1me in FiSure 7-3 given to the card file is
LARD (any unique name may be given). The entries are:
BLKSIZE=80 tells IOCS that the size of each block of data to be read is 80 bytes or
80 card columns. If this entry is omitted, the Assembler assumes a default of 80
(depending on the device).
DEVnDndR=SYSrhT §IVeS ^ entry SYSIPT' the PrimarV system input device De¬
pending on the system we may designate SYSRDR (the system reader device) or
programmer logical unit”, SYSnnn appropriate to the computer installation
151 The DOS DTF File Definition Macro
5 444
initial » 2 A T I Q N
6 PROG 7 A START x^ACze*
7 BALR 3•0
e INITIALIZE BASE REGISTER
USING • .3
9 OPEN CARD,PR INTER ACTIVATE FILES
19 ♦ 44
page 0 V E R F L O W
20 A 1 OH E AC NVI CTLCHAR , X•ae*
MOVE FORMS CONTROL CHARACTER
2 I PUT PRINTER,PRINT
SKIP TO NEW PAGE
27 ZAP LINECT.=P>0* CLEAR LINE COUNT
29 ♦ 44 M A I N P R i0 C E S S I N G
30 e1 ORE AC GET CARO,CARD IN
36 M VC RECPR.CARDIN
MOVE RECORD TO PRINT AREA
37 MVI CTLCHAR.X•09• MOVE CONTROL CHARACTER
38 PUT PRINTER,PRINT PRINT, SPACE 1 LINE
44 AP LIN E C T, = P■ 1• ADD TO LINE COUNT
45 CP LINECT, — P • 5 0 ' END OF PAGE ?
46 EH A10HEAC YES - SKIP PAGE
47 B B10 RE AO
NO - READ NEXT RECORD
49 444 E N C - 0 F - FILE
50 Z1OEND CLOSE CARD.PR INTER OE-ACTIVATE FILES
59 EO J
NORMAL END-OF-JOB
63 44 4 D E C L A R A
1 45 END PRCG7A
DEVICE = 2501 designates the card reader device to be used by the file. If the oper¬
and is omitted, the Assembler assumes a 2540 reader.
EOFADDR=Z1 OEND indicates the address of our end-of-file routine, and may be
any unique program name. IOCS recognizes the /* trailer card and links to our
end-of-file address. Never branch to this address from any other point.
IOAREA1 =IOARCD1 is a required entry that specifies the name of the first buffer (or
I/O area). We have defined this buffer elsewhere in the program as IOARCD1
DS CL80. Any unique name could be used. IOCS reads input records into this
area.
IOAREA2 = IOARCD2 gives the name of the second buffer (or I/O area). It is defined
elsewhere in the program as IOARCD2 DS CL80. A second buffer is optional,
but provides more efficient processing.
RECFORM = FIXUNB means that the format of records to be read is "fixed length,
unblocked." All card records are in this format normally, but tape and disk
records may be variable in length, and "blocked"—several records per block. If
this entry is omitted, the Assember assumes FIXUNB.
TYPEFLE = INPUT means that the type of file is input. The operand for punched
output is OUTPUT, and for a combined punch-feed-read device is CMBND. If
the entry is omitted, the Assembler assumes INPUT.
WORKA=YES tells IOCS that we want to process records in a "workarea" rather than
directly in a buffer. IOCS is to transfer records from the buffers to our workarea
as specified in the macro GET CARD,CARDIN. CARDIN is defined elsewhere as
DS CL80. This entry may be omitted, but if so, we must specify another entry as
IOREG = (r), and process the input records directly in the buffers. This practice
may be done with DTFCD, but is illustrated later under DTFDI.
Other entries may also be coded; however, IOCS varies by operating system,
and many programs have unique needs. The Supervisor manual for each system
gives more specific details.
DTFPR DEFINE THE PRINTER FILE. The name in Figure 7-3 given to the printer is
PRINTER. Note that there is no entry for TYPEFLE because DTFPR is understood to be
an output file. The entry EOFADDR is omitted because it is only for input files.
DTFPR also permits entries other than the ones shown in the example.
BLKSIZE 121 tells IOCS that the size of the block of output data is 121 bytes The
first (leftmost) byte is reserved for the forms control character, so that only 120
device re Pnnted' ^ maX'mum block len§th dePends on the particular printer
CTLCHR^YES means that the program is using the 360/370 forms control character
sociationTet^ ^ C°dm8 CTLCHR=ASA stipulates the American Standards As-
DEVICE = 1403 designates the printer device for the file, such as 1443, 3203, etc.
IOAREA1 =IOARPR1 specifies the name of the first buffer (I/O area). We have de¬
fined this buffer elsewhere in the program as IOARPR1 DS CL1 21. Any unique
name could be used. The entry is required.
IOAREA2 = IOARPR2 gives the name of the second (optional) buffer. It is defined
elsewhere as IOARPR2 DS CL121. The use of more than one buffer provides
more efficient processing.
RECFORM = FIXUNB means that the output format is "fixed length, unblocked."
WORKA=YES tells IOCS that we want to process records in a "workarea" rather
than in buffers. IOCS is to transfer records from our workarea to the buffers, in
the example by means of the macro PUT PRINTER,PRINT. PRINT is defined
elsewhere as DS CL121, and is our workarea for defining output records.
IOCS MODULES. For each file, the Linkage Editor includes an IOCS logic module
immediately following the program. A macro such as PUT PRINTER,PRINT links to
the DTFPR, which in turn links to the printer logic module following the program.
Program
The size and location of these modules are available on the Linkage Editor Map (use
the control statement ACTION MAP). An example of the Linkage Editor Map and
names of the IOCS logic modules are given in Chapter 15.
The IOCS modules are preassembled and catalogued, and the Linkage Editor
includes the appropriate modules with all programs that require input/output.
DCB, Data Control Block, is equivalent to the DOS DTF macro, and is used to define
a "data set." Because OS has considerable device independence capability, a rec¬
ommended approach is to define all data sets as disk in order to facilitate this feature.
Many of the entries required for DTF's are omitted for DCB's. Under OS, we may
specify additional I/O attributes at execute-time by means of the DD, Data Defini¬
tion, job control cards. This feature permits some programming changes concerned
with I/O without reassembling the program.
The Assembler completes as much of the "data control block" as possible from
the DCB entries. Prior to execution, the system checks for missing entries, and
*** INITIALIZATION
PR0G7B START 0
*** END-OF-FI L E
***
declarati V E S
SAVEAREA DS l 8F
REGISTER SAVE AREA
ENO PRCG7e
154
155 The OS DCB File Definition Macro
accesses them from the DD statement. In this way, entries in the DCB have priority
over those in the DD statement. If there is information not provided, the system may
make a default assumption, or if not possible, the program will possibly "bomb"
when attempting an I/O operation.
Figure 7-4 illustrates the OS DCB macro and initialization, using the same
example as the previous one for OS, reading and writing card records.
DCB FOR INPUT. In the example, the name of the data set is FILEIN. Some of the
DCB entries may be made on the DD job control cards.
DCB FOR OUTPUT. In Figure 7-4, the name of the DCB printer data set is FILEOT,
and provides one possible coding:
BLKSIZE, DEVD, and DSORG are similar to the definitions for the input data set.
DDNAME = SYSPRINT means that the system printer is the device for this data set.
MACRF=(PM) means that the macro format is "Put and Move" from a workarea (the
coding is to be PUT FILEOT,workarea).
RECFM = FM. F means "fixed, unblocked". M is for "machine code", the format for
the regular 360/370 print control characters. For ASA characters, use A. The
requirements for other installations may be quite different. Some systems block
print records onto disk prior to printing, and the entry may be FBM or FBSM.
156 INPUT AND OUTPUT
LOCATE MODE
The DTF and DCB requirements differ. For the DTF, the entry IOREG replaces
WORKA, as IOREG = (reg) specifying an available general register. IOCS is to load
the register with the address of the buffer that contains the next record to be pro¬
cessed. The DCB entry to denote processing in a buffer ("Locate Mode") is
MACRF = (GL) for input and MACRF=(PL) for output. The system uses register-1 for
the address of the buffer that contains the record to be processed.
The example in Figure 7-5a shows the first GET executed. IOCS reads record-1
into buffer-1 and loads the address of buffer-1 into "register-r". Then, while the
program processes the record in buffer-1, IOCS reads record-2 into buffer-2:
FIGURE 7-5a
The example cites "register-r" to mean the specified register in the DTF or register-1
for the DCB.
Figure 7-5b shows the second GET executed. IOCS loads the address of
buffer-2 (which contains record-2) into register-r. Then, while we process record-2
IOCS reads record-3 into buffer-1:
FIGURE 7-5b
Processin§ continues "flip-flopping" between the two buffers (or more under
OS). GET reads a record into one of the buffers, but which one? After the GET the
register will contain the address of the first byte of the buffer in which the next input
record is located. For the programmer, the simplest action is to move the contents of
the buffer to a workarea for processing. We can use the address in the register
fo^MVC is" ^ MVC °Perat'0n lmmediatelV following the GET. The symbolic format
157 Locate Mode
MVC D1(L,B1),D2(B2)
The MVC instruction works as follows: Using the address in register-r (base register-r,
no displacement), move from the specified storage location to INAREA (an 80-byte
move, based on the length of INAREA). The GET operation is basically the same for
uub and Ob, although OS requires the use of register-1 only. The PUT statements
and file definitions differ.
DOS CODING FOR LOCATE MODE. The changes required to process in the
suffer are compared in Figure 7-6 with the conventional use of a workarea. The
example arbitrarily selects register-4 for the input register and register-5 for the output
one, with the IOREG entry replacing the WORKA entry. Any available register (2
through 12) will work, but not the base register(s). For printing, the OPEN statement
establishes in register-5 (in this case) the address of the first available print buffer.
Before the PUT, we move the contents of the PRINT area to the buffer: operand-1 of
the MVC, coded as 0(121,5) uses base register-5, displacement zero and length 121
explicitly to move the contents of PRINT to the designated storage locations. The
following PUT statement initializes register-5 with the address of the next available
buffer.
WORKA=YES IOREG=(5)
OS CODING FOR LOCATE MODE. Under OS, the DCB entry for processing in the
buffer for the input data set is MACRF=(GL) for Get Locate, and the entry for the
output data set is MACRF=(PL) for Put Locate. Figure 7-7 compares the conventional
use of a workarea with Locate Mode. Since the DCB contains the entry for (PL), we
158 INPUT AND OUTPUT
MACRF=(GM) MACRF=(GL)
Output file definition DCB . DCB .
MACRF=(PM) MACRF=(PL)
must code the PUT with no operand-2. PUT inserts into register-1 the address of the
first byte of the buffer that is to receive the next output record. We code PUT to locate
the output buffer, and then can use register-1 explicitly to move data into the buffer.
But watch out—the coding for PUT and MVC under OS is reverse to that for DOS.
We are not yet fully ready for explicit use of base/displacement, covered in a
later chapter. What have we accomplished? Using standard workareas, IOCS would
perform these functions automatically. Processing fully in a buffer without moving to
a workarea requires extensive use of explicit base/displacement processing. Chapter
1 5, under DSECT, does provide a sophisticated method of processing within a buffer,
and giving names to the various fields in that area. Meanwhile, feel free to continue
using workareas, the approach most commonly used in handling input/output.
With DTFCD and DTFPR we can normally read and write data only on the card
reader, punch, and printer. Some situations, however, require more I/O flexibility.
For example, assume a multiprogramming system that is executing two programs.
The first program fully uses the only printer, but the second program also needs the
printer. We may ask the system to direct the second program's output onto magnetic
tape, which can later be used to print the output when the printer is available. We
can enhance the flexibility of device independence (assigning tape output for a
printer, for example) with the use of the macro DTFDI (Define the File Device
Independent) in place of DTFCD and DTFPR. OS and larger DOS/VS versions, de¬
signed for device independence, do not require such a special macro.
The module that DTFDI generates is larger than those for DTFCD and DTFPR,
but is more versatile. Among restrictions, records must be fixed length, unblocked
and with no workarea specified. Figure 7-8 illustrates DTFDI macros for input and for
output.
159 Device Independence Under DOS
DTFDI FOR INPUT. The name in the figure given to the file is FILEIN. Entries
EOFADDR, IOAREA1, and IOAREA2 are coded the same as for DTFCD.
DEVADDR uses only the primary system input device names SYSIPT and SYSRDR.
IOREG = (4) tells IOCS to load register-4 with the address of the buffer that contains
the current input record. Any available register, 2 through 12, may be assigned.
With IOREG, we code GET filename (with no workarea indicated).
RECSIZE = 80 designates the length of the input area as 80 bytes, the maximum length
allowed.
Note the use of RECSIZE instead of BLKSIZE. We do not code DEVICE (because
it is device independent), RECFORM (always fixed, blocked), TYPEFLE (files can be
input or output), or WORKA (processing is in a buffer, not a workarea).
DTFDI FOR OUTPUT. The name given to the output file in the figure is PRTR. Note
that we do not code CTLCHR, DEVICE, RECFORM, or TYPEFLE. Entries DEVADDR,
IOAREA1, and IOAREA2 are the same as for DTFPR.
IOREG = (5) tells IOCS to load register-5 with the address of the buffer that is next to
be used for output. Initially, the OPEN macro loads register-5, and subsequently
the PUT macro as executed. Any available register, 2 through 12, may be
assigned. With IOREG, we code PUT filename (with no workarea indicated).
RECSIZE = (121) defines the length of the output record. The first byte is reserved for
the control character. The maximum length is normally 121 for SYSLST (printer)
and 81 for SYSPCH (card punch).
160 INPUT AND OUTPUT
ABNORMAL TERMINATION
Both DOS and OS have macros that are used to terminate the program abnormally
when a serious error condition is encountered. Both provide a hexadecimal dump of
the registers and the program storage area. The DOS macro is DUMP and the OS one
is ABEND.
THE DOS DUMP MACRO. DUMP terminates program execution and provides a
storage dump. Generally, PDUMP is more convenient to use when testing a program
because it continues processing the program. The CANCEL macro also terminates
processing, and flushes all input records through tothe/& Job End card. If we precede
program execution with a // OPTION DUMP job card, the Supervisor automatically
produces a storage dump after the CANCEL. (// OPTION PARTDUMP on some larger
systems.)
THE OS ABEND MACRO. To provide for a serious error condition where we want
an "abnormal end" of the program, we code the ABEND macro. The operand
includes a "completion-code", any decimal value up to 4095, as ABEND 25,DUMP.
There could be several ABENDS in the program, but the completion code 25 iden¬
tifies which ABEND when it prints at termination. The DUMP operand invokes the
ABDUMP macro (abnormal DUMP) which prints a hexadecimal dump of the reg¬
isters and relevant parts of main storage.
DEBUGGING TIPS
Coding errors based on input/output are many and serious. The Assembler can
identify the most obvious spelling errors, but others include:
PROBLEMS
Up to now, most of the emphasis in this book has been with the technical aspects of
Assembler programming. In this chapter we take a break, and examine program
organization, style, and standards. Much of this material is relevant to any programm¬
ing language.
PROGRAMMING OBJECTIVES
1. Accuracy. A program must produce 100 percent accurate results, since the recip¬
ient of the report may base decisions on the information. For example, if a report
detailing delinquent customer payments is incorrect, the company may start bad¬
gering customers who are fully paid up.
2. Efficiency. In these days of large main storage, "virtual” storage, and fast
execute-time, efficiency is no longer such a consideration as once it was. There
may even be justification for some inefficiency, where the added cost of pro-
762
163 Subroutines and Linkage
gramming time exceeds the expected cost of CPU time, or when there is an urgent
need for information. However, in the interests of less execute-time and storage
space, an efficient program is always a reasonable objective.
3. Clarity. Since many installations devote considerable time to program corrections
and revisions, it is vital to design programs that are clear and maintainable. In the
past, there have been many programmers with great technical skill who coded
incredibly complex routines, and used the most sophisticated instructions where
simple ones would work equally well. Today's emphasis is on code that is simple,
clear, and well-organized.
The use of subroutines has several advantages: (a) It simplifies program writing.
Commonly used routines, or complex routines, may be separated from the main
program. The main program logic then is simplified, (b) A subroutine may be written
once, then catalogued as a permanent part of the system, available for use by other
programs, (c) It facilitates teams of programmers working on one program.
BRANCH AND LINK—BAL. BAL is similar to BALR, covered earlier. The rules are:
For example, BAL 8,P10PAGE means: load the address of the next instruction in
register-8, and branch to the address of P10PAGE.
STATEMENT DESCRIPTION
1 BAL loads the address of the next instruction, statement 2, into register-8
and branches to P10PAGE, statement 9.
9-12 The subroutine, P10PAGE, is executed. At statement 12 the program
branches to the address stored in register-8, statement 2.
Statements 2, 3, and 4 are executed.
5 BAL loads the address of the next instruction, statement 6, in register-8
and branches to P10PAGE, statement 9.
9-12 Statements 9, 10, and 11 are executed. At statement 12 the program
branches to the address stored in register-8, statement 6.
BR 8
5 BAL 8, P10PAGE
6 .
7 .
8 EOJ
We must ensure that the subroutine is a separate part of the program. The only
way this subroutine should be normally entered is with BAL 8,P10PAGE. The normal
exit in this example is back through register-8. The program, however, may branch
out of the subroutine to any address, such as to an error routine.
i
PI OP AGE (_" ENTRY )
HEADING
ROUTINE
p. XX
A_
P10PAGE
HEADING
ROUTINE
p. XX
c RETURN
The symbol in the main program that represents the subroutine processing
shows:
For a complete example of main logic and subroutines, refer to the flowchart
and program at the end of this chapter.
166 STRATEGY, STYLE, AND STANDARDS
PROGRAMMING STYLE
A subroutine need not be limited in use to a common section of code, such as the
example page heading. Good programming practice today is in the style of "struc¬
tured programming". Now, Assembler language does not lend itself well to struc¬
tured programming requirements, which are better facilitated by high-level lan¬
guages like PL/I and COBOL. But we can adhere to some of its main features:
— Organization of the program into a "main logic" section with various subsidiary
routines (subroutines). The main logic handles input and testing for record code
or sequence to determine the action to take. It then uses BAL to perform the
required subroutine.
Each subroutine has a specific identifiable purpose and contains only logic re¬
lated to its purpose. In a Payroll program, for example, one subroutine calculates
income tax, another calculates pension deduction, etc.
— The main logic and the subroutines are each contained within one page of
printed code (or the number of lines on a visual display terminal). By this limita¬
tion, the mind can grasp (hopefully!) the entire processing logic of the routine.
Routines that continue for pages become incomprehensible. (One exception
could be for a routine that performs many repetitious Move/Edit operations.)
— Each subroutine has one entry-point, at its start, and one exit-point, at its end. The
program accordingly organizes itself into clear, logical sections, with no confus¬
ing branches back and forth between routines.
Within a subroutine, branch statements should go forward as much as possible.
The only statements that branch backwards are those that loopAe.g., branch
back to read the next input record). The following example illustrates an un¬
necessary branch backwards caused by an illogical approach:
UNNECESSARY BRANCH
PROPER CODING
CP CUSTBAL.CREDLIM CP CUSTBAL.CREDLIM
BH D30 BNH D20
D20 •
• MVC MESSOUT, = COVER LIMIT’
•
D20
D30 MVC MESSOUT, = COVER LIMIT’
B D20
Fully structured programming as used in PL/I and COBOL entirely eliminates the GO
TO statement (in Assembler, B, BH, BNE, etc.) because of their powerful "macro
statements", DO WHILE and PERFORM. powerrui macro
The examPle program at the end of this chapter illustrates a Payroll program
at is organized according to the foregoing conventions. The objective of such
programming style is to gain better clarity and to facilitate program maintenance.
167 Program Documentation
— The use of meaningful names that describe the fields being defined, such as
TOTALTAX instead of AMOUNTA, or worst of all, cryptic one-letter names such
as A and X.
— A systematic labelling convention that provides easy locating of branch points
and clearly identifies the section in which it belongs. In the example program at
the end of this chapter, the Main Logic routine has labels that all begin with 'A':
A1 OREAD, A20, A30; the Wage Calculation subroutine labels are 'B'; and Em¬
ployee Total subroutine labels begin with 'D'; etc.
— Assigning certain registers always with specific purposes, such as 3, 4, and 5 for
base registers; 6 and 7 for subroutine linkage; etc. Such conventions help
minimize errors in register usage.
PROGRAM DOCUMENTATION
1. Title Page. The first page could contain program number, program name, the
names of the programmers who wrote it, and the date completed. It might also
specify who authorized the program originally, and the date. This section could
also contain the dates of any revisions, who requested them, and who made
them.
2. Contents Page. If the size of the program warrants it, a contents page may be
useful.
3. Program Objective. This section consists of one or two paragraphs providing the
objective(s) of the program, in effect what the program is to accomplish.
4. Operator's Guide. Many installations have a preprinted operator's guide that the
programmer completes to facilitate running of the program. The guide contains
inputs and their sequence, output devices, printer forms, control totals, and error
168 STRATEGY, STYLE, AND STANDARDS
messages, listing of job control cards (if any), and approximate run time. A copy
of this guide is often usefully included in the program documentation file.
5. Layouts for Input and Output Records and the Printed Report. The report layout
shows the print position of every field in the headings, detail line, total lines, and
error messages.
6. Flowcharts. The current program flowchart (or decision tables in some installa¬
tions) should be filed. A large program could also have an overall summary
flowchart.
7. The Program Listing. The current program listing is included, with the date
clearly identified.
8. Example Test Data. A program using tape or disk input generally is tested using
"live" data. If input is from punched cards, it is not difficult to arrange and list
sample data for testing the program. The test cards should be kept for use in
testing the program whenever it is revised. On the listing of the data, each input
field should be clearly indicated, along with any intentional errors. The list of
input data should show expected results (the totals that we expect the run to
produce), and a random sample of calculations (such as hour x rate in the
documented program following).
9. Program Report Output. This section gives a sample of the program's printed
output, either from live data or from test data, with adding machine tapes to
prove the accuracy of the test.
10. Previous Listing. The previous program listing should be preserved in case re¬
visions turn out to be wrong, or the revision is cancelled and we have to reverse
the changes.
TITLE PAGE
CONTENTS
Page
Program Objective 1
Operator Guide 2
Program Description 3
Input Record Layout 4
Printer Forms Layout 5
Program Flowchart 6
Program Listing 8
Listing of Test Input Data 12
Test Output 13
PROGRAM OBJECTIVE 1
To calculate employees’ wages for the current pay period, and to pro¬
duce the weekly wage report.
169
OPERATOR GUIDE 2
7 70
PROGRAM DESCRIPTION 3
Accumulates total Employee hours and wages, and prints Employee detail line
(see print layout). Returns to read the next record (Section B).
SECTION D: EMPLOYEE TOTALS
Prints total Employee hours and wages (one *), accumulates final total hours and
wages, and clears Employee totals.
SECTION E: FINAL TOTALS
Prints total hours and wages (two **’s).
SECTION H: PAGE OVERFLOW & HEADINGS
Prints page heading at the start of the run and on reaching the end of each page.
SECTION P: PRINT SUBROUTINE
Performs all printing and adding to line counter.
SECTION R: ERROR ROUTINES
The Operator’s Guide describes the three error routines.
REGISTERS USED: Register: Purpose:
3 Base register for addressing
7 Subroutine linkage
9 Table look-up for Job number
SWITCHES USED: None.
7 77
MULTIPLE-CARD LAYOUT FORM
7 72
5
7 73
6
174
7
Print subroutine
175
- 8
TIALIZATION
1 N I
N LOGIC
21 ♦** M A I
READ A RECORD
23 AlOREAC GET FILEIN,INAREA
VALID RECORD CODE?
CLC CODE IN, = C* 04*
29 NO - ERROR
30 BNE R1OCODE
EMPLOYEE SEQUENCE?
CLC EMPNOIN.PREVEMP
32 EQU - PROCESS
33 BE A20
LOW - ERROR
34 BL R20SEQ
HI - NEW EMPLOYEE
35 ♦
PREVEMP.LOVALUE FIRST INPUT RECORD?
36 CLC
YES - BYPASS CTL BREAK
37 BE A20
NO - PRINT E MPL TOTALS
3e B AL 7,01CEMP
PERFORM CALCULATIONS
44 A30 BAL 7.BIOCALC
45 B AlOREAO
47 END - 0 F - F 1 L E
72 B B20
7 76
9
95 850 M VC PR I NT,DETALINE
96 GAL B.P20WSP1 PRINT 4 SPACE 1
97 >*VC DETALINE.blank CLEAR PRINT AREA
98 AP EMPHRPK.HRSPK ADD TOTAL HOURS 4 WAGES
99 AP EMPWGPK.WAGEPK FOR EMPLOYEE
100 MVC PREVEMP.EMPNOIN
10 1 BR 7
l 39 MVC PRINT.HEA0ING2
140 E AL 8.P30WSP2 PRINT 4 SPACE 2
14 1 ZAP LINECTR.TOPAGE INITIALIZE LINE COUNT
142 AP PAGECTR.=P*1* INCREMENT PAGE NO.
143 eR 7 RETURN
1 46 ** PRINT SUBROUTINE
164 0R 8 RETURN
7 77
10
ID
V
188 4 LARATIVES
178
11
END PRCG08
179
12
RUN *] VALID TEST INPUT CA TA
04 11111 ANOERSON 04 10„5 Expected AMU.l£&:
04 mu ANDERSON 0 1 2 15
0411111 ANDERSON 01 315
04 1 1111 ANDERSON 0 1 105 Job 01 7.25 x
0411111 ANDERSON 04 105 Hours 99.9
04^2222 BROWN C2 400 724.28 *
0422222 BROUN 02 500
04 22233 CARPENTER 01 999 Job 04 7.45-x
04 22233 CARPENTER 04 o i5 Hours 01.0
04 22233 CARPENTER 02 250 7.45-*
04 2223S DIXON 02 400
04 22240 EMMETT 01 150 Job 02 6.15 x
04 22240 EMMETT 0 1 150 Hours 25.0
04 22240 EMMETT 04 050 153.75 *
04 2230 1 FLANDERS 01 255
04 2230 1 FLANDERS 0 1 255 Total 724.28
04 2230 1 FLANDERS 01 050 wage£ 7.45-
0 4 22355 GAROMSKI 04 015 153.75
04 22355 GAROMSKI 04 015 870.58
04 22355 GARC*SKI 04 0 15
04 22350 HENDERSON 02 080 Employee 22360:
04 22360 HENDERSON 02 080 Job 02 6.15
04 22360 HENDERSON 02 080 Hours 8.0
04 22360 HENDERSON 02 080 49.20
04 22360 HENDERSCN 02 Iceo
Total WouJii, 41 3.9 Total 49.20
wage* 5
246.00
RUM #Z INVALIO TEST INPUT DAT
180
13
2 14.5 4 * 1.416.35 44
181
182 STRATEGY, STYLE, AND STANDARDS
DEBUGGING TIPS
BAL 9,subroutine
PROBLEMS
8-1. Three programming objectives are accuracy, efficiency and clarity. Discuss the
significance of each objective.
8-2. What are the advantages (if any) of organizing a program into subroutines?
8-3. Consider the following code. Is there a bug? If so, explain.
BALR 3,0
USING *,3
BR 3
8-4. Consider the following code. If there is a bug, explain.
BALR 3,0
USING *,3
BR 3
8-5. What are the features of "structured programming” that can be applied to
Assembler programs? eu lo
8-6. What are the purposes (if any) of program documentation?
8-7. Revise a previous program, organizing it into a main logic routine and various
broutines, each containing related processing, in a logical sequence.
PART III
BINARY OPERATIONS
CHARTER 9
Chapter 6 introduced registers and their use in base addressing. The registers may
also perform binary arithmetic and manipulate data in binary format. Indeed, binary
arithmetic is done only in the general registers, and conversely the registers perform
arithmetic only in binary format. This chapter covers basic binary and register oper¬
ations: first, defining of binary data and then the instructions for binary arithmetic.
Binary data may enter the program from sources such as:
185
186 REGISTERS AND BINARY PROGRAMMING
1. For reference, hits are numbered from left to right, with the leftmost bit numbered
zero:
2. The sign is the leftmost bit, position zero: a 0-bit indicates a positive value, and a
1-bit indicates negative. A zero value is always positive.
3. The rules of binary addition are:
0 + 0 = 0 i+i=io
0+1=1 1+1+1=11
For simplicity, the following examples of decimal and binary addition assume
5-bit fields, with the leftmost bit the sign:
■t
Add 1 = i iooi
(two's complement representation of -7)
sign bit
Note that there is a carry into and out of the sign position. Where there is both a
carry into and out of the sign bit, the result is correct, not an overflow.
6. Invalid overflows occur on the following conditions:
a. Overflow caused by carry into the sign position:
There is a carry into the sign position, and none out of it. The sum is an
incorrect negative value. (To determine the value of 1 0010, reverse the bits (0
1101), then add '1' (0 1110). Since this value is +14, then 1 0010 has a value
of —14, but was supposed to be +18.)
b. Overflow caused by carry out of the sign position:
There is no carry into the sign position but one out of it. The sum is an
incorrect positive value, +14 instead of -18.
BINARY CONSTANTS
Both DS and DC may define a binary field. There are three types: B (ordinary binary),
F (fullword fixed-point), and H (halfword fixed-point). The following sections de¬
scribe DC's; DS statements are written similarly except that the constant is optional
and acts as a comment.
[symbol] DC dBLn'constant’
LENGTH DECIMAL
IN BYTES ASSEMBLED AS VALUE
BIN1 DC B‘00010011 ’ 1 00010011 19
BIN2 DC BLI‘110’ 1 00000110 6
BIN3 DC BL2‘100010011’ 2 00000001 00010011 275
dPconstant’ (Fullword)
Isymbol] DC dHconstant’ (Halfword)
With bit 0 (the leftmost bit) as the sign, maximum and minimum values are:
24 *
LOC
8420 RECORDIN DS 0CL29
8420 ACCTIN DS CL5
8428 AMTIN DS F (F-format causes alignment here)
842C NAMEIN DS CL20
In the example, the Assembler location counter for ACCTIN is at X'8420'. Since
it is a 5-byte field, the next field (AMTIN) would normally begin at 8425. But AMTIN
is defined as DS F, so the Assembler aligns its address on a fullword boundary
following: 8428. There are now three “slack” bytes between the two fields, causing
the record to be defined with 32 bytes instead of the expected 29. Unfortunately, an
input operation would read the 29-byte record byte-for-byte beginning at RECORD-
IN. The first three bytes of the binary amount will be in the slack bytes, and the
program will reference incorrect data in AMTIN and NAMEIN.
A simple remedy is to code the binary fullword as FL4 rather than F. If a
fullword or halfword declarative contains a length (Ln), the Assembler does not align
the field.
190 REGISTERS AND BINARY PROGRAMMING
1. The address constant is enclosed within brackets. We may define more than one
address, each separated by a comma. The constant may be either an absolute
value (rarely used) or a symbolic name.
2. The Assembler generates a fullword constant, aligned on a fullword boundary
(provided no length indication is codedT The constant is right-adjusted in the
field. The maximum value is 231-1 (the highest fullword value).
Figure 9-2 gives a number of examples. (At A10, the LM instruction loads the
three addresses into registers 4, 5, and 6. A later section describes this way to
initialize base registers.)
4 *
5 * DC ADDRFSS CONSTANTS
6
0 03 ft 00 0S30 7 BEGIN ralr 3,0 INITIALIZE BASF REGISTER 3
8 USING *,3,4,5,6
00380? 9846 30?6 ASSIGN BASE REGISTFRS
9 A10 LM 4,6,ADDRESS5 LOAD REGISTERS 4, 5, 6
10 * •
11 *
003806 C1C4C4D9C5E?F?40 1? DECLAR DC C1ADDRFSS CONSTANTS
0 03 8 OF C3D6D5E?F3C105E3
003816 F?
003817 00
003818 00004F20 13 A DDR F SSI DC A(20000 ) ADDRESS OF 20000
0 0381C 00003806 14 ADDRFSS2 DC A(DECLAR )
003820 00003802 ADDRESS OF DECLAR
15 ADDRFSS3 DC A( A10 )
0038 ?4 0000480? ADDRESS OF A10
16 ADDRESS4 DC A(A10+4096) ADDRESS OF A10 + X’10001
003828 0000480200005802 17 ADDRFSS5 DC A ( A 10 + 409 6, A 10+2*40' t A 10+3*409 6) A10 + X11000' ,
003830 0000680?
18 *
A 1 0 + X12000' , A 10+ X'3000'
For both operations, operand-1 specifies a general register, and operand-2 references
a storage location defined as a doubleword, aligned, containing packed data. Note a
significant difference. CVB converts data from operand-2 (storage) to operand-1 (a
register); CVD converts data from operand-1 (a register) to operand-2 (storage). We
can use CVB to convert packed to binary in a register, perform binary arithmetic, use
CVD to convert back to packed, and then edit for printing.
In Figure 9-3, the packed field, AMTPK, is moved to a doubleword field,
DBFWD1. CVB converts the packed contents of DBFWD1 into binary format in
register-6. CVD converts the binary contents of register-6 into packed format in a
doubleword, DBFWD2.
192 REGISTERS AND BINARY PROGRAMMING
37 *
38 * CVB CONVERT TO BINARY
39 *
00384E F87 1 305E 40 ZAP DBLWD1,AMTPK MOVE TO DOURLE WORD
003854 4 F 60 305E 41 CVB 6,DBLWD1 CONVERT DBLWD1 TO BINARY
43 *
49 * •
To load binary fullwords and halfwords in registers, we use load operations. The
most common load instructions are L (Load Fullword), LH (Load Halfword), LR (Load
Register), LM (Load Multiple), and LA (Load Address). These do not set the condition
code. The next section gives a number of less-used Load operations: LCR, LNR, LPR,
and LTR.
L R1,X2 or R1,D2(X2,B2)
LH R1.X2 or R1 ,D2(X2,B2)
[symbol] LR R1.R2
LM R1.R3.S2 or R1,R3,D2(B2)
LA R1.X2 or R1,D2(X2,B2)
LOAD FULLWORD—L. The L operation loads a binary fullword value into a reg¬
ister. The rules are:
Figure 9-4 illustrates four L operations, under LOADFULL. The first loads a
fullword literal into register-2. (The Assembler aligns H and F literals the same as
declaratives.) The second example loads the fullword FULWRD1 into register-8. The
third depicts a coding error: operand-2 is a halfword literal rather than a fullword.
(The Assembler does not generate an error message, even if the literal is not a
fullword. The error occurs at execute-time, when the computer loads the halfword
193 Loading Registers—L, LH, LR, LM, LA
plus the following two bytes.) The fourth example loads a literal address constant into
register-5.
Figure 9-4 depicts LH under LOADHALF. The first example loads a halfword
literal into register-9. The second loads a halfword constant into register-0. The third
example illustrates a coding error: operand-2 is a fullword rather than a halfword.
Again the Assembler does not generate an error message. At execute-time LH loads
only the leftmost two bytes of the fullword into register-8, causing an error that may
be difficult to locate.
LOAD MULTIPLE—LM. LM can load more than one register in one operation. LM
is an RS-format instruction, with three operands. The rules are:
1. Operands 1 and 2 each specify a register. They represent a span of registers. That
is, 8,10 means registers 8 through 10, or 8, 9, and 10.
2. Operand-3 references a fullword address in storage, the first of a number of
adjacent fullword values—one for each register that LM is to load successively
into the designated registers.
Figure 9-4 illustrates LM under LOADMULT. The first example loads registers
6, 7, and 8 with FULWRD1, FULWRD2, and FULWRD3 respectively. The second
example shows how the registers may “wrap around". Because registers 15 through
1 are referenced, LM loads registers 15, 0, and 1 with the fullwords.
LM has two common uses. One is to restore registers that were saved when the
program links to a subprogram (covered in Chapter 15). The other use is in base
register initialization. We have used BALR to initialize the first base register. LM may
load subsequent registers with base addresses, although LM is restricted to sequential
register loading. Figure 9-2 gave an example of the use of LM to load base registers 4,
5, and 6. But watch out—after the BALR only base register-3 is initialized, and the LM
will execute correctly only if the constant ADDRESS5 is defined within the first 4K of
the program.
194 REGISTERS AND BINARY PROGRAMMING
55 £ -
56 * L LOAD FULLW0RD DECIMAL
57 * - REG: VALUE
003870 5820 3 1A 6 58 L0ADFUIL L 2 » =F *123456* 2: 123456
003874 5880 309A 59 L 8.FULWRD1 8: 6936
003878 5810 3 1AE 60 L 1 ,=H*287* ERROR: OP-2 SHOULD RE FULLW0RD
00387C 5850 31 AA 61 L 5 * = A(TABL E) 5: ADDRESS OF TABLE
63 A —-
64 « LH LOAD HALFWORD
65 * -
003880 4890 31 B0 66 L0ADHALF LH 9,=H * 500* 9: 0500
003884 4800 3098 67 LH 0 t HAL FWRD1 0: 0595
003888 4880 309 A 68 LH 8,FUL WRD1 ERROR: OP-2 SHOULD BE HALFWORD
70 *
71 * LR LOAD REGISTER
72 *
00388C 5880 309 E 73 LOADREG L 8 >FULWRD2 8 : 7+174
003890 1878 74 LR 7,8 7: 4174
76 *
77 * LM LOAD MULTIPLE
78 *
79 LOADMULT LM 6,8,FULWRD1 6: 6936 7: 4174
003892 9868 309 A 8: 5637
80 LM 15,1,FUL WRD1 15: 6936 0: 4174
003896 9 8 F1 309A 1: 5637
00389A 0253 82 HALFWRD1 DC H * 59 5 '
00389C 00001B1R 83 FULWRD1 DC F *6936*
00 3 8AO 0000104E 84 FULWRD2 DC F *4174*
0038A4 00001605 85 FULWRD3 DC F *5637'
0038A8 86 TABLE DS 50CL5
0039A8 87 L TORG
00 39 A 8 0001E 240 88 = F'123456 *
0039 AC 00 00 38A 8 89 = A(TABLE )
0039B0 011 F 90 = H’2 87 '
0039B2 01 F4 91 =H* 500'
41 90 36 60
(a) (B) ©
©
(a) The machine language code for LA is X'41'.
(B) The operand-1 register is 9.
(c) There is no index register signified.
(§) The base register is 3 and displacement is 660.
The instruction adds the contents of the base register (X'4200') plus the displace¬
ment (X 0660 ). The sum X'004860', the address of A10, is loaded into register-9.
2. LA 9,5(0,0): This example illustrates explicit use of base/displacement. (The next
chapter covers this practice more fully.) The object code instruction
is 141 | 90 | 00 | 05 | —assume no base register, no index register, but load the
displacement X'005'into register-9. In effect, the value 5 loads into register-9.
Note: The 5 is a displacement, not a register.
3. LA 9,5: The Assembler treats operand-2 as if it were coded like example-2:5(0,0).
This is a convenient way to load a value into a register, up to a maximum
displacement of 4095.
4. LA 9,1 (0,9): The generated object code is | 41 | 90 1 90 1 01 —load the con¬
tents of "base" register-9 plus a displacement of 001 into register-9. In effect, the
contents of register-9 are incremented by 1. This method of adding to a register,
although efficient, works only for increments up to 4095 (the maximum displace¬
ment), and only if the value in the register is positive and does not exceed 24
bits (because LA clears bits 0-7 to zero).
Figure 9-5 illustrates an efficient way to load additional base registers by means
of the index register feature. The program is assumed to load at X'4800'. BALR loads
register-3 with X'4802'. We now want to load registers 4, 5, and 6 with each base
address successively containing X'5802', X'6802' and X'7802'. We first load 2048 or
X'0800' into register-6. We then load register-4 with:
004800 2
3 *
START X'4800'
REG-3 REG-4 REG-5 REG-6
004800
004802
004802
0530
4160 0800
68
4 *
5
7
BALR
USING
LA
3,0
*,3,4,5,6
6,2048
4802
4802 0800
10
004806 4146 3800 LA 4,2048(6,3) 4802 5802 0800
00480 A 4156 4800 9 LA 5,2048(6,4) 4802 5802 6802 0800
00480E 4166 5800 LA 6,2048(6,5) 4802 5802 6802 7802
(In hex, 800 + 800 = 1000.) Check the generated object code for each LA operation.
Registers 5 and 6 are loaded accordingly.
Note: LA is a "logical" instruction (like MVC and CLC) that treats data
as unsigned.
OTHER LOAD OPERATIONS—LCR, LNR, LPR, LTR. There may be occasional use
for these load register (RR) instructions. Each sets the condition code.
LOAD COMPLEMENT—LCR. LCR loads the contents of the operand-2 register (R2)
into the operand-! register (R1), and reverses the sign.
LCR 5,8 Load the contents of register-8 into register-5, reverse the sign, and set
the condition code.
LOAD NEGATIVE—LNR. LNR loads the contents of R2 into R1 and sets the value
to negative. The condition code is set to 0 (zero) or 1 (nonzero minus).
LNR 5,5 Load the contents of register-5 into register-5, force a negative sign, and
set the condition code.
LOAD POSITIVE—LPR. LPR loads the contents of R2 into R1 and sets the value to
positive. The condition code is set to 0 (zero) or 2 (nonzero plus).
LPR 9,7 Load the contents of register-7 into register-9, force a positive sign, and
set the condition code.
LOAD AND TEST—LTR. LTR loads the contents of R2 into R1, just as LR, but in
addition sets the condition code for zero, minus, and plus.
LTR 4,4 Load the contents of register-4 into register-4 and set the condition
code. This example sets the condition code only, a useful technique to
test a register's contents for sign.
We use store operations to store or "save" the contents of registers. A large program
may require the use of many registers for base addressing, binary calculations, sub¬
routines, and input/output operations. It is necessary then to save the contents of
registers, use them for other purposes, and then use L or LM to reload them
The Store operations, ST, STH, and STM, are effectively the reverse of L, LH,
and LM, respectively. They store the contents of registers in storage, on fullword or
halfword boundaries. Note that like CVD, these store instructions move the contents
of operand-1 (a register) to operand-2 (storage).
STORE—ST. ST stores the contents of the operand-1 register (R1) into the fullword
in storage referenced by operand-2. The fullword should be aligned on a fullword
boundary.
101100102
0039BC 00002103 98 DC F • 8451'
0039 CO 99 SAVEFULL OS F
0039C4 SAVEHALF OS H
0039 C 8 THREEFW OS 3F
FIVEFW OS 5F
003904
0039E8 9846 3 IB2 103 LM 4,6,FULLA REGS 4,5,6 : 1653, 312, 8451
105 *
106 * ST STORE FULLWORD
107 *
0039EC 5050 31BE
1111112
108 ST0RE1
10
ST 5 , SAVEFULL SAVEFULL : 312
115
*
*
ST0RE2
*
STH
STH 6
STORE HALFWORD
fullwords labelled THREEFW. The second STM stores the contents of registers 1 5, 0,
1, 2, and 3 in five fullwords labelled FIVEFW.
The following instructions perform binary addition and subtraction in registers. These
operations all treat the leftmost sign bit as a plus or minus sign, not data.
A R1.X2 or R1,D2(X2,B2)
S R1.X2 or R1,D2(X2,B2)
AH R1.X2 or R1,D2(X2,B2)
[symbol) SH R1.X2 or R1,D2(X2,B2)
AR R1,R2
SR R1.R2
For valid results, all data must be in binary format. These instructions all set the
condition code (to zero, minus, or plus), which the usual BC operation may interro¬
gate.
7
8 4 A ADD FULLWORD DECIMAL
9 4 S SUBTRACT FULLWORD VALUE :
10 4
003002 5850 4 02 A 11 ADDFULL L 5 , FWD1 REG-5: 125
003006 5A 50 402E 12 A 5,FWD2 REG-5: 195
00300A 5B50 4046 13 S 5,=F'50' REG-5: 145
15 4
16 4 AH ADD HALFWORD
17 4 SH SUBTRACT HALFWORD
18 4
00300E 5880 402A 19 ADDHALF L 8,FWD1 REG-8: 125
003012 4 A 8 0 4 04 A 20 AH 8,=H'50’ REG-8 : 175
003016 4 B 80 404C 21 SH 8, = H'25 ' REG-8: 150
23 4
24 4 AR ADD REGISTER
25 4 SR SUBTRACT REGISTER
26 4
00301 A 4F10 4036 27 ADDREG CVB 1rDBPKl REG-1: 250
00301E 4F00 403F 28 CVB 0»DBPK2 REG-0: 075
003022 1A0 1 29 AR 0,1 REG-0: 325
003024 1B 11 30 SR 1,1 REG-1: 000
003026 4E00 4036 31 CVD O.DBPKl CONVERT 325 TO PACKED
00302 A 0000
00302C 00000070 33 FWD1 DC F' 125' BINARY FULLWORD
003030 00000046 34 FWD2 DC F ' 70' BINARY FULLWORD
003038 35 DS OD FORCE DOUBLEWORD ALIGN
003038 000000000000250C 36 DBPK1 DC PL 8'2 50 ' PACKED VALUE
003040 000000000000075C 37 DBPK2 DC PL8'075' PACKED VALUE
003048 38 LT0RG
003048 00000032 39 =F'50'
00304C 0032 40 =H’50'
00304E 0019 41 = H'2 5'
containing 125 (in decimal notation) is loaded into register-5. Afullword containing
70 is added, and a fullword literal containing 50 is subtracted. Although notation is in
decimal format for ease of reading, the fields and registers actually contain binary
values.
In ADDHALF, a fullword is loaded into register-8, a halfword is added, and a
halfword is subtracted. In ADDREG, two packed fields are defined as doublewords.
DS 0D forces alignment on a doubleword boundary. The packed values are con¬
verted to binary in registers 0 and 1. (These registers should be used only for tempor¬
ary calculations.) AR adds the contents of register-1 to register-0. Then SR clears
register-1, and CVD converts the contents of register-0 to packed format.
These operations compare binary data, just as CLC compares character data, and CP
compares packed data. Each of these operations algebraically compares the contents
of operand-1 to operand-2, and sets the condition code (to equal, low, or high).
200 REGISTERS AND BINARY PROGRAMMING
C R1.X2 or R1,D2(X2,B2)
1 symbol! CH R1.X2 or R1,D2(X2,B2)
CR R1.R2
Figure 9-8 illustrates compare operations. Note how each sets the condition
code. COMP1 loads a fullword FWD3 into register-6. C then compares register-6 to
the contents of FWD4 in storage. COMP2 loads a halfword HWD1 into register-7
and compares its contents to HWD2, another halfword in storage. COMP3 loads
FWD3 into register-8 and a fullword literal into register-9. Then CR compares reg¬
isters 8 and 9.
46 *
66
47 * c COMPARE FULLWORD DATA C0ND'N
48 * CODE :
003050 5860 406A 49 COMP 1 L ,FWD3 _
003054 5960 406E 50 C ,F W D4 1250 < 2575 LOW
52 *
53 * CH COMPARE HALFWORD
54 *
003058 4870 4072 55 C0MP2 LH 7,HWD 1
00305C 4970 4074 56 CH 7,HWD2 365 > 215 HIGH
58 *
59 * CR COMPARE REGISTERS
60 *
003060 5880 406A 61 C0MP3 L 8 » FWD3
003064 5890 4076 62 L 9,=F'975'
00306A
00306C
003070
0000
003068 1989
00000
000004 E?
A0 F
63
6668
65 FWD3
FWD4
CR
DC
8,9
F'1250
1250 > 975 HIGH
DC F'2575
003074 016D 67 HWD 1 DC H'36 5'
003076 00D7 HW02 DC H'215 '
003078 69 LT0RG
003078 000003C F 70 =F•975
MULTIPLICATION—M, MH, MR
M, MH, and MR multiply fields in binary format. They do not set the condition code.
M R1.X2 or R1,D2(X2,B2)
[symbol] MH R1.X2 or R1 ,D2(X2,B2)
MR R1 ,R2
Certain binary operations require a pair of registers to express values greater than
231-1- A double register permits values up to 263-1. The registers are an even-odd
numbered pair, such as 4 and 5, or 8 and 9, with the sign bit in the leftmost bit of the
even register.
Both M and MR require an even-odd pair of registers. We load the multiplicand
into the odd-numbered register. The product is developed in the pair of registers,
with one sign bit and 63 data bits. For most multiplication operations, the product
never exceeds 231 — 1 or 2,147,483,647.* Therefore only one register (the odd one) is
sufficient to contain the product. In this case, the leftmost bit of the odd register
contains the correct sign, the same as that of the even register. Provided we are sure
the product cannot exceed 231-1, we may treat the value in the odd register as the
correct signed product.
1. Operand-1, the mutiplicand, specifies any register, not necessarily an even one.
The mutiplicand is assumed to be 31 data bits.
*When we compute averages and ratios, a value such as 21,474.83647 may be easily
exceeded. Ensure that such a value is not exceeded regardless of the decimal position
(see Double-precision in a later section).
202 REGISTERS AND BINARY PROGRAMMING
74 * REG: REG:
75 *
76 M MULTIPLY FULLWORD
77
00307C 5850 4 09 E 78 MUL T 1 L 5,MULTCAND 5 : 03333
003080 5C40 40A2
8
79
1 *
82 *
M
MH
4,MULTPLER
MULTIPLY HALFWORD
4: 00000 5: 66660
83 *
003084 5870 409 E 84 MULT2 L 7,MULTCAND 7: 03333
003088 4C70 4 0A 6 85 MH 7,MULTHALF 7: 09999
89 *
90 MULT3
MR MULTIPLY REGISTER
88
L 3,MULTPLER 3: 00020
003090 5890 409E 91 L 9,MULTCAND
003094 9: 03333
88,8
1C83 92 MR 8,3 : 00000 9 : 66660
003096 5880 40 A 2 94 MUL T 4 L
8
, MULTPLER : 00020
00309A 5890 4 09 E 95 L 9, MULTCAND 9: 03333
00309E 1C 88 96 MR
: 00000 9: 66660
0030A0 00000005
0030A4 00000014
0030A8 000 3 100
98
99
MULTCAND DC
multpler DC
MULTHALF DC
F'3333*
F • 20'
H' 3'
register-8. In spite, of its appearance, MR 8,8 does not mean multiply the contents
of register-8 and register-8. Operand-1 refers to the multiplicand in the odd register
(9) of an even-odd pair (8 and 9). Operand-2 refers to the multiplier that happens
to be in register-8. It is erased by the multiplication.
Warning: In these examples, the product does not exceed the capacity
of a single register, which is 231 — 1 or 2,147,483,647. If there is a possibil¬
ity of such a large product, then we must provide additional programm¬
ing. The technique is given later in this chapter in Conversion of Double
Precision Binary to Decimal Format.
We can shift binary data in a register either left or right a specified number of bit
positions. This feature, for example, can clear unwanted bit positions from a field, or
multiply or divide a field by a power of two. The following operations shift the bit
contents of registers, other than the leftmost sign bit which is unaffected. Bits shifted
out of the register are lost. The condition code is set.
1. Operand-1 specifies a register whose 31 -bit contents other than the sign bit are to
be shifted to the right. The leftmost sign bit is not moved.
2. Operand-2 denotes the number of bits to be shifted. Normally we code the shift
factor as a decimal number less than 32.
3. Bits shifted off to the right are lost. The sign bit replaces leftmost shifted bits.
There is no overflow or program interrupt.
SHIFT LEFT ALGEBRAIC—SLA. SLA is similar to SRA with the following dif¬
ferences:
1. SLA shifts up to 31 bit positions to the left. The leftmost sign bit is unaffected.
2. SLA replaces rightmost shifted bit positions with 0-bits. For example, shift left
three bits: 00001011 becomes 01011000.
3. A leftmost bit shifted out that is different from the sign bit may cause an overflow
and interrupt.
We may use SLA to multiply the contents of a register by a power of 2. For example,
shifting left three bits is equivalent to multiplying by 23, or 8.
SHIFT LEFT DOUBLE ALGEBRAIC—SLDA. SLDA is similar to SLA except that, like
SRDA, operand-1 specifies the even-numbered register of an even-odd pair. The sign
bit of the pair is that of the even register. The sign bit of the odd register is treated as a
data-bit, giving a 63-bit doubleword.
For each shift operation, if operand-2 contains zero, the instruction executes
without shifting. This use of shift is a convenient way to set the condition code If we
want to vary the number of bits shifted throughout the program, we may use the
xise-displacement facility of operand-2, D(B). For example, register-3 contains the
value 12. Given SRA 9,0(3) the contents of register-9 shift right according to the
contents of register-3, that is 12 bits.
Figure 9-10 illustrates shift operations. Check the hex representation for the
fullword constants, and the effect of the shift. Note that it is the bits that shift For
0100 (X'4-! 3 ary ValUe COntaining 0001 ,X'n is left-shifted two bits, the result is
In SHIFT!, SRA shifts the contents of register-9 two bits to the right. This shift is
equ,valent to divtdmg by four. The second example specifies zero in operand-2 No
sh'ft occcm, u, e value ts positive, the condition code is set to high/plus.
In SHIFT2, SLA shifts the contents of register-7 two bits to the left. This shift is
equivalent to multiplying by four. The second example explicitly uses a base register.
205 Binary Division—D, DR
123 $
HEX CONTENTS:
124 $
125 ❖ SRA SHIFT RIGHT ALGEBRAIC
126 $
0039FC 5890 322A 127 SHIFT 1 L 9 tFULLWD2 00004327
003A00 8A90 0002 128 SRA 9,2 000010C9
003A04 8A90 0000 1 30 SRA 9,0 NO SHIFT. SET COND'N CODE
132 * TO HIGH/PLUS
133 * SLA SHIFT LEFT ALGEBRAIC
134 £
003A08 5870 3256 135 SHIFT2 L 7 , = F117191' 00004327
003A0C 8B70 0002 136 SLA 7,2 00010C9C
003A10 4180 0003 138 LA 8,3 LOAD 3 IN REG 8
003A14 8870 8000 139 SLA 7,0(8) SHIFT REG-7 LEFT 3 BITS
141 £
142 £ SRDA SHIFT RIGHT DOUBLE ALGEBRAIC
143 *
003A18 9867 3226 144 SHIFT3 LM 6,7,FULLWD1 0000013F/00004327
003A 1C 8 E 60 0004 145 SRDA 6,4 00000013/F0000432
147 *
148 $ SLDA SHIFT LEFT DOUBLE ALGEBRAIC
149
003A20 9889 3226 150 SHIFT4 LM 8,9 , FUL LWD1 0000013F/00004327
003A24 8F80 0012 151 SLDA 8,18 04FC0001/0C9C0000
BINARY DIVISION—D, DR
DIVIDE AND DIVIDE REGISTER. Both D and DR, like M and MR, require the use
of a doubleword of 63 bits plus a sign in an even-odd pair of registers. D and DR treat
the pair of registers, all 63 bits, as a dividend field. Possibly, for example, an M or MR
operation generated a two-register product, and it is now necessary to divide this
product by some value. Often, however, the programmer loads the dividend into a
register, and only one register is required to contain the fullword dividend. In this
case, the dividend is in the odd register, but the even register must be initialized so
that it contains the same sign as the dividend. We may force similar signs by the
following practice:
4. The sign of the quotient is determined by normal algebraic rules. The remainder's
sign is the same as the dividend. The condition code is not set, but we can ZAP
the quotient into itself to set it.
Figure 9-11 illustrates the D and DR operations. For D, the even-odd pair is
registers 0 and 1. The binary fullword DIVD is loaded into register-0. Then the
contents of register-0 are shifted into register-1, leaving register-0 correctly ini¬
tialized. The fullword divisor DIVSR divides into the even-odd pair. Register-1 now
contains the quotient, 326, and register-0 contains the remainder, 5.
207 Binary Division—D, DR
158 *
159 D DIVIDE REG : REG : DECIMAL
1 60 £
FORMAT:
003A30 5800 324 A 161 L 0 * DIVD 0: 4 569
003A34 8 E 00 0020 162 SRDA 0,32 0: 0000 1: 4569
003A38 5000 3 24E 163 D 0,DIVSR 0: 0005 1: 0326
1 65 £
166 * DR DIVIDE REGISTER
167 *
003A3C 5 8C0 324E 168 L 12,DI VSR 12 : 0014
003A40 58 AO 32 4A 169 L 10,DIVD 10: 4569
003A44 8EA0 0020 170 SRDA 10,32 10: 0000 11 : 4569
003A48 1 D AC 171 DR 10, 12 10: 0005 11: 0326
003A4A 0000
003A4C 000011D9 173 DI VD DC F'4569' FULLW0RD DIVIDEND
003A50 0000000E 174 DI VSR DC F ' 14 ' FULLW0RD DIVISOR
For DR, the even-odd pair is registers 10 and 11. The divisor and dividend are
loaded respectively into registers 12 and 10. The contents of register-10 are shifted
into register-11, leaving register-10 correctly initialized. DR then divides register-12
into the even-odd pair. Register-11 now contains the quotient, 326, and register-10
contains the remainder.
A binary multiplication may develop a product that exceeds the capacity of one
register (2,147,483,647). The result is a double-precision, or a two-register, product.
This situation requires additional programming in order to convert the result to
decimal format. Consider a situation in which registers 4 and 5 contain only four bits
0011 and 0111. The sign is the leftmost bit of register-4. The decimal value of this
quantity is 32 + 16 + 0 + 4 + 2 + 1 = 55. Converting register-4 to decimal yields
the decimal value 3, instead of 32 + 16 = 48. To correct this value 3, we may
multiply it by a constant value 16, or 3 x 16 = 48. The constant 1 6 is used because
the register” contains four bits, and the maximum value is 24 = 16. (Determine the
constant required if the registers contain 5, 6, or 32 bits.) With register-4 correctly
converted to decimal value 48, we may now process register-5. Conversion of
register-5 to decimal results in the value 7, which when added to 48 yields the
correct answer 55.
Consider another example of a negative value, minus 59. Its bit representation
in two's complement is:
The even register contains the sign, a minus, in the leftmost bit. CVD converts the
contents of the even register to -4. (Depict 4 in binary, reverse the bits, and add 1 to
check that the two's complement of -4 is 1100.) Multiplying -4 by 16 gives -64.
The odd register containing 0101 when converted to decimal yields +5. And -64 +
5 gives the correct answer, -59.
But a problem arises if the odd register contains a 1 in its leftmost bit, because
CVD treats the value as negative. Assume the value in the double-register is +40, or
0010 1000. Converting the even register to decimal yields +2. Multiplying +2 by 16
gives +32. CVD converts the odd register to -8, and the sum of +32 and -8, which
is 24, is incorrect.
We can use LTR to test the leftmost sign bit in the odd register. If there is a 0-bit,
the nonminus condition code is set; the conversion may proceed as already de¬
scribed. If, however, the odd register sign is a 1 -bit, the condition code is minus. The
following procedure produces the correct answer for the same example of 0010 1000:
— The odd register is "minus”. Add 1 to the even register, giving 0011 1000.
— Converting the even register to decimal gives +3. Multiplying +3 by 16 yields
+48.
— Converting the odd register to decimal gives -8. 48 plus -8 gives the correct
answer, 40.
This additional step of testing if the odd register is "minus" and adding 1 to the
even register provides the correct answer in all cases. Note that the incorrect answer
was 24 instead of 40, a difference of 16. But the addition of 1 was equivalent to
incrementing the double-precision value by 24, or 16. Figure 9-13 gives the pro¬
gramming for this procedure, in which multiplication of binary values produces a
two-register product.
8 DS 0D
9 DAT A 1 DC PL 8>0123456 >
10 DATA2 DC PL8>-456789>
11 DBLWD DS D
12 PR0DPK DC PL 16 > 0 1
13 CONSTANT DC P14294967296'
14 * REG-6 HEX REG-7 HEX DECIMAL
The two fields, DATA1 and DATA2, are converted into binary format in reg¬
isters of 6 and 7. When the registers are multiplied, the product exceeds the capacity
of register-7. Since register-7 contains a “minus value", 1 is added to register-6. Regis-
ter-6 is converted to decimal format into PRODPK. The constant now used to multi¬
ply is not 24 but 232, or 4,294,967,296. Register-7 is next converted to decimal format
in DBLWD, and PRODPK is added to it. The final product is correct'
56,393,342,784-.
For some types of loans, finance charges are precomputed; that is, the amount of
interest is precalculated for the term of the loan and added to the amount of the loan.
For example, $500.00 is borrowed for a term of 6 months with precomputed finance
charge of $30.00. The sum of $530.00 is repayable in 6 equal instalments of $88.33.
A borrower who repays the full amount of the balance remaining before the end of
the term is entitled to a partial rebate on the precomputed finance charge. The rebate
can be calculated by the “sum of digits" formula.
r2+r
r2+r
x F
t2+t
2
Example:
t = 6, r = 5, f = $30.00
Figure 9-14 gives the programming that calculates the rebate. The program also
checks for minimum f.nance charge of $10.00. That is, finance charge less rebate
must equal at least $10.00. Example: $30.00 - $21.42 = $8.58. Since $8 58 is
less than $10.00, the rebate is $30.00 - $10.00 = $20.00.
DEBUGGING TIPS
003806 0000
003808 00000006 8 0RIGTERM DC F ' 06 '
00380C 00000005 9 REMGTERM DC F '05'
003810 00000BB8 10 F INCHGE DC F >03000' 030.00
003814 11 REBAT E DS F XXX.XX
12 *
REG: DECIMAL FORMAT:
13 * CALCUL ATE R SQUARED + R
003818 5890 300A 14 CALCREB L 9 »REMGTERM 9: 05
0038 1C 18 79 15 LR 7.9
003 81E 1C69 16 MR 6.9 7: 25
003820 1 A 79 17 AR 7.9 7: 30
— Binary division causes more problems than multiplication because the even reg¬
ister should be initialized with the same sign as the odd one.
— Binary calculations may unexpectedly generate a large value that exceeds the
capacity of one register.
212 REGISTERS AND BINARY PROGRAMMING
PROBLEMS
6 9 8 7 -9
±5 ±4 +(~4)
1 1 13 3 3 -17
9-2. Explain halfword, fullword, and doubleword alignment, and the significance of
alignment on the 360 and the 370.
9-3. Given the following declaratives, explain concisely what each of the following
unrelated operations does. Check for possible coding errors.
BINA DC F’285’
BINB DC F’394’
BINC DS D
In many previous examples, we coded the length explicitly to override the implicit
length of the field, such as: MVC P+30(2),=C'**'. In a similar fashion a base register
may explicitly override the assigned base register. This chapter uses base registers
explicitly to permit the use of such operations as EDMK and COMRG, and to modify
an address for table look-up. We may use a base register explicitly in any operand
that references storage, with a reference to a base register (B1 or B2). Since a base
register contains the address of an area of storage, we may override the program's
normal base register with another register containing an address of some other area.
Figure 10-1 is illustrative only and not intended to be realistic. BALR initializes
register-4 with X'3002'. The examples show three different ways to move a field
(ASTERS) to the print area.
ASSGN1 shows a conventional move operation, with both operands subject im¬
plicitly to base register-4. The assembled object code for operand-1
(PRINT+60), is 4056, or base register-4, displacement X'056'. The effective
address is X'3002' plus X'056', or X'3058'.
ASSGN2 explicitly uses a base register. The address of PRINT+60 (X'3058') is loaded
into register-8. MVC explicitly uses the contents of register-8. Since the format
213
214 EXPLICIT USE OF BASE REGISTERS
1 7 4 EXPLICIT base/displacement:
003012 seao 409A 0309C 1 8 ASSGN3 L 0•=A(PR I NT )
0030 16 0201 803C 4093 0003C 03 09 5 19 MVC 60(2.8).ASTERS
20 4 •
2 1 4 •
22 4 •
00301C 404C404040404040 23 PRINT OC CL 12 1* •
003095 5C5C 24 ASTERS OC C* •
003098 25 LTORG
0 030 9 8 00003058 26 =A(PRINT+60)
00309C 000030 1C 27 =A(PPINT)
FIGURE 10-1 Base register assignment and explicit use of a base register.
for MVC is D1 (L,B1 ),D2(B2), we code the first operand explicitly with zero
displacement, a length of 2, and base register-8, or 0(2,8). The assembled object
code for operand-1 is 8000, or base register-8, displacement zero. The
effective address is X'3058'.
ASSGN3 illustrates both explicit base register and displacement. The address of
PRINT (X'301C) is loaded into register-8. Since the move operation is to refer¬
ence PRINT + 60, we need a displacement of 60. The first operand is expressed
as 60(2,8). The assembled object code for operand-1 is 803C, or base register-8
plus displacement X'03C'. The effective address is X'301C' plus X'03C, or
X'3058'. Note how the Assembler generates the same effective address in each
case:
EDMK is identical to ED except that it inserts into register-1 the address of the
firstsignificantdigit in the edited field. We may then decrement register-1 by one since
the dollar sign must be printed one position to the left. We then use register-1 as an
explicit base register to move a dollar sign.
In Figure 10-2, the editword is moved into P+30, and the address of the X'21' is
P+33. We load the address of P+34 into register-1. After EDMK, register-1 contains
the address of the first significant digit at P+33. Decrementing register-1 causes it to
contain the address of P+32, where MVI inserts the $.
22 *
33 4 EOMK EDIT A MARK
34 4
0 03 0A 0 4 110 4CE2 35 LA 1.P+24 LOAD ADDRESS OF SIGNIFI<
» START CHARACTER +1
0020A4 D206 40 DE 40B6 36 M VC P + 30 <7).EDKORO |40|20|20|21|4B|20|20|
0 0 30 A A OF C 6 400E 4 CBD 37 EDMK P+30(7).AMOUNT |40|40l*0JF3|48|F5|F2l
003060 4e i o 4 1 3E 38 SH 1.=H*I• DECREMENT REG1 (OR BCTR
0030B4 9258 1 000 39 MVI o< i>.c*** |40|40|58|F3|48|F5|F2|
40 4 • *3.52
A l 4 •
42 4 • + P+32
003086 4C202021482020 43 E04QRD oc X*402020214B2020*
0 03 0 BF 00352C 44 AMOUNT oc P* 003.52* ■ILL EDIT AS *3.52
C030C2 4C4C4C4C404C4040 45 P cc CL 12 1* •
Some operations involve explicit use of base registers. These include Assembler
instructions EDMK, SRP, MVCL, and CLCL and IBM macros COMRG and TIME.
THE COMRG AND TIME MACROS. The communication region is a storage area in
the Supervisor. The first eight bytes contain the date as initialized each day by the
216 EXPLICIT USE OF BASE REGISTERS
computer operator. The format for the date, including the slashes, is: dd/mm/yy or
mm/dd/yy.* Although we do not know the address of the communication region,
under DOS we can use COMRG to ask the Supervisor for the address. The Supervisor
places the address of the communications region in register-!. We then can use
register-! explicitly to address the communications region:
The OS macro is called TIME. It returns the date in packed format in register-1,
as /00/YY/DD/DC/. The day (D) is Julian, the day of the year. C is a sign digit. Also,
the time is stored in register-0.
SHIFT AND ROUND PACKED—SRP. The 370 instruction, SRP, permits rounding,
and shifting of packed digits either left or right. SRP can therefore replace MVO and
AP in decimal multiply and divide, and replace MP where used to shift the dividend
to the left.
Although SS-format, SRP has three operands. Operand-1 denotes the field con¬
taining packed data to be shifted and optionally rounded. Operand-2 is a base/
displacement reference that indicates the number of digits to be shifted. The
maximum shift is 31 digits. Operand-3 provides the value 0-9 to be used for round¬
ing. a left shift will normally have a 0 to indicate no rounding, and a right shift usually
rounds with 5. SRP sets the condition code for zero, minus, and plus.
LEFT SHIFT A positive value as the shift factor indicates a left shift. For example
+ 2 means shift left two digits (digits, not bytes). We may load the shift factor in a
*The communications region contains other fields that may be of interest to the ad¬
vanced programmer. See the IBM Supervisor manual for your installation. The 370 also
contains a different area called "input/output communications area.”
217 Operations Explicitly Using Base Registers
register, and then reference the register explicitly with the SRP, as shown by SHIFL2A
in Figure 10-3. More conveniently, we may code the shift factor as an explicit dis¬
placement using base register-0 (that is, no base register), as in SFHIFL2B and
SHIFL2C. Shifting a significant digit (1-9) off the left sets the decimal overflow
condition but does not cause termination, so we can use Branch Overflow to test if a
significant digit was lost.
♦ Hex representation:
AMOUNT oc PL5* 1234567* 00 12 34 56 7C
RIGHT SHIFT. A negative value as the shift factor indicates a right shift. We may
load the negative value into a register and reference the register with the SRP, as
shown by SHIFR2A. Although it is more convenient to code the shift factor as a
displacement rather than load a base register, we cannot code such a right shift as
SRP AMOUNT,-2,5; the Assembler does not accept negative "displacements" [that
is, -2(0) for D2(B2)]. Now, we can solve the problem by representing the -2 as a
hexadecimal value. Since SRP can shift only up to 31 digits, we can express the shift
factor with six bits (5 data bits plus a "sign" bit: 011111 =31). The value 2 as six
binary digits is 00 0010, and -2 in two's complement is 11 1110. The hex repre¬
sentation of this number is X'3E', which we can use directly as a shift factor as in
SHIFR2B in Figure 10-3. Similarly, the decimal equivalent of X'3E' is 62, which we
may code as a shift factor, as shown in SHIFR2C.
Note that other right shifts include: 1 = X'3F' or 63, 3 = X'3D' or 61, and 4 =
X'3C' or 60, up to a shift of 31 digits.
MOVE LONG AND COMPARE LONG—MVCL AND CLCL. Move Long (MVCL)
and Compare Logical Long (CLCL) are available only on the 370. MVCL will move
fields and records that exceed 256 positions. One major use is to clear storage. CLCL
compares fields and records that exceed 256 positions. The instruction has an
additional attribute: if the two fields are unequal, CLCL makes the address of the
unequal byte available.
218 EXPLICIT USE OF BASE REGISTERS
MVCL and CLCL require the use of four registers. Operand-1 and -2 both
reference the even-numbered register of an even-odd pair. The complexity of MVCL
and CLCL rather limits their practical use; see the IBM Principles of Operation
manual for details.
TABLES
Many programs require the use of tables (or arrays) in storage for the following
purposes: (1) To provide additional information, such as the tax rate for an income
tax table; and (2) To provide storage by categories as data is processed, such as
accumulating sales according to inventory number.
A simple example of a table is one that stores the numeric and the alphabetic
month. The numeric month from an input record is used to locate the alphabetic
month in the table, used to print on the report heading. In tabular form, the table
appears as:
01 JANUARY
02FEBRUARY
12DECEMBER
TERMINOLOGY. In the preceding example, the numeric month on the input re¬
cord used to search through the table is called the search argument. Each entry in the
table in storage consists of a table argument (the numeric month against which the
search argument is compared), and a function (the alphabetic month, which is the
item for which we are searching). The function may contain more than one field.
Each table argument in the table is the same length and format, and each function is
the same length and format. The search argument is the same length and format (such
as character or packed) as the table argument. Further, the table arguments normally
are defined in an ascending sequence.
TYPES OF TABLES. There are two common types of tables used in business nro-
grammmg. The preceding table of months consists of discrete entries in which the
T„;-'T8Un'‘-;nl must eXiT*ly eclual ,he sear< h argument. Another example of this type
could be an Inventory table containing Stock numbers as arguments and Stock prices
as functions. Also, a second field in the function could be used to accumulate total
219 Tables
Stock issues by Stock number. The Stock numbers in the table are sequential but not
necessarily consecutive, because not all Stock numbers are used. If the search argu¬
ment does not equal one of the table arguments, then a possible error condition
exists. The table could appear as:
121 5.25
135 3.10
137 4.00 etc ...
The second common type of table consists of table arguments that provide
ranges or segments, such as the sequential steps of taxable income in an income tax
table. In this case, the search argument will fall within one of the segments. The
function is the tax rate for the segment. The table could appear as:
6,000.00 8.0%
8,000.00 etc.... 10.0% etc....
In the table, all taxable income up to $6,000 is taxed at 8.0%, and taxable income
from $6,000.01 through $8,000 is at 10%.
We may define and store tables one of two ways:
1. The table arguments and functions are defined by DC's as constants. This method
is useful when the arguments and functions do not change very often.
2. The area for the table is defined, but the contents of the table, the argument and
function, are read sequentially as data at the start of the program and stored in the
table. This method is useful when the arguments or functions are subject to
frequent change. This method permits changes to the table without reassembling
the program.
1. The Search Argument Is Equal. In this case the required function has been found,
and the search is terminated.
2. The Search Argument Is High. We must continue the search by examining the
next entry in the table.
3. The Search Argument Is Low. The action depends on the type of table. If the table
contains segments such as a tax table, then the required function has been found;
the tax rate is in this step. If, however, the table contains discrete entries (such as
220 EXPLICIT USE OF BASE REGISTERS
nonconsecutive inventory stock numbers), then the required table argument does
not exist. This latter condition is a common situation that must be checked for in
this type of table.
TERMINATION OF THE LOOP. We must ensure that the search can be termi¬
nated. If no provision is made to end the loop, then the program may compare a
very high search argument against all the entries in the table and against the area
following the table. Several means may force termination:
1. We may assign the last table argument with the highest possible value, such as
packed nines for packed fields, and hex F's for character or hex fields. Because
the search argument cannot exceed this value, there will always occur a branch
on equal (found), or low (found or nonexistent argument depending on the type of
table). Figure 10-4 gives an example.
2. If we know the number of entries in the table, the program may count each time it
compares to an entry. When the count exceeds the number of entries, the search
is terminated. Figure 10-5 gives an example.
3. If we know the address of the last table argument, the program can compare the
address being modified against this address. If the modified address exceeds the
address of the last argument, then the table argument does not exist. Figure 10-6
gives an example.
4. If we know the value of the highest table argument, the program may compare the
value of the search argument to this value. If the value of the search argument
exceeds the known value, then the table argument does not exist, and the search
does not have to be performed.
TABLE LOOK-UP WITH HIGH ARGUMENT. Figure 10-4 provides the coding for
the table look-up of the numeric and alphabetic month discussed earlier, explained
as follows:
003112 0501 4090 8000 0 30 CIOLOOP CLC MON IN.0(8) INPUT MONTH : TABLE MONTH?
003 1 18 4780 4126 0 31 BE C20EqUAL * EOUAL - FOUND
00311C 4740 50A4 0 32 BL RIOINV • LOW - NOT IN TABLE
003120 4A8C 42A6 33 AH 8,=H*11* INCREMENT BY 11 FOR NEXT ENTRY
003124 47FC 4110 0 34 B ClOLOOP * IN THE TABLE
003128 0208 40F6 8002 0 36 C20EQUAL M VC PRINT*100(9),2(8) MOVE ALPHABETIC MONTH TO PRINT
TABLE LOOK-UP USING A COUNT: BCT, BCTR, BXLE, BXH. Th is section exam¬
ines two ways of performing a table search using the techniques for loop termination
described earlier. The following instructions may be used to decrement a count and
to test termination of a loop. The condition code is not changed.
Figure 10-5 depicts a table search using two registers and BCT. The search
argument is a 3-character field called JOBNO. The table, called JOBTABLE contains
60 5-byte entries, a 3-character Job number as the table argument, and' a 2-byte
00312E
4 1 JOENO OS CL3
003131 JOB NUMBER - SEARCH ARGUMENT
42 RATE OS PL 2
RATE FOR STORING FOUND FUNCTION
00325F 0C
003260 4160 4131 52 LA 6,JOBTABLE
003264 4190 003C LOAO AOORESS OF JOB TABLE
S 3 LA 9,60 LOAD NO. OF ENTRIES
003268 D5 02 412C 6000 55 K10LOOP CLC JOBNO.0<6)
00326E 4780 427C INPUT JOB* 1 TABLE JOB* ?
56 BE
003272 4160 6005 K20EQUAL * EQUAL - FOUND
57 LA 6.510.6) INCREMENT BY 5 FOR NEXT ENTRY
003276 4690 4266
58 BCT 9.K10L00P
0 032 7 A 47F0 50A4 DECR REG 9 BY 1. NOT ZER07 - LOCP
59 B R10INV
* ZERO? - NOT IN TABLE. ERROR
00327E F611 412F 6003
61 K20ECUAL ZAP RATE.3(2,6)
STORE RATE from TABLE
packed rate as the function. The function when found is to be stored in a field called
RATE. The example loads the number of entries in the table, 60, into a register. BCT is
used to decrement this count. If the loop is performed 60 times, the count is reduced
to zero, and the required argument is known to be not in the table. An advantage of
this approach is that Job numbers need not be in ascending sequence, so that the
most commonly referenced Job numbers could be first in the table.
Note: If the register in operand-2 is odd rather than even, the compari¬
son is made to the operand-2 odd register rather than to the next register.
Therefore, the operand-2 register is both the increment (decrement), and
the limit.
Figure 10-6 illustrates a table search using three registers and the BXLE instruc¬
tion. The table, JOBTABLE, is defined in Figure 10-5. This example loads the length
of each entry (5) and the address of the last entry into the even-odd registers, 8 and 9.
BXLE increments the address of base register-6 by the constant 5 in register-8. If the
base register exceeds the address of the last entry, the program has stepped through
the table without locating the required argument.
66 ♦
67 ♦ 8XLE BRANCH CN INDEX LOW OR EQUAL
ee *
69 LA 6.J0BTA8LE LOAD ADDRESS OF JOB TAeLE
70 LA 8.5 LOAD LENGTH OF EACH ENTRY
71 LA 9.J0BTABL£+59*5 L0AC AODRESS OF LAST ENTRY
SUMMARY. The preceding examples give some of the common methods of ter¬
minating a table search. The commonest and simplest method is to define the last
table argument with a high value, such as hex F's for character and nines for packed
format. The methods using BCT and BXLE are efficient if enough registers are avail¬
able. We should use whatever method is efficient and clearly understood.
Table arguments are normally arranged sequentially, but are not necessarily con¬
secutive. Consider a table composed of discrete arguments, such as Job numbers or
inventory Stock numbers. If the table is both sequential and consecutive, such as
I D, I i ,1 z, then we do not require table arguments or a table look-up. To locate
he required function, we can by direct table addressing calculate its reladve por¬
tion m the table For example, the function for Stock item 0010 would be the tenth
entry m the table. Direct table addressing is an extremely efficient way of locating
functions, because no repetitive looping and comparing are required Y §
Refer to the table of numeric and alphabetic months in Figure 10-4 The table
contains arguments of numeric months from 01 through 12 that are both sequential
tThl C°"fCUtlVe- AFl§ure 10-7 omits the arguments and finds the function by direct
e addressing. Assume that the search argument, MONIN, contains 04 for Aoril
The month is tested and found valid. It is converted into a register aTd decremented
Note: We must ensure that the search argument is valid. For example if
the search argument is incorrectly punched as 14, then the program will
calculate an address that is outside the bounds of the table.
225 Direct Table Addressing
The function is located by the formula: A(F) = A(T) + [(SA-N)x L], In the example
program, A(T) = X'4000', L = 9, and N = 01 (for January). Given search arguments of
respectively 01, 02, and 12, the calculation of A(F) is as follows:
Check the logic of the formula and the calculations of A(F) against the table in Figure
10-7.
226 EXPLICIT USE OF BASE REGISTERS
This routine works as follows: Function-1 (the first rate of pay) is compared
against function-2. If function-1 is higher, the two entries are exchanged. Function-1
is next compared against function-3. If function-1 is higher, they are exchanged.
Function-1 is compared successively against each other function, until eventually
the lowest entry is stored in entry-1. Function-2 is then compared against function-3,
function-4, etc., until the second lowest entry is stored in entry-2. The remaining
functions are compared against the higher functions as in the preceding steps, ex¬
changing entries where necessary. Once the next-to-last function compares to the
last function, the sort is ended.
BINARY SEARCH
For long tables that do not lend themselves to direct addressing, it is often more
efficient to use a binary search rather than a regular sequential table look-up. The
search uses an approach of successive halving. It starts at the midpoint of the table—
if the search argument is higher than the mid entry, we compare to the midpoint of
the upper half of the table; if lower than the mid entry, we compare to the midpoint
of the lower half. The search continues in this fashion until the argument is found or
determined as not in the table. The following routine uses the same table as in Figure
10-8, the sort.
Note that COUNT initially contains a value of one more than the number of
arguments in JOBTABLE (i.e., if JOBTABLE has 50 arguments, then COUNT contains
51). The routine initializes register-6 with 1 for the low entry-point, and loads
COUNT in register-10 for the initial high entry-point. It uses these two values to
calculate the midpoint (initially [1 +51] -e 2 would give entry 26 as the middle).
Since the length of each entry is five bytes, the routine multiplies this midpoint value
by 5 to calculate a displacement, and adds the starting address of JOBTABLE (actually
JOBTABLE-5) for the direct address of the midpoint. Use JOBTABLE as defined in
Figure 10-8 with five arguments, and work through the binary search routine in
Figure 10-9 to locate each of the five arguments.
The flowchart in Figure 10-10 and the program in Figure 10-11 illustrate the use of
subroutines and many features in the last two chapters. The objective is to calculate
the cost of inventory Stock on hand. There is one type of input record containing:
The program reads each input record and checks sequence on Branch/Stock number:
228 EXPLICIT USE OF BASE REGISTERS
REGISTER USAGE ;
5 FOR CALCULATION OF THE TABLE AODRESS.
6 LOW ENTRY NUMBER for the TABLE. INITIALIZED TO 1.
a MID-POINT NUMBER
FOR THE TABLE.
9 FOR CALCULATION OF THE TABLE DISPLACEMENT.
10 HIGH ENTRY NO. FOR TABLE. INITIALIZED WITH NO. OF ENTRIES +■
The program prints totals of cost by Stock number (minor), Branch number
(intermediate), and final total (major). It is organized as follows:
Initialization Section initializes the base register, opens the reader and print files and
sets the line counter to a high value to force an initial page overflow.
Main Logic Section reads input records and sequence-checks by Branch/Stock
totals*1"' AUheend of file' A40END'the Program prints Stock, Branch, and Final
Process Receipts Subroutine, E10RECT, adds the quantity received to Stock quantity.
Cost Calculation Subroutine, CIOCALC, is performed for a new Stock number and
229 Sample Program—Calculate Stock Value
Branch totals
Process receipt subroutine
subroutine
PROGIO START 0
SAVE <14,121
e ALR 3.0 INITIALIZE BASE REGISTER
USING 4.3
ST 13.SAVEAREA+4
LA 13.SAVEAREA
OPEN (FILE IN.< INPUT)•PRTR,(OUTPUT))
LH 10, = H # 55• SET LINE COUNT PAST MAXIMUM
e al 9,P1 OPAGE PRINT HEAO ING FOR PAGE I
4 MAIN LOGIC
4
A10READ GET FILEIN,INAREA
CLC CTLIN.PREVCTL NEK BRANCH/STOCK J PREVIOUS?
BE A30EQ 4 EQUAL - PROCESS RECEIPT
BL R10SEC 4 LOK - OUT-OF-SEQUENCE
*
4 HIGH - NEK STOCK NO.
CL I PREVCTL.X*00• FIRST RECORD OF FILE?
BE A30EQ 4 YES - PROCESS RECORO
E AL 9,P1 OPAGE CHECK FOR PAGE OVERFLOK
eAL 9.G10CALC CALC. A PRINT UNIT COST
ENO-OF-FILE
FIGURE 10-11
230
MVC 0ESCRIPR.7I2)
MOVE DESCRIPTION (FROM TABLE)
HVC STOCKPR .PREVSTK
* STOCK NO.
PVC BRANPR.PREVBR * BRANCH NO.
eAL 11.M10WSP1
PRINT STOCK INFORMATION
AP BRCOSTPK .COSTPKDW+4(4) ADD COST TO BRANCH TOTAL
ZAP CTYPKDW.=P*o• CLEAR STOCK QUANTITY
BR 9
RETURN
231
4 ERROR ROUTINES
*
RIOSEQ MVC P+41IL*ERRSEO),ERRSEQ OUT OF SEQUENCE BRANCH-STOCK
B RBO
* DECLARATIVES
* _
SAVEAREA DS
REGISTER SAVE AREA
DS
00 PACKED - ALIGNED 00U8LEK0RD:
CCSTPKDW DC PL8 # 0 • *
QTYPKD4 DC PL8• 0 • *
qtypk DC PL2•0•
NORMAL PACKED DECLARES:
BRCOSTPK DC PL4 • 0 • *
FINCOSPK DC PL 4*0* 4
PAGEPK DC PL 2 • 1 • 4
PREVCTL DS 0CL6
PREVIOUS CONTROL WORD
PREVSR DC XL 2 • 0 0 •
* BRANCH NO.
PREVSTK DC XL4•00•
* STOCK NO.
E DCCS DC
X*40202068202021482020C309*.C*44*
EDUNIT DC X*402020214B2020*
EDQTY DC X*402020202020C309*
edpage CC X * 40202020•
4
STOCK table:
COSTABLE DC C* 1234*.P*0 01.0 0* .C•GIDGET S• STOCK NO.. COST. DESCR * N
DC C•24$8* .P* 015.25* *C* 4I0GETS* 4
DC C * 24 70•*P•100.17*.C*MIDGETS* 4
DC
C*2844*,P*020.00*,C*FIDGETS* 4
OC 4X*FF* »PL3*0*,C*INVALID*
* end of table
INAREA DS 0CL80
INPUT RECORD:
CODE IN DS CL2
01-02 RECORD CODE
CTLIN DS 0 CL 6
branchin DS BRANCH/STOCK CONTROL MORD
CL2
03-04 BRANCH
STOCKIN OS CL 4
05-08 STOCK NO.
DS CL2
09-10 UNUSED
QTYRECIN DS ZL3
11-13 QUANTITY
DS CL6 7
14-80 UNUSED
232
PRHEADl DS 0CL133
heaoing-i area:
DC CL29* • *
DC CL 104*1 N V E N T 0
RY UNIT COST REPORT
BLANK DC C • •
BLANK FOR CLEARING PRINT AREA
PRINT DS OCL133
REPORT PRINT AREA
P DS CLO 1 ♦
DC CL I6• • ♦
BPANPR DS CL 0 2
♦ BRANCH NO*
CC CL03• • *
STQCKPR OS CL 04
♦ STOCK NO.
DC CL02* • *
OESCRIPR OS CLOT
* DESCRIPTION
DC CLC 9• • *
qttpr DS ZLca * QUANTITY
DC CLOI• • ♦
UNCGSPR DS ZL07
♦ UNIT COST
DC CL01* • *
COSTPR DS ZL 12 * cost
OC CL60* • ♦
END PROG 10
R Y UNI T
for end-of-file. The routine includes a table look-up, binary multiplication, and
printing of the Stock detail line. It also adds Stock cost to Branch cost.
Branch Total Subroutine, HIOBRNCH, is performed on a change of Branch and at
the end-of-file. It prints Branch cost and adds to Final cost.
Final Total Subroutine, IIOFINAL, performed at the end-of-file, prints total Final cost.
Page Heading Subroutine, PIOPACE, is performed at the start of the program and
whenever the end of a page is reached.
Error Routines process out-of-sequence records and Stock items not in the table.
Register Usage:
DEBUGGING TIPS
Among the many common errors that programmers tend to make when using tables
are the following:
There are arguments missing from the table, or the functions are incorrect.
Argument/function also may not be consistently the same length.
— The increment value for stepping through the table is incorrect.
— There is no way to ensure termination of the search, so that a CLC, for example
may continue frantically checking right through main storage.
— The branch instruction that returns to perform the next compare goes instead to
the preceding instruction that initializes the search:
W30SRCH LA 9,TABLE
CLC
B W30SRCH
This chapter completes comments on debugging. At this point you are far
enough advanced and your programs so complex that your best debugging aids are
carefulness, detective skills, hex storage dumps, and access to an experienced svs
terns programmer. wpenencea sys-
235 Problems
PROBLEMS
TOTAL DS PL5
AMOUNT DS PL4
LA 8,TOTAL
LA 9, AMOUNT
AP 6(5,8),0(4,9)
10-3. Provide the code to extract today's date from your computer system. Assume
any necessary declaratives.
10-4. What are the various ways an Assembler program may use to force termina¬
tion of a table look-up? What may be the result if some provision is not made
to force termination if the argument is (a) packed; or (b) character?
10-5. Assume that register-4 is initialized to zero in each case. Given declaratives
BIN1 and BIN2, explain the code and determine the contents of register-4 in
each case.
(a) (b)
BIN1 DC F‘20’ L 6, BIN 1 LA 5,100
BIN2 DC F‘200’ A15 A 4, = F‘2’ LM 8,9,BIN1
BCT 6,A15 B15 A 4,=F‘3’
BXLE 5,8,B15
LA 6,W30
LA 5,10
BCTR 5,6
10-7. Define the table required to calculate the current federal income tax. Use a
field called TAXINC for taxable income to locate the required rate. Calculate
TAX based on this rate.
10-8. Direct table addressing. Assume a payroll table, with consecutive job num¬
bers from 031 through 055. Each job number has an associated rate-of-pay
(xx.xx) as the function. The following declaratives are given:
JOBNO DS CL3
HOURS DS P’00.0’
WAGES DS P’0000.00’
Code the declaratives for the payroll rate table, called JOBTAB. Write the
routine to use JOBNO to locate the correct rate in the table. Multiply HOURS
by the rate, round the result to two decimals, and store it in WAGES.
10-9. CUSTOMER BILLING FOR ELECTRIC CONSUMPTION.
236 EXPLICIT USE OF BASE REGISTERS
Procedure:
— Check for valid record codes, and sequence-check the file according to
region-customer number. Within a region, customer numbers are in as¬
cending sequence. Each customer has one billing master card (31) fol¬
lowed by one consumption card (32).
— Calculate electric consumption in kilowatt-hours = present reading -
previous reading and calculate the billing amount based on the electric
billing schedule for your community.
— Print the detail for each customer, and print total consumption and billing
amount for each region and for the final total.
— Use subroutines extensively.
CHAPTER 11
Certain logical operations, such as CLC, CLI, MVC, and LA treat data as "logical”.
The operations assume that the fields contain no sign, and act nonalgebraically on
each byte as a string of eight bits. Similarly, certain binary operations process binary
data as logical by treating all 32 bits of the binary fullword as unsigned data. The first
section discusses the logical operations that add, subtract, compare, and shift. These
instructions are useful if arithmetic fields are of such magnitude that they require
double precision, a 63-bit field plus a sign bit. Such a field requires two registers: the
left one contains the sign and the leftmost 31 data bits; the right register contains the
rightmost 32 data bits.
Of greater use are the other logical operations: Test Under Mask, Translate, and
Translate and Test. Although technically a branch operation, Execute is also in¬
cluded. These instructions provide a repertoire of powerful techniques to manipulate
bits, to translate bits to other codes, and to handle variable length records. Logical
operations are also used to translate binary (fixed-point) to floating-point format.
LOGICAL OPERATIONS
ADD AND SUBTRACT LOGICAL—AL, ALR, SL, SLR. These instructions treat bi¬
nary fields as unsigned logical data.
237
238 LOGICAL OPERATIONS AND BIT MANIPULATION
AL R1 ,X2 or R1,D2(X2,B2)
[symboll ALR R1 ,R2
SL R1,X2 or R1,D2(X2,B2)
SLR R1 ,R2
AL, ALR, SL, and SLR are similar to A, AR, S, and SR, with the following
differences: (1) Since the field is treated as logical data there is no sign; all 32 bits are
added or subtracted; (2) There may be a carry out of the leftmost bit (bit 0). For
subtract, if the carry out of bit 0 differs from bit 1, an overflow occurs; (3) The
condition code is set as follows:
DOUBLE PRECISION ADDITION. Double precision binary fields contain a sign bit
and 63 data bits. We must give such fields special programming consideration,
because a register can handle only 32 bits.
Assume two 64-bit fields, called DBL1 and DBL2, are to be added, and the
result stored in DBL1. Figure 11-1 gives the coding. It is necessary to split each field
into two 32-bit fields. DBL1 is loaded into register-6 (the leftmost 32 bits) and
register-7 (the rightmost 32 bits). The sign is the left bit of register-6. The rightmost 32
bits of DBL2 are added to register-7. We use a logical add because register-7 has no
sign bit. If an overflow occurs, a bit has been lost; adding 'V to register-6 remedies
this situation. Then the leftmost 32 bits of DBL2 are added to register-6. The example
shows two 5-bit registers for ease of understanding. Check the binary values for each
step.
6 * REG-6: REG-7
7 DBL1 os 0 00 101 110 10 ASSUME 10-BIT FI ELC 186
8 DBL2 DS 0 0001 1 10110 ASSUME 10-BIT FIELD 11 8
These instructions are similar to C and CR. However, CL and CLR compare logically
all 32 bits from left to right regardless of sign. An unequal compare terminates the
operation. The usual condition code is set: Equal (0), Low (1), High (2).
SHIFT LOGICAL—SRL, SLL, SRDL, SLDL. These instructions shift bits right or left
logically regardless of sign, and treat the entire 32 or 64 bits as a single unsigned
field. Operand-1 of SRDL and SLDL references the even register of an even-odd pair.
The rules for SRL, SLL, SRDL, and SLDL are similar to those for SRA, SLA,
SRDA, and SLDA except that: (1) All 32 or 64 bits shift; (2) Zero bits replace bits
shifted off the left or right; (3) The condition code is not set and no overflow occurs.
only a 1 -bit field: 0 for domestic or 1 for commercial rate. Service Code can contain
4 possibilities requiring two bits:
Character format requires 10 bytes to store the data. Binary format requires only
30 bits or one fullword of 4 bytes. If there are 400,000 records kept on a disk or tape
file, then we have saved 400,000 x 6 = 2,400,000 bytes of disk or tape storage (not
main storage). We have to condense or compress these fields into one binary
fullword prior to writing the data on disk or tape. Figure 11 -2 illustrates coding that
performs this condensing. Because there are no signs, we can use logical shift oper¬
ations. The "packed" binary format is to be:
BITS BITS
1 56 PACK DOUBWORO.ACCOUNT
157 CVB 7.DOUBWORO 7: -- 15ZER0S -- 00100010100010011
158 SLL 7,15 7: 00100010100010011— 15ZEROS -
159 SLDL 6.17 6: 000001 1010001 1000100 01010001001 1
BOOLEAN LOGIC
ADDITION MULTIPLICATION
0 0 1 1 0 0 1 1
+0 +1 +0 +1 X0 XI X0 xl
0 1 1 1 0 0 0 1
Assembler language uses Boolean logic for the logical functions AND, OR, and
Exclusive OR (XOR) to perform bit manipulation. For each of the three logical
functions there are four instructions, in RR, RX, SI, and SS format (not available on
some smaller models).
For all twelve instructions, operand-1 is called the target field and operand-2 is
the mask. The operations compare the bits in the mask against those in the target,
one at a time from left to right. The target bits are modified to 0 or 1 according to the
bit contents and the logical operation. The condition code is set as follows:
The following shows two 4-bit fields, called MASK and TARGET. The three
unrelated cases illustrate AND, OR, and XOR. Each case sets the condition code to 1.
AND. The logical function AND is equivalent to Boolean multiplication. If both the
mask AND and the target bit are 1, then the target bit is set to 1. All other cases set the
242 LOGICAL OPERATIONS AND BIT MANIPULATION
target bit to zero. In Figure 11-3, NR ANDs the contents of register-8 (the mask) with
that of register-9 (the target). N ANDs the contents of MASK in storage (a fullword
aligned) with the target in register-8. Nl, an immediate operation, ANDs the single
immediate byte with the first byte of TARGET. NC ANDs the first two bytes of MASK
and TARGET.
OR. The logical function OR is equivalent to Boolean addition. If either or both the
mask or the target bit is 1, then the target bit is set to 1. Where both bits are zero, the
target bit is set to zero. Figure 11-3 illustrates the four OR operations.
EXCLUSIVE OR (XOR). If either the mask or the target bit (but not both) is 1, then
40 •
41 * OR - OR. C, 01, OC
42 *
43 OR L 8•MASK LOAD MASK VALUE
44 L 9.TARGET LOAD TARGET VALUE
45 OR 9.8 •OR* TARGET WITH MASK
52 OC TARGET(2).MASK
•OR* FIRST 2 BYTES OF TARGET
54 *
55 * EXCLUSIVE OR - XR, X. XI, XC
56 *
57 XOR L 8 tMASK
LOAD MASK VALUE
58 L 9.TARGET
LOAD TARGET VALUE
59 XR 9.8
•XOR* TARGET WITH MASK
61 L 8.TARGET
LOAD TARGET VALUE
62 X 8,MASK
•XOR* TARGET WITH MASK
64 XI TARGET,B*01010101*
•XOR* FIRST BYTE OF TARGET
XOR sets the target bit to 1. Where both are zero or 1, the target is set to zero. Figure
11-3 illustrates the four XOR operations.
SIGN corrects the sign in an unpacked field. Earlier we saw that a packed field
such as/23/4C/ when unpacked becomes /F2/F3/C4/. This amount prints incorrectly
as 23D. The solution used MVZ to insert an "F"-sign in place of the C-sign, /F2/F3/F4/.
This example unpacks a page counter, PAGENO, in the print area. 01 forces all
four sign bits to be turned on, thereby adjusting the sign to X'F'. For example,
C4 OR'd with F0 gives F4.
REVERSE shows how XR may interchange two registers without the use of an
intermediary register. The 4-bit areas illustrate how the example works.
SWITCF1 illustrates switching. We may manipulate the mask in the Branch on
Condition (BC) instruction to change the program flow. BC 15 (unconditional
branch) is commonly written as B. BC 0 is a no-operation condition which performs
no branch at all; the extended mnemonic is NOP. The mask is in bits 8-11 of the
object code. The example switches the mask from X'O' to X'F' (NOP becomes B) and
vice versa. Clever, but not good programming practice.
CODES uses bits that represent yes or no conditions for customers. In the
example, a utility company customer has an 8-bit code designed as follows:
A 1 -bit means the condition exists, and more than one bit may be validly on. The
example tests if the customer has any of the conditions: electric, gas, budget. The Nl
operation tests bits 0, 1, and 2; any equal bits set the condition code to 1.
ZONES tests for F-zones in a character field. This is a useful check for validity of
input data, such as date, account number, and amounts (except the units portion of
minus amounts, such as F1F2F3F4D5).
The TM instruction in the next section may more effectively test bits.
OTHER OPERATIONS
TEST UNDER MASK—TM. The previous section used bits as switches or indicators.
An efficient instruction to test bit conditions is TM, Test Under Mask
compares the 1 -bits in the mask against the selected bits in operand-!, bit for bit. For
example, if the immediate operand is B'01001100', then TM tests only bits 1,4, and
5 of operand-!. Operand-! is unchanged. The condition code is set as follows:
CONDITION
SELECTED BITS IN OPERAND-1 CODE TEST USING
TM tests only the bit position of the mask that contains a 1 and ignores zero
mask positions. (Boolean operators, however, process all bit positions regardless of 0
or 1.) The extended mnemonics for testing the condition code are the same—BZ,
BM, and BO, but for TM are described differently. Branch Minus is called Branch
Mixed and Branch Overflow becomes Branch Ones.
In the example CODES in the previous section, an 8-bit code represented yes or
no conditions for utility customers. The next three examples in Figure 11-5 test this
code for BZ, BM, and BO.
To test if the customer has an industrial account with a rented meter, we test
bits 3 and 6 of CODE. In the example TESTZERO, the selected bits in CODE are both
0. Because the condition code is set to 0, BZ causes a branch. To test if the customer
has an electric account, electric heating, and is 30 days delinquent in paying his bill,
we test bits 0, 4, and 5 of CODE. In the example TESTMIX, the selected bits are: bit 0
is on, bit 4 is off, bit 5 is on. Because the bits are mixed off and on, the condition code
is set to 1. BM causes a branch. To test if the customer has electric, gas, and budget,
we test bits 0, 1, and 2. In the example TESTONES, the selected bits in CODE all
contain 1. The condition code is set to 3, and BO causes a branch.
246 LOGICAL OPERATIONS AND BIT MANIPULATION
For both instructions, operand-1 references the rightmost 8 bits of a register (bits
24-31). Operand-2 references one byte of storage. 1C, like LH, transfers data from
operand-2 (storage) to operand-1 (register). STC, like STH, transfers data from
operand-1 (register) to operand-2 (storage). However, the 1C and STC operations do
not affect the other bits (0-23) of the register. Further, operand-2 can specify any
storage position, odd or even.
EXTENDED 1C AND STC EXAMPLE. Figure 11-6 illustrates both 1C and STC and
introduces variable length fields. This example reads a record from an input device.
11 e ♦
119 * IC INSERT CHARACTER
120 * STC STORE CHARACTER
12 1 *
122 XR 1. 1 CLEAR REC 1
123 LA 9,NAMADOR
ADDRESS OF 1ST LENGTH INDICATOR
124 IC 1.0(0.91 LENGTH OF NAME IN REG 1
125 LR 8. 1
LOAD REG 1 INTO REG 8
126 8CTR 1 .0 DECREMENT REG 1 ST 1
138 • •
139 NAMADOR OS CL 4 2
VARIABLE NAME A AODRESS
140 PRINT DC CL 121* •
PRINT AREA
FIGURE 11-6 Moving variable name and address fields using 1C and STC.
247 Other Operations
name address
0A ADAM SMITH OC 423 JONES ST
hex character hex character
The name is 10 characters long. Therefore X'OA' is stored as a length indicator before
the name. Because the address is 12 characters long, X'OC' is stored before the
address. The entire record consists of 1 +10 +1 +1 2 = 24 bytes. Other records would
vary in length accordingly. The maximum record length is assumed to be 42 bytes.
The purpose is to move the name and the address separately to the print area. 1C
extracts the length indicator, and STC inserts the length indicator (minus 1) into the
second byte, the length, of the MVC instruction. (At execute-time, the computer adds
1 to the instruction length.) Carefully check each instruction. The next section uses
the EX instruction for the same example.
The ability of EX to modify the second byte of the subject instruction gives us
the power, depending on the instruction format, to change the register reference, the
immediate operand, or the operand lengths. The second byte (in machine object
code) that is subject to change is underlined:
FORMAT OPERANDS
RR R1,R2
RS R1,R3,D2(B2)
RX Rj,D2(X2,B2)
SI D1(B1),|2
SS (1) D1(L,B1),D2(B2) (one length)
SS (2) D1(U,B1),D2(L2,B2) (two lengths)
The rules for EX are: (1) Operand-1 designates a register containing some value
used to modify the second byte of the subject instruction; (2) operand-2 refers to the
subject instruction, defined somewhere in storage, to be executed by EX. Any instruc-
248 LOGICAL OPERATIONS AND BIT MANIPULATION
tion except another EX may be subject to EX; (3) EX ORs bits 8-15 (byte 2) of the
subject instruction with bits 24-31 (the rightmost byte) of the operand-1 register. The
subject instruction, however, is not actually changed in storage. Exception: If
register-0 is specified, no modification is done. After executing the subject instruc¬
tion, the program either returns to the next sequential instruction following the EX or,
if the subject instruction is a branch, to where the branch is directed.
Figure 11-7 depicts each instruction format subject to EX. (In practice, the
contents of the operand-1 register would generally be a result of a calculation.) In
each case the second byte of the subject instruction (ADDREG, STOREGS, etc.) is
defined as zero because the byte is to be ORed. These examples are intended to
illustrate how EX works, but not how we would use it in practice.
EXRR inserts X'14' into register-5 and ORs byte 2 of ADDREG with X'14'. This
process causes the second byte of ADDREG to reference temporarily registers 1 and
4. ADDREG executes out-of-line as: add the contents of register-4 to register-1. EXRS
ORs the second byte of STOREGS with X'DF'. This process causes byte 2 of
STOREGS to reference registers 13 and 15. STOREGS executes out-of-line as: store
the contents of registers 13, 14, and 15 in SAVEREGS.
6 *
7 * EX EXECUTE
8 ♦
00.38 0 2 4 3 5 C 43EE 9 EXRR IC 5,=X•14• INSERT X*14• IN REG 5
C0380t 4450 4 OC 0 10 EX 5.ACCREG A 00 CONTENTS OF REG 4 TO REG 1
EXRX ORs the second byte of STORCH with X'20\ This process causes byte 2
of STORCH to reference base register-2 and index register-0. STORCH executes aS:
store the rightmost 8 bits of register-2 in SAVEBYTE. EXSI ORs the second byte of
MOVIMM with X'5B'($). This process causes byte 2 of MOVIMM to "contain" X'5B\
(Remember that the subject instruction is not physically changed.) MOVIMM then
moves X'5B' to P+20, and the instruction can thus move any immediate value.
EXSSL and EXSSLL both modify operand lengths. Remember that when execut¬
ing an SS instruction, the computer adds 1 to the operand length. EXSSL uses
MOVECHAR to move a specified number of asterisks (up to three) to the print area,
and could be used to print one, two, or three asterisks to denote the total level.
EXSSLL executes an AP operation in which byte-2 contains both length codes.
22 XR i. i CLEAR REG 1
23 LA 9.Nahaodr ADDRESS OF 1ST LENGTH INDICATOR
24 I C 1,0< 0,9) LENGTH OF NAME IN REG 1
25 Lfi 8, 1 SAVE LENGTH IN REG 8
— Some systems use ASCII mode (American Standard Code for Information Inter¬
change). If delivered as input to the 360 or 370 (by magnetic tape or teleproces¬
sing), ASCII must be translated to EBCDIC.
250 LOGICAL OPERATIONS AND BIT MANIPULATION
— Card columns may be punched with invalid characters in amount fields that are
to be packed. For example, a column punched with 12-6-8 punches is read as
X'4E'. When packed, the byte becomes X'E4'. Because the byte is not in valid
packed format, operations such as AP or SP cause a program interrupt.
— Source programs on other computers may have similar but not identical codes.
The 360 or 370 may have to translate the different codes to EBCDIC in order to
list a program source deck.
— Alphabetic letters are normally recorded in upper-case format. It may be required
to translate and print in lower-case on either the console typewriter or a special
print device.
The instruction that translates code from one format to another is Translate, TR. The
rules for TR are: (1) Operand-1 references the address of the argument—the byte or
bytes to be translated. TR may translate a field or record up to 256 bytes long (such as
a record coded in ASCII). (2) Operand-2 references a table of functions, which
contains the required new code (such as the correct EBCDIC code). The definition of
the table is the key to the use of TR (and TRT following).
TR starts with the leftmost byte of the argument. A byte can contain any value
X'00' - X'FF', and TR adds this value to the address of the table, giving a range of
addresses from table+X'00' through table-t-X'FF'. The contents of the table address is
the function that TR uses to replace the argument byte. The operation continues then
with the next argument, proceeding from left to right one byte at a time until complet¬
ing the argument length.
Figure 11-9 translates hex numbers to alphabetic characters. Assume that the
number one (X'01') is to be translated to the first character “A" (X'CI'), 10 or X'OA'
to the tenth character 'J', 19 or X'13' to the 19th character 'S', etc. The only valid
expected values are 0 through 26 (X'l A'). The table is defined as TABLE, with a blank
followed by the letters A through Z. Assume that the argument, ARGUMENT, con¬
tains X'0104010D'. The example works as shown on page 251:
45 ♦ -
46 * TR TRANSLATE
47 * -
43 ARGUMENT DS CL4 ASSUME CONTAINS X* 01040100*
49 TABLE DC C* ABCOEFGHIJKLMNOPQRSTUVWXYZ•
Contents of TABLE:
— TR adds the first byte of ARGUMENT containing X'01' to the address of TABLE. At
TABLE + 1 is the letter 'A' (X'CI'). 'A' replaces X'01' in ARGUMENT.
— TR adds the second byte of ARGUMENT containing X'04' to the address of
TABLE. At TABLE+4 is the letter 'D' which replaces X'04' in ARGUMENT.
— TR adds the third byte of ARGUMENT containing X'01' to TABLE. The letter 'A'
replaces X'01' in ARGUMENT.
— TR adds the fourth and last byte of ARGUMENT containing X'OD' to TABLE. At
TABLE + 1 3 is the letter 'M' which replaces the X'OD'. ARGUMENT is now cor¬
rectly translated to 'ADAM'.
Question: Why does TABLE begin with a blank byte rather than the
letter 'A'? Warning: An argument may be invalid with respect to the
table of functions. For example, assume that ARGUMENT contains X'28',
or decimal value 40. TR will access the address TABLE+40, which yields
a "function" that is outside the bounds of the table. Preediting the argu¬
ment for validity prior to the TR is recommended. For many types of
translations where almost any argument is valid, it is necessary to define a
table with all possible 256 EBCDIC codes, as illustrated in the next sec¬
tion.
55 ♦ position:
56 TABL62 DC 208X* FO' 000-207 20 3 BT TES INVALID
57 DC X* 000 102030405 06070809' 208-217 10 BYTES -0 THRU
58 OC 22 X•F 0• 218-239 22 BYTES INVALID
59 DC X* FOF1F2F3F4F5F6F7F8F9' 240-249 10 BYTES -*■0 THRU
60 DC 6 X•FO• 250-255 6 BYTES INVAL10
These valid values are to stay the same, whereas all other hex values are to translate
arbitrarily to X'FO'. We therefore define all possible keypunch codes in a table of
functions that "translates” valid argument bytes to the same value, and translates
invalid bytes to X'FO'. Note the positioning of the table functions:
TABLE TRANSLATES
FUNCTIONS HEX VALUE DEC. VAL. TO
The example shows how invalid bytes in INAREA, assumed to be an amount field,
are translated to X'FO'. Devise some examples of valid and invalid data to check the
operation. Another approach translates a field to check if all bytes are numeric. The
following translates all numeric (0-9) bytes to asterisks/and checks if the TR changed
every one to an asterisk. (Checking if the rightmost byte could contain a minus
overpunch will require special treatment.)
TRT is similar to TR in that: (1) Operand-1 references the address of the argu¬
ment, up to 256 bytes in length; (2) operand-2 references a table of functions contain¬
ing the required new code; (3) the operation begins with the first byte of the argu¬
ment, and processes one byte at a time. TRT adds the value of each argument byte to
the address of the table to find each function in the table.
TRT differs from TR in that: (1) If the value of the table function is zero, TRT
continues with the next argument byte; (2) if the value of the function is nonzero,
253 Other Operations
TRT inserts into register-1 the address of the argument in bits 8-31 (bits 0-7 are
unchanged), and inserts into register-2 the contents of the function in bits 24-31 (bits
0-23 are unchanged); (3) the argument byte is unchanged—there is no translation. In
effect, TRT is a scan operation; (4) TRT terminates on finding a nonzero function or
on reaching the end of the argument; (5) the condition code is set as follows:
The three examples in Figure 11-11 illustrate the condition codes set by TRT.
Each example assumes the same argument, ARG. For SCAN 1, each byte (pair of hex
digits) of ARG is scanned. For instance, X'02' is directed to TABLEA+2, etc. All
function bytes are found to be zero. Therefore, the condition code is set to zero and
registers 1 and 2 remain unchanged, as shown in comments to the right.
ARG: 02\ 03
. v-
00 06'' 04
/
\
TABLEA: 00 5C 00 00 06 5C 00 (all located function bytes = 0)
70 *
7 l ♦ TRT TRANSLATE 4 TEST
72 *
73 ARG DC X* 0203000604*
74 ♦ REG—1: REG-2: CODE:
For SCAN2, X'02', X'03', and X'00' in ARG direct the operation to zero
functions in TABLEB. X'06' in ARG, however, directs the operation to TABLEB + 6,
which contains X'5C'. Therefore TRT does the following: (1) Inserts the address of
ARG + 3 in register-1; (2) inserts the table function X'5C' in register-2; and (3) sets the
condition code to 1.
For SCAN3, the first four bytes of ARG locate zero functions in TABLEC. The
last byte, X'04', however, directs the operation to TABLEC+4, which contains X'5B'.
254 LOGICAL OPERATIONS AND BIT MANIPULATION
TRT does the following: (1) Inserts the address of ARG + 4 in register-1; (2) inserts the
table function X'5B' in register-2; and (3) because the last byte of ARG was pro¬
cessed, sets the condition code to 2.
EXTENDED TRT EXAMPLE. The next example for variable length fields is similar to
those for 1C, STC, and EX in Figures 11-6 and 11-8. This example has no length
indicator preceding the name and address. Instead, a "delimiter” character, in this
case an *, indicates the end of the variable length field:
In Figure 11-12 TRT scans the record to find the delimiter. We then use the
address of the delimiter to calculate the length of the name and the address, and to
determine the address of the next field. The program uses two TRT and two EX
operations to move the name and address to the print area. The table, TABSCAN,
contains only a nonzero function for the X'5C' (*) position, and zero functions for all
other codes. The example assumes, perhaps unwisely, that a delimiter always follows
both name and address.
Further examples of EX, TRT, and variable length records are in the next
chapter.
86 ♦
POSITION:
0 0 3A 9 1 OCCOOCOCCCOCOOOO 87 TABSCAN cc 92X•00• 000-091 92 ZERO FUNCTIONS
003AEC 5C 88 DC X • 5C • 092-092 1
0 03 A EE ASTERISK *
OOOCOCOOOOCOOOOO 89 DC 163X•0 0• 093-255 1 63 ZERO FUNCTIONS
003B91 91 NAMADC DS CL4 2 VARIABLE NAME 4 ADDRESS
0C3Bee 00
0L3BBC 1 B1 1 93 SR 1. 1 CLEAR REG 1
0038BE 4190 438F 94 LA 9.NAMADC LOAD ADDRESS OF VARIABLE
0038C2 DD14 9000 428F RECORD
95 TRT 0(21,9) .TABSCAN SCAN FOR NAME DELimiter
96 * EZ
NOT FOUNDi ERROR
OOZBCe 1671 98 LR 7,1
003BCA 1019 SAVE ADDRESS OF OELIMITER
99 SR 1.9
003BCC 0610 CALCULATE LENGTH CF NAME
100 BCTR 1.0
003BCE 4410 43E2 DECREMENT LENGTH BY 1
101 EX 1.M50M0VE
003BD2 4190 7001 EXECUTE M50 MOVE INSTRUCTION
102 LA 9.1(0,71
INCREMENT FOR ADDRESS FIELC
003806 0014 9000 428F 1 04 TRT 0(21.9).TABSCAN
♦ SCAN FOR ADDRESS OELIMITER
105 BZ ••• * NOT FOUND. ERROR
0C3B0C 1B19 106 SR 1.9
003BDE 0610 107 CALCULATE LENGTH OF ADDRESS
BCTR 1.0
OO30EO 4410 43E8 DECREMENT LENGTH BY 1
108 EX I .M6CM0VE
♦ EXECUTE M60 MOVE INSTRUCTION
1 C9 •
110 ♦ •
FIGURE 11-12 Moving variable name and address fields using TRT
255 Problems
BINARY OPERATIONS—SUMMARY
Most arithmetic can be performed adequately with packed data and decimal arith¬
metic. Since input data on cards is normally in character format, an additional step is
required to translate into packed format. To convert the packed data to binary re¬
quires yet another step. However, the following reasons often determine the need for
binary format:
PROBLEMS
11-1. Figure 11-2 "packs" four fields into one binary fullword. Assume that the
fullword has been read from tape into a storage field called FULLWORD DS
FL4. Write the coding to "unpack" the fullword into four individual charac¬
ter fields called DIST, ACCOUNT, RATE, SERVICE.
11-2. STC stores the rightmost 8 bits of a register into a field called BYTE. Use
Boolean operations to (a) force the leftmost 4 bits of BYTE to be zeros; (b)
force the leftmost 4 bits of BYTE to be ones; (c) reverse all 8 bits, zeros to ones
and vice versa.
11-3. Figure 11-5 shows how to test bit values. Code the instruction to test if the
customer has both gas and industrial account.
11-4. Figure 11-6 illustrates variable length name and address. Change
NAMADDR to 63 bytes, allowing for a third variable field, city. Revise the
coding to move this field to P+80. Also, recode the routine as a loop so that
there is one set of instructions executed three times, one for each field. HINT:
Change operand-1 of the MVC to explicit register format. Expand the code to
include a read and print, then test the program.
11 -5. Recode Figure 11 -8 using one EX for the same changes required in Problem
11-4.
11 -6. Design a table for TR to translate upper case letters (A-Z) to lower case (a-z).
Leave unchanged characters 0-9, comma, and period. Convert all other
characters to X'40'.
11-7. ASCII code is given in IBM S/370 Reference Summary card. Design two
tables of functions to translate (a)ASCI I to EBCDIC and (b)EBCDIC to ASCII.
11-8. In Figure 11-10 TR translated invalid bytes on a card to character zero.
Change the example so that the program prints the card column where the
invalid code occurred. A card may contain more than one invalid column.
256 LOGICAL OPERATIONS AND BIT MANIPULATION
11-9. Translate hex into character format. Each four bits (hex digit) of register-9 is to
print as a single character (as is done by dumping the contents of storage).
Hex zero should print as character zero, X'9' as character 9, X'A' as character
A, etc. Since register-9 contains 32 bits, eight characters are required, print¬
ing from P+11 to P+18. Suggestion: Shift the four leftmost bits of register-9
into register-8. Store these in a one-byte field and use TR to translate from hex
to character. Repeat the loop eight times. The table can be defined as quite
short.
11-10. Recode Figure 11-12 using one TRT for the same changes required in Prob¬
lem 11 -4.
PART IV
EXTERNAL STORAGE
CHAPTER 1 2
MAGNETIC TAPE
Up to this chapter, the only input/output devices have been the card reader and the
printer. This chapter and the next cover two other common devices that store
data—magnetic tape and disk storage. Tape, like punched cards, stores data as
records. It may help to think of a reel of tape records as a series of "punched card"
records. The reel is "loaded" onto a tape drive in much the same manner as a
conventional tape recorder. The data records are then read into the computer's main
storage as a card file would be.
We write data on tape and disk over the old data, much as a tape recorder
records a new sound over the previous. The data may be reread and rewritten, almost
indefinitely. Tape and disks are used for both input and output. Normally a tape reel
designated as input to a program is only read, and not written on until its contents are
obsolete, and a reel designated as output is written on, to be read later. The data on
the reel is saved for a predetermined time as an "audit trail" or "backup" if jobs must
be rerun. Recent developments in disk storage devices have permitted storing large
files on disks. Disk storage gives the advantage of processing records both sequen¬
tially and directly. Most installations now use disk to store large files.
259
260 MAGNETIC TAPE
Magnetic tape is not only a means of rapid input/output. It also acts as a medium to
store large quantities of condensed, easily filed data. Like cards, tape is used to store
master and transaction files. It also acts as intermediary storage, for example as
output from a program, storing data to be used in a subsequent program. Many
department store chains and utility companies maintain customer records on mag¬
netic tape. Their records are many in number, long in length, and are stored sequen¬
tially. Among the advantages of magnetic tape over punched cards are:
This chapter limits discussion to IBM magnetic tape units, although tape units of
other manufacturers have similar features. The tape consists of a thin ferromagnetic
coating on flexible plastic, %-inch wide. A full reel is 2400 feet long with shorter
lengths available such as 1200 and 600 feet. 8
TAPE SPEED. Tape read/write speed varies considerably by tape drive model At
5 inches per second dps), a tape drive could read a 2400-foot reel, with very little
261 Magnetic Tape Characteristics
time for processing, in about 230 seconds. For example, IBM 3420 Magnetic Tape
units are available in the following models, with tape densities of 800, 1600, and
6250 bpi. (Another density, 556 bpi, provides compatibility with second generation
equipment.)
CODE STRUCTURE. Tape records data using a 9-bit code similar to the byte in
storage: eight bits for data and one bit for odd parity, arranged vertically on the tape.
(A 7-bit code is also accepted to provide compatibility with earlier tape models.)
TAPE MARKERS. Near both ends of the reel is an aluminum strip called a tape
marker that is sensed by a photoelectric device on the tape drive:
— The load point marker is a strip about ten feet from the start of the reel to provide
space for the initial threading of the tape. Reading or writing begins after this point.
— The end-of-tape marker is a strip about 14 feet from the end of the reel. When
tape is being written, the marker warns the system that the end of the tape is near.
Four feet provides space to finish writing data after the marker, and ten feet
permits threading of the tape.
TAPE READ/WRITE. The operator loads the reel to be processed onto the tape drive
and initializes the tape at the load point marker. The drive contains an empty reel to
take up the processed tape. The tape passes a read/write head. For input each byte is
read, then reread, to ensure the read was performed correctly. For output an erase
operation prior to the write clears old data from the tape. The write operation mag¬
netizes small areas within the tracks. A byte written is reread to check its validity.
These validity checks are entirely automatic. When the tape has been completely
processed, there are two alternatives:
1. Most often the tape is rewound onto the original reel. The operator may then
unload it from the tape drive or leave it for further processing.
2. The tape may be reprocessed by reading it backwards. Although the tape runs
backwards, data from each record reads into storage in the normal sequence. IBM
library tape sort programs and occasionally programmers use this feature.
262 MAGNETIC TAPE
TAPE FORMATS. A block of data written on tape consists of one or more records.
The minimum block length is about 18 bytes. The maximum is subject to available
storage in programs using the tape file and the operating system used. IOCS reads a
tape block into, and writes from, an input/output area (or buffer) in storage. Blocks
consisting of one record only are unblocked. Blocks having more than one record
are blocked. The blocking factor specifies the number of records in a block. The
program that initially writes (or creates) the tape file defines the record length and
block length. All other programs that read the file must designate the same record
and block lengths. After each block, the tape drive automatically generates a space of
about 0.6 inch. On tape with density of 6250 bytes per inch, the IBG is about 0.3
inch. This space, called an interblock gap (IBG), has two functions:
1. The IBG clearly defines the beginning and end of a block of data. A tape read
starts with the first byte of data in a block. The IBG terminates the read operation.
2. The IBG allows space for the tape drive to slow down after a read or write, and to
restart with the next read/write (stop/start time).
FIXED AND VARIABLE LENGTHS. Records and blocks may be fixed in length
(each has the same length throughout the entire file), or variable (the length of each
record and the blocking factor are not predetermined). There are five distinct tape
formats:
Figure 12-1 depicts the first two formats. A later section describes variable
length records.
The DOS file definition macro that defines a magnetic tape file is DTFMT (OS uses
DCB). We specify one DTFMT entry with a unique name for each tape input or
output file that the program processes. The entries are similar to the DTFCD DTFPR
ri nSTa ?rDETma<Z
m a?d
!vOVfredexplained
e,arlier' We use ,he same imperative macros': OPEn)
later, IOCS handles all label processing, block-
ing and deblocking. 5/
263 DOS Tape Programming Example
Fixed unblocked
—
m m m. m
jIBG: Rec-1 ]ibg; Rec-2 IBG; Rec-3 me: Rec-4 Iibg;
Wa 'm ii m m
One record = one block
Fixed blocked
m
:IBG; Rec-1
i
1 Rec-2
i-
^ Rec-3
yv/y/, -1
IIBG: Rec-4 ' Rec-5
i- m.
Rec-6 jlBG:
m m 1
i_1
1
m
Three records = one block
Figure 12-2 illustrates reading cards and writing them on tape. The cards are
read into CARDIN. Required fields are transferred to the tape workarea called
TAPEWORK. This workarea is then "PUT" to the tape output file called FILEOTP.
IOCS blocks four records before physically writing the block onto tape. Therefore, for
every four cards read, IOCS writes one tape block onto tape. The DTFMT entries are
described next:
BLKSIZE = 360 means that each block to be written from the lOAREA is 360 bytes
long (4 records x 90 bytes).
DEVADDR=SYS025 denotes the logical address of the tape device that will write the
file. The operator assigns one of the system's tape drives with this (or some other)
logical device name, as required by the installation.
FILABL=STD indicates that the tape file contains "standard labels", as discussed in a
later section.
IOAREA1 and IOAREA2 are the two IOCS buffers, similar to those for card and
printer files. We define the two lOAREAs as the same length as BLKSIZE, 360
bytes. Some programmers omit defining a second buffer in order to reduce
program size, especially if the blocked record area is large.
RECFORM = FIXBLK specifies that output records are to be fixed in length, and
blocked (tape records may also be variable length or unblocked).
RECSIZE = 90 means that each fixed-length record is 90 bytes in length, the same as
the workarea.
TYPEFLE=OUTPUT stipulates that the type of file is output: the file is for writing tape,
not reading.
WORKA=YES means that we are to process output records in a workarea. In this
program, TAPEWORK is the workarea, and is the same length as RECSIZE, 90
bytes. (Alternatively, we may code IOREG, just as for card and printer files, and
use the macro PUT FILEOTP with no workarea coded.)
20 MAIN PRCC S S I N G
41 * ENC-OF-F ILE
56 * DECLARATIVES
117 IOARCD11 DS CL 8 0
ICCS CARD BUFFER-1
118 I0ARC0I2 DS CL80
IOCS CARD BUFFER-2
name of our routine where IOCS branches when it reaches the end of the tape file.
The next chapter illustrates tape input. Further information on DTFMT is in the IBM
Supervisor manuals.
For OS, there are several additional entries that the DCB requires for magnetic tape.
The entry DEN specifies tape density: DEN = 2 is for 800 bytes per inch and DEN = 3
is 1600, and must agree with the actual tape drive setting. LRECL (logical record
length) designates the length of each record, if fixed-length. RECFM indicates the
"record format": F (Fixed), FB (Fixed Blocked), V (Variable), and VB (Variable
Blocked).
The program in Figure 12-3 is a revision of the preceding DOS example that
reads records and writes them on tape. The DD (Data Definition) job cards appear
first. Note that the example illustrates a common practice: BLKSIZE, RECFM, and
DEN are coded in the tape DD entry instead of the DCB, enabling a user to change
the entries without reassembling the program.
Tape and disk records may be processed directly in the buffers, using Locate
Mode. The DCB requires MACRF = (GL) for input and (PL) for output.
Another DCB entry, EROPT, provides for specifying the action if an input
operation encounters problems. The options are:
ACC and SKP can use a SYNAD entry for printing an error message and continue
processing. If the error routine is called R20ERROR, the DCB coding could be:
EROPT=SKP,
SYNAD = R20ERROR
Use of ACC and SKP may cause invalid results, so it may be preferable to use
ABE (or allow it to default) for important production jobs. Be sure to examine the OS
Supervisor manuals for other DCB options.
Tape files are typically stored in ascending sequence by control field, such as Cus¬
tomer number. Files ("data sets" under OS) may be organized according to how
much tape space they require. For compatibility with disks, a reel of tape is called a
volume. The simplest case is a one-volume file, in which one file is entirely and
exclusively stored on one reel (volume). This storage is common where the file is
medium-sized.
//GO.TAPEOT DD DSNAME-TRFILE,DISP=(NEW,PASS),UNIT-3420, \DD for tape data
DCB=(BLKSIZE-360,RECFM—FB,DEN-3) f set output
♦ INITIALIZATI 0 N
PR0G12B START
SAVE (14,12)
e alr 3,0
USING *,3
ST 1 3. SA VE ARE AT- 4
LA 13.SAVEAREA
OPEN (FILE IN. ( INPUT),F ILEOTP, (OUTPUT))
♦ ** MA/N PROCESSI N G
* END-OF-F ILE
* OECLARAT I VES
SAVEAHEA DS 18F
REGISTER SAVE AREA
L T Q KG *
END PR0G12B
266
267 Tape File Organization
STANDARD LABELS. Under the various operating systems, tapes require unique
identification. Each reel and each file on a reel contains certain descriptive standard
labels supported by IOCS for the following reasons:
— To uniquely identify the reel and the file for each program.
— To provide compatibility with disk storage devices (to facilitate device indepen¬
dence).
— To provide compatibility with other IBM systems and those of other manufacturers.
Most installations use standard labels. Nonstandard labels and unlabeled tapes
are permitted but are not covered in this text. There are two kinds of standard labels:
volume and file labels. Figure 12-4 illustrates standard tape labels for the cases: one
I. A one-volume file
End-of-file label(s)
file on a volume, a multivolume file, and a multifile volume. IBG's are denoted by
striped lines. TM, meaning tape mark, is discussed in a later section, IOCS.
VOLUME LABELS. The volume label is the first record after the load point marker.
The label describes the volume (reel). The first three bytes contain the identification
VOL. Although some systems support more than one volume label, this text describes
only the common situation of one label.
On receipt of a new tape reel, we use an IBM utility program to write the
volume label and a temporary file label ("header”). In all programs that process the
reel, IOCS expects the volume label to be the first record. It checks the tape serial
number against the number supplied by the special tape job control card TLBL or
under OS, DD (Data Definition). The following describes each field of the 80-byte
standard volume label:
STANDARD FILE LABELS. A tape volume contains a file of data, part of a file or
more than one file. Each file is uniquely identified to ensure, for example that the
correct file ,s being processed and that the tape we are using to write on is obsolete
To provide such identification there are two file labels for each file for each reel ■ the
header label and the trailer label.
1. HEADER LABEL. There is a header label at the start of the file. If the file reouires
more than one volume (multivolume file) then there is one header for each of the
volumes, each numbered consecutively from one. If there is more than on!SL„
a volume (multifile volume) then a header label begins each file ' ^
volume label. IOCS checks the file identification, date, etc., against information
supplied by the tape job control card, TLBL or DD.
OS supports two header labels, HDR1 and HDR2, plus two trailer labels.
The second label is also 80 bytes and immediately follows the first. It contains
such data as record format (fixed, variable, or undefined), the block length, record
length, and density in which the tape is written.
2. TRAILER LABEL. There is a trailer label at the end of each file (EOF). For a
multivolume file, there is also a trailer at the end of each volume (EOV). (OS
requires a second trailer label.) If the trailer label is the end of the file (the file may
require more than one volume), then the first three bytes of the label contain EOF.
If the file requires more than one volume, then the first three bytes of the trailer
label at the end of each volume contain EOV. The trailer label is otherwise
identical to the header label with one exception: a block count field. IOCS counts
the blocks as they are written and writes the total in the trailer label. Remember
that IOCS fully performs label processing for standard labels.
The following describes each field of the 80-byte standard file label, for both
the header and the trailer.
48-53 Expiration The year and day when the file may be erased and re¬
Date written. Same format as creation date.
54-54 File A special security code used by OS.
Security
55-60 Block Count Used in trailer labels to store the number of blocks
since the previous header label.
61 -73 System Code Identifies the programming system.
74-80 Reserved.
1. Processing the Volume Label. Through the OPEN macro, IOCS checks that the
first record is a volume label (VOL). It compares the volume serial number against
the serial number (if any) on the tape job control card (TLBL or DD).
2. Processing the Header Label. After the volume label, IOCS reads the header label.
It checks the expiration date against the date in the communications region. If the
expiry date has passed, IOCS backspaces the tape and writes a new header
(HDR1) over the old header, using data from the tape job card. (Under OS, a
second header (HDR2) is written next.) Then IOCS writes a tape mark, a special
block that it recognizes.
3. Writing Records. The PUT macro uses either a workarea or an IOREG. If the
records are unblocked (one record per block), processing is similar to printing. If
records are to be blocked, however, IOCS performs the required blocking. For
example, assume two lOAREAs (buffers), three records per block, and a workarea.
We format the record to be pripted in the workarea. The first PUT executed writes
the workarea record into the first record of IOAREA1:
IOAREA1 IOAREA2
There is no physical writing of tape at this time. The second PUT writes the
workarea record in the second record of IOAREA1, and the third PUT writes in the
third record:
271 IOCS for Magnetic Tape
I0AREA1
At this time, IOCS physically writes the contents of IOAREA1 onto tape, and while
this is happening, internal processing continues. The fourth PUT writes the work-
area in the first record of IOAREA2, the fifth in the second record of IOAREA2,
and the sixth in the third record. At this time, IOCS physically writes IOAREA2
onto tape. The seventh PUT resumes writing the workarea in the first record of
IOAREA1. Records blocked in three require three PUT commands before a block
is physically written.
4. End-of-Volume. If the system detects the reflective marker near the end of the reel,
IOCS writes an EOV trailer label similar to the header label. The EOV label
includes a block count of all blocks written. Next, IOCS writes a tape mark. If an
alternate tape drive is assigned, IOCS OPENs the alternate volume, processes its
labels, and resumes writing of the file. It rewinds the old reel if required.
5. End-of-File. When all data is processed, we CLOSE the tape file. IOCS writes the
last block of data (if any). The last block may contain fewer records than the
blocking factor specifies. IOCS then writes a tape mark and an EOF trailer label
with a block count. Finally, IOCS writes two tape marks and deactivates the file
from further processing.
INPUT. This section briefly outlines the IOCS functions for tape input. When an
input file is opened, IOCS checks the header and volume labels. The file identifica¬
tion in the header must agree with that on the TLBL job control card to ensure that the
correct file is being read. For input, IOCS does not check the expiration date or write
a new header. The GET macro reads records, specifying either a workarea or IOREG.
If the tape records are unblocked, processing is similar to reading cards. If records are
blocked, IOCS performs the required "deblocking.”
Assume again two lOAREAs, three records per block, and a workarea. The first
GET executed reads a tape block containing records 1, 2, and 3, into IOAREA1,
filling it with three records. IOCS then transfers the first record to the workarea, and
reads the second tape block, containing records 4, 5, and 6, into IOAREA2:
If IOCS encounters the end-of-volume label before the end of file (meaning that
the file is continued on another reel), IOCS checks that the block count is correct.
272 MAGNETIC TAPE
The reel is rewound, an alternate tape drive is opened, labels are checked, and
reading of the next reel resumes.
END-OF-FILE. Each GET operation causes IOCS to transfer a record to our work-
area. Once every record has been transferred, and we attempt to read the end-of-file
label into the workarea, this means there are no more records to be read. They have
all been processed. IOCS then checks the block count and rewinds the reel. Control
is transferred to our end-of-file address designated in the DTFMT or DCB macros. We
should now CLOSE the file and attempt no further reading of it.
Tape and disk files provide for variable length records, both unblocked and blocked.
The use of variable length reduces the amount of unused tape or disk storage, but a
disadvantage is in additional programming steps. A record may be variable length
because it contains one or more variable length fields or a variable number of fixed
length fields:
1. Variable Length Fields. Some fields, such as name and address, may vary consid¬
erably in length. In the normal fixed-length format, we define the length as that of
the longest possible content. It is possible to store only the significant characters
of the field. For example, an address such as 123 W. 35TH ST. requires only 15
characters, whereas an address such as 1234 SOUTH HOLLINGSWORTH DRIVE
requires 30 characters.
2. Variable Number of Fields. Certain applications require some data fields for one
customer and not for another. For example, a utility company sells both electricity
and gas, and customers may adopt paying by budget. For any given customer the
basic subrecord could be customer number, name, address, and balance owing
Optionally, the customer may have an electric subrecord (containing rate and
history of consumptions), a gas subrecord (containing rate and history of con¬
sumptions), and a budget subrecord (containing payment record). Customers mav
have any combination of these subrecords, but their record need not provide
space for all possibilities. If the customer buys only electricity and does not pay by
budget, then only the basic subrecord and electric subrecord are stored.
Therefore, immediately preceding each block is a 4-byte block control word contain¬
ing the length of the block. We calculate and store the record length; IOCS calculates
and stores the block length.
Figure 12-5 illustrates both variable unblocked and blocked records. For vari¬
able unblocked note the following: (1) The first record (Rec-1) is 310 bytes long and
the record control word contains '314'. The block control word contains '318',
which is the length of the entire block. (IOCS generates a block control word even for
unblocked records.) (2) The second record (Rec-2) is 260 bytes long. The record
control word contains '264', and the block control word contains '268'.
Variable unblocked
For variable blocked the example shows three records stored in the first block.
A record control word precedes each record, and a block control word (containing
'866') precedes the block. IOCS calculates the length in the block control word as:
We designate a maximum block length in the DTF entry BLKSIZE, and IOCS fits as
many records into this block as possible. For example, the block length may have
been defined as (maximum) 900. If it had been defined as 800, only the first two
274 MAGNETIC TAPE
records would have fit in this block and IOCS would begin the next block with the
third record. Although records are blocked, the block length and the number of
records per block will vary depending on the lengths of the records.
1. Record Length. As with fixed-length records, the program may process variable
records in a workarea or in the I/O areas (buffers). We define the workarea as the
length of the largest possible record, including the 4-byte record control word.
When creating the record, we calculate and store the record length in the record
control word field. This field must be four bytes in binary format, aligned on a
halfword boundary (DOS uses only the first two bytes).
2. Block Length. We define the I/O area as the length of the largest desired block,
including the 4-byte block control word. On output, IOCS stores as many com¬
plete records in the block as will fit. IOCS performs all blocking and calculating of
the block length. On input, IOCS deblocks the records similar to its deblocking of
fixed-length records.
1 -4 Record length 5-9 Account number 10-82 Variable name and address
The name is immediately followed by a "delimiter", in this case a ' + ' (12-8-6 punch,
or X 4E'), to denote the end of the name. A ' + ' delimiter also terminates the next
field, the house address, and another terminates the city:
Figure 12-6 illustrates a simple program that reads and prints the variable length
records. Devise several records and trace the logic of this routine carefully, step by
step. Note that DTFMT specifies RECFORM = VARBLK (record form = variable
blocked). The program reads each record and uses TRT and a loop to scan each of
the three variable length fields for the record delimiter. The length of the field is
calculated, and EX moves each field to the print area. The program also checks for
the absence of a delimiter.
l9 4*4
20
main p R 0 C ess I N G
A1CGET 6ET FILE 1TP.TAPEWORM READ TAPE RECORO
26 LA 6. IDENTPIN
27 ESTAB. AOORESS OF INPUT IDENT
LR 7.6
ESTABLISH ADDRESS OF
28 AH 7.RECLEN
ENO OF RECORO
29 SH 7 » =H•9•
30 M VC PA 10 IS).ACCTTP IN
MOVE ACCOUNT NO. TO PRINT
60 ♦ enc-of-f:I L E
61 * l OEOF CLOSE FILE ITP.FILEOPR OE-ACTIVATE FILES
70 EO J NCRMAL END-OF-JOB
74 4
DECLARAT!IVES
75 SCANTA6 DC 78X* 00• TRT TABLF:
76 OC X* 4E •
» DELIMITER POSITION
77 DC 1 77X *00 • ♦ REST OF TABLE
78 4
TAPE RECORD MORKAHEaI
79 DS CH
* ALIGN ON EVEN BOUNDARY
80 TAPEiCR K DS 0CL82
« TOTAL MAX. RECORO * LENGTH
8 1 RECLEN DS H
* 2-BYTE RECORO LENGTH
82 OC H' 0 •
* 2 BYTES UNUSED IN DCS
83 ACC7 TP IN OS CL5 * ACCOUNT NUMBER
84 IOENTPIN DS CL 7 3
* AREA FOR VAR. NAME|ADDRESS
275
276 MAGNETIC TAPE
PROBLEMS
12-1. Name seven advantages that magnetic tape has over punched cards. What
are some disadvantages?
12-2. Explain the following: (a) tape density; (b) tape markers; (c) IBG; (d) blocking
factor; (e) fixed and variable length.
12-3. Give an advantage and a disadvantage of increasing the blocking factor.
12-4. What is the purpose of (a) volume label; (b) header label; (c) trailer label?
12-5. Distinguish between (a) EOV and EOF on the trailer label; (b) a multifile
volume and a multivolume file; (c) volume sequence number and file se¬
quence number.
12-6. Revise the program in Figure 12-2 or 12-3 for the following: 6 records per
block, locate mode. Change file identification to your own name. Assemble
and test the program.
12-7. Revise any previous card program so that the input data is on magnetic tape.
Provide for fixed, blocked records.
12-8. Assume a variable tape file, with six records whose lengths respectively are
326, 414, 502, 384, 293, and 504. Maximum block length is 1200 bytes.
Depict the records showing all block and record lengths.
12-9. Write a program that creates a Supplier Master File.
— Input fields are: Supplier number (7 bytes); Amount payable (7 digits to
be stored in packed format); Name (20 bytes); Street (24 bytes); City (24
bytes); Date of last purchase (ddmmyy).
— Name, street, and city are to be stored as variable length fields, with hex
'FF' as a delimiter after each field.
— Next, write a program that updates the file with two tape files: (1) pur¬
chase entries (supplier number, amount, date); and (2) miscellaneous
changes to name and address records.
CHAPTER 1 3
Every installation has its own unique file organization and processing requirements.
Also, its budget constraint limits the size of main storage and the type and number of
devices. For one installation, the optimum configuration is a simple small diskette
system, whereas for another it is a combination of magnetic tapes, direct access
storage devices, and teleprocessing terminals. Direct Access Storage devices (DASD)
have a significant advantage not provided by other devices: DASD permits the
organization and processing of files not only in sequence (as for cards and tape), but
also directly (randomly). On tape, to access a particular record, we must process
every preceding record; under DASD, however, we may directly access any record
on the file.
This capability of direct accessing is particularly useful for "on-line" process¬
ing. For example, a department store keeps its accounts receivable on a DASD.
When customers present their credit cards for a purchase, the cashier submits the
customer credit number through a terminal to the computer center. A computer
program uses this credit number to directly access the customer number in the file,
determines the customer's credit rating, and signals the rating to the cashier. The
cashier is informed almost immediately whether the customer can have more credit,
or has exceeded the limit, or possibly that the card was reported lost.
277
278 DIRECT ACCESS STORAGE
DASD's are also commonly used for storing on-line the installation's operating
system, the various support programs, and catalogued macros and subroutines. The
DASD then, like tape, acts as both an input/output device and external storage.
There are many types of direct access storage devices, of which the more common
ones include:
— Drives with removable disk packs: 231 1, 2314, 3330, and 3340.
— Drives with nonremovable storage: 2305, 3344, and 3350.
Each type of device has unique physical differences. However, the program¬
ming for each device is similar. Each record stored on a device has a specific location
with a unique address and has a control field (“key'') for identification.
DASD CHARACTERISTICS
Certain of the DASD's, such as the 231 1, 3344, and 3330, have disks for recording
data. These disks, made of metal coated with magnetic oxide, are similar to phono¬
graph record surfaces. But a record has tracks that spiral inward, whereas the DASD
tracks are concentric—each track makes a unique circle, as shown in Figure 13-1.
The track contains the data, generally recorded bit-by-bit, with records and
blocks stored just as on magnetic tape. Similarly, data may be written and rewritten
on the same track for permanent or temporary records. Although innermost tracks are
shorter in circumference, all tracks contain the same number of bytes. On a 2311, for
example, the disk surface has 200 primary tracks plus 3 alternate tracks used if any of
the primary tracks become defective. The number of tracks on a disk surface and
their capacity varies by device.
A disk pack consists of a number of rotating disks on a vertical shaft. Except for
the top and bottom disk, the surfaces are recorded on both sides. Figure 1 3-2 shows
the access arms that move horizontally to position at any track. Each arm has two
read/write heads—one for the upper surface and one for the lower. Only one head at
a time reads and writes. To read a record, for example, on the outermost track, all the
access arms position there. The record to be read is on one of the surfaces—only the
279 DASD Characteristics
head for that surface is activated to read the record. As the disk rotates, the read occurs
when the data record reaches the head. Figure 1 3-3 lists the number of tracks and
their capacity. The 3330, for example, has 19 surfaces, giving a total of 100 million
bytes of storage (certain of this space is required for nondata records and gaps).
TIMING. There is some delay from the time a read/write instruction is executed
until the data is actually received. As shown in Figure 1 3-3, the time varies consider¬
ably by device, but includes:
Access Motion. The more often and further that the access arm moves, the more time
is taken. The section Cylinder Concept explains how data is organized to
minimize this seek time.
Capacity Speed
Bytes Tracks Number Total Ave. Ave. Data
Device per per of bytes seek rot’l rate
track cylinder cylinders time delay KB/
(ms) (ms) sec.
2311 3625 10 200 7,250,000 75 12.5 156
Rotational Delay. As the disk rotates, time is required for the data to reach the
read/write head. The average rotational delay ("latency”) is half a rotation.
Data Transfer Rate. The device's rotation speed and density of data affect the time to
transfer data between the device and main storage.
TRACK FORMAT. Every track contains certain information about its address and
condition. Between the different records on the track are gaps; these vary by device
and their location on the track. The basic format for a track is:
© ® ©
Index Home Track Descriptor Data Data
Point Address Record (R0) Record (R1) Record (R2) etc.
(a) The Index Point tells the read/write device that this point is the physical begin¬
ning of the track—data is recorded following the Index Point.
® The Home Address tells the system the address of the track (the cylinder and
head, or surface, number) and whether the track is a primary or alternate track or
defective. '
© The Track Descriptor Record (R0) immediately follows the Home Address The
system stores information about the track in this record. There are two separate
ie ds. a Count Area and a Data Area. The Count Area contains '0' for record
281 DASD Characteristics
number and '8' for data length. It is otherwise similar to the Count Area described
next for Data Record under item (d). The Data Area contains eight bytes of
information used by the system. The Track Descriptor Record is not normally
accessible to the programmer.
(d) Data Record Formats (R1 through Rn). Following the Track Descriptor (RO)
record is one or more of our data records, each consisting of the following:
Address Marker. The I/O control unit stores a two-byte Address Marker prior to
each block of data. When reading records, the control unit uses the Address
Marker to locate the beginning of data.
Count Area. This is a field that the system also stores and uses. Included are:
An Identifier field gives the cylinder/head number (similarto that inthe Home
Address), and the sequential record number (0-255) in binary, represen¬
ting RO through R255. (The Track Descriptor Record, RO, contains zero
for record number.)
The Key Length field is explained in the next section, Key area.
The Data Length is a binary value 0 through 65,535 that specifies the number
of bytes in the Data Area field (the length of our block of data). For
the end-of-file, the system generates a last (“dummy") record containing
a length of zero in this field. When the system reads the file, this zero
length indicates that there are no more records.
Key Area. Under DASD, the key is the control field for the records in the file, such
as customer or inventory number. The key, if stored in this separate Key Area,
can facilitate locating of records. The key area is optional. If omitted, then
the fi le is cal led formatted without keys (Count-Data-Format). The key length
in the Count Area contains zero. If the file is formatted with keys (Count-
Key-Data-Format), then the Key Length contains the length of the Key area.
Data Area. We store our data blocks in this area in any format—unblocked or
blocked, fixed length or variable, just as on magnetic tape.
Under normal circumstances, the programmer is not concerned with the Home
Address and Track Descriptor record, nor with the Address Marker, Count Area, and
Key Area portions of the Data Record field. The system completely handles the
processing of these fields. As shown in the following example programs, it is simply
necessary to specify appropriate entries in the DTF or DCB and job control state¬
ments. We can then read and write sequential disk records much like cards and tape.
The system stores as many records on the track as possible. Usually, records are
stored completely (intact) on a track. A record overflow feature permits records to
overlap from one track to the next.
282 DIRECT ACCESS STORAGE
FILE ORGANIZATION
There are several ways to organize a DASD file. The choice of method is a systems,
not a programming, problem, and therefore this text gives a limited description of
organization methods. The four main methods of DASD file organization are:
1. Sequential Organization. In this method, also used by cards and magnetic tape,
each record follows another successively according to a predetermined key (con¬
trol field). We would adopt sequential if we do not require on-line processing,
and if most records are processed when the file is read. The DOS organization
method is Sequential Access Method (SAM), and we use the macro DTFSD (De¬
fine The File Sequential Disk). Advantage: sequential provides simplest design
and programming, and minimizes DASD storage space. Disadvantage: it is dif¬
ficult to locate a unique record and to insert a new record without rewriting the
file.
2. Direct (Random) Organization. This method stores records based on a relation¬
ship between the key (control field) and the track address where the DASD record
is stored. Our program performs a calculation on the key number to locate the
address of the record. The DOS method is Direct Access Method (DAM), and we
use DTFDA (Direct Access). Advantage: Direct Access provides fast and efficient
use of DASD storage for directly accessing any record. Disadvantages: (1) The file
keys must lend themselves to such a calculation. (2) A calculation for more than
one key may generate the same track address ("synonyms”). (3) The file may be
arranged in a sequence other than sequential, and require special programming to
produce sequential reports. (4) We must provide special programming to locate
the record.
3. Indexed Sequential Organization. Records are stored sequentially, permitting
normal sequential processing. In addition, this method has indexes related to the
file; we may use these indexes to locate records directly. The DOS method is
Indexed Sequential Access Method (ISAM), and we use DTFIS (Indexed Sequen¬
tial). Advantage: Indexed Sequential permits both sequential and direct process¬
ing of files with little special programming effort. Disadvantage: IS may use more
DASD storage and process more slowly.
4. Virtual Storage Access Method. VSAM is a more recent development for the 370
systems, and permits both sequential and direct processing.
This text covers programming for Sequential and Indexed Sequential organization.
Programming for sequential disk is similar to that for magnetic tape. The program in
Figure 13-4 creates a sequential disk file. The input is the tape file created in Chapter
12, Figure 12-2. A later section describes the disk job control entries, DLBL and
6 INITIALIZATI 0 N
7 PROG 13A START X*3850'
X•380 0• + X•5 O' FOR LBLTVP TAPE
8 BALR 3,0
INITIALIZE BASE REGISTER
9 USING *,3
10 OPEN T APE * SO ISK ACTIVATE FILES
20 * MAIN PROCESSING
2 1 A10GET GET TAPE READ I TAPE RECORO
26 MVC TAPEIN.0<5) MOVE FROM TAPE BUFFER
27 MVC ACCTCKO,ACCTIN MOVE TAPE FIELDS TO DISK
28 M VC NANEOKO.NAMEIN * AO RK AREA
29 M VC AOOROKO.AOORIN *
30 ZAP BALNDKO.BALNIN *
3 I MVC OATEDKO.DATEIN *
32 PUT SDISK.DISKWORK WRITE WORK AREA ONTO DISK
38 B A 1 OGET
40 * end-of-file
4 1 P10END CLOSE TAPE.SOISK DE-ACTIVATE FILES
50 EO J NORMAL END-OF-JOB
54 • DECLARATIVES
55 TAPEIN DS OCL90 TAPE INPUT AREA
56 ACCTIN DS CL6 * ACCOUNT NO.
57 NAME IN DS CL20 * NAME
58 AOCRIN DS CL40 * ADDRESS
59 BALNIN OS PL4 * BALANCE
60 DATE IN DS CL6 ' DOMMVY• * DATE
61 OS CL 14 * UNUSED
♦
I0AREA1=I0ARTPI1. 4
I0REG=<5>.
RECF0RM=FlX8LK , 4
RECSIZE=90, 4
TYPEFLE=OUTPUT , 4
VERIFY=YE S • 4
•ORKA=YES
162 I0AR0KC1 DS CL368 IOCS OISK BUFFER-1
283
284 DIRECT ACCESS STORAGE
EXTENT (bottom of the figure). Entries for the DTFSD macro are similar to those for
DTFMT.
Note that there is no FILABL entry because DASD labels must be standard.
BLKSIZE = 368 means that the blocksize for output is 360 bytes (4 x 90) plus 8 bytes
for IOCS to construct a count field. The lOAREAs are also 368 bytes. We provide
for these extra 8 bytes only for output; for input the entry is 360.
DEVICE = 3340 means that for this program, records are written on a 3340 DASD.
VERIFY = YES tells the system to reread each output record to check its validity.
This example creates a sequential disk file. In a later section, this file becomes input
to create ("load") an indexed sequential file. It is also possible to update an SD file
directly (rewrite a record over the previous one); this chapter does not cover this
practice.
Note: DEVADDR may be omitted (the system uses the SYSnnn from the
job control entry).
OS PROGRAM EXAMPLE
The example OS coding in Figure 13-5 is a revision of the previous DOS example
that reads tape records and copies them onto disk. The DD job control cards contain
some of the DCB entries: for tape input, BLKSIZE, RECFM, and DEN, and for disk
output, BLKSIZE, and RECFM.
For a disk DCB, an entry MACRF-(GM,PM) means the program can both read
and write the same file.
DISK LABELS
Disks, like magnetic tape, use labels to identify the volume and the file. This text
describes the IBM standard labels as supported by IOCS. Cylinder-0, track-0 is re¬
served for labels, as depicted in Figure 13-6:
INITIALIZATION
ZAP 8ALNDKQ.BALK IN *
MVC DATEOKO.DATE IN *
*»* END-OF-F I L E
* ** DECLARAT
285
286 DIRECT ACCESS STORAGE
Cylinder-O, Track-0
Record 0 i 2
3\ v_
Volume label
4 5 6
Y
VOLUME LABELS. The standard Volume label uniquely identifies the DASD vol¬
ume. A 4-byte key area immediately precedes the 80-byte volume data area. The
Volume label is the fourth record (R3) on cylinder-O. The 80 bytes are arranged
similarly to a tape volume label with one exception: positions 12-21 are the "Data
File Directory", containing the starting address of the VTOC.
FILE LABELS. File labels identify and describe a file (data set) on a volume. The file
label is 140 bytes long, consisting of a 44-byte key area and a 96-byte file data area.
Each file on a volume requires a file label for identification. In Figure 13-6 all file
labels for the volume are stored together in the Volume Table Of Contents (VTOC).
Although we may place the VTOC in any cylinder, its standard location is cylinder-O,
track-0. There are four types of file labels:
1. The Format-1 label is equivalent to the magnetic tape file label. The Format-1
label differs, however, in that it defines the actual cylinder-track addresses of the
start and end of the file—the "extent". Further, a file may be stored intact in an
extent or in several extents on the same volume. Format-1 permits up to three
extents on a volume. (Format-3 is used if the file is scattered over more than three
extents.)
2. The Format-2 label is used for indexed sequential files.
3. The Format-3 label is stored if the file occupies more than three extents.
4. The Format-4 label is the first record in the VTOC, and defines the VTOC for the
system.
60-60 Extent Count No. Number of extents for this file on this volume.
61 -61 Bytes Used in Last Used by OS only.
Block of Directory
62-62 Reserved.
63-75 System Code Contains the name of the operating system.
76-82 Reserved.
83-84 File Type Contains a code to identify if SD, DA, or IS type
of organization.
85-85 Record Format Used by OS only.
86-86 Option Codes IS only—to indicate if file contains Master index
and type of overflow areas.
87-88 Block Length IS only—the length of each block.
89-90 Record Length IS only—the length of each record.
91 -91 Key Length IS only—the length of the key area for data
records.
92-93 Key Location IS only—the leftmost position of the key field
within the record.
94-94 Data Set Indicators SD only—indicates if this is the last volume.
95-98 OS only.
99-103 Last Record Pointer OS only.
104-105 Reserved.
106-106 Extent Type s|
107-107 Extent Sequence No.!> Descriptors for the first or only extent for the file.
108-111 Extent Lower Limit 1
112-115 Extent Upper Limit • 1
116-125 Descriptors for the second extent, if any.
1 26-1 35 Descriptors for the third extent, if any.
136-140 Pointer Address of the next label. For IS, the format-2
label; for SD and DA, the format-3 label if any.
This chapter covers mainly the concepts and the more important features of Indexed
Sequential File Organization; more details are available in the Supervisor manuals.
DOS sequential files for card, tape, and disk use the Sequential Access Method
(SAM). DOS Indexed sequential files use Indexed Sequential Access Method (ISAM).
ISAM provides the facilities to process disks both sequentially and directly. Before
examining the programming requirements, we should first see how an indexed se-
quential lie is organized. In addition to our data records in a prime data area,
there are indexes that assist ISAM to locate our record.
288 DIRECT ACCESS STORAGE
THE PRIME DATA AREA. ISAM writes ("loads") our records on tracks in the
"prime data area." These records are written with keys, in key sequence, and may be
unblocked or blocked. Preceding our data records in the track is the Home Address
(HA). See Figure 1 3-7: Under the Prime Data Area, for cylinder-O/track-1, the first key
is 0001 and the highest is 0021. The last record on the ISAM file is on track-n (the
number of surfaces varies by device) and contains the highest key on the cylinder,
0825.
THE TRACK INDEX. When creating the file, ISAM establishes a "track index" in
track-0 of each cylinder used. The track index contains an entry for the highest key
for each track on the cylinder. See Figure 1 3-7: For the track index for cylinder-0, the
first entry is the Home Address. Next is the "Cylinder Overflow Control Record"
(COCR), covered later. Next is an entry "key 0021, cylinder-0/track-1," which
means that the highest key on cylinder-0/track-1 is 0021. The last entry is key 0825
on cylinder-0/track-n. This entry is followed by a "dummy entry" to indicate the end
of the index. The dummy entry contains the highest possible value in the key, X'F's.
Therefore, we should never use X'F's as our own key. (Figure 13-7 is intentionally
simplified. There are actually two entries for each track: a normal entry (shown) and
an "overflow entry" (not shown).)
THE CYLINDER INDEX. ISAM creates a "cylinder index" for the file on a separate
cylinder (or on a separate volume). The cylinder index contains an entry for the
highest key for each cylinder—the home address. In Figure 13-7, the first entry is
"key 0825, cylinder-0," meaning that the highest key on cylinder-0 is 0825. The
cylinder index is also terminated by a dummy record containing X'F's in the key. We
tell ISAM where to store the cylinder index. At execute-time, ISAM can load the
cylinder index into main storage for faster reference during the run, thereby reducing
disk access and processing time.
The program may access an ISAM file either sequentially or directly. Sequential
processing involves the use of the GET and PUT macros, as GET filename,workarea.
Direct processing uses READ and WRITE; to access a record directly, we code READ
filename, key and ISAM uses our key to locate the disk record. Assume that the key is
0024 and the program is accessing directly:
— ISAM searches the cylinder index to locate the cylinder where the required
record is stored. The first entry in the index is high key 0825, cylinder-0. Since
our key 0024 is lower than 0825, our record must be on cylinder-0.
— Having located the cylinder, ISAM accesses cylinder-0/track-0 for the track index
to locate the track where the record is stored. The first index entry is high key
0021, track-1. Our key is greater, so the record is not on track-1. The second
entry is key 0056, track-2; record 0024 is on cylinder-0/track-2.
— ISAM has now located the correct cylinder/track, so it accesses track-2, reads
record 0024, and transfers it to the program's input area.
THE MASTER INDEX. If the cylinder index occupies more than four tracks, it may
be more efficient to have an optional higher level of index, a "master index." The
master index immediately precedes the cylinder index and contains one entry for
each track of the cylinder index—the highest key and the track. The system can first
search the master index to locate the track where the required cylinder index is
stored.
OVERFLOW AREAS. When we update a file we often have to insert new records,
such as new employees and customers. Under sequential processing we rewrite the
file, inserting the new records. But ISAM permits us to insert new records without
rewriting the entire file. ISAM writes the new records as unblocked in an overflow
area, and stores an overflow entry in the track index to point to the overflow record.
There are two types of overflow areas; either or both may be used:
1. Cylinder Overflow Area. The EXTENT card defines the number of tracks in each
cylinder for ISAM to insert added records. The cylinder overflow area is in the
290 DIRECT ACCESS STORAGE
prime area and stores all overflow records for that cylinder. The Cylinder Over¬
flow Control Record (COCR) in Figure 1 3-7 stores the address of the last overflow
record in the track and the number of unused bytes in the overflow area.
2. Independent Overflow Area. We may define the number and location of cylin¬
ders used exclusively for new added records. Our job control extent statement at
execute-time tells ISAM where to store records in the independent overflow area.
3. Use of Both Areas. If we specify both types of overflow areas, ISAM places all new
records first in the cylinder overflow area. When any cylinder is full, ISAM places
excess overflow records for that cylinder in the independent overflow area.
ISAM handles all overflow records and the linkage from the prime area to the
overflow area. As the overflow areas become full, more processing time is required to
access records. We may periodically use a special utility program to “reorganize”
the file. The program rewrites the file, and merges the overflow records in with the
prime area records.
There are four approaches to programming ISAM:
1. load or Extend an ISAM File. The initial creation of an ISAM file is called "load¬
ing. Once the file is loaded, it is possible to include higher-key records at the end
of the file—"extending".
2. Adding Records to an ISAM File. New records have keys that do not exist on the
file. Special programming is required to insert or "add" these records within the
file.
3. Random Retrieval of an ISAM File. New data requires that the file be updated at
regular intervals. We can read the new data (such as sales records), use the key to
randomly locate the ISAM master record, and rewrite the updated ISAM master.
4. Sequential Processing of an ISAM File. If there are many records to update and the
new detail records are in sequence, then we can sequentially read and rewrite the
ISAM master.
The following illustrates required imperative macros and the DTFIS file definition
macro for indexed sequential under DOS. The DOS Supervisor and I/O Macros
manual supplies additional useful information.
LOAD OR EXTEND AN ISAM FILE UNDER DOS. Figure 1 3-8 creates an ISAM file
The input is sequential disk (SD) records created in Figure 13-4. This program writes
these records onto an indexed sequential (IS) file called DISKIS. The new instructions
isirm TheDLLB|WRI
\SAM ( ) The DLBL card rT"
7'entry ^ DTF'S'
for codes' TheISC,
contains J°b meaning
COntro1 Indexed
also “
Sequential
reate (Load), and (2) there is an EXTENT card for both the cylinder index and for the
data area. In addition, ISAM requires that we check the status condition caused by
each macro (covered later). y
6 •
initializat 0 N
7 PROG 13C START X* 3050* X•3800* ♦ X•50' FOR LBLTVP NSD
8 e ALR 3.0 INITIALIZE BASE REGISTER
9 USING *.3
10 OPEN OISKSO.OISKIS ACTIVATE FILES
19 SETFL DISKIS SET ISAM LIMITS
25 tm DISK ISC.0*10011000* ANT SETFL ERRORS?
26 BO R10ERR YES - ERROR ROUTINE
28 • MAIN PROCESS I N G
29 A1CGET GET OISKSO.SOISKIN GET SEQUENTIAL DISK RECORD
35 M VC KEVNO.ACCTIN SET UP KEY NUMBER
36 M VC RECORD.SOISKIN SET UP ISAM DISK RECORD
37 WRITE DISKIS.NEWKEY WRITE ISAM RECORD
42 TM OISK1SC.0*1 1111110* ANY WRITE ERRORS?
43 BO R10ERR YES - ERROR ROUTINE
44 B A10GET NO - CONTINUE
46 • ENO-OF-FILE
47 P1OEND ENOFL DISKIS END ISAM FILE LIMITS
59 TM DISKISC.B*11000001• ANT ENOFL ERRORS?
60 BO RIOEfiR YES - ERROR ROUTINE
61 P20 CLOSE OISKSO.OISKIS DE-ACTIVATE FILES
70 EOJ NORMAL END-OF-JO0
74 • D A S 0 ERROR R O U T I N E S
75 R1OERR Equ • DASD ERROR
76 * • RECOVERY ROUTINES
77 B P20
79 4 DECLARATIVES
8C SDISK IN DS 0CL90 SEQ*L DISK INPUT AREA
81 ACCTIN DS CL6 * KEY
82 DS CL 8 4 • REST OF RECORD
DEVICE=3340. ■f
0SKXTNT=2. ♦
I0AREAL—IOARISAM.
IOROUT=LOAD, ♦
KEYL EN=6. ♦
NRECDS=1. ♦
RECFORM=FIXUN6. ♦
RECSIZE=90. ♦
VERIFY=YES. ♦
WORKL=ISAMOUT
182 IQARISAM DS CL 10 4 ISAM OUTPUT AREA
291
292 DIRECT ACCESS STORAGE
ISAM MACROS FOR LOAD AND EXTEND. We code the usual OPEN and CLOSE
to activate and deactivate the files. The new macros are:
SETFL filename
WRITE filename, NEWKEY
ENDFL filename
SETFL (Set File Load Mode). When we load or extend a file, SETFL initializes the
ISAM file by preformatting the last track of each track index. The operand
references the DTFIS name of the ISAM file to be loaded.
WRITE. The macro WRITE loads a record onto the ISAM file. The filename is our
DTFIS name. Operand-2 is the word NEWKEY. We store the key and data area
in a workarea (called ISAMOUT in Figure 1 3-8). DTFIS knows this area through
the entry WORKL=ISAMOUT. For the WRITE statement, ISAM checks that the
new key is in ascending sequence. Then ISAM transfers the key and data area to
an I/O area (this is IOARISAM in the program, known to DTFIS by
IOAREAL=IOARISAM). FHere ISAM constructs the count area:
WORKL= ISAMOUT:
IOAREAL= IOARISAM:
ENDFL (End File Load Mode). After all records are written, ENDFL performs the
following: (1) writes the last block of data (if any); (2) writes an end-of-file
record; and (3) writes any required index entries.
THE DTFIS MACRO. The maximum length for an ISAM filename is seven. In Figure
13-8, the DTFIS entries for the file to be loaded are:
CYLOFL— 1 gives the number of tracks on each cylinder to be reserved for each
cylinder overflow area (if any). The maximum depends on the device.
DEV1?7.?340 'S the DASD unit containin§ the prime data area or overflow area for
the file.
DSKXTNT—2 designates the number of extents that the file uses. The number consists
ot one for each data extent and one for each index area and independent
overflow area extent. This program has one extent for the prime data area and
one for the cylinder index.
IOAREAL=IOARISAM provides the name, IOARISAM, of the ISAM load I/O area
0uSTa°IC n^me IOARISAM references our DS output area. For loading
unblocked records, the IOAREAL field length is calculated as: 8
IOROUT=LOAD tells the Assembler that the program is to load an ISAM file.
KEYLEN-6 provides the length of our key area.
NRECDS=1 gives the number of records per block for this file (unblocked).
RECFORM=FIXUNB means that the records are to be fixed-length and unblocked.
RECSIZE = 90 is the length of each record's data area.
VERIFY=YES tells the system to check the parity of each record as it is written.
WORKL=ISAMOUT gives the name, ISAMOUT, of our load workarea (the DS for the
workarea is defined elsewhere in the program). For unblocked records, this
length is calculated as:
STATUS CONDITION. ISAM macros may generate certain error conditions, and
the system allows us to test them. After each I/O macro operation, ISAM places the
"status" in a 1-byte field called filenameC. For example, if our DTFIS name is
DISKIS, then ISAM calls the status byte DISKISC. Following is a list of the eight bits in
filenameC that the system may set when a program loads an ISAM file:
In Figure 1 3-8, TM operations test DISKIS after the macros SETFF, WRITE, and
ENDFF. After SETFF, for example, the TM instruction tests if bits 0, 3, and 4 are on. If
any of the conditions exist, the program branches to an error routine (not coded).
There, special programming action may isolate the error, print an error message, and
possibly terminate the job.
6 * I M I T I A L I Z A ION
7 PROG 1 3D START X« 3850* X*3800* ♦ X • 50* FOR LBLTYP NSD
e 6 ALR 3.0 INITIALIZE 9 A SE REGISTER
s USING 4.3
10 OPEN CARO.DISKIS ACTIVATE FILES
20 * MAIN PRCCE I N G
21 A10GET GET CARC.CARDIN READ INPUT RECORD
27 M VC KEYNO,ACCTIN SET UP KEY NUMBER
28 READ DISKIS.KEY READ ISAM RANDOMLY
33 TM DISKISC.B*11010101* ANY READ ERROR?
34 BO R10ERR YES - ERROR ROUTINE
35 WAITF DISKIS COMPLETE RE AO OPERATION
40 M VC ACCTOKO,ACCTIN MOVE CARO FIELDS TO CISK
41 MVC NAMEDKO.NAMEIN * WORK AREA
42 M VC ADORCKO.ACCRIN *
43 PACK BALNDKO.BALNIN
44 MVC DATEDKO.OATEIN *
45 WRITE OISKIS.KEV WRITE NEW ISAM RECORD
50 TM DISKI SC.BMIOCOOGC* ANY WRITE ERROR?
51 80 RIOEfiR YES - ERROR ROUTINE
52 e A10GET NO - CONTINUE
54 ♦ END-OF-FIt
55 PiCEND CLOSE CARC,DISKIS OE-ACTIVATE FILES
64 EOJ NORMAL END-OF-JOB
68 ♦ DASO ERROR O U T I N E S
69 R10ERR EQU • DASD ERROR
70 ♦ • RECOVERY ROUTINES
71 e PIOENO
READ filename,KEY
WAITF filename
WRITE filename,KEY
READ. The READ macro causes ISAM to access the required record from the file.
Operand-1 contains the DTFIS filename, and operand-2 contains the word KEY
We must store our key in the field referenced by the DTFIS entry KEYARG In this
program KEYARG=KEYNO. For each card read, the program transfers the ac¬
count key number to KEYNO.
WAITF The WAITF macro allows a READ or WRITE operation to be completed
before another is attempted. In a random retrieval we are reading and rewriting
the.sa??fA^ords' a"d wer must ensure that the operation is finished. We may
READ/WRITE anywhere f°"°Win§ a READ/WRITE, and preceding the nex^
WRITE. The WRITE macro rewrites the ISAM record. Operand-1 is the DTFIS
i ename, and operand-2 is the word KEY. KEY refers to our entry in KEYARG.
73 * DECLARAT IVES
74 CARO DTFCD DEVACDR=SYSIPT. CARD INPUT FILE DECLARATION «■
ICAREAl=IOARC0I1, ♦
10AR E A2=IOARCCI2. ♦
BLKSIZE=80. 4-
DEV ICE —25 01 . ♦
E0FADDR=PI0END. 4-
TYPEFLE=INPUT. 4-
WORKA=YES
1 15 IOARCDI1 DS CL 8 0 IOCS CARD BUFFER 1
1 16 10ARCOI2 DS CL 80 IOCS CARD BUFFER 2
DSKXTNT=2. 4-
IOAREAR=IOARISAM, 4*
I0R0UT=RETRVE, 4*
KEYARG=KEYNC. 4-
KEYLEN=6, 4-
NRECDS=1. 4-
RECF0RM=FIXUNB• 4-
TYPEFLE=RAN0CM, 4-
VERIFY=YES. 4-
WQRKR—ISAMOUT
22 1 END PROG13D
IOAREAR= IOARISAM gives the name, IOARISAM, to the ISAM retrieve I/O area.
Our symbolic name IOARISAM references the DS area for retrieving unblocked
records. The IOAREAR field length is: Key length (6) + "Sequence Link field"
(10) + Record length (90.)
TYPEFLE = RAN DOM means that we are to retrieve records randomly, by key. Other
entries are SEQNTL for sequential processing, and RANSEQ for both random
and sequential.
WORKR=ISAMOUT is the name of our retrieval work area.
STATUS CONDITION. The status condition byte for Add and Retrieve is different
from Load. The following is a list of the bits:
296 DIRECT ACCESS STORAGE
Figure 1 3-9 tests for various conditions after the ISAM macros. Once again, the
program would normally isolate the error, print a message, and perhaps terminate the
job.
IOROUT= RETRVE
TYPEFLE=SEQNTL or RANSEQ
KEYLOC=n (to indicate the 1 st byte of the key in the record, if process¬
ing begins with a specified key or group of keys, and rec¬
ords are blocked)
Processing ISAM files under OS is similar to, but not identical to, DOS processing
LOAD AN ISAM FILE UNDER OS. The OS imperative macros concerned with
creating an indexed sequential file are the conventional OPEN, PUT, and CLOSE.
DCB entries are:
SEQUENTIAL RETRIEVAL AND UPDATE. Under OS, sequential retrieval and up¬
date involves the OPEN, SETL, GET, PUTX, ESETL, and CLOSE macros. Once the
data set has been created with standard labels, many DCB entries are no longer
required. DDNAME and DSORG = IS are still used, and the following are applicable:
MACRF=(entry) (GM) or (GL) for input only. (PM) or (PL) for output only.
(GM,SK,PU) if read and rewrite in place: S — useof SETL, K
= Key or Key class used, PU = use of PUTX macro.
EODAD=eofaddress For input, if reading to end-of-file.
SYNAD = address Optional error checking.
THE SETL MACRO. SETL (Set Low address) establishes the first sequential record to
be processed, used because the programmer may want to start anywhere in the data
set.
SETL dcb-name,start-position,address
B = Begin with first record in the data set. (Omit operand-3 for B or BD.)
K = Begin with the record with the key in the operand-3 address.
KC = Begin with the 1 st record of the "Key class" in operand-3. If the first record is
"deleted," begin with the next nondeleted record. A Key class is any group of
keys beginning with a common value, such as all keys 287XXXX.
| = Begin with the record at the actual device address in operand-3.
298 DIRECT ACCESS STORAGE
BD, KD, KDH, KCD, and ID cause retrieval of only the data portion of the record.
Following are some examples of SETL to set the first record in an ISAM file
called DISKIS, using a 6-character key:
The ESETL macro, used as ESETL dcb-name, terminates sequential retrieval. If there is
more than one SETL, ESETL must precede each additional one.
In Figure 1 3-10, the program sequentially reads an ISAM file. The objective is to
insert a delete code (X'FF'j in any record that is more than five years old. The
standard date from the TIME macro is packed 00yyddd + , and the date in the records
in positions 26-28 is in the same format. The PUTX macro rewrites any such old
record, with the delete byte.
There are many other features and macros associated with OS. Check espe¬
cially the IBM OS Data Management Services Guide and Data Management Macro
Instructions manuals.
PROG13 START
SAVE <14.12)
EALR 3.0
USING *.3
ST 13 .SAVEAREA+4
LA 13.SAVE AREA
OPEN (ISFILE)
SETL ISFILE,B START 1ST RECORD OF DATA SET
TIME
ST 1.TODAY
SP TODAY, = P•5000 • C ACC DATE 3 TEARS AGO
SAVEAREA CS 18F
TOCAT DS F
T OD AT•s date: OOYYDDD*
I 0ARE A CS CL 100
DISK 10 AREA
ISFILE OC0 CDNAME=INDEXDD.DSOR G=I S.EO0AD=A90EN0.NACRF=<GL.S.PU)
END PR0G13
PROBLEMS
ADVANCED TOPICS
CHAPTER 14
MACRO WRITING
The Greek word makros means ''long.” In programming, macro means a "long”
instruction, one that causes the generation of several or many instructions. For each
macro, the Assembler generates one or more instructions. We generally suppress the
generated code, but in this chapter print it by means of PRINT GEN. There are two
sources of macros:
303
304 MACRO WRITING
WRITING MACROS
TYPEFLE and WORKA may be in any sequence, and are recognized as keywords
by the Assembler. In some cases we may omit keywords; the Assembler then
assumes default values. Figure 14-3 depicts a keyword macro.
3. Mixed. A macro definition may combine both positional and keyword. Positional
entries are specified first, in sequence. Figure 14-9 illustrates mixed types.
Certain rules govern writing and assembling macros. Figure 14-1 is a simple packed
divide positional macro, and shows the basic terminology for a macro definition:
®©© ®
symbolic parameters
Header 3 MACRO
Prototype 4 DIVIO 4QU0T.4DIVDEN0.4DIVISO
Model 5 ZAP 4QU0T.4DIVDEND MOVE DIVIDEND TO OUOT
Statements 6 DP 4QU0T,ADI VISOR
divide by divisor
Traj ler 7 MEND
The first statement of the macro definition is the header statement, containing the
operation MACRO. This instruction tells the Assembler that a macro is being
defined next. 8
The prototype statement informs the Assembler the name of the macro (in this
example DIVID), and how the macro-instruction will be coded. The operand
305 Writing Macros
10 * •
There are three entries in the macro-instruction operand, MILEAGE, MILES, and
GALS, for each of the three parameters in the prototype, ", &DIVDEND, and
&DIVISOR. For a positional macro, the macro-instruction operands correspond
exactly with the prototype. The Assembler replaces each parameter in the macro
definition:
MILEAGE, MILES, and GALS are defined in the source program. The Assembler
uses their addresses and lengths when producing the generated code (see the ZAP
and DP instructions generated).
We insert macro definitions before the main source program. Only comments
and Assembler control instructions EJECT, PRINT, SPACE, TITLE, ICTL, and ISEQ may
precede the header. We may define more than one macro, one after another, but we
may not define a macro within another macro. Also, a macro may be separately
assembled and catalogued for use in other programs.
Within the program we may use the macro-instruction any number of times,
using either the same labels or labels of any other valid fields. However, there is no
306 MACRO WRITING
1. Symbolic Parameters. We may use these in the macro definition name field and
operand. In the prototype DIVID, one symbolic parameter is ". In the
macro-instruction we coded a value MILEAGE that the Assembler assigned to the
symbolic parameter ".
2. System Variable Symbols. The Assembler automatically assigns values to these
special symbols. There are three: &SYSECT, &SYSLIST, and &SYSNDX, covered
later.
3. Set Symbols. These permit us to define temporary storage and work areas to be
used within the macro definition. They are defined and processed by Conditional
Assembly instructions, covered later.
EXPLANATION OF THE MACRO DEFINITION. The general format for macro def¬
inition is as follows:
HEADER. The MACRO header statement is blank in the name or operand fields It
tells the Assembler that a macro is to be defined.
PROTOTYPE. The name field may be blank, as in Figure 14-1, or it may contain a
symbolic parameter (a name preceded by an ampersand [&] as explained earlier)
The operation is a unique symbolic name, such as DIVID, that is not the name of
another macro or Assembler instruction. The operand may contain zero to 100
symbolic parameters separated by commas. OS permits up to 200 parameters.
307 Writing Macros
MODEL STATEMENTS. These statements define the Assembler statements that are
to be generated. There may be none or many model statements. We indicate con¬
tinuation in column 72 with any character. The name field may be blank (as in Figure
14-1), or it may contain an ordinary symbol, a variable symbol, or a sequence
symbol (a name preceded by a period, explained later). The operation may contain
an Assembler instruction, a macro-instruction or a variable symbol. The operand
may contain ordinary symbols (such as AMTPK) or variable symbols (such as
").
COMMENTS. Comments may begin anywhere after a blank following the operand.
In Figure 14-1, model statement comments begin in column 41. Also, an entire line
may be coded as a comment. We may include comment lines anywhere in the
macro definition following the prototype statement. There are two ways: (1) An
asterisk (*) in column 1 causes the Assembler to print the comment along with the
generated code (see Figure 14-5 and 14-6); (2) A period in column 1 followed by an
asterisk (.*) tells the Assembler not to print the comment with the generated code (see
Figures 14-5 and 14-6).
KEYWORD MACROS. Keyword macros have two advantages over positional mac¬
ros: (1) We may code keyword parameters in any sequence; (2) the symbolic param¬
eters in the prototype statement may contain standard values allowing us to omit the
parameter when using the macro-instruction. Other than the prototype statement,
keyword macros are defined the same as positional macros. The parameters of the
keyword prototype are immediately followed by an equal sign (=) and an optional
standard value.
The macro in Figure 14-3 is similar to the one in Figure 14-1. The prototype is
keyword, and is coded as DIVID "=QUOTIENT,&DIVDEND=,&DIVISOR=.
Figure 14-4 uses the macro twice, depicting two ways to code keyword macros.
The first operand, "=, is followed by a standard value, QUOTIENT. When
using the macro-instruction, we may omit the parameter ". In this case, the
Assembler assumes that the name to be used by " is always QUOTIENT (see
B1ODIV in Figure 14-4). Alternatively, we may override the standard value by coding
a different label, such as QUOT=SPEED (see B20DIV in Figure 14-4).
1 MACRO
2 DIVIO 4QU0T = aU0TIENT,4DIVDEND=.40 I VISOR=
3 ZAP 4QUOT,40 IVDEND MOVE DIVIDEND TO QUOT
4 DP 4QUOT.4DIVISOR DIVIDE BY DIVISOR
5 MEND
1. Concatenate Symbolic Parameters. Figure 14-5 codes a load operation that varies
according to the type of data to be loaded. We code L concatenated with a
symbolic parameter, called here &TYPE, as L&TYPE. If &TYPE contains blank H
E, or D, the Assembler generates L, LH, LE, or LD.
2. Concatenate Characters. If a symbolic parameter is concatenated with digits,
letters, left bracket, or a period, there must be a period joining the two fields'
Assume a symbolic parameter &AREA. If it references a label called FIELD, then
&AREA A results in generated code FIELDA. Figure 14-5 illustrates concatenation
with a bracket &PR!N.(&LEN) to permit different length codes.
The macro in Figure 14-5 multiplies both binary fullword or halfword fields and
illustrates symbolic parameters, comments and concatenation. The prototype, MPY,
1 macro
2 AL ABEL 1
3 •♦ MPY 4REG1.4REG2, A MUL TC A N . 4MUL T PL R , 4TYP.&LEN,APR IN
LOAD REGISTERS WITH MULTIPLICAND 4 MULTIPLIER
4 4LABEL1
L4TYP AREG2,4 MULTC AN LOAD MULTIPLICAND
5
L4TYP 4REG1» 4MULTPLR LOAO MULTIPLIER
6
MULTIPLY two registers
7
MR 4REG1.4REG1 MULTIPLY REGISTERS
8
CONVERT PRODUCT TO DECIMAL
9
CVO 4REG2.D8LEW0RD STORE PRODUCT
10
1 1 MEND 4PRIN*(4LEN'*DBUE"0RD UNPACK IN PRINT AREA
contains a symbolic parameter &LABEL1 in the name field. When using MPY as a
macro-instruction we may code a label such as M10MULT, which the Assembler
includes in the generated code. The symbolic parameters in the prototype operand
are:
The first model statement contains the same symbolic parameter &LABEL1 as
the prototype, because the Assembler is to generate this label for this statement. The
operation loads the full or halfword multiplicand into the odd register. The second
model statement loads the full or halfword multiplier into the even register. The third
model statement multiplies the contents of the two registers. (Operand-! of MR is the
even register of an even-odd pair.)
The fourth statement converts the product in the odd register to decimal format
in DBLEWORD, defined in the main source program. Finally, the decimal product is
unpacked in the print area. Note the concatenation to append the length code in
operand-1.
The program in Figure 14-6 tests the macro-instruction twice. M10MULT des¬
ignates H in the &TYP position. Note that LH is generated for L&TYP. M20MULT
DS H HALFWORD MULTIPLIER
38 FIELDH2
F FULLWORD MULTIPLICAND
39 FIELDF1 DS
DS F FULLWORD MULTIPLIER
40 FIELOF2
DC CL 12 1 * PRINT AREA
41 PRINT
omits the &TYP position by means of two commas. The instruction L is generated for
L&TYP.
This example is still relatively simple. The Conditional Assembly instructions in
the next section test for validity and permit more variations.
1. Branching and Testing. AGO, ANOP, AIF, and ACTR permit testing attributes and
branching to different locations within the macro definition.
2. Defining Symbols (SET Symbols) and Varying Their Values. Local set symbols,
LCLA, LCLB, and LCLC, provide defining within a macro expansion. Global set
symbols, GBLA, GBLB, and GBLC, enable symbols to be known in other macro
expansions. The values in the SET symbols are modified by SETA, SETB, and SETC
instructions.
ATTRIBUTE NOTATION
L’ Length Length of symbolic parameter.
r Integer Integer attribute of fixed-point, float, ordecimal number.
S’ Scaling Scale attribute of fixed-point, float, or decimal number.
K’ Count Number of characters in a macro instruction operand.
N’ Number Number of operands coded in the macro-instruction.
T Type Type of DC or DS, such as P, C, X, F, etc.
LENGTH. Only AIF, SETA, and SETB statements may reference the length of a
variable symbol. For example &X SETA L'&Y means store the length of &Y in the field
defined by the SET symbol &X.
INTEGER AND SCALING. The macro may check the defined integer and scaling
attnbutes of fixed-point (binary), floating-point, and decimal numbers with AIF
SETA, and SETB. In the statement AMT DC P'1234.56' the integer attribute is 4 (4
digits left of the decimal point), and the scale is 2 (2 digits right of the decimal point)
Integer and scaling are not further covered.
311 Conditional Assembly Instructions
COUNT AND NUMBER. The count attribute refers to the number of characters in a
macro-instruction operand. The number attribute refers to the number of operands in
a macro-instruction. They may be referenced with AIF, SETA, and SETB. For exam¬
ple: DIVID MPG,MILES,GALS. The count attribute of GALS, having four characters,
is four. The number attribute of the macro, having three operands, is three. Count and
number are not further covered.
TYPE. The type attribute refers to the type of DC, DS, or instruction. Among the
types are:
The type may be referenced by AIF, SETC, and SETB. The next section under AIF and
Figure 14-7 give examples.
1 MACRO
2 4LABEL2 DIVID 4QUDT,4DIVDENC,4DlVISOR
3 .* TEST IF DIVIDEND 4 0IVIS0R BOTH DEFINED PACKED
4 AIF (T * 4 CIV DEND NE T•4DI V ISOR).NOTPAK
5 AIF < T•4DIVDEND NE *P').NOTPAK
TEST IF QUOTIENT LENGTH ADEQUATE
>1 O'
*
AIF (L*4C I VDEND-H. •4CIVIS0R GT L•4QUOT).WRONLN
8 AGO .D-IVE VALID PACKED FIELDS
9 .notpak MNOTE 'PARAMETER NOT DEFINED AS PACKED*
10 MEXI T
1 1 •WRONLN MNOTE 'LENGTH OF DIVIDEND + DIVISOR GREATER THAN QUOTIENT'
12 MEXIT
13 .* PERFORM DIVISION
14 • DIVE ANOP
15 4LABEL2 ZAP 4QU0T.4DIVDENC MOVE DIVIDEND TO QUOTIENT
16 DP 4QU0T,4DIVISOR DIVIDE BY DIVISOR
17 MEND
Sequence symbol
or blank AGO Sequence symbol
Sequence symbol (logical expression) sequence symbol
or blank AIF
312 MACRO WRITING
AGO .B25
AIF—CONDITIONAL BRANCH. AIF means "ask if". The operand consists of two
parts: (1) A logical expression in brackets; and (2) Immediately following, a sequence
symbol. The AIF logical expression may use relational operators:
1. AIF (T’&AMT EQ P’).B25PAK (If the type of &AMT equals packed, then branch
to .B25PAK.)
2. AIF (L’&AMT GT 16).E35ERR (If the length of &AMT is greater than 16 then
branch to .E35ERR.)
3. AIF (T &LINK NE I ).R45ERR (If the type of &LINK does not equal an instruction
branch to .R45ERR.)
This testing occurs when the Assembler converts the macro to generated
code. The first example tests if &AMT is defined as packed, not what the field
actually contains. (This macro may be catalogued for use by other programmers.)
The Assembler cannot test the contents of a field at execution-time.
Logical operators AND, OR, and NOT combine terms in a logical expres¬
sion:
4. AIF ( &TAB EQ AND T’&ARG EQ 0’).R65 (If contents of &TAB are blank and
&ARG is omitted, branch to .R65. The latter is a way of checking if a macro¬
instruction operand is omitted—intentionally or accidentally.)
Finally, arithmetic operators, +(add), -(subtract), ^(multiply), and /(divide)
may combine terms of an expression:
5. AIF (L PROD GE (L &MULTCD+L &MPR+1)).VALID (If the length of product is
greater than or equal to the length of &MULTCD plus &MPR plus 1 branch
SDVAUD' ThlS teSt enSUr6S that the defined Product area is large enough for an
MP operation.) 6
Examine the AGO and AIF instructions in Figure 14-7. This example is similar
to Figure 14-1 with the additional checks that the dividend and divisor are defined as
packed, and that the quotient area is at least as large as the dividend plus divisor.
Figure 14-8 tests the macro. D10DIV shows valid operands that generate the correct
instructions. D20DIV and D30DIV illustrate invalid operands that generate error
313 Other Instructions
OTHER INSTRUCTIONS
There are as well three instructions not yet covered: ANOP, MNOTE, and MEXIT.
Figure 14-7 illustrates the use of ANOP, where AGO has to branch to
&LABEL2. Since AGO cannot branch to a variable symbol, it goes to .MULT contain¬
ing the ANOP operation, and immediately preceding &LABEL2.
MNOTE AND MEXIT. We use these operations to print error messages and to exit
from the macro.
Sequence symbol,
variable symbol,
or blank MNOTE any message, within apostrophes
Sequence symbol
or blank MEXIT blank
messages in Figure 14-7 warn that the dividend or divisor are not packed format and
that the quotient length is too short. In Figure 14-8 when the error condition occurs,
the Assembler statements are not generated. Before program execution, we should
first check for and correct any assembly errors.
MNOTE ’message’
AGO .FINISH (or any sequence symbol)
.FINISH MEND
SET SYMBOLS
SET symbols are variable symbols that define and assign values. We may then use
them to test values and to build instructions. SET symbols are assigned values when
we code SETA, SETB, or SETC Conditional Assembly instructions. They must first
have been defined by an LCL or GBL instruction. Local or global instructions may
define and assign an initial value. GBL's, and then LCL's, must be coded in the macro
definition immediately following the prototype statement.
, TCT ,USed deflne a SETA symbol. It creates a 32-bit field initialized with
zero. LCLB defines a SETB symbol that creates a 1 -bit field initial,zed with zero LCLC
GBLA GBLB, and GBLC similarly define SET symbols, for values that are to he
known in other macro expansions in the same assembly. They are briefly discuss^
SETA
i A, ^ETBtnd'snTTh61'' defi"e values
bE I B, and SETC, then assign ^ ini‘ialiZe SET 5ymbok The SET operations
to SET symbols.
315 Set Symbols
The maximum and minimum values of the expression are + 231 —1 and -231.
An expression consists of a term or an arithmetic combination of terms. Valid terms
are:
— Self-defining terms. Such a term has an inherent value, one that is not assigned a
value by the Assembler. These may be decimal (as 11), hexadecimal (as X'B'),
and binary (as B'l011 ')•
— Variable symbols, such as &AMT.
— Attributes for count, integer, length, number, and scale. Examples of SETA arith¬
metic are:
LCLA &FLD1.&FLD2
&FLD1 SETA 15
&FLD2 SETA &FLD1 +L&AMT+25
TERM VALUE
The maximum number of terms in the expression is 16. Also, brackets may contain
terms in the expression, such as (&COUNT — X'l B')*3.
Figure 14-9 illustrates LCLA and SETA. In this mixed-type macro, the first two
parameters are positional whereas the third and fourth are keyword. This macro
prints a heading line containing a heading title, page number, and the date. The
macro centers the heading title on the page.
3 MACRO
4 4NAME HEONG AHEAC.APACE.AC AT=0ATE.APRT = PRI NT
5 LOLA ALEN.AMID LENGTH A MIO-POINT
6 LCLC ALIT•AL1.AL2 AREA FOR CHARS.
7 TEST VALIOITV OF PARAMETERS
a A IF IT•APAGE NE *P*1.ERRPACK
9 AIF ( T • AHE AO NE 'CM.ERRCHAR
10 A IF I L •AHEAO GT 901.ERRSIZE HEADING > 90 CHARS?
11 .« SET VALUES
12 4LEN SETA L # AHEAC LENGTH OF HEAC1NG
13 AMID SETA I 120 —ALENl/2 CENTER HEADING
14 AL IT SETC * = C•*PACE*•• LITERAL FOR •PAGE’
15 AL 1 SETC •L••• LENGTH CODE
16 AL2 SETC •A CAT• DATE
17 .4
18 ANAME UNPK APRT + 1 15(31 .APAGE UNPK PAGE CTR.
19 0 I APRT♦117,X*F0• CLEAR UNITS ZONE
20 M VC APRT 4110(4 ) . AL IT MOVE PACE LITERAL
2 I MVC APRT+AM10.(ALEN).AHEAD MOVE HEADING
22 M VC APRT 41(AL1AL2).ADAT MOVE OATE
23 MEXI T
24 ERROR MESSAGES
25 .ERRPACK MNOTE •PAGE COUNT NOT DEFINED AS PACKED*
26 MEXI T
27 .ERRCHAR MNOTE •HEACING NOT DEFINED AS CHARACTER*
28 MEX IT
29 •ERRSIZE MNOTE •LENGTH OF HEACING EXCEECS PRINT AREA*
30 MEND
&LEN and &MID define two SETA symbols. AIF checks that the length of
heading does not exceed 90 bytes. (Assume 120 print positions with space for date
and page.) SETA assigns the length of &HEAD to &LEN. The title is centered by
calculating the first print position of &HEAD. For example:
These lengths are used in Figure 14-10. Check that they cause centering of the
heading and that the correct code is generated.
Figure 14-10 also illustrates the SETC symbol, covered next.
63 * •
64 * •
65 PRINT OC CL 12 1 • • PRINT AREA
66 CIUTAREA DC CL 12 1• • PRINT AREA
67 PAGEPK OC PL 2 • 0 • PAGE COUNTER
68 HEAOG1 DC CL23•HOTROO CUSTOM IMPORTERS*
69 HEADG2 DC CL 16* ABC OISTRIEUTORS*
70 HEADG3 DC CL 1 1*BAKER CORP.*
71 HEADG4 DS CLloO LONG HEADING
72 CATE DS CL 12 DATE AREA
73 CATOT DS CL 12 DATE AREA
&CHAR1: the character value SAM'S is assigned to the SETC symbol &CHAR1. Two
apostrophes within the expression denote a single apostrophe.
&CHAR2: Assume that &TYPE contains the value FIELD. The expression concate¬
nates FIELD with A and assigns FIELDA to &CHAR2.
&CHAR3: the value L'FLOAT is assigned to the SETC symbol &CHAR3.
In Figure 14-9 SETC defines three symbols, &LIT, &L1, and &L2. One SETC
assigns &LIT with a character expression to be used as a literal. Note the literal,
=C'PAGE', in the generated code in Figure 14-10. Instead of using &LIT in
the macro-definition, we could have coded the literal itself: MVC
318 MACRO WRITING
&PRT+110(4),—C'PAGE'. &L1 and &L2 are used to create a symbolic length refer¬
ence for moving the date to the print area. Note the macro-definition and generated
code for this example.
We have now covered all the features used in the macro HEDNG. Some
remaining items, SETB symbols, system variable symbols, and global SET symbols,
are covered next.
SETB—SET BINARY. SETB assigns the binary value 0 or 1 to a SETB symbol. SETB
determines if a condition is false (0) or true (1). SETB is commonly used as a switch
indicator in the macro definition.
In Figure 14-11 SETB is a switch &ERRB that determines it any errors have been
encountered ,n the macro-instruction. If an error is found, the Assembler prints the
appropriate message and the switch is set. The macro then continues with the next
test. Only after all validity testing does the macro terminate processing. In this wav
we fully test the macro-instruction each time it is used.
1 MACRO
2 4L00K LOOKP 4TABLE. ADDRESS OF TABLE
4SERARG. ADDRESS OF SEARCH ARGUMENT
4FUNCTN, ADDRESS TO STORE FUNCTION
4N0TFND ADDRESS IF ARG*T NOT FOUND
3 GBLB 4SAVIND SAVE AREA INDICATOR
4 LCLA 4LSER.4LENTRY LENGTH OF SEARCH 4 ENTRY
5 LCLB 4ERRB ERROR SWITCH INDICATOR
6 LCLC 4H,4HALF HALFWORD LITERAL
7 4ERRB SETS ( 1 ) SET ERROR INDICATOR TO 1
8 •* TEST FOR VALIDITY
9 A I F <T'4NOTFNO EQ • I • ) . A 10 IS NOTFND A VALID ADDRESS?
10 MNOTE •ADDRESS FOR NOTFOUNO IS INVALID*
i 1 4ERRB SETB (0 ) SET ERROR INDICATOR TO 0
l2 . A10 A IF (T•4T ABL E EQ *C* ANC T • 4SERARG EQ *C*) .A 20
13 A IF (T•4 T ABLE EO *P* ANC T • 4SERARG EQ *P*).A20
1 4 MNOTE •TABLE 44 SEARCH NOT BOTH CHAR OR PACKED*
1 5 4ERRB SETB (0 ) SET ERROR INDICATOR TO 0
16 . A20 A IF (4ERRB).A30 IS ERROR INDICATOR = 1?
1 7 MNOTE •MACRO CANNOT BE RESOLVED - TERMINATED*
ia MEXIT
1 9 .* SET VALUES
20 • A30 ANOP
2 1 4LSER SETA L* 4SERARG LENGTH OF SEARCH ARGUMENT
22 4LENTRY SETA 4LSERFL•4FUNCTN LENGTH OF SEARCH FUNCTION
23 4H SETC • =H• SET UP HALFWORD
24 4H ALF SETC •••4LENTRY'•• * CONSTANT
25 4LCOK ST 10.SAVREG SAVE REGISTER-10
26 LA 10.4T ABLE LOAD ADDRESS OF TABLE
27 AI F (T•4TABLE EO •P* ) .B1 0 IS TABLE DEFINED AS PACKED?
28 .* COMPARE SEARCH TO TABLE ARGUMENT
29 R4SYSNDX CLC 4SERARG,0(10) COMPARE CHARACTER
3C AGO • B 20
3 1 • BIO ANOP
22 R4SYSNOX CP 4SERARG.0(4LSER.10) COMPARE PACKED
33 .820 BE T4SYSNDX * EQUAL - FOUND
34 BL S4SYSNDX * LOW - NOT IN TABLE
35 AH 10.4H4HALF INCREMENT NEXT ENTRY
36 B R4SYSNDX
37 .* DEFINE savearea FIRST T IME ONLY
38 AIF (4SAVIND).830 HAS SAVIND BEEN DEFINED?
39 SAVREG DS F REGISTER SAVE AREA
40 4 SA VI NO SETB (1 ) SET INDIC AT OR ON (1)
4 l • B30 ANOP
42 .* ARGUMENT NOT FOUND
43 S4SYSNDX L 10.SAVREG RESTORE REG-10
44 B 4NOTFND GO TO ERROR ROUTINE
45 .* ARGUMENT FOUND
46 T4SYSNDX M VC 4F UNCTN.4LSER.(10) MOVE FUNCTION FROM TABLE
47 L 10.SAVREG RESTORE REG-10
48 MENO
The Assembler automatically assigns values to the three local system variable sym¬
bols, &SYSECT, &SYSLIST, and &SYSNDX. Because of its limited use &SYSECT is not
covered.
320 MACRO WRITING
LCLA, LCLB, and LCLC define local SET symbols for use within the same macro-
definition. GBLA, GBLB, and GBLC define Global SET symbols for communicating
values between different macro-definitions.
Global operations define the same initial values as do local operations. However,
they are initialized only once, the first time the Assembler encounters the GBLA
GBLB, or GBLC. We define global instructions immediately after the prototype
statement. Figure 14-11 gives an example. GBLB defines and initializes &SAVIND to
zero, and prevents SAVREG DS F from being defined more than once. The macro
??!w,k1SAV'ND contains zero- lf S<A 't Permits SAVREG to be defined and sets
&SAVIND to 1. &SAVIND is now permanently set to 1, through all succeeding
macro-instructions, and the Assembler, through the AIF statement, bypasses generat¬
ing more than one DS for SAVREG. (Consider how &SYSNDX could achieve the
same result.)
321 Extended Example—Table Look-Up Macro
X
N
O
61 + AH
II
INCREMENT NEXT ENTRY
62 + B ROOO 1
63+SAVREG DS F REGISTER SAVE AREA
64+ SO00l L 10.SAVREG RESTORE REG-10
65 + B R 10NCFND GO TO ERROR ROUTINE
66+T000I M VC RATEPK,4(10) MOVE FUNCTION FROM TABLE
67 + L 10.SAVREG RESTORE REG-10
The table look-up macro, LOOKP, is defined in Figure 14-11 and used in Figi
14-12. LOOKP permits us to code in one statement a table look-up routine that
The macro allows for either character or packed arguments. It requires that the
table contain discrete arguments (unique numbers such as Job or Stock numbers,
rather than table ranges as in income tax), in ascending sequence. The comments
beside each parameter explain the symbolic parameters in the prototype operand.
We must code as the fourth parameter in the macro-instruction the address to which
the look-up routine branches if the search argument cannot be found. The program
must contain the address of this error routine. The routine should provide usual error
handling, such as the printing of a message.
PROBLEMS
SUBPROGRAMS AND
OVERLAYS
This chapter covers the concept of writing and assembling programs as separate
subprograms. This chapter uses the general term subprogram to mean a section of
coding that comprises a separate part of the program, such as a control section
(CSECT) or a phase. The link edit step combines the separate subprograms into a
single executable program. We may want to code a program in more than one
subprogram for the following reasons:
CSECT—CONTROL SECTION
Chapter 6 introduced the term control section (CSECT). A CSECT is a block of coding
that can be relocated without affecting the operating logic of the program. Both the
Assembler and Linkage Editor process control sections, not programs. We may code
323
324 SUBPROGRAMS AND OVERLAYS
CSECTs as separate assemblies, each with its own unique base registers. Then we link
edit the CSECTs into one or more phases, the Linkage Editor output. A program may
consist of one or more phases, and a phase may consist of one or more control
sections. Among the ways to section a program into subprograms are:
1. The program may consist of a single phase—one or more control sections. The
CSECTs are assembled separately or together, and link edited into a single phase.
For execution, the system loads the entire phase into storage.
2. The program may consist of more than one phase, each with one or more CSECT.
Each phase is separately assembled, then link edited together. At execution-time,
the system loads the first (root) phase into storage. The root phase loads (overlays)
the other phases into storage as required.
There are two main problems associated with the use of subprograms:
1. Some data is common to more than one subprogram. But data is defined in only
one subprogram. Because subprograms are assembled separately, the Assembler
treats each subprogram as a completely different program. Data defined in one
subprogram is not therefore known in another. Among the ways of making data
known between subprograms are the use of "DSECTs" and "passing parameters".
2. A subprogram must be able to link to another subprogram, its register contents
must be saved (especially base registers), and there must be some means of
returning and restoring the register contents. The Assembler macros that provide
this linkage are CALL, SAVE, and RETURN. The Assembler requires a standard
savearea for registers and a standard linkage convention.
We will first examine a simple case of how a DSECT works. Then we will see
how to assemble and link together two CSECTs for execution. The last example
combines three separately assembled phases into one program—a root phase and
two overlay phases.
DSECT—DUMMY SECTION
We may want to describe a data area without actually reserving any storage. For
example, the main subprogram, SUBPROGA, contains the main data and certain
other coding, including instructions to link to SUBPROGB. SUBPROGB is a sepa¬
rately assembled control section. Within SUBPROGB we want to reference the main
data that is defined and exists in SUBPROGA. We may describe this main data in
SUBPROGB so that when-assembling SUBPROGB, the Assembler knows the names,
lengths, formats, and relative position of each field in SUBPROGA. For this purpose
we may use a special Assembler instruction, DSECT, Dummy Section.
The name of the DSECT refers to the first (leftmost) byte of the section. DSECT
reserves no storage. Instead, it gives the Assembler a mask or image of data defined
elsewhere. Figure 15-1 illustrates a DSECT defined within a CSECT. The partial
program reads card records with two buffers and no workarea (IOREG = 5). Rather
than transfer the current buffer to a workarea with MVC CARDIN,0(5), we want to
process input records directly in the buffer, and we want the fields defined.
Note the following: The DSECT, called DATAIN, generates no object code. The
fields defined within the DSECT tell the Assembler the names and formats. USING
DATAIN,5 assigns register-5 as a base register for DATAIN. This is because the CARD
buffers are under register-5 (IOREG = 5). Register-5 acts as a base register with respect
GET INCARD
LR 5,1
It is also possible to use register-1 as the DSECT base register, provided the
program executes no macro that destroys the base address while it is still required.
SUBPROGRAM LINKAGE
We may use DSECTs to make data known between separately assembled subpro¬
grams. Additionally, we use standard linkage and saveareas to link between subpro¬
grams and to save the contents of registers.
LINKAGE REGISTERS. The standard linkage registers are 0, 1, 1 3, 14, and 15:
REGISTER
USE
0 & 1 Parameter registers, used by the CALL macro to pass "parameters" (i.e.
addresses of data) to the called program.
13
Savearea re8'ster—contains the address of the calling program's savearea,
to be stored by the called program.
14
Return register—contains the address of the calling program, to which the
called program is to return.
327 Subprogram Linkage
Displace¬
Word ment Contents of each fullword
1 0 Used by PL/I programs.
2 4 Address of the savearea of the calling program.
The called program saves this in its own savearea.
3 8 ♦Address of the savearea of the called program.
4 12 ♦Contents of register-14, return address to the calling
program.
5 16 ♦Contents of register-15, the address of the entry
point to the called program.
6 20 ♦Contents of register-0.
7-18 24 ♦Contents of registers-1 through 12.
Assume that SUBPROGA is the main subprogram, loaded in storage and being
executed. SUBPROGA calls SUBPROGB for execution (SUBPROGB must also be in
storage). SUBPROGA is the calling program, and SUBPROGB is the called program.
TE1E CALL MACRO. We use CALL in the calling program to link to the called
program. The operand 'entrypoint' is the name of the first executable instruction of
the called program. (Following entrypoint is an optional parameter list. Parameters
are symbolic addresses that we want known in the called program.) CALL loads the
address of the next sequential instruction in register-14 and branches to the called
program.
LOC OBJECT CODE STMT SOURCE STATEMENT
45 END BEGINA
// EXEC ASSEMBLY
34 END PROGB
328
329 Linking Two Control Sections
THE SAVE MACRO. When we link to the called program, we must save the con¬
tents of the registers of the calling program. The calling program defines the standard
savearea for this purpose. Before issuing the CALL macro, we first load the address of
the savearea in register-13. At the beginning of the called program we code SAVE
(14,12) to save the contents of the registers, except 13.
THE RETURN MACRO. In order to return to the calling program, we code RETURN
(14,1 2) to restore the original contents of the calling program's registers and to return
to the calling program.
Next we examine the generated code for the macros and the additional instruc¬
tions needed to complete the linkage.
Figure 15-3 gives skeleton coding for two separately assembled CSECTs—a calling
subprogram, PROGA, and a called subprogram, PROGB. The savearea in PROGA is
called SAVEA, and that in PROGB is SAVEB. PROGA defines common data under
DATA (immediately at the start). DATA is subject to base register-4, and the rest of
the program following BEGINA is under base register-3. Before calling PROGB we
load register-13 with the address of our savearea, SAVEA. For the macro CALL
PROGB, the Assembler generates:
are many subprograms, we can refer to this field for debugging and tracing if the
program does not work correctly. The linkage routine has now stored the following:
SAVEA SAVEB
Word Displ't Contents Word Displ't Contents
1 0 1 0
2 4 2 4 A(SAVEA)
3 8 A(SAVEB) 3 8
4 12 A(A10RTN) 4 12
5 16 A(PROGB) 5 16
6-18 20 Contents of registers 6-18 20
0-12
Now PROGB may perform required processing, and reference the fields de¬
fined in the DATAB DSECT (actually DATA in PROGA). In order to return to the
calling program, PROGA, we simply reload register-13 with SAVEB+4, the address
of SAVEA.
The RETURN macro next generates:
RETURN restores the original SAVEA registers (14 through 12). Since register-
14 now contains the return address (A1ORTN), BR branches to this address. We now
resume normal processing in PROGA, with base registers reinitialized.
The question may arise: Why doesn't PROGA save its own registers in SAVEA
before linking to PROGB? Assume that this is done, and PROGB then initializes its
own register values. When PROGB returns to PROGA, PROGA's base registers are
not loaded—and without a base register PROGA has no way to reload its own
registers.
In this example, SAVEB does not require a full save area. This is the way we
would define SAVEB if PROGB were to link to another subprogram. If so, then the
called program would store PROGB's registers, linkage address, and savearea in
SAVEB.
TECHNICAL NOTE ON USING. One rule of the Assembler is "in calculating the
base register to be used, the Assembler always uses the available register giving the
smallest displacement". This rule sometimes causes the Assembler to override a
DROP or another USING. Suppose, for example, that the program uses two base
registers (3 and 4). The common data is under register-5 and is defined toward the
end of the CSECT:
331 Passing Parameters
BALR 3,0
USING *>3,4 3 & 4 are base registers for program
USING DATA,5 5 is base register for common data
Depending on the size of the program preceding DATA, the Assembler may
apply register-4 to DATA rather than the specified register-5. For this reason, the
program defines the common data before the BALR/USING where the Assembler is
sure to apply the correct base register.
PASSING PARAMETERS
Another way to make data known between subprograms is through the use of “pass¬
ing parameters." The CALL statement contains a parameter list of the address(es) to
be passed to the called program:
CALL subprogram,(parameter-list)
Each parameter generates a fullword address, one after the other. CALL loads into
register-1 the address of the first parameter in the list. Since the parameter is itself an
address, register-1 will contain the address of the first address. The called program
can load the address of the first parameter into an available register.
Figure 1 5-4 provides the same simple example as the previous one, converted
to parameters. In the calling program, the instruction
CALL PROGB,(WAGEPK)
loads the address of WAGEPK's address into register-1 and links to PROGB. The code
that the CALL generates is (in part) the following:
The called program uses this address to load the actual address of WAGEPK into
332 SUBPROGRAMS AND OVERLAYS
// EXEC ASSEMBLY,SI2E=64K
16 * •
0000 1 E 5600 9026 17 L 13.SAVEB+4 LOAD ADDRESS OF SAVEA
18 RETURN (14.12) RETURN TO PROGA
25 END PROGB
register-8: L 8,0(0,1). The program can use this address explicitly as a base address
reference. In the instruction
MP 0(4,8),4(2,8)
any input/output or CALL executed in PROGB will destroy the contents of registers
13 and 15, causing a subsequent execution error.
LINKING PHASES
We may assemble and link edit one or more control sections, and may arrange the
assembly so that the Linkage Editor output is one or more phases. Up to now our
programs consist of only one phase. The Linkage Editor writes the object code phase
into the Core Image or Load library. The job card // EXEC causes the first or only
phase to load into main storage and to begin execution. If we have organized the
program into additional phases, the system does not load them into storage. We use
the LOAD or FETCH macros to load subsequent phases. The purposes of organizing a
program into phases are:
The name gives the symbolic name of the phase, up to 8 characters. If the
program consists of more than one phase, then the first four characters of each phase
name must be identical. The origin gives the address of where the phase is to load at
execute-time. Among the commonly used entries are:
334 SUBPROGRAMS AND OVERLAYS
// OPTION LINK,NQXREF.LOG
ACTION MAP
PHASE PMASA.BOOT
✓/ EXEC ASSEMBLY.SIZE=64K
38 4 •
39 4 •
40 LOAD PHASC
000042 1 8F1 LOAD PH AS C INTO STORAGE
46 LR 15.1
000044 4 IDO LOAO PHASC ENTRY POINT
3052 47 LA 13.SAVEA
LOAD ADDRESS OF SAVEAREA
48 CALL < 15)
LINK TO PHASC ENTRY POINT
51 4 •
52 4 •
53 CLOSE PRTR
61 EGJ
0C00D8 90 IOARPRT1 DS CL 12 1
000151 91 BUFFER-1 PRINTER FILE
IOARPRT2 DS CL 12 1
92 BUFFER-2 PRINTER FILE
ENTRY PRTR
C001DC 93 LTORG
0001 DO 5B5BC2D6D7CSD540 94 =C•$iBOPEN •
000108 D7C8C1E2C2404040 95 = CL8•PHASB •
0001E0 D7C8C1E2C3404040 96 = CL8•PHASC•
0001E8 5E5BC2C3D3D6E2C5 97 =C•$ SBCLOSE•
0001FO 00000000 98 =A(OATA)
99 END BEGINA
PHASE PMASB.*
// EXEC ASSEMBLY
PHASE PHASC1PHAS8
// EXEC ASSEMBLY
40 EXTRN PRTR
oooice 4 1 LTORG
00000000 42 =A(PRTR)
000106
43 = X • 40202021204B20202060 •
0001OC 40202021204B2020
PHASE name,ROOT: The name phase is the root phase, to be always in storage
during execution of the program. Only the first phase may be ROOT. Under a
simple operating system, the root phase begins at a doubleword address im¬
mediately following the Supervisor. In a multiprogramming system, the root
phase loads at the beginning of a partition.
PHASE name,*: The * references the Linkage Editor location counter (similar to that
of the Assembler). If not the first phase, the Linkage Editor assigns it to begin at a
doubleword address following the previous phase. If the first phase, it is assigned
a starting location like the root phase.
PHASE name,symbol: We may instruct the Linkage Editor that at execute-time this
phase is to be overlaid in storage beginning at the same address as a previously
defined phase.
In Figure 15-5 there are three phases. They are organized as follows:
Supervisor
PHASE PROGA, ROOT defines PROGA as the root phase, always in storage during
execution.
PHASE PROGB,* tells the Linkage Editor to begin the phase PROGB following the
previous phase (PROGA).
PHASE PROGC,PROGB tells the Linkage Editor to assign the phase PROGC to begin
at the same storage location as PROGB (an overlay).
THE LOAD AND FETCH MACROS. These macros are used to load a phase into
storage during program execution.
337 Linking Phases
THE LOAD MACRO. The operand contains the name of the phase to be loaded.
We may use the phase name or load the phase name into register-!. LOAD causes
the phase to load into storage and returns control to the calling phase. LOAD also
stores in register-! the entry point address of the called phase. This address is re¬
quired because we later use it to CALL the overlay phase for execution. LOAD should
be placed so that the overlay phase does not erase it.
THE FETCH MACRO. The operand contains the name of the phase to be loaded.
We may use the phase name or load the phase name into register-1. FETCH loads the
phase into storage and branches to its entry point address. In effect, FETCH acts as a
combined LOAD and CALL, but with no automatic return.
THE LINKAGE EDITOR MAP. In Figure 15-5, each phase name begins with the
same first four characters, PROG. At the end of the sample program is the Linkage
Editor Map. We cause this map to print with the DOS control statement ACTION
MAP. The map lists the starting address of each phase and CSECT in the program. In
large programs, the map is a useful debugging and tracing device.
The CSECT beginning IJD in the Linkage Editor Map represents the module
that IOCS generated for the DTFPR macro for the fi le PRTR in the program. The module
is called PRMOD. Details are in the IBM Supervisor and I/O Macro manual.
Other DOS modules include the following:
OVERLAY PROGRAM. Figure 15-5 illustrates a simple overlay program that links
three phases. The first phase initializes hours (HRSPK) in a product field (WAGEPK)
and links to the second phase. This phase multiplies hours by rate-of-pay (RATEPK) to
calculate wage, and returns to phase-1. Next, phase-1 loads phase-3 over phase-2,
and links to phase-3, which prints the wage.
338 SUBPROGRAMS AND OVERLAYS
DETAILED EXPLANATION. After assembly and link edit, the // EXEC card loads the
first phase, PHASEA, into storage. The first statements define the common data area.
At BEGINA, base register-3 for the program and register-4 for the common data area
are loaded. Then LOAD causes PHASB, the second phase, to load into storage,
following PHASA. LOAD also places in register-1 the address of the entry point to
PEHASB. The program stores this entry point in ADDRESB for later use. The program
then initializes WAGEPK with HRSPK, and links to PHASB.
PHASB saves the registers of PHASA and initializes its own registers. Then it
multiplies WAGEPK by RATEPK (DSECT entries, defined in PHASA), and returns to
PHASA.
PHASA next loads and links to PHASC, which saves the registers, prints
WAGEPK, and returns to PHASA. At this point, PHASA, and the program, terminate.
Under OS, the relative location of each CSECT appears in the "CROSS REFER¬
ENCE TABLE" following the last assembled CSECT. Look for "CONTROL SECTION"
that could appear with such entries as:
CONTROL SECTION
NAME ORIGIN LENGTH
PHASA 00
PHASB 6D8
PHASC 6D8
If the entry-point addresss (EPA) of the first CSECT, PHASA, is 99080, then the
entry-point of both PHASB and PHASC in this case is:
Any field can be found in a storage dump through use of the EPA plus the
contents of the location counter (LOC) on the program printout.
Note also that execution diagnostics show the contents of the registers under
"SA" (save area) in the same 18 fullword format as explained in this chapter.
OVERLAY CONSIDERATIONS
LOAD brings a phase into storage, where it remains until overlaid by another phase.
Therefore, once we LOAD a phase, we may CALL it any number of times. To load
339 Problems
and immediately execute a phase once, we may use FETCH. If there is insufficient
storage, large programs may require loading and reloading phases as needed. A
common use of overlays is the following:
1. The ROOT phase contains all common declaratives and basic main logic. It loads
(or fetches) the initialize phase.
2. The initialize phase contains routines executed only once, such as OPEN files,
handle date card, and extract the date from the communications region.
3. The ROOT phase then overlays the initialize phase with the general processing
phase, which includes calculations, and input/output. (Storage restrictions may
require overlaying some of these phases as required.)
4. At the end of the run, the ROOT phase overlays the general processing phase with
an end-of-file phase. This phase includes final totals and CLOSEs the files.
There are countless ways to handle program overlays. However, in all pro¬
gramming problems, the simplest way is generally the best way. And simpler may
include dividing a problem not into phases but into completely separate programs.
PROBLEMS
15-1. For what reasons would it be useful to organize a program into subprograms?
15-2. What is the difference (if any) between a CSECT and a DSECT?
15-3. USING tells the Assembler to apply a base register to a particular section of
code. What instruction tells it to discontinue applying the base register?
15-4. Recode and test a previous program using Locate Mode for input and output,
with buffers defined under a DSECT.
15-5. Why is it an especially dangerous practice to use register-13 as a base reg¬
ister?
15-6. For subprogram linkage, what is the purpose of registers 0, 1, 1 3, 14, and 15?
15-7. What are the three macros, and their purpose, required to link to another
subprogram, to preserve register contents and to return?
15-8. Revise and test any previous program into two separately assembled CSECTS.
Use a DSECT for common data.
15-9. Revise problem 15-8, changing the common data from a DSECT to passing
parameters.
15-10. What is the difference between the LOAD and CALL macros? Between
LOAD and FETCH?
15-11. Revise any previously written program into 4 phases. Phase-1 (ROOT) calls
Phase-2 for initialization and OPEN. Phase-1 then overlays Phase-2 with
Phase-3 for processing. At end-of-job, Phase-1 overlays Phase-3 with
Phase-4 for final processing.
CHAPTER 1 6
OPERATING SYSTEMS
The topic of operating systems is large and complex. This chapter introduces material
that is useful for advanced Assembler programming. The first section examines gen¬
eral operating systems and its various support programs, including the Assembler and
the Linkage Editor. The following sections examine the functions of the Supervisor,
the Program Status Word, and the interrupt system. Finally, there is a discussion of
channels, Physical IOCS, the channel program, and the input/output system.
A knowledge of these features can be a useful asset when serious bugs occur
and where the solution requires a more intimate knowledge of the system. For the
serious student, these topics are a useful introduction to systems programming and
the relationship between the computer hardware and manufacturer-supplied
software.
OPERATING SYSTEMS
IBM supplies various programs ("software”) to support the computer system. These
include language translators such as Assembler, COBOL, and PL/I, and "utility”
programs to facilitate disk and tape processing. The levels of programming support
340
341 Operating Systems
depend on the size of the CPU and the needs of the user. Among the categories of
support are Basic Programming Support (BPS) for the minimum card, tape and disk
installations, and operating systems.
On earlier and on smaller computers the operators were very much involved in
operating the computer. For example, to assemble and execute a program, the oper¬
ator would have done the following:
1 Preceding the job is a job control card that tells the operating system to assemble
' a program. The Assembler program is stored (catalogued) in a library on disk. The
system loads the Assembler program from the disk library into storage.
342 OPERATING SYSTEMS
2. The Assembler reads and translates the source program. It writes the object pro¬
gram onto another library on disk.
3. Following the source program is a job control card telling the system to execute
the assembled object program. The system then loads the object program from the
disk library into storage.
4. The program executes the data.
5. Following the data is a job card telling the system that there is no more data. The
operating system is now ready to process the next job.
The computer central processing unit (CPU), main storage, and input/output
devices are called the hardware. IBM "customer engineers" install the hardware and
service breakdowns. The operating system is a group of IBM-supplied programs, and
is called software. IBM "system engineers" help install and maintain the software.
Large installations have their own "systems programmers" who are responsible for
maintaining these complex operating systems. An operating system is composed of
several interrelated parts. Disk Operating System (DOS), on which this text is mostly
based, is organized as in Figure 16-2. The three main parts are Control Program
System Service Programs, and Processing Programs.
CONTROL PROGRAM. The control program controls all other programs that are
processed. It consists of the Supervisor, Job Control, and Initial Program Load. Under
OS, the functions are Data Management, Job Management, and Task Management.
The Supervisor is the nucleus of the operating system. At all times part of the
Supervisor resides in lower storage. The system loads user programs (ours) in storage
after the Supervisor area. Therefore there are always two (or more) stored programs in
storage: the Supervisor program and our program(s). Only one is executed at one
time, but control passes between them. The Supervisor's functions include the han-
343 Operating Systems
dling of "interrupts" (such as our program asking to use an input or output device),
fetching required routines from the program library, and handling program execution
errors. An important part of the Supervisor is the Input/Output Control System (IOCS)
to handle the complex input/output. IOCS handles such items as checking for valid
tape and disk files, and data transfer between I/O units and storage. A later section
covers the Supervisor in detail.
Storage:
IBM
Supervisor
Program
User
Program(s)
lob Control handles the transition between jobs run in the system. When
required, the Supervisor loads job control into storage. We provide job control cards
with our job to tell the system what we want to do next.
Initial Program Load (IPL) is a program that the operator uses to load the
Supervisor into storage (done daily or whenever required).
SYSTEM SERVICE PROGRAMS. These include the Linkage Editor and the Libra¬
rian.
THE LINKAGE EDITOR. The Linkage Editor has two main functions:
344 OPERATING SYSTEMS
THE LIBRARIAN. The operating system contains libraries on disk or tape to store or
catalogue IBM and our own commonly used programs and routines. Under the Disk
Operating System (DOS), there are three libraries:
1. The Source Statement Library (SSL) catalogues any program or routine still in
source code. We use instructions, such as COPY, to include the catalogued
source code into our program for subsequent assembling.
2. The Relocatable Library (RL) catalogues frequently used routines such as IOCS.
The routines are stored in assembled format not yet ready for execution. We use
the instruction INCLUDE to tell the Linkage Editor to include such routines in with
our assembled program.
3. The Core Image Library (CIL) contains programs and routines in executable for¬
mat, ready for execution. The CIL contains, for example, Assembler, PL/I,
COBOL, and other translator programs, and the various utility programs such as
Sort. We use the job control card EXEC to request the Supervisor to load a
program from this library into main storage for execution.
1. Language Translators supplied by IBM with the system include Assembler, PL/I,
Fortran, COBOL, RPG, and ALGOL.
2. Utility Programs supplied by IBM include various utility and special purpose
programs, such as copy disk to printer, disk initialization, and various sort/merge
programs.
3. User-Written Programs are written by the user (us) and are not maintained or
supported by IBM. All examples in this text are user-written programs.
THE SUPERVISOR
The size of the operating system and of the Supervisor vary considerably according to
their complexity and functions they must perform. A medium-sized Supervisor under
345 The Supervisor
DOS typically requires some 10,000 bytes of main storage, whereas under a large
system the Supervisor often requires over 100,000 bytes.
Although the Supervisor program resides permanently in lower main storage,
the first section up to X'200' is allocated for use by the CPU. These "Fixed Storage
Locations" are listed in Figure 16-3. Some of the locations are explained in the later
section, Program Status Word.
The Supervisor loads operating system routines stored on disk (usually) into
main storage as required. The section of storage that the Supervisor uses for tempor¬
ary routines is the "transient area". Figure 16-4 illustrates the layout of the Supervisor
in main storage (not an exact representation).
346 OPERATING SYSTEMS
1. Communication Region. This area contains the current date as well as other fields
shown in the diagram. (There is one Communication region for each partition
under multiprogramming.)
CO
a_
ID Address: Address:
Address:
User Area - set to zero Uppermost Uppermost Length of
Date Uppermost
when JOB statement is Job Name Byte of Byte of Problem
Mo/Doy/Yr u Byte of
Reserved read. (Communication (Entered from Current phase with Program
or i Problem
within o job step or un Job Control) Problem highest Label
Day/ Mo/Y r E Program
between job steps) o Program ending Area
Area
Phase oddress
?
ci
Bytej 0 7 8 11 12 22 23 24 31 32 35 36 39 40 43 44 45
2. Channel Scheduler. The channels provide a path between main storage and the
input/output devices, and permit overlapping of program execution with I/O
operations. The Channel Scheduler routine handles all I/O. If the requested chan¬
nel, control unit, and device are available, the channel operation begins. If busy,
the Channel Scheduler places its request in a queue to wait until the device is
available. The channel notifies the Channel Scheduler when the I/O operation is
complete, or that an error has occurred (these are "I/O interrupts").
3. Storage Protection. Storage Protection is an optional feature that prevents the
problem program from erroneously moving data into the Supervisor area and
destroying it. Under a multiprogramming system, storage protection is required to
prevent a program in one partition from erasing a program in another partition.
4. Interrupt Handling. An interrupt is a signal that informs the system that special
action is required, to interrupt the program currently being executed, and to give
control to the appropriate Supervisor routine. This topic is covered in detail in the
next section, PSW.
5. System Loader. This routine is responsible for loading programs into main storage
for execution.
6. Error Recovery. For each I/O device (or class of devices) there is a special routine
to handle device error-recovery. When an error is sensed, the Channel Scheduler
invokes the required routine which attempts to correct the error.
347 The Program Status Word—PSW
7. Program Information Block (PIB). The PIB contains information tables required by
the Supervisor about the current program(s) in storage.
8. I/O Devices Control Table. This area contains the table of I/O devices that relate
physical unit addresses (X'nnn') with logical units (SYSxxx).
9. Transient Area. This area provides temporary storage for routines that the Super¬
visor loads as required: OPEN/CLOSE, DUMP, computer operator messages,
end-of-job handling, some error recovery, and "checkpoint" routines.
The PSW is a doubleword of data stored in the control section of the CPU. (On small
models, the PSW is only a fullword in length, and its format differs from that de¬
scribed here; its functions, however, are similar.) The PSW controls an executing
program and indicates its status. There are two PSW modes that provide control and
status information: Basic Control (BC) mode and Extended Control (EC) mode. Both
the 360 and 370 use BC mode, and the mode is indicated by a 0 in the PSW bit-12.
EC mode is available only on the 370 for "virtual storage", with the "extended-
control" facility. When in EC mode, PSW bit-12 contains a 1. For each mode the
PSW format is the same in only certain positions. The charts next show the two
modes (bits are numbered from left to right zero through 63):
0 6 7 8 11 12 IS 16 23*24 31
Program
ILC CC Instruction address
mask
32 34 36 39 40 7^48 sICT S3
0-5 Channel 0 to 5 masks 32-33 (ILC) Instruction length code
6 Mask for channel 6 and up 34-35 (CC) Condition code
7 (E) External mask 36 Fixed-point overflow mask
12 (OOI Basic control mode 37 Decimal overflow mask
13 (M) Machine-check mask 38 Exponent underflow mask
14 (W«1) Wait state 39 Significance mask
15 (P—1) Problem state
32 39 40 47*48 5S66 63
1 (R) Program event recording mask 15 (P=1) Problem state
5 (T=1) Translation mode 18-19 (CC) Condition code
6 (I) Input/output mask 20 Fixed-point overflow mask
7 (E) External mask 21 Decimal overflow mask
12 (C— 1) Extended control mode 22 Exponent underflow mask
13 (M) Machine-check mask 23 Significance mask
14 (W=1) Wait state
Bit 15: State. In both modes, 0 = Supervisor state and 1 = Problem state (the
computer always functions in one or the other state). When the computer is
executing the Supervisor program, the bit is 0, and all instructions are valid.
When in the Problem state, the bit is 1, and certain privileged instructions (such
as Start IO and Load PSW) cannot be executed.
Bits 16-31: Program Interrupt Code (BC mode only). The computer sets these bits
according to the type of program interrupt when one occurs. The following list
of interrupt codes shows the hex representation of the 16-bit code:
Bits 34-35: Condition Code (BC mode only. Under EC mode, the Condition code is
in bits 18-19). Certain arithmetic and logical instructions set this code.
Bits 40-63: Instruction Address (both modes). This area contains the address of the
next instruction to be executed. The CPU accesses the designated instruction
from main storage, decodes it in the control section, and then executes it in the
arithmetic/logical section. The first two bits of every machine code instruction
indicate its length. Assume an RR-format instruction, two bytes long; when
executing the RR instruction, the CPU increments the instruction address in the
PSW by two, and this now indicates the address of the next instruction. In the
case of a "branch'' instruction, the branch address may replace the PSW instruc¬
tion address.
INTERRUPTS
An interrupt occurs when it is necessary for the Supervisor to perform some special
task. There are six main classes of interrupts:
3. External Interrupt. An external device may need attention. For example, the com¬
puter operator may press the request key on the console typewriter, or there may
be a request for telecommunications.
4. Machine Check Interrupt. The machine-checking circuits may detect a hardware
error, such as a byte not containing an odd number of bits (odd parity).
5. Input/Output Interrupt. Completion of an I/O operation making the unit available
or malfunction of an I/O device (such as damaged tape) cause this interrupt.
6. Restart Interrupt on the 370 permits the operator or another CPU to invoke
execution of a program.
For every interrupt, the system alters the PSW as required, and stores the PSW
in a Fixed Storage Location, where it is available to any program for testing.
The PSW referenced to this point is often called the “current" PSW. When an
interrupt occurs, the computer stores the current PSW and loads a “new” PSW that
controls the new program (usually the Supervisor Program). The current PSW is in the
control section of the CPU, but the “old" and “new" PSW's are stored in main
storage.
Main storage
The interrupt replaces the current PSW: (1) It stores the current PSW into main
storage as the "old" PSW, and (2) It fetches a “new" PSW from main storage, to
become the “current" PSW. (The old PSW will therefore contain in its instruction
address the location following the instruction that caused the interrupt.) The com¬
puter stores PSW's in 12 doubleword locations in Fixed Storage; six are for “old"
PSW's and six for “new" PSW's, depending on the class of interrupt:
1. Assume that our program requests input from disk. The input macro-instruction,
GET or READ, contains a Supervisor Call to link to the Supervisor for I/O. This is a
Supervisor interrupt.
2. The Instruction Address in the current PSW contains the address in our program
immediately following the SVC that caused the interrupt. The CPU stores this
current PSW in the old PSW for Supervisor interrupt, location 32. The new PSW
for Supervisor interrupt, location 96, contains Supervisor state bit = 0 and the
address of the Supervisor Interrupt routine. The CPU moves this new PSW to the
current PSW, and is now in Supervisor state.
3. The PSW Instruction Address contains the address of the Supervisor I/O routine,
which now executes. The Channel Scheduler requests the channel for disk input.
4. To return to our program, the Supervisor loads the old PSW from location 32 back
into the current PSW. The instruction "goes to" the PSW instruction address,
which is the address in our program following the original SVC that caused the
interrupt. The system switches from Supervisor back to Problem state.
In the case of a program check interrupt, the computer sets the cause of the
program check in PSW bits 16-31, the Program Interrupt code. If the Problem pro¬
gram attempts arithmetic on invalid data, the computer senses a "Data Exception,"
and stores X'0007' in PSW bits 16-31 (i.e., B'l 1 V in bits 29-31). The computer then
stores the current PSW in old PSW location 0040, and loads the new PSW from 0104
into the current PSW. This PSW contains the address of the Supervisor s Program
Check routine, which tests the old PSW to determine which type of program check
caused the interrupt.
The Supervisor prints the contents of the old PSW in hexadecimal and the cause
of the program check, "DATA EXCEPTION", "flushes" the interrupted program, and
begins processing the next job. Suppose that the invalid operation is an MP at
location X'6A320'. Since MP is six bytes long, the instruction address in the PSW and
the one printed will be X'6A326'. We can tell from the Supervisor diagnostic mes¬
sage first, that the error is a "Data Exception", and second, that the invalid operation
immediately precedes the instruction at X'6A326'.
CHANNELS
On the 360/370, channels direct data between devices and main storage. A channel
is a component that functions as a separate computer operated by "channel com¬
mands" to control input/output devices. Channels permit attaching a great variety of
I/O devices. There are two types of channels:
or X'01 E'. Assume that the two disk devices are numbered 0000 and 0001; if they are
both attached to channel 1, control unit 9, their physical addresses are respectively
X'l90' and X'191'.
SYSIPT The card reader, tape, or disk device used as input for programs.
SYSRDR The card reader, tape, or disk device used as input for job control for the
system.
SYSIN The system name to assign both SYSIPT and SYSRDR to the same card
reader, tape, or disk device.
SYSLST The printer, tape, or disk used as the main output device for the system.
SYSPCH The card punch, tape, or disk used as the main device for "punching."
SYSOUT The system name to assign both SYSLST and SYSPCH to the same tape
device.
SYSLNK The disk area used as input for the Linkage Editor.
SYSLOG The console typewriter (or printer) used by the system to log operator
messages and job control statements.
SYSRES The disk or tape device where the operating system resides.
SYSRLB The devices for the relocatable and system libraries.
and
SYSSLB
In addition, there are programmer logical units, SYS000 - SYSnnn. A user may
assign any valid symbolic name to a device, such as assigning a disk drive, physical
address X'l60', with a logical address SYS002. The Supervisor stores these physical
and logical addresses in a table in order to relate them. The table is called I/O
Devices Control Table, and in simplified form could contain the following:
Lor example, a reference to SYSLST is to the printer, and the disk device
X'l 60', is known as SYSLNK, SYSRES, and SYS002, depending on its particular use!
We may assign a logical address permanently or temporarily, and may change
353 Physical IOCS
logical addresses from job to job. For instance, we could use an ASSGN job control
statement to reassign SYS035 from tape output for a program to disk output on
X'l 60'.
PHYSICAL IOCS
The basic level of IOCS provides for channel scheduling, error recovery, and inter¬
rupt handling. We must write the “channel program" (the Channel Command
Word), and synchronize the program with completion of the I/O operation. We must
also provide for testing the Command Control Block for certain errors, checking
wrong-length records, switching between I/O areas where two are used, and, if
records are blocked, for blocking and deblocking. PIOCS macros include CCW,
CCB, EXCP, and WAIT.
COMMAND CONTROL BLOCK—CCB. There must be a CCB for each I/O device
that PIOCS macros reference. The CCB comprises the first 1 6 bytes of most generated
DTF tables. The CCB communicates information to PIOCS to cause required I/O
operations, and receives status information after the operation.
Blockname—The symbolic name associated with this CCB, used as an operand for
the EXCP and WAIT macros.
SYSnnn—The symbolic name of the I/O device associated with this CCB.
Command-list name—The symbolic name of the first CCW used with the CCB.
354 OPERATING SYSTEMS
THE EXECUTE CHANNEL PROGRAM (EXCP) AND WAIT MACROS. The operand
of both EXCP and WAIT gives the symbolic name of the CCB macro to be referenced.
The EXCP macro requests Physical IOCS to start an I/O operation, and PIOCS relates
the blockname to the CCB to determine the device. When the channel and the
device become available, the channel program is started. Program control then
returns to our program. The WAIT macro synchronizes program execution with
completion of an I/O operation, since the program normally requires its completion
before it can continue execution. For example, we have issued EXCP to read a data
block—we must now WAIT for delivery of the entire data block before we can begin
processing it. (When bit-0 of byte-2 of the CCB for the file is set to 'V, the WAIT is
completed and processing continues.)
EXAMPLE PHYSICAL IOCS PROGRAM. Figure 16-6 simply generates and prints
the sum of the digits from 1 through 10, i.e., 1 + 2 + 3+ ... + 10. The program
prints successively 1, then 3, then 6, etc., and terminates after the tenth calculation
with 55. Note that the operands of both EXCP and WAIT specify PRTR, the name of
the CCB. Operand-2 of the CCB designates PRCOMWD, the name of the CCW.
PHYSIO START 0
6 ALR 3.0
USING * .3
LA 8.10 ESTABLISH COUNT OF 10
DIGIT cc PL2•1•
SUM DC PL2•0•
SUM-OF-DIGITS ACCUMULATOR
END PHYSIO
CCW FLAG BITS. The flag bits in the CCW may be set and used as follows:
Blt 3^S/htm Data fla§Sby X 80 • This bit sPecif'es "data chaining". When the
CCW has processed the number of bytes defined in its Count field the I/O
operation does not terminate if this flag bit is set. The operation continues with
355 Problems
the next CCW in storage. We can use data chaining to read or write data into or
out of storage areas that are not necessarily adjacent. In the following three
CCW's, the first two specify data chaining with X'80' in the Flag bits, operand-3.
An EXCP and CCB may then reference the first CCW, and as a result, the chain
of three CCW's causes the contents of an 80-byte input record to be read into
three separate areas in storage—20 bytes in NAME, 30 in ADDRESS, and 30 in
CITY.
Bit 33, "Chain Command flag", set by X'40'. This bit specifies "command chaining"
to enable the channel to execute more than one CCW before terminating the I/O
operation. Each CCW applies to a separate I/O record. The following set of
CCW's could provide for reading three input blocks, each 100 bytes long.
Bit 34, "Suppress Length Indication flag", set by X'20', is used to suppress an error
indication that occurs when the number of bytes transmitted differs from the
count in the CCW.
Bit 35, "Skip flag", set by X'10', is used to suppress transmission of input data. The
device actually reads the data, but the channel does not transmit the record.
Bit 36, "Program Controlled Interrupt flag", set by X'08', causes an interrupt when
this CCW's operation is complete (used when one Supervisor SIO instruction
executes more than one CCW).
Bit 37, "Indirect Data Address flag". This flag as well as other features about Physical
IOCS are covered in the IBM Principles of Operation manual and in the appro¬
priate Supervisor manual.
PROBLEMS
16-1. What is the purpose (if any) of an operating system?
16-2. Where is the Supervisor program located?
16-3. What are the two main features of the Linkage Editor?
356 OPERATING SYSTEMS
FLOATING-POINT
OPERATIONS
The preceding chapters discussed arithmetic data in two formats: packed decimal
and binary, or fixed-point. There are two disadvantages that may derive from per¬
forming arithmetic in these formats: (1) The maximum and minimum values may be
inadequate for the calculation being performed; and (2) the programmer is fully
responsible for maintaining decimal and binary point precision. Assembler floating¬
point format has its own unique set of instructions designed to overcome these
disadvantages. (On many smaller models, floating-point is optional.) Its most common
use is for calculations such as in astronomy or in nuclear physics that require ex¬
tremely high or low values. Most programs requiring floating-point arithmetic are
written in high-level languages such as FORTRAN and PL/I. These languages replace
much of the tedious detail that Assembler programming requires. Studying the As¬
sembler floating-point instructions gives better understanding of the high-level lan¬
guages and results in better programming performance. Ftowever, be warned that the
problem in Assembler of translating between binary and floating-point is formidable.
FLOATING-POINT FORMATS
357
358 FLOATING-POINT OPERATIONS
f = fraction
A floating-point value omits the base (10) and stores only the exponent (e) and the
fraction (f). As a fullword, the floating-point value could be stored as
[03 123450
f
exponent
f
fraction
CONVERTING BASE 10 TO BASE 16. The 360 and 370 store floating-point values
in base 16. The following technique converts decimal values into hexadecimal.
Assume a decimal value of 123.45:
7B.0000
0.45
x 16 Multiply by 1 6
= 7.20 Extract the 7 = .7000
0.20
x 16 Multiply by 1 6
- 3.20 Extract the 3 = .0300
0.20
X 16 Multiply by 1 6
= 3.20 Extract the 3 = .0030
359 Floating-Point Formats
0.20
x 16 Multiply by 16
= 3.20 Extract the 3 = .0003
A/-|6 ~ 1 6e x f16
7B.7333 = 16° x 7B.7333
= 161 x 7.B7333
- 162 X .7B7333
We may therefore store this floating-point number without the base (16) as
02 7B7333
exponent fraction
meaning 1 62 x X77B7333'.
Floating-point, like binary data, may be defined in storage or loaded in reg¬
isters. Either way, floating-point values are represented in three formats:
SIGN. The sign, in bit position zero, applies to the fraction. A 0-bit means plus, and
a 1 -bit means minus fraction.
The exponent is incremented by 64 (X'40), and stored in hex format in bit positions
1-7. The lowest exponent is X'-40'; it is stored as X'-40' + X'40' = X'00'. The
highest exponent is X'3F'; it is stored as X'3F' + X'40' = X'7F'. This maximum
exponent is stored with all 7 bits on. Although the characteristic has no sign stored,
there is an implicit sign. For example, the exponent -2 is stored as X'-02' + X'40' =
X'3E'. Under base 16, such an exponent means 1 6-2.
Example: positive exponent, positive fraction. The decimal value 128.0 equals X'80',
or 162 x X',8'. It is stored in short form as:
hex binary
42 80 00 00 0100 0010 1000 0000 0000 0000 0000 0000
—t—- t "--
sign fraction sign char fraction
char
hex binary
hex binary
3E C8 00 00 0011 1110 1100 1000 0000 0000 0000 0000
t t
sign fraction sign char fraction
& char
The characteristic is calculated as X'3E' - X'40' = -02. We may now compute the
Normalize by shifting the fraction left two digits and decrement the characteristic
by 2:
Certain float operations involve prenormalizing (before the operation) and postnor-
malizing (after the operation). This practice is discussed along with the instructions.
DECLARATIVES
[symboll DC dTLn'constant’
6 *
7 * DC E SINGLE-PRECISION
8
003804 9 FLOATE1 DS E DEFINE FULLW0RD AREA
003808 427B7333 10 FL0ATE2 DC E • 123.451 POSITIVE VALUE
00380C C27B7333 1 1 FLOATE 3 DC E’-123.451 NEGATIVE VALUE
003810 413243FE413243FE 12 FLOAT E4 DC 3E•3.1416’ 3 CONSTANTS
003818 4 13243FE
0038 1 C 4164 FDF4RD9D4952 13 FL0ATE5 DC E'6.312,-.00015,O' MULTIPLE DECLARATION
003824 00000000
003828 427B7333 14 FL0ATE6 DC E 1 123.45E0' 123.45 X 1 = 123.45
00382C 427B7333 15 FLOATE’7 DC E' 1.2345E2' 1.2345 X 100 = 123.45
003830 427B7333 16 FLOAT E8 DC E•12345E-2' 12345 X .01 = 123.45
003834 450007B7 1 7 FL0ATE9 DC E S3 1123.45' UNNORMALIZED, USE OF SCALE
MODIFIER
19
20 $ DC D DOUBLE-PRECISION
21
003838 22 FL0ATD1 DS 0D ALIGN ON DOUBLEWORD BOUNDARY
003838 427B733333333333 23 FL OAT 02 DC 0'123.45' POSITIVE DOUBLE-PRECISION
003840 475912BC00000000 24 FL0ATD3 DC D ' 93.4E6' 93,400,000
003848 450007B733333333 25 FL OAT 04 DC 0S3'123.45' UNNORMALIZED, USE OF SCALE
MODIFIER
FLOATE9 uses a scale modifier to prevent normalization. TFie S3 causes the assem¬
bler to shift the fraction three positions to the right. The generated constant,
450007B7, is interpreted as
Note that compared to FLOATE6, this constant has lost some precision.
The second group defines double-precision or long form.
FLOATING-POINT REGISTERS
From context it should be clear where “register” in this chapter means floating-point
and where it means general register. The four floating-point registers (FPR's) num¬
bered 0, 2, 4, and 6, are each a doubleword in length (8 bytes or 64 bits). The only
valid references to FPR's are 0, 2, 4, and 6. The type of instruction determines that it
is a floating-point and not a general register. For example, AR references two general
registers, whereas ADR references two floating-point registers. A float operation may
364 FLOATING-POINT OPERATIONS
specify the use of the entire 64-bit register (double-precision) or the leftmost 32 bits
(single-precision).
FLOATING-POINT INSTRUCTIONS
The floating-point instruction set, although less extensive, is similar to that for binary.
The instructions are in RR and RX format, where R references a FPR and X references
a storage address subject to the usual base and index register. These instructions
permit data manipulation between registers and between registers and storage. Op¬
erations include load, store, add, subtract, compare, halve, multiply, and divide. The
operations are named to describe their purpose. Consider the following three Load
operations:
position: 12 123 1 23
Position-! signifies the type of operation, such as L for load, A for add. Exceptions are
LC, LN, LP, LT, and ST which require two letters.
Position-2 defines the length of the operation. E as in LE means single-precision, and
D as in LD means double-precision. U as in AUR implies single-precision un¬
normalized, and W as in AWR implies double-precision unnormalized.
Position-3 for RX format is blank. For RR, the letter R indicates a register, such as LER
and LTER.
LE R1,X2 or R1 ,D2(X2,B2)
Isymboll LD R1,X2 or R1 ,D2(X2,B2)
LER R1 ,R2
LDR R1,R2
3. LE and LER, being single-precision, process only the leftmost 32 bits of the
register; the right half is not affected.
4. These loads do not set the condition code.
29 *
35
36 * LD £ LDR LOAD DOUBLE PRECISION
37
003856 6800 305E 38 L0ADD1 LD 0 , FL OA TDP 1 REG-0: C27B74BC 6A7EF9DB
00385A 2860 39 LOAD02 LDR 6,0 REG-6: C27B74BC 6A7EF9DR
00385C 00000000
003860 C27B74BC6A7EE9DB 41 FL OAT DP 1 DC D'-123.456'
003868 434D28F6 42 FL0ATEP1 DC E ' 1234.56’
These instructions are similar to the previous load operations. Each in addition sets
the condition code: 0—zero fraction, 1—less than zero (except LPER and LPDR),
2—greater than zero (except LNER and LNDR).
LOAD COMPLEMENT—LCER and LCDR load the operand-2 register into operand-1
and reverse the sign bit: 0 becomes 1 and 1 becomes 0.
LOAD NEGATIVE—LNER and LNDR load the operand-2 register into operand-1 and
set the sign bit to 1, for minus.
366 FLOATING-POINT OPERATIONS
LOAD POSITIVE—LPER and LPDR load the operand-2 register into operand-1 and
set the sign bit to 0, for positive.
LOAD AND TEST—LTER and LTDR load the operand-2 register into operand-1.
These work the same as LER and LDR but in addition set the condition code.
STORE INSTRUCTIONS. STE and STD store the contents of a floating-point register
into a storage address. (The binary correlates are STH and ST.) The rules are: (1) STE
and STD store the contents of the operand-1 register in the operand-2 storage address
without normalization; (2) STE stores the leftmost 32 bits of the register; the storage
address must be an aligned fullword; (3) STD stores the entire 64 bits into an aligned
doubleword address.
In Figure 17-3, LD loads a long form value into register-0. STE stores the
leftmost 32 bits of register-0 in the fullword area, STORSING. STD stores the entire
64 bits of register-0 in the doubleword area, STORDOUB.
46 *
47 * STE 6 STD STORE FLOATING-POINT
48 *
00386C 6800 3076 49 LD 0 * EL TD1 REG-0: 44392800 00000000
003870 7000 3086 50 STE 0,STORSING STORSING: 44392800
003874 6000 307E 51 STD 0,STORDOUB STORDOUB: 44392800 00000000
ADDITION AND SUBTRACTION. There are instructions for both normalized and
unnormalized addition and subtraction. Subtraction inverts the sign of operand-2
and then adds the operands. The first step in add and subtract ensures that the
characteristics of both operands are equal. If unequal, the field with the smaller
characteristic is adjusted by shifting its fraction to the right and incrementing the
characteristic by 1 until the characteristics are equal.
41 290000 41 290000
+40 120000 = +41 012000 shift right and add
41 2A2000
367 Floating-Point Instructions
Example: fraction overflow. If the fraction overflows because of addition, then the
operation shifts the fraction right one hex digit, and increments the characteristic by
1. (If the characteristic overflows a program interrupt occurs.)
41 940000
41 760000
41 11A0000 fraction overflows
42 11A000 shift fraction right, add I to characteristic
ADD AND SUBTRACT NORMALIZED. The normalized add and subtract instruc¬
tions are:
AE R1.X2 or R1 ,D2(X2,B2)
[symbol] AD R1.X2 or R1 ,D2(X2,B2)
AER R1,R2
ADR R1.R2
SE R1.X2 or R1,D2(X2,B2)
[symbol] SD R1.X2 or R1,D2(X2,B2)
SER R1.R2
SDR R1.R2
Each operation sets the condition code as follows: 0—zero fraction in the result,
1 fraction less than zero, 2—fraction greater than zero, 3—exponent overflow in
the result.
ADD NORMALIZED. AE, AD, AER, and ADR add the contents of operand-2 to
368 FLOATING-POINT OPERATIONS
operand-1, and normalize the result. The short form operations—AE and AER—
process only the leftmost 32 bits of the register; the rightmost 32 bits are unaffected.
SUBTRACT NORMALIZED. SE, SD, SER, and SDR subtract the contents of
operand-2 from operand-1 and normalize the result. The short form operations—SE
and SER— process only the leftmost 32 bits of a register; the rightmost 32 bits are
unaffected.
59
60 ae e AER ADD SINGLE-PRECISION NORMALIZED
61
00388C 6820 3 OC 6 62 ADDFLTE LD 2 * AMTFLT 1 REG-2: 427B7333 33333333
003890 7A20 30CE 63 AE 2 * AMTFL T2 REG-2: 429AB603 33333333
003894 6840 3006 64 LD 4,AMTFLT3 REG-4: 435C0999 9999999A
003898 3A42 65 AER 4,2 REG-4: 4365B4F9 9999999 A
67 *
68 £ AD £ ADR ADD DOUBLE-PRECISION NORMALIZED
69 *
00389A 6820 30C 6 70 ADDFLTD LD 2 , AMTFL T1 REG-2: 427B7333 33333333
00389 E 6A20 30C.F 71 AD 2,AMTFLT2 REG-2: 429AB604 1 89374BC
00 3 8A 2 6840 3006 72 LD 4,AMTFL T3 REG-4: 435C0999 9999999A
0038Afe 2A42 73 ADR 4,2 REG-4: 4365B4F9 DB22D0E 5
75 £
76 SE £ SER SUBTRACT SINGLE-PRECISION NORMALIZED
77 *
003 8 A 8 6820 30 C 6 78 SUBFLTE LD 2 , AMTFLT1
0038AC 7R2 0 3 0CF REG-2: 427B7333 33333333
79 SE 2,AMTFL T2 REG-2: 42 5C3063 33333333
0038R0 6840 3006 80 LD 4,AMTFLT3 REG-4: 435C0999 9999999 A
00 3 8 84 3842 81 SER 4,2 REG-4: 43564692 9999999 A
83 *
84 * SD £ SDR SUBTRACT DOUBLE-PRECISION NORMALIZED
85
0038R6 6820 30C 6 86 SUBFLTD LD 2,AMTFLT1
0038RA REG-2: 427B7333 33333333
6B20 30CF 87 SD 2,AMT FLT 2 REG-2: 425C3062 4DD2 F1 AA
0038RE 6840 3006 88 LD 4, AMTFL T3 REG-4: 435C0999
0038C2 2842 89 9999999A
SDR 4,2 REG-4: 43564693 74BC6A7F
0038C4 00000000
003RCR 427R733333333333 91 AMTFL T1 DC D' 123.45' DOUBLEWORD
0038D0 421F42D0E5604189 92 AMTFLT 2 DC D ' 31.261' DOUBLEWORD
003808 435C099qQ999999A 93 AMTFLT3 DC D'1472.6' DOUBLEWORD
AU R1.X2 or R1,D2(X2,B2)
[symbol] AW R1.X2 or R1 ,D2(X2,B2)
AUR R1 ,R2
AWR R1 ,R2
SU R1,X2 or R1 ,D2(X2,B2)
[symbol] sw R1.X2 or R1,D2(X2,B2)
SUR R1.R2
SWR R1,R2
CE R1.X2 or R1,D2(X2,B2)
[symbol) CD R1.X2 or R1,D2(X2,B2)
CER R1.R2
CDR R1.R2
370 FLOATING-POINT OPERATIONS
97 *
1 05
106 * AM £ AWR ADD DOUBLE-PRECISION UNNORMALIZED
107 £
0038FF 6820 3116 108 addfltw LD 2 , AMT FLU 1 REG 2: 427B7333 33333333
00 38 F 2 6E20 31 IF 1 09 AW 2,AMTFLU2 REG-2: 44009AB6 04189375
0038F6 6840 3126 110 LD 4,AMTFLU3 REG-4: 435C0999 9999999A
0038FA 2F42 111 AWR 4,2 REG-4: 44065B4F 9DB22D0E
113 ❖
1 14 * su £ SUR SUBTRACT SINGLE -PRECISION UNNORMALIZED
115 *
0038 FC 6820 31 16 116 SURFLTU LD 2,AMTFLU1 REG-2: 427B7333 33333333
003900 7F20 3 11 F 117 SU 2,AMTFLU2 REG-2: 4400 5C 30 33333333
003904 6840 3126 1 18 LD 4,AMTFLU3 REG-4: 435C0999 9999999A
003908 3F4 2 119 SUR 4,2 REG-4: 44056469 9999999A
121
122 * SW £ SWR SUBTRACT DOUBLE--PRECISION UNNORMALIZED
123
00390A 6820 3116 124 SURFLTW LD 2,AMTFLU1 REG-2: 427B7333 33333333
0039 0 F 6F20 31 IF 125 SW 2, AMTFLU2
003912 2F44 REG-2: 44005C30 624DD2F1
126 SWR 4,4 REG-4: 00000000 00000000
003914 00000000
003918 427B733333333333 128 AMTFLU1 DC D' 123.45' DOUBLEWORD NORMALIZED
003920 44001F42D0E56042 1 29 AMTFLU2 DC DS2'31.261' DOUBLEWORD UNNORMALIZED
00 392 8 435C09999999999A 130 AMTPLU3 DC D'1472.6' DOUBLEWORD NORMALIZED
1. The characteristics of the two operands are checked. The shorter one is in¬
cremented and its fraction shifted right, as for normalized subtract.
2. Operand-1 is compared algebraically to operand-2, including the sign, expo¬
nent, and fraction. However, if both fractions are zero, the result is equal regard¬
less of sign and exponent.
3. CE and CER compare only the leftmost 32 bits.
4. For CE operand-2 is an aligned fullword in storage. For CD, operand-2 is an
aligned doubleword.
5. The condition is set for 0 (equal), 1 (low), and 2 (high).
134 *
135 ❖ CE £ CER COMPARE SINGLE-PRECISION
136 $
003930 7820 314 F 137 COMPE LE 2 , COMP 1
003934 7920 3156 1 38 CE 2.C0MP2 427B7333 > 421F42D0
003938 7840 315E 139 LE 4»COMP 3
00393C 39 24 140 CER 2.4 427B7333 < 435C0999
142 *
143 * CD £ CDR COMPARE DOUBLE-PRECISION
144 *
0039 3E 6820 314F 145 COMPD LD 2.COMP 1
003942 6920 3156 146 CD 2,COMP 2 427B7333 33333333 >
003946 6840 315F 147 LD 4, COMP 3 421F42D0 E5604189
00394A 2924 148 COR 2,4 427B7333 33333333 <
435C0999 9999999A
00394C 00000000
003950 427B733333333333 150 C0MP1 DC D' 123.45' DOUBLEWORD
003958 421F42DOE5604189 151 C0MP2 DC D'31.261' DOUBLEWORD
003960 435C09999999999A 152 C0MP3 DC D' 1472.6* DOUBLEWORD
In Figure 1 7-7 a doubleword is loaded in register-6. HER shifts only the left 8
hex digits one bit to the right, and HDR shifts all 16 hex digits.
1 56 *
157 * HER £ HDR HALVE
1 58
003968 6860 316E 159 HALVE LD 6,AMTHALF REG-6: 434D28F5 C28F5C29
00396C 3446 1 60 HER 4,6 REG-4: 4326947 A
ME R1.X2 or R1,D2(X2,B2)
Isymbol] MD R1.X2 or R1,D2(X2,B2)
MER R1.R2
MDR R1.R2
The multiply operation prenormalizes the field if necessary. Then it adds the charac¬
teristics and multiplies the fractions. The rules are:
168 *
1 69 * ME £ MER MULTIPLY SINGLE-PR EC ISI ON
170 *
003978 7820 3196 171 MULTE LE 2 »MUL TC AN 1 REG-2 : 4326D666
00397C 7C20 319E 172 ME 2»MULTPLER REG-2: 445CB979
003980 7840 31A6 173
LE 4,MULTCAN2 REG-4: 441205B8
003984 3C42 174
MER *’2 REG-4: 47687 ICC
1 76 *
177 *
MD £ MDR MULTIPLY DOUBLE-PRECISION
178 *
003986 6820 3196 179 MULTD LD 2 , MUL TCAN 1
00398A 6C20 31 9E REG-2: 4326D666 66666666
180 MD 2.MULTPLER
00398E 6840 31A6 181 REG-2: 445CB97A E147AE13
LD 4,MULTCAN2 REG-4: 441205B8 51EB851F
003992 2C42 1 82 MDR 4,2
REG-4: 476871D0 639C0ERE
003994 00000000
003998 4326066666666666 184 MULTCAN 1 DC D'621.4'
0039A0 4226333333333333 DOUBLEWORD
185 MULTPLER DC D'38.2’
0039A8 441205B851EB851F DOUBLEWORD
186 MULTCAN2 DC D'4613.72*
DOUBLEWORD
DE R1.X2 or R1,D2(X2,B2)
[symboll DD R1.X2 or R1 ,D2(X2,B2)
DER R1 ,R2
DDR R1.R2
The divide operation prenormalizes the fields if necessary. The rules are:
190 *
198 *
199 00 £ DDR DIVIDE DOUBLE-PRECISION
200
0039BE 6820 3 ICE 201 DIVIDD L0 2,DIVIDN01 REG-2: 4326D666 66666666
0039C2 6D20 3106 202 DO 2,DIVSOR REG-2: 4210445B 24304055
0039C6 6840 310F 203 LD 4,DIVIDND2 REG-4: 441205B8 51EB851F
0039CA 2042 204 DDR 4,2 REG-4: 4311B9FC E537151B
0039CC 00000000
003900 4326066666666666 206 DIVIDND1 DC D'621.4' DOUBLEWORD
003908 4226333333333333 207 DIVS0R DC D'38.2 ' DOUBLEWORD
0039 E0 441205B851EB851F 208 DIVIDND2 DC O'4613.72' DOUBLEWORD
general register. We may make use of an unique short cut in the conversion. Con¬
sider a normalized float value, 4541 6E20. Its correct unnormalized hexadecimal
value is X'416E2', or decimal 268,002. We can use an unnormalized add operation,
AW, with an operand containing a characteristic of 4E to shift the radix point from
the left to the right as follows:
The rightmost 8 hex digits now contain the correct binary value, which we can next
convert to packed. If the float number had contained any significant digits to the
right, the operation would have shifted them out.
If the float value is negative, we must convert it to two's complement in binary.
A minor adjustment to the preceding routine gives correct results for either positive or
negative values. The AW operation adds X'4E00000100000000. The '1' in the frac¬
tion has no effect on positive numbers, but forces two's complement on negative.
Assume a float value of C5416E20:
The rightmost 8 hex digits now contain the correct two's complement value which
we can now translate to packed.
Figure 1 7-11 converts normalized single-precision float to packed format. The
float value is the one just discussed, C5416E20, and is loaded into floating-point
register-4. The first step checks that the value does not exceed 231 —1. Next, AW
unnormalizes the number. STD stores the entire 64-bit register in DOUBLE. Finally,
the rightmost four bytes of DOUBLE are converted into packed.
Conversion rules can be much more complicated. The examples given pro¬
cessed only single-precision with integers—that is, the implicit decimal point for the
number is to the right. The binary or decimal number may be mixed, that is with a
binary or decimal point not to the right, such as 123.45. If so, then the integer portion
must be separated from the fraction portion.
PROBLEMS
HEXADECIMAL AND
DECIMAL CONVERSION*
HALFWORD HALFWORD
Hex Decimal Hex Decimal Hex Decimal Hex Decimal Hex Decimal Hex Decimal Hex Decimal Hex Decimal
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 268,435,456 1 16,777,216 1 1,048,576 1 65,536 1 4,096 1 256 1 16 1 1
2 53b,870,912 2 33,554,432 2 2,097,152 2 131,072 2 8,192 2 512 2 32 2 2
3 805,306,368 3 50,331,648 3 3,145,728 3 196,608 3 12,288 3 768 3 48 3 3
4 1,073,741,824 4 67,108,864 4 4,194,304 4 262,144 4 16,384 4 1,024 4 64 4 4
5 1,342,177,280 5 83,886,080 5 5,242,880 5 327,680 5 20,480 5 1,280 5 80 5 5
6 1,610,612,736 6 100,663,296 6 6,291,456 6 393,516 6 24,576 6 1,536 6 96 6 6
7 7 117,440,512 7 7,340,032 7 458,752 7 28,672 7 1,792 7 112 7 7
1,879,048,192
8 134,217,728 8 8,388,608 8 524,288 8 32,768 8 2,048 8 128 8 8
8 2,147,483,648
150,994,944 9 9,437,184 9 589,824 9 36,864 V 2,304 V 144 9 9
9 2,415,919,104 9
A 167,772,160 A 10,485,760 A 655,360 A 40,960 A 2,560 A 160 A 10
A 2,684,354,560
184,549,376 B 11,534,336 B 720,896 B 45,056 B 2,816 B 176 B 11
B 2,952,790,016 B
c 3,221,225,472 C 201,326,592 C 12,582,912 C 786,432 C 49,15.2, C 3,072 C 192 c 12
D 13,631,488 D 851,968 D 53,248 D 3,328 D 206 D 13
D 3,489,660,928 D 218,103,808
234,881,024 14,680,064 E 917,504 E 57,344 E 3,584 t 224 t 14
E 3,758,096,384 E E
F 4,026,531,840 F 251,658,240 F 15,728,640 F 983,040 F 61,440 F 3,840 F 545 F 15
6 5 4 3 2 i
8 7
377
378 APPENDIX A
TO CONVERT HEXADECIMAL TO DECIMAL To convert integer numbers greater than the capacity of
EXAMPLE table, use the techniques below:
1 . Locate the column of decimal numbers corresponding to Conversion of
the left-most digit or letter of the hexadecimal; select Hexadecimal Value D34 HEXADECIMAL TO DECIMAL
from this column and record the number that corresponds
to the position of the hexadecimal digit or letter. 1 . D 3328 Successive cumulative multiplication from left to right,
adding units position.
2. Repeat step 1 for the next (second from the left)
2. 3 48
position . Example: D34 j ^ = 3380jq D = 13
3. Repeat step 1 for the units (third from the left) 3. 4 4 x16
position . 208
4. Decimal 3380 3 = + 3
4. Add the numbers selected from the table to form the 211
decimal number. xl 6
3376
4 = +4
TO CONVERT DECIMAL TO HEXADECIMAL 3380
EXAMPLE
1 . (a) Select from the table the highest decimal number DECIMAL TO HEXADECIMAL
Conversion of
that is equal to or less than the number to be con¬
Decimal Value 3380
verted . Divide and collect the remainder in reverse order.
(b) Record the hexadecimal of the column containing
1 . D -3328
the selected number.
52
(c) Subtract the selected decimal from the number to
be converted.
2. 3 -48
2. Using the remainder from step 1(c) repeat all of step 1 4
to develop the second position of the hexadecimal
(and a remainder). 3. 4 -4
3. Using the remainder from step 2 repeat all of step 1 to 3380]0 = D34
4. Hexodecimal D34 16
develop the units position of the hexodecimal .
POWERS OF 16 TABLE
16n n
1 0
16 1
256 2
4 096 3
65 536 4
1 048 576 5
16 777 216 6
268 435 456 7
4 294 967 296 8
68 719 476 736 9
1 099 511 627 776 10 = A
17 592 186 044 416 11 = B
281 474 976 710 656 12 = C
4 503 599 627 370 496 13 = D
72 057 594 037 927 936 14 = E
J 152 921 504 606 846 976 15 = F
'V'
Decimal Values
APPENDIX B
PROGRAM INTERRUPTS BY
CODE
A program interrupt occurs when the program attempts an operation that the CPU
cannot execute. The following lists the various program interrupts, by code.
379
380 APPENDIX B
In each case, the system issues an error message, giving the type of program
interrupt and the address where the interrupt occurred. Sometimes the programming
error causes the program to enter a declarative area or some other invalid area
outside the program. (The computer may even find some valid machine operation,
such as X 3C', Multiply Float!) In debugging, we must determine how the program
arrived at the invalid address. In many cases, a dump of the program's registers and
storage area will be essential in tracing the cause of the error.
382
383 360/370 Instruction Set
•Second operand not shown; in all cases it Is ^For OS/VS and DOS/VS;
D2(X2,B2) for RX format or R2 for RR format. source: GC33-4010.
APPENDIX D
Figure D-1 illustrates an example of conventional job control to assemble and exe¬
cute a program under the Disk Operating System.
384
385 DOS and OS Job Control
We use the same job control cards for magnetic tape as for card and printer pro¬
grams. However, tape files require additional information to provide greater control
over the file. Under DOS, two additional job cards are LBLTYP and TLBL.
// LBLTYP TAPE precedes // EXEC LNKEDT, and informs the Linkage Editor to
reserve 80 bytes ahead of our program for processing tape file labels. If our program
normally loads in location X'3800', with LBLTYP it will load in X'3850'. TLBL follows
// EXEC LNKEDT and provides details of our file to IOCS.
Each extent for the file requires two job control cards, DLBL and EXTENT, equivalent
to the magnetic tape TLBL card (a file may be stored on more than one extent).
© © © ©
(a) filename The name of our DTFSD, 1-7 characters.
© ‘file-ID' Our file-ID (within apostrophes), 1-44 characters. This is the
first field of the format-1 label. We can code file-ID and option¬
ally generation and version number. If we omit this entry, IOCS
uses the filename.
© retention One of two formats: (1) dddd = retention period in days; and (2) yy/ddd
date = the date of retention, e.g., 85/030 means retain file until January 30,
1 985. If we omit this entry, IOCS assumes 7 days.
(d) codes The type of file label: SD-Sequential Disk; ISC-Index Sequential
Create; ISE-Index Sequential Extend; DA-Direct Access. If we
omit this entry, IOCS assumes SD.
Note: the LBLTYP job control entry used for tape is also required for non-
sequentuaPdisk. For example, if there are two non-sequential disk files in the
program, the entry is//LBLTYP NSD(2).
OS JOB CONTROL
There are different versions of OS job control language. The following illustrates one
version, providing for assembly, link-edit, and execution of test data. The program
uses a card and a printer file, both of which require a DD (Data Definition) job card.
The use of OS job control for magnetic tape and disk is explained along with
the program examples.
APPENDIX E
Included in this appendix are the special macros used at the beginning of this text:
INIT, PUTPR, DEFCD, and DEFPR. The macros are simple to implement and to use,
and anyone is free to catalogue them. Beginners often have trouble coding the
regular full macros, making punctuation and spelling errors and omitting entries. The
use of macros such as the ones in this appendix can avert a lot of initial coding
mistakes and can free the beginner to concentrate on programming logic.
The INIT macro (used to establish base register addressability) requires versions
for both DOS and OS (Figure E-1 and E-2). A further refinement (recommended)
could include the DOS STXIT or OS SPIE macro for error recovery.
PUTPR (Figure E-3) generates two instructions, of the form:
388
MACRO
SINITZE IN IT
SINITZE START X* CA078*
E ALR 3,0 L 0 AO BASE REGISTER 3
USING *.3.4,5 ASSIGN BASE REGS 3,4 S 5
LA 5.2048 LOAD X•800• (1/2 OF X * 1000• )
LA 4,2 0 4 8( 3,5 ) LOAD BASE REG 4
LA 5.2048(4,5) LOAD BASE REG 5
FIGURE E-1 MEND
MACRO
SINITZE INIT
SINITZE C SEC T
SAVE (14.12) SAVE REGISTERS FOR SUPERVISOR
B ALR 3,0 LOAC BASE REGISTER 3
USING *.3.4,5 ASSIGN EASE REGS 3 • 4 <4 5
ST 13.SAVEAREA+4 SAVE ADDRESSES FOR RE TURN
LA 13,SAVE AREA * TO SUP ER V I SOR
LA E• 204e LOAD X•8 C 0• (1/2 OF X'looo*)
LA 4,2048(3.5) LOAD BASE REG 4
LA 5,2048(4,5) L C AD eASE REG 5
B SAVE AREA+le*4
SPACE
SAVEAREA DC 18F■0• REG . SAVEAREA FOR INTERRUPTS
FIGURE E-2 MEND
MACRO
&WR1TE PUTPR SF1LE.SPRAREA.SCTLCHR
LCLC SCTL
. *
. VALAREA AIF ( •SCTLCHR• NE •WSPl• ).NEXT 1 PRINT S SPACE 17
SCTL SETC •X*'G9'••
AGO •NEXT9
.♦
.NEXT 1 AIF (•SCTLCHR* NE •■SP2•).NEXT2 PRINT S SPACE 27
SCTL SETC •X* *1 1* ••
AGO • NE XT 9
.*
• NE XT 2 A I F (•SCTLCHR* NE •*SP3•).NEXT3 PRINT S SPACE 37
SCTL SETC •X*•19*••
AGO • NE XT 9
.*
• NEXT 3 AIF (•SCTLCHR* NE *SP1*).NEXT4 SPACE 1. NO PRINT7
SCTL SETC •X* *00* *•
AGO • NEXT 9
. *
•NEXT4 SPACE 2, NO PRINT?
AIF (•SCTLCHR* NE *SP2*).NEXT5
SCTL SETC •X* • 13* * •
AGO • NE X T 9
. *
• NEXT 5 AIF (•SCTLCHR* NE *SP3*).NEXT6 SPACE 3, NO PRINT?
SCTL SETC •X* • IB* • *
AGO •NEXT9
. *
.NEXT 6 A IF (•SCTLCHR* NE 'SK1M.NEXT7 SKIP TO NEW PAGE?
SCTL SETC •x*•ee*••
AGO •NEXT9
.*
•NEXT7 A IF (•SCTLCHR* NE • WSPO* I.NEXTd PRINT S SPACE 0?
SCTL SETC •X* *01• ••
AGO • N E XT 9
389
390 APPENDIX E
DEFCD and DEFPR define the card reader and the printer respectively, and
assume a workarea for PUT and use of IBM machine code rather than the ASA
control characters. DEFCD checks the validity of the supplied end-of-file address, a
useful test. The DOS versions (Figure E-4 and E-5) generate DTFCD and DTFPR, and
the OS versions (Figure E-6 and E-7) generate DCB's. The particular entries may vary
slightly by installation.
MACRO
4CDFILE DEFCD 4ECF
A IF (T * 4EOF EO *1* OR T * 4EOF EO • M* ).A 10 EOF ADDRESS VALID?
MNOTE 1••EOF ADDRESS NOT DEFINED* NO -
4EOF CLOSE 4C0FILE * GENERATE EOF ROUTINE
EOJ
•A1 0 ANOP
4CDFILE DTFCD BLKSI2E=B0. DEFINE CARD FILE ♦
DEVADDR=SYSIPT• ♦
CEVICE=1442. ♦
E0FADDR=4ECF, ■f
IOAREA1=CDBUFF1 • ♦
I0AREA2=CDBUFF2 • ♦
TYPEFLE=INPUT• +
»ORKA=YES
SPACE
COBUFF 1 DC CLBO* • CARC BUFFER-1
CDBUFF2 OC CL 80 * • CARD BUFFER-2
FIGURE E-4
MACRO
4PRFILE DEFPR
4PRFILE DTFPR BLKSIZE=133, DEFINE PRINTER FILE •f
CTLCHR=YES.
+
CEVADDR=SYSLST.
♦
DEVICE=1403,
♦
IOAREA1=PR0UFF1,
♦
I0AREA2=PRBUFF2,
♦
*ORKA=YE S
SPACE
PR8UFFl CC CL133* •
PRINT BUFFER-1
PRBUFF2 DC CL133* •
PRINT EUFFER-2
SPACE
MEND
FIGURE E-5
MACRO
4CDFILE DEFCD 4EOF
A IF ( T • 4EOF EC • I • OR T•4EOF EQ *M*).A10 EOF ADDRESS VALID?
MNOTE 1••EOF ADDRESS NOT DEFINED* NO -
4EOF CLOSE 4CDFILE *
GENERATE EOF ROUTINE
EOJ
• Alb ANOP
4CDFILE DC B DDNAME = SYSIN,
DEFINE CARD FILE +
DEV 0= CA,
♦
D S0RG = P S•
+
EQDAD=4E0F,
♦
MAC RF =(GM )
MEND
FIGURE E-6
391 Special Macros: INIT, PUTPR, DEFCD, DEFPR, EOJ
MACRO
SPRFILE DEFPR
+
SPRFILE DC 8 DDNAME=SYSPRINT,
OEVO=DA,
+
DSCRG=PS.
RECFM=FBSM,
MACRF = < PM)
SYSPRINT EQU SPRFILE
ENTRY SYSPRINT
MEND
FIGURE E-7
DOS already has a simple EOJ macro. The one included here (Figure E-8) is for
OS, to generate the load savearea and return, to tie in with the OS INIT macro.
MACRO
SLABEL EOJ
* DOS COMPATIBLE EXIT ROUTINE FOR OS G. KIDD
SLABEL L 13.SAVEAREA+4 END-OF-JOB. RETURN
RETURN (14.12) * TO SUPERVISOR
MEND
FIGURE E-8
INDEX
392
393 INDEX