A Programmer's Introduction to IBM System/360 Assembler Language
Total Page:16
File Type:pdf, Size:1020Kb
--..- - ----- ---- A Programmer's Introduction - -.~-- --- --_---_.-- - - --- .. - to IBM System/360 Assembler Language Student Text --"---~-- - ---- A Programmer's Introduction - -.---- -~- ------ - - --- to IBM System/360. -~-.- Assembler Language Student Text 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 Preface This student text is an introduction to System/360 Computing System Fundamentals and Introduction to assembler language coding. It provides many examples of System/360. The student who is not ehrolle~ in a compre short programs shown in assembled form. Some elementary hensive programming course will tmd the P. I. book programming techniques and the specific instructions illus Fundamentals of Programming a valuable guide to problem trated in the programs are discussed in simple, relatively analysis and program flowcharting. nontechnical terms. Much of the text is based on infor The text and programs of this book have been revised mation in IBM System/360 Principles of Operation throughout, mainly to reflect changes in programming (GA22-6821). This includes a brief review of relevant conventions attributable to the development of System/360 System/360 concepts and descriptions of selected assembler operating systems. Chapter 1 is new, and several sections in language instructions for arithmetic, logical, and branching other chapters have been entirely rewritten. The sample operations. Standard (flXed-point) , decimal, and floating programs have been reassembled under the widely used point arithmetic are discussed. The book also includes an Disk Operating System (DOS). As far as possible, usages elementary introduction to assembler language and the limited to DOS have been avoided, and the programs and assembler program, and chapters on base register addressing text in general are applicable to System/360 models 25, 30, and on program linkages and relocation. The coding of 40,50,65, and 75, under any of the operating systems. many other common programming techniques, such as the IBM publications that may be useful to the student are: use of branches, loops, and counters, is shown. The use of IBM System/360 Principles of Operation (SRL manual macro instructions is demonstrated, but not covered in GA22-6821) detail. Program flowcharting and input/output operations IBM System/360 Reference Data (card GX20-1703) are beyond the scope of the book. IBM System/360 System Summary (SRL manual The publication is a sampler rather than a comprehensive GA22-6810) textbook. It is intended for supplementary reading for the Number Systems (Student Text GC20-1618.) student in a regular course of study on System/360 assem Introduction to IBM System/360 Architecture (Student bler language coding, and for the novice programmer. In Text GC20-1667) . general, the reader will fmd that the program examples are Introduction to System/360 (P J. Course GR29-0256 quite simple at the beginning of each chapter, or ·major through -0259) subject division, and become progressively more complex. Computing System Fundamentals (p. I. Course If the going seems difficult, it is suggested tltat he simply GR29-0280 through -0282) skip to the next subject and come back later. Fundamentals of Programming P J. Course SR29-OO19) The student should have access to two IBM System/360 System/360 Assembler Language Coding (p. I. Course System Reference Library (SRL) manuals for reference SR29-0231 through -0235) purposes: the Principles of Operation and the assembler The form numbers of the assembler specification specification manual for one of the System/360 operating manuals for the various System/360 programming systems systems. (All publications and their form numbers are listed are: at the end of the Preface.) He should also be familiar with Basic Programming Support (Tape System)-GC24-3335 fundamental concepts of data processing and the basic Basic Operating System-GC24-3361 operating principles of System/360. Two IBM programmed Tape Operating System } 4 instruction (p. I.) courses, or their equivalent, are pre Disk Operating System GC24-341 requisite to a. full understanding of this student text: Operating System-GC28-6514 iii Contents Chapter 1: Introduction .. 1 An Example. .. 52 What Is Assembler Language? 1 More than One Base Register . 54 Machine Language . 1 Separate Base Registers for Instructions and Data.. 56 Assembler Language . 1 Questions and Exercises. .. 58 Why Learn Assembler Language? . 4 The Assembler Program . 5 Chapter 5: Decimal Arithmetic . 60 The System Environment. 5 Addition and Subtraction in Decimal 61 Functions of the Assembler 5 Decimal Multiplication .. 63 Final Processing ... 6 Decimal Division ..... 64 Use of the Coding Form . 7 Shifting of Decimal Fields. 66 An Assembler Language Program 9 Shifting to the Right . 66 Writing the Program . 9 Shifting to the Left .. 67 The Assembly Listing .... 10 Decimal Division with Shifting 68 Error Analysis by the Assembler. 12 Format and Base Conversions. 69 Modifying an Assembler Language Program . 15 Decimal Comparison: Overtime Pay 71 The Social Security Problem in Decimal. 72 Chapter 2: System/360 Review 17 The "Indian" Problem. 73 Main Storage ........... 17 Questions and Exercises. 74 Bytes and Data Field Lengths 17 Addressing . 18 Chapter 6: Logical Operations on Characters and Bits. Positioning on Integral Boundaries. 18 75 Alphameric Comparison: An Address Sort 76 Central Processing Unit . 19 General and Floating-Point Registers . 19 Logical Tests. 78 The Wallpaper Problem. 78 Arithmetic and Logical Unit . 19 Setting Bits On and Off. 79 Program Execution . 23 A Self-Checking Number Routine. 80 Sequential Instruction Execution. 23 A Final Example. 82 Branching ............ 23 Questions and Exercises . 84 Instruction Format. 23 Generation of Main Storage Addresses 24 Interruptions and the Program Status Word 25 Chapter 7: Edit, Translate, and Execute Instructions. 85 Hexadecimal Numbers. 26 The Edit Instruction. 86 Hexadecimal Code . 26 The Edit and Mark Instruction. 91 Hexadecimal Number System. 26 The Translate Instruction 92 How it Works. 92 Chapter 3: Fixed-Point Arithmetic . 29 An Example ....... 93 Addition and Subtraction . 29 The Translate and Text Instruction and the Execute Multiplication . 32 Instruction . .. 97 Multiplication and Division with Decimal Points. 34 An Assembler Application of Translate and Test and Shifting and Data Manipulation 37 Execute ............... 100 Branches and Decision Codes 39 Processing Variable-Length Blocked Records 102 The Condition C~de . 39 Questions and Exercises . 105 A Sorting Procedure . 39 Further Decisions: The Social Security Problem 42 Chapter 8: Subroutine Linkages and Program Simple Loops: Finding a Sum ........ 45 Relocation. 107 Case Study: Averaging a List of Temperatures 48 Subroutine Linkages. 108 Questions and Exercises. 50 Standard Linkage Registers 111 Program Relocation . 115 Chapter 4: Programming with Base Registers and the The Linkage Editor. 115 USING Instruction .. 51 The CALL and PDUMP Macros. 116 The USING Instruction . .. 51 Reading a Dump . 117 iv Communication between Separate Programs 120 Appendix ............ 139 Questions and Exercises . 124 System/360 Machine Instructions . 139 Condition Code Settings 140 Chapter 9: Floating-Point Arithmetic 125 Extended Mnemonic Codes . 140 Floating-Point Numbers . 126 EBCDIC Chart ......... 140 Floating-Point Instructions 130 System/360 Assembler Instructions. 142 Questions and Exercises . 134 Types of Assembler Language Constants 142 Answers to Questions and Exercises 135 Index ................. 143 FIGURES Assembly Listings of Programs 1-2 PROGA The program in Figure 1-1 . 3 1-5 PROGC The program rewritten with deliberate errors . 12 1-7 PROGB The same program modified to store the binary contents of register 6 . 15 3-2 STOCK The program in Figure 3-1 . 30 3-5 GROSS A program to perform binary (fixed-point) multiplication. 32 3-9 INTA A program involving binary multiplication and division with the result rounded off. 34 3-10 INTB A different version of the program of Figure 3-9, using a scale modifier for constants. 35 3-11 SHIFTA A program to separate three quantities stored in one fullword ............ 37 3-12 SHIFTB Modified version of the program of Figure 3-11, making it operate correctly with negative quantities. 38 3-15 SORT A program to carry out the sorting procedure charted in Figure 3-14 . 41 3-18 FICAI A program based on the flowchart in Figure 3-17 . 43 3-19 FICA2 A much better version of the program to calculate Social Security tax. 44 3-20 SUMA First version of a program to form the sum of 20 numbers . 45 3-21 SUMB Second version of program to form the sum of 20 numbers . 46 3-22 SUMC Third and shortest version of program to form the sum of 20 numbers, using the BXLE instruction . .. 47 3-23 AVGTEMP A program to compute average monthly temperature, which takes into account the possibility of omitted readings. .. 48 4-1 PROGE A program to show how the assembler calculates and supplies addresses of all storage operands ., 52 4-3 PROGF An incomplete program with an Origin (ORG) assembler instruction to simulate a length of over 4096 bytes, thus requiring two base registers . .. 54 4-4 LOOPA Program with separate base registers for processing and data, showing how a base register can be used to provide indexing for loop control .. .. 56 5-3 STOCK 1 The decimal arithmetic program in Figure 5-2 . .. 61 5-5 INTC A program that performs decimal multiplication; step-by-step results to be expected during exe- cution are shown in the comments field .......................... , 63 5-6 AVG Assembled program showing decimal division and "shifting"; step-by-step results to be expected during execution are included in the comments field .