Assembler Language As a Higher Level Language
Total Page:16
File Type:pdf, Size:1020Kb
Assembler University 306-307 Assembler Language as a Higher Level Language: Macros and Conditional Assembly Techniques SHARE 99, Summer Conference 2002, Sessions 8167-8168 John R. Ehrman [email protected] [email protected] International Business Machines Corporation Silicon Valley (nee Santa Teresa) Laboratory 555 Bailey Avenue San Jose, California 95141 Synopsis: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-----. This tutorial introduces the powerful concepts of conditional assembly supported by the IBM High Level Assembler for MVS & VM & VSE , and provides examples of its use in both "open code" and in macro instructions. The examples in this document are for purposes of illustration only, and no warranty of correctness or applicability is implied or expressed. Permission is granted to SHARE Incorporated to publish this material in the proceedings of the SHARE 99, Summer Conference 2002. IBM retains the right to publish this material elsewhere. Copyright Notices and Trademarks -------------------------~ © Copyright IBM Corporation 1995, 2002. All rights reserved. Note to U.S. Government Users: Doc umentation subject to restricted rights. Use, duplication, or disclosure is subject to restrictions set forth in GSA ADP Schedule Contract with IBM Corp. The following terms, denoted by an asterisk C-) in this publication, are trademarks or registered trade marks of the International Business Machines Corporation in the United States and/or other coun tries: IBM ESA System/370 System/390 MYS/ES A OS/390 YM/ESA zSeries YSE/ESA YSE z/OS z/VM DFSMS zlArchitecture Publications, Collection Kits, Web Sites -------------------------. The currently available product publications for High Level Assembler for MYS & YM & YSE are: High Level Assembler for MYS & YM & YSE Language Reference, SC26-4940 High Level Assembler for MYS & VM & YSE Programmer's Guide, SC26-4941 • High Level Assembler for MVS & YM & YSE General Information, GC26-4943 High Level Assembler for MVS & VM & YSE Licensed Program Specifications, GC26-4944 • High Level Assembler for MYS & VM & VSE Installation and Customization Guide, SC26-3494 • High Level Assembler for MVS & VM & YSE Toolkit Feature Interactive Debug Facility User's Guide, GC26-8709 • High Level Assembler for MVS & VM & YSE Toolkit Feature User's Guide, GC26-8710 High Level Assembler for MVS & VM & VSE Toolkit Feature Installation and Customization Guide, GC26-8711 High Level Assembler for MVS & VM & VSE Toolkit Feature Interactive Debug Facility Reference Summary, GC26-8712 • High Level Assembler for MYS & VM & VSE Release 2 Presentation Guide, SG24-3910 Soft-copy High Level Assembler for MVS & VM & YSE publications are available on the following IBM Online Library Omnibus Edition Compact Disks: • VSE Collection, SK2T-0060 MVS Collection, SK2T-0710 • Transaction Processing and Data Collection, SK2T-0730 • VM Collection, SK2T-2067 • OS/390 Collection, SK2T-6700 (BookManager), SK2T-6718 (PDF) HLASM publications are available online at the HLASM web site: http://www.ibm.com/software/ad/hlasm/ Acknowledgments ---------------------------------. I am grateful to several people have helped make this material more reliable and readable: • Many friends and colleagues at SHARE have offered advice (and correction) during and after pres entations. Abe Kornelis ([email protected], Linschoten, The Netherlands) provided many helpful suggestions and caught many inaccuracies. ii Assembler Language as a Higher Level Language, SHARE Summer 2002 Contents Conditional Assembly and Macro Overview 1 Part 1: The Conditional Assembly Language 3 Evaluation, Substitution, and Selection 5 Variable Symbols . 6 Oeclaring Variable Symbols ...... 8 Substitution . .... 10 Comments on Substitution, Evaluation, and Re-Scanning 12 Assigning Values to Variable Symbols: SET Statements 14 Evaluating Conditional-Assembly Expressions ....... 15 Evaluating and Assigning Arithmetic Expressions: SETA 16 Arithmetic Expressions: Internal Arithmetic Functions 17 SETA Statements vs. EQU Statements ........ 19 Evaluating and Assigning Boolean Expressions: SETB . 20 Evaluating and Assigning Character Expressions: SETC 22 String Concatenation 25 Substrings . ... 26 String Lengths ........................... 28 Character Expressions: Internal Character Functions 29 External Conditional-Assembly Functions ...... 32 Conditional Expressions with Mixed Operand Types 33 Statement Selection .................... 34 Sequence Symbols and the ANOP Statement 35 ANOP Statement ........ 36 The AGO Statement . .... 37 The Extended AGO Statement . 38 The AIF Statement . ......... 39 The Extended AIF Statement .......... 40 Logical Operators in SETA, SETB, and AIF Statements 41 Displaying Variable Symbol Values: The MNOTE Statement . 42 Examples of Conditional Assembly ............... 43 Example 1: Generate a Sequence of Byte Values ..... 44 Example 2: Generating System-Dependent 1/0 Statements 46 Conditional Assembly Language Eccentricities ........ 47 Part 2: Basic Macro Concepts ............... 48 What is a Macro Facility? .................... 49 Benefits of Macro Facilities ................. 50 The Macro Concept: Fundamental Mechanisms ............... 51 Text Insertion . 52 Text Parameterization and Argument Association .............. 53 Text Seledion . ............ 54 Macro Call Nesting . ... 55 Macro Definition Nesting . ..... 57 The Assembler Language Macro Definition ...... 59 Macro-Instruction Definition Example . 60 Macro-Instruction Recognition Rules . .. 61 Macro-Instruction Recognition: Details 62 Macro-Definition Encoding . ..... 63 Nested Macro Definition in High Level Assembler ...... 64 Macro Expansion, Generated Statements, and the MEXIT Statement 65 Macro Comments and Readability Aids ............... 66 Example 1: Define Equated Symbols for Registers ......... 67 Macro Parameters and Arguments . 68 Macro-Definition Parameters . ... 69 Macro-lnstrudion Arguments . ..... 70 Macro Parameter-Argument Association 71 Constructed Keyword Arguments 73 Contents iii Example 2: Generate a Sequence of Byte Values (BYTESEQ1) 74 Macro Parameter Usage in Model Statements ...... 75 Macro Argument Attributes and Structures ........ 76 Macro-Instruction Argument Properties: Type Attribute 78 Macro-Instruction Argument Properties: Count Attribute 80 Macro-Instruction Argument Properties: Number Attribute 81 Macro-Instruction Argument Lists and Sublists ....... 82 Macro-Instruction Argument Lists and the &SYSLIST Variable Symbol 84 Macro Argument Lists and Sublists ...... 85 Inner-Macro Sublists ..... '. .... 85 Control of Macro Argument Sublists 87 Global Variable Symbols ........ 88 Variable Symbol Scope Rules: Summary 89 Macro Debugging Techniques ....... 91 Macro Debugging: The MNOTE Statement 92 Macro Debugging: The MHELP Statement 93 Macro Debugging: The ACTR Statement 95 Macro Debugging: The LIBMAC Option . 96 Macro Debugging: The PRINT MCALL Statement . 97 IBM Macro Libraries 98 Part 3: Macro Techniques 99 Macro Techniques Case Studies 101 Case Study 1: Defining Equated Symbols for Registers 103 Case Study 2: Generating a Sequence of Byte Values 107 Case Study 3: "MVC2" Macro Uses Source Operand Length 110 Case Study 4: Conversion Between Hex and Decimal 112 Macro-Time Conversion from Hex to Decimal . 113 Macro-Time Conversion from Decimal to Hex ....... 115 Case Study 5: Generate a List of Named Integer Constants 117 Case Study 6: Using the AREAD Statement .......... 121 Case Study 6a: Creating Length-Prefixed Message Texts 122 Simplest Prefixed Message Text .......... 123 More General Prefixed Message Text ...... 123 Prefixed Message Text with the AREAD Statement 126 Case Study 6b: Block Comments ........... 128 Case Study 7: Macro Recursion . ... 130 Recursion Example 1: Indirect Addressing ..... 131 Recursion Example 2: Factorial Function Values 133 Recursion Example 3: Fibonacci Numbers ..... 135 Case Study 8: Defining Macros for Bit-Handling Operations . 137 Basic Bit Handling Techniques ............ 138 Case Study 8a: Bit-Handling Macros - Simple Forms 140 Simple Bit-Manipulation Macros .......... 143 Simple Bit-Manipulation Macros: Setting Bits ON 144 Simple Bit-Manipulation Macros: Inverting and Setting Bits OFF 146 Simple Bit-Testing Macros ...................... 148 Case Study 8b: Bit-Handling Macros - Advanced Forms 150 Bit-Handling "Micro Language" and "Micro-Compiler" 151 Declaring Bit Names .............. 154 Improved Bit-Manipulation Macros ..... 159 Using Declared Bit Names in a BitOn Macro 161 Using Declared Bit Names in a BBitOn Macro 164 Case Study 9: Defining and Using Data Types 172 Case Study 9a: Type Sensitivity - Simple Polymorphism 174 Shortcomings of Assembler-Assigned Types 177 Symbol Attributes and Lookahead Mode 178 The LOCTR Statement ........ 179 Case Study 9b: Type Checking ..... 180 Instruction-Operand Type Checking . 181 Instruction-Operand Type Checking (Generalized) 183 The AINSERT Statement . 184 iv Assembler Language as a Higher Level Language, SHARE Summer 2002 User-Defined Assembler Type Attributes ...... 188 Instruction-Operand-Register Type Checking 190 Case Study 9c: Encapsulated Abstract Data Types 192 Calculating with Date Variables ...... 196 Calculating with Interval Variables .... 198 Comparison Operators for Dates and Intervals 202 Case Study 10: "Front-Ending" a Macro .... 204 Summary ..................... 206 Appendix A. External Conditional Assembly Functions ............... 208 Ex1ernal Conditional Assembly Functions 209 SETAF External Function Interface ..... 210 Arithmetic-Valued Function Example: LOG2 211 SETCF External