System/360 concepts and descriptions of selected assembler language instructions for arithmetic, logical, and branching operations.

70 KB – 159 Pages

PAGE – 3 ============
Minor Revision (August 1970) This publication is a minor revision of Form SC20-1646-5 incorporating corrections made on pages dated (8/70). The original publication is not obsoleted. Requests for copies of IBM publications should be made to your IBM representative or to the IBM branch office serving your locality. Address comments concerning the contents of this publication to IBM Corporation, DPD Education Development -Publications Services, Education Center, South Road, Poughkeepsie, New York 12602. © Copyright International Business Machines Corporation 1956, 1969

PAGE – 4 ============
This student text is an introduction to System/360 assembler language coding. It provides many examples of short programs shown in assembled form. Some elementary programming techniques and the specific instructions trated in the programs are discussed in simple, relatively nontechnical terms. Much of the text is based on mation in IBM System/360 Principles of Operation (GA22-6821). This includes a brief review of relevant System/360 concepts and descriptions of selected assembler language instructions for arithmetic, logical, and branching operations. Standard (flXed-point) , decimal, and point arithmetic are discussed. The book also includes an elementary introduction to assembler language and the assembler program, and chapters on base register addressing and on program linkages and relocation. The coding of many other common programming techniques, such as the use of branches, loops, and counters, is shown. The use of macro instructions is demonstrated, but not covered in detail. Program flowcharting and input/output operations are beyond the scope of the book. The publication is a sampler rather than a comprehensive textbook. It is intended for supplementary reading for the student in a regular course of study on System/360 bler language coding, and for the novice programmer. In general, the reader will fmd that the program examples are quite simple at the beginning of each chapter, or ·major subject division, and become progressively more complex. If the going seems difficult, it is suggested tltat he simply skip to the next subject and come back later. The student should have access to two IBM System/360 System Reference Library (SRL) manuals for reference purposes: the Principles of Operation and the assembler specification manual for one of the System/360 operating systems. (All publications and their form numbers are listed at the end of the Preface.) He should also be familiar with fundamental concepts of data processing and the basic operating principles of System/360. Two IBM programmed instruction (p. I.) courses, or their equivalent, are requisite to a. full understanding of this student text: Preface Computing System Fundamentals and Introduction to System/360. The student who is not in a hensive programming course will tmd the P. I. book Fundamentals of Programming a valuable guide to problem analysis and program flowcharting. The text and programs of this book have been revised throughout, mainly to reflect changes in programming conventions attributable to the development of System/360 operating systems. Chapter 1 is new, and several sections in other chapters have been entirely rewritten. The sample programs have been reassembled under the widely used Disk Operating System (DOS). As far as possible, usages limited to DOS have been avoided, and the programs and text in general are applicable to System/360 models 25, 30, 40,50,65, and 75, under any of the operating systems. IBM publications that may be useful to the student are: IBM System/360 Principles of Operation (SRL manual GA22-6821) IBM System/360 Reference Data (card GX20-1703) IBM System/360 System Summary (SRL manual GA22-6810) Number Systems (Student Text GC20-1618.) Introduction to IBM System/360 Architecture (Student Text GC20-1667) . Introduction to System/360 (P J. Course GR29-0256 through -0259) Computing System Fundamentals (p. I. Course GR29-0280 through -0282) Fundamentals of Programming P J. Course SR29-OO19) System/360 Assembler Language Coding (p. I. Course SR29-0231 through -0235) The form numbers of the assembler specification manuals for the various System/360 programming systems are: Basic Programming Support (Tape System)-GC24-3335 Basic Operating System-GC24-3361 Tape Operating System } 4 Disk Operating System GC24-341 Operating System-GC28-6514 iii

PAGE – 5 ============
Contents Chapter 1: Introduction .. 1 What Is Assembler Language? 1 Machine Language . . . . 1 Assembler Language . . . 1 Why Learn Assembler Language? . 4 The Assembler Program . . . . 5 The System Environment. . . 5 Functions of the Assembler 5 Final Processing . . . 6 Use of the Coding Form . . . . 7 An Assembler Language Program 9 Writing the Program . . . . . 9 The Assembly Listing . 10 Error Analysis by the Assembler. 12 Modifying an Assembler Language Program . 15 Chapter 2: System/360 Review 17 Main Storage .. 17 Bytes and Data Field Lengths 17 Addressing . . . . . . . . . . . 18 Positioning on Integral Boundaries. 18 Central Processing Unit . . . . . . . . 19 General and Floating-Point Registers . 19 Arithmetic and Logical Unit . . . 19 Program Execution . . . . . . . . . 23 Sequential Instruction Execution. 23 Branching 23 Instruction Format. . . . . . . . 23 Generation of Main Storage Addresses 24 Interruptions and the Program Status Word 25 Hexadecimal Numbers. . . . . . . 26 Hexadecimal Code . . . . . . . 26 Hexadecimal Number System. . 26 Chapter 3: Fixed-Point Arithmetic . 29 Addition and Subtraction . . . . . . 29 Multiplication . . . . . . . . . . . . 32 Multiplication and Division with Decimal Points. 34 Shifting and Data Manipulation 37 Branches and Decision Codes 39 The Condition . . . . 39 A Sorting Procedure . . . . 39 Further Decisions: The Social Security Problem 42 Simple Loops: Finding a Sum .. 45 Case Study: Averaging a List of Temperatures 48 Questions and Exercises. . . . . . . . . . . . 50 Chapter 4: Programming with Base Registers and the USING Instruction .. 51 The USING Instruction . . . . . . . . . . . . . . .. 51 iv An Example. . . . . . . . . . . . . . . . . . . .. 52 More than One Base Register . . . . . . . . . . . 54 Separate Base Registers for Instructions and Data.. 56 Questions and Exercises. . . . . . . . . . . . . .. 58 Chapter 5: Decimal Arithmetic . . . 60 Addition and Subtraction in Decimal 61 Decimal Multiplication .. 63 Decimal Division .. 64 Shifting of Decimal Fields. 66 Shifting to the Right . . 66 Shifting to the Left .. 67 Decimal Division with Shifting 68 Format and Base Conversions. 69 Decimal Comparison: Overtime Pay 71 The Social Security Problem in Decimal. 72 The “Indian” Problem. . 73 Questions and Exercises. . . . . . . . . 74 Chapter 6: Logical Operations on Characters and Bits. 75 Alphameric Comparison: An Address Sort 76 Logical Tests. . . . . . . . 78 The Wallpaper Problem. . . . . 78 Setting Bits On and Off. . . . . 79 A Self-Checking Number Routine. 80 A Final Example. . . . . 82 Questions and Exercises . . . . . . 84 Chapter 7: Edit, Translate, and Execute Instructions. 85 The Edit Instruction. . . . . . 86 The Edit and Mark Instruction. The Translate Instruction How it Works. . . . . . . . An Example . . 91 92 92 93 The Translate and Text Instruction and the Execute Instruction . . . . . . . . . . . . . . . . . .. 97 An Assembler Application of Translate and Test and Execute . Processing Variable-Length Blocked Records Questions and Exercises . . . . . . . . . . . Chapter 8: Subroutine Linkages and Program 100 102 . 105 Relocation. . . . . . . . . 107 Subroutine Linkages. . . . 108 Standard Linkage Registers 111 Program Relocation . . . . 115 The Linkage Editor. . . 115 The CALL and PDUMP Macros. 116 Reading a Dump . . . . . . . . 117

PAGE – 6 ============
Communication between Separate Programs Questions and Exercises . . . . . . . . 120 Appendix . 124 System/360 Machine Instructions . 139 139 140 140 140 142 142 Condition Code Settings Chapter 9: Floating-Point Arithmetic Floating-Point Numbers . . Floating-Point Instructions 125 Extended Mnemonic Codes . . . . 126 EBCDIC Chart . 130 System/360 Assembler Instructions. 134 Types of Assembler Language Constants Questions and Exercises . . Answers to Questions and Exercises 135 Index .. . 143 FIGURES Assembly Listings of Programs 1-2 PROGA 1-5 PROGC 1-7 PROGB 3-2 STOCK 3-5 GROSS 3-9 INTA 3-10 INTB 3-11 SHIFTA 3-12 SHIFTB 3-15 SORT 3-18 FICAI 3-19 FICA2 3-20 SUMA 3-21 SUMB 3-22 SUMC 3-23 AVGTEMP 4-1 PROGE 4-3 PROGF 4-4 LOOPA 5-3 STOCK 1 5-5 INTC 5-6 AVG 5-7 CONVERT 5-8 OTPAY 5-9 FICA3 5-10 INDIAN 6-1 SORTABC The program in Figure 1-1 . . . . . . . . . . . . . . . . . . . . . . . 3 The program rewritten with deliberate errors . . . . . . . . . . . . . 12 The same program modified to store the binary contents of register 6 . 15 The program in Figure 3-1 . . . . . . . . . . . . . . . . . . . . . . . 30 A program to perform binary (fixed-point) multiplication. . . . . . . 32 A program involving binary multiplication and division with the result rounded off. 34 A different version of the program of Figure 3-9, using a scale modifier for constants. 35 A program to separate three quantities stored in one fullword 37 Modified version of the program of Figure 3-11, making it operate correctly with negative quantities. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 A program to carry out the sorting procedure charted in Figure 3-14 . 41 A program based on the flowchart in Figure 3-17 . . . . . . . . . . . 43 A much better version of the program to calculate Social Security tax. 44 First version of a program to form the sum of 20 numbers . . . . . . 45 Second version of program to form the sum of 20 numbers . . . . . . 46 Third and shortest version of program to form the sum of 20 numbers, using the BXLE instruction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 47 A program to compute average monthly temperature, which takes into account the possibility of omitted readings. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 48 A program to show how the assembler calculates and supplies addresses of all storage operands ., 52 An incomplete program with an Origin (ORG) assembler instruction to simulate a length of over 4096 bytes, thus requiring two base registers . . . . . . . . . . . . . . . . . . . . .. 54 Program with separate base registers for processing and data, showing how a base register can be used to provide indexing for loop control .. . . . . . . . . . . . . . . . . . . . . . . .. 56 The decimal arithmetic program in Figure 5-2 . . . . . . . . . . . . . . . . . . . . . . . . .. 61 A program that performs decimal multiplication; step-by-step results to be expected during exe-cution are shown in the comments field .. , 63 Assembled program showing decimal division and “shifting”; step-by-step results to be expected during execution are included in the comments field . . . . . . . . . . . . . . . . . . . .. 68 Assembled program showing various instructions for changing the format of data; contents of registers 5 and 6 to be expected during execution are given in the comments field . . . . .. 69 Assembled program that computes a man’s gross pay, including any overtime pay, in decimal arithmetic; results expected during execution are shown in the comments field . . . . . .. 71 Assembled program to calculate Social Security tax in decimal arithmetic; results expected during execution are shown in the comments field . . . . . . . . . . . . . . . . . . . . .. 72 Assembled program to compute compound interest, with counting in binary and calculations in decimal arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . , . . . . . . . ., 73 A program to sort three 13-character items into ascending sequence on keys in the middle of each item . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ., 76 v

PAGE – 8 ============
7-10 Examples of multiple edits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 7-11 Examples of the application of the Edit and Mark instruction to get a floating currency symbol 91 7-12 Baudot teletypewriter code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 7-13 Table for translation of Baudot code to EBCDIC . . . . . . . . . . . . . . . . . . . . . . . . 93 8-8 Hex dump of registers and storage produced by execution of the PDUMP macro in the program in Figure 8-7 . 117 8-9 Hex dump of the program (Figure 8-7) loaded at 3000 . . . . 118 8-10 Hex dump of the program (Figure 8-7) loaded at 4000 . . . . . . . . . . . . . . . . . . . . . . . . . . 118 8-13 First dump produced by the subroutine in Figure 8-12, SUBR . . . . . . . . . . . . . . . . . . . . . . 122 8-14 Second dump produced by the subroutine in Figure 8-12, SUBR. . . . . . . . . . . . . . . . . . . . . . .. 122 8-15 Dump produced by the main program!n Figure 8-11, MAIN 1 . 122 9-1 Assembly listing of decimal integers specified as short floating-point constants. . . . . . . . . . . . . . . .. 127 9-2 A listing of the same examples as in Figure 9-1, showing them in the comments field in a form that is easy to read . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 9-3 The same values shown as negative numbers .. 128 9-4 Some fractional and mixed decimal numbers expressed as short floating-point constants 129 9-5 Some long floating-point constants . . . . . . . . . . . . . . . . . . . . 129 9-6 Some decimal values with exponents expressed as floating-point constants . . . . . . . . 129 TABLES 2-1 Extended Binary Coded Decimal Interchange Code (EBCDIC) for Graphic Characters 2-2 Hexadecimal Code .. . 2-3 Hexadecimal and Decimal Integer Conversion Table . 3-1 Masks for testing various states of the condition code 7 -1 Summary of Editing Functions . . ” . . . . . . . . 8-1 DOS Linkage Registers .. . . . . . . . . . . . . . . 9-1 Equivalent Values of the Characteristics of Some Floating-Point Numbers 9-2 Instruction Set for the System/360 Floating-Point Feature . 22 26 27 39 88 111 127 130 vii

PAGE – 9 ============
WHAT IS ASSEMBLER LANGUAGE? Machine Language A computer is a willing servant. It will invariably and reliably do exactly what it is told to do, as long as it is told in its own language. This is true of any computer. Let’s take a quick look at the language that System/360-the machine itself-understands. If an IBM System/360 computer is given the instruction 1B67, it will subtract whatever amount is in register 7 from the amount in register 6. When the operation is fmished, the contents of register 7 will be the same as they were originally, but the contents of register 6 will be the difference between the two original quantities. The code 1B signifies to the computer (1) just what operation it is to perform, (2) what format it can expect the two quantities to be in, and (3) whether they are in registers or in main storage. Specifically, 1B indicates that the computer is to subtract two 32-bit binary numbers, both of which are in registers. The two quantities to be operated on are called operands. The one that is written frrst is called the frrst operand and in this case is in register 6. The second operand is in register 7. The instruction 1 B6 7 is in machine language. It is a representation in the hexadecimal number system (base of 16) of the actual binary arrangement in the computer. The computer responds to it in a particular way because its circuitry has been designed to do so whenever it senses this combination of signals. Let’s take another example of a machine language instruction, say 5A20B02A. The operation code 5A causes the computer to add two 32-bit binary numbers (the frrst in a register and the second in main storage) and to place the result in the first operand location. In this case, the frrst operand is in register 2, and the second operand is in storage, beginning at the location designated by OB02A. Not many years ago all programs were written in machine language. The most valuable tool the programmer had was an eraser. He was concerned with an enormous amount of clerical detail. He had to remember dozens of numerical codes for the computer operations and try not to make a mistake when using them. He had to keep track of the storage space he used for instructions, data, and work areas, and actually calculate any addresses he needed to refer to in his program. Revising a program (a very frequent occurrence then, as it is now), often meant changing every address that followed the revisions. All this detail meant many errors and much time spent on checking, calculating, keeping tables, and other clerical tasks. Chapter 1: Introduction Assembler Language The realization that the computer itself was better suited than man for doing this type of clerical work led to the development of assembler languages (each has its own assembler language). In System/360 assembler language, every operation code is written in alphabetic letters that are easy to remember, called mnemonics, and the addresses of locations in storage can be given symbolic names like PAY, HOURS, and RATE by the programmer. The machine guage instruction 1B67 would be written in assembler language as SR 6,7 (SR for Subtract Register). The tion 5A20B02A might be A 2,CON (A for Add), with another instruction to defme CON as a certain value. We do not have to say where it is-the computer will take care of that. An assembler language program as prepared by a grammer is shown in Figure 1-1. The operations to be performed start in column 10, the operands in column 16. As we said at the beginning, however, the computer cannot understand any language except its own machine language. Therefore, a program that translates our symbolic program into machine language or object code is needed. Such a program, actually a component part of an IBM System/360 operating system, is brought from the system “library” into a separate area in main storage when needed, and it does the job. This program is called an assembler. Besides translating the problem program statements into machine language, it calculates storage locations for all instructions, keeps track of any symbols like CON that are used, and performs a number of other necessary functions. The program written by the programmer is not executed during the assembly process; it will be executed later, after further processing. Figure 1-2 shows the listing produced by the assembler for our sample program. Machine Instructions All the columns to the left of the statement number (STMT) column are in machine language. The LOC, ADDRl, and ADDR2 columns have to do with address arithmetic handled by the assembler, and will be discussed later. The heart of our program has been translated into the code headed OBJECT CODE. The circled area at the left tains the code for every executable instruction in the entire program. What we mean by an executable instruction is one that, when the problem program is run, will tell the puter to perform an actual operation in the machine itself. Each of the executable instructions has a corresponding System/360 machine operation code; these operation codes Introduction 1

PAGE – 10 ============
IBM Syot.ml3S0 Aaaamblar Coding Farm X28-6509 Figure 1-1. An assembler language program as prepared by the programmer are represented by the frrst two characters (the frrst two hexadecimal numbers, really) in the circled object code. In the example, the executable instructions include one of the branching instructions (BALR, op code 05), Load (L, op code 58), Add (A, op code SA), one of the Shift Left instructions (SLA, op code 8B), Subtract (S, op code 5B), Store (ST, op code 50), and so on. In assembler language, the executable instructions are called machine instructions. Not counting floating-point arithmetic instructions, System/360 assembler language has about 100 different machine instructions. I t is fairly easy to recognize and remember all of the mnemonics for them-certainly easier than remembering the machine language operation codes. Some other examples are C for Compare, CVD for Convert to Decimal, SH for Subtract Halfword, STH for Store word, M for Multiply, and BC for Branch on Condition. A full list of System/360 machine instructions appears in the Appendix; floating-point instructions are given in the ter on that subject. Each machine instruction and what it does is described in complete detail in the IBM Systems Reference Library (SRL) manual IBM System/360 ples of Operation (A22-6821). Many will be described in this bock in nontechnical language, but not in complete detail. Assembler Instructions What about the TITLE, START, and USING instructions that have not· generated any object code in the assembly 2 listing in Figure 1-2? The mnemonic TITLE does not even show up at all (it was in the source program), but we see that the assembly listing has the heading ILLUSTRATIVE PROGRAM. TITLE is an instruction to the assembler that tells it to print a heading or title at the top of each page in the listing. Similarly, START and USING are instructions to the assembler; these concern the addressing plan it is to follow. Although they will affect the way in which the assembler assigns addresses, they will have no direct tion in the execution of the problem program. In contrast to machine instructions, they are called assembler instructions. They may be defmed as instructions to the assembler program itself. Skipping the EO] for the moment, we see the monics DC (Defme Constant) and DS (Defme Storage). These two instructions are also assembler instructions. DC’s generate object code for the values they define, but no operation codes. DS’s actually reserve storage space of a specific size, but they too do not generate operation codes. In other words, DC’s cause the assembler to create object code for actual values and DS’s reserve actual storage spaces, but they do not themselves give rise to any action during program execution. Instead, they are used for either information or space by other instructions in the program. If we look again at the assembly listing, we see that DATA, CON, RESULT, etc., are operands of some of the table instructions. Assembler-instruction mnemonics, which are also listed

PAGE – 11 ============
LOC OBJECT CODE ,-.\-..—_../ 000 000100 05BO 000102 I’ ,\ 000102 0001065A’20 BCl2A 00Dl0t 8B20 0001 00010E 5B20 OOOlle 5020 aD2E 000116 5860 00011A 5A60 0001lE” 4E60 ..B03E 000122 OAOE 000 124 \,;jo;’;;o;’;o .., 000128 OOOOOOOF 00012C OOOOOOOA Ł 000130 000134 OOOOOOOC 000138 0000004E 000140 , 000100 Mflch/ne Instructions in Machine language 00124 0012C 00001 00128 00130 00134 00138 00140 15+ 16 DATA 17 DC 18 CON DC 19 RESULT DS 20 BINI DC 21 BIN2 DC 22 DEC ”””’ DS 23 F’ t5″ F’lO’ ‘ , F F’12\’ F ’78 ‘\. D \ BEGIN Machine instructions in assembler IOf/!/uaStl LOAD REGISTER 2 ADD 10 THIS HAS EFFECT OF MULTIPLYING BY 2 NOTE RELATIVE ADDRESSING DEC IMAL Figure 1-2. Assembly listing of the program in Figure 1-1. The executable instructions (see text) are circled in both assembler language and the machine language translation. in the Appendix, generally suggest their purpose. USING indicates a particular register to be used by the assembler for keeping track of storage addresses, EJECT tells the assembler to start a new page in the program listing, and END to terminate the assembly program. tions and the functions of the assembler program are described fully in each of the SRL assembler language uals for the various IBM operating or programming systems (see Preface for list). It should be explained that variations of the System/360 assembler program are able for different operating systems and sizes of computers. Basically, they all work similarly, but some are more ble and versatile than others. Many differences do exist, however, in the input/output (I/O) programming for different systems. Largely for this reason, the subject of I/O will not be covered in this book. Macro Instructions In an entirely different category, System/360 assembler language includes another type of instruction, called a macro instruction or macro. If a programmer writes a series of instructions for a routine that will be needed again and again during the program, he does not have to code the entire sequence each time. He can make up his own code name to represent the sequence, and, by using his code word in a single statement whenever it is needed, he can cause the sequence of instructions to be assembled and inserted. Incorporated in the system library, the sequence can also be used in entirely separate programs and by all programmers associated with a computer installation simply by writing one statement in the source program. The monics used for macro instructions are often unique to an installation. Some macros are prepared and supplied by IBM; they have mnemonics like EOJ, READ, WRITE, OPEN, CLOSE, WAIT, WAITF, DTFCD, DTFIS, etc. The mnemonics for both the user-prepared and the supplied macros constitute an extension to System/360 assembler language. The macros supplied by IBM are mainly for procedures that affect other components of the IBM operating system, like the supelVisor and the input/output control system, and they ensure accuracy and consistency in maintaining the interrelations within the operating system. The EOJ (End of Job) in the program example is a supelVisormacro instruction. It generates just two statements, which are indicated in the listing by plus signs. The frrst is simply for identification, and the second is the executable SupelVisor Call instruction (SVC, op code OA). Most I/O routines are long and complicated, and for any particular device and operating system are programmed in exactly the same way in program after program. Most of the macros supplied by IBM are for these I/O routines. Some of the Disk Operating System (DOS) macro instructions we shall use in this book, besides EOJ, are CALL, SAVE, RETURN, and PDUMP. The book does not cover the preparation of new macros, but shows, in the chapter on subroutines, another method for reusing a sequence of instructions. However, the programmer can save much time and effort by using the macros that are already available in his system library. Their use will also ensure accuracy and standardization of frequently repeated procedures. Summary To summarize, these are the three kinds of instructions used in System/360 assembler language, and what each does: 1. A machine instruction specifies an actual operation Introduction 3

70 KB – 159 Pages