High Level Assembler Macro Facility
Total Page:16
File Type:pdf, Size:1020Kb
A++: Using the World's Most Powerful Macro Facility With High Level Assembler Parts 1 and 2 SHARE 119, Anaheim CA, Summer 2012 Presented by Tom Wasik, IBM [email protected] Contents prepared by John R. Ehrman [email protected] International Business Machines Corporation Silicon Valley Laboratory 555 Bailey Avenue San Jose, California 95141 USA Synopsis: This tutorial introduces the powerful concepts of conditional assembly supported by the High Level Assembler for z/OS, z/VM, & z/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 119. IBM retains the right to publish this material elsewhere. © Copyright IBM Corporation 1995, 2012. All rights reserved. Copyright Notices and Trademarks © Copyright IBM Corporation 1995, 2012. 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 (*) in this publication, are trademarks or registered trademarks of the International Business Machines Corporation in the United States and/or other countries: IBM System/370 System/390 zSeries z/OS z/VM z/VSE OS/390 DFSMS z/Architecture ESA Publications and Web Site The currently available product publications for High Level Assembler for z/OS, z/VM, and z/VSE are: • High Level Assembler for z/OS, z/VM, and z/VSE Language Reference, SC26-4940 • High Level Assembler for z/OS, z/VM, and z/VSE Programmer's Guide, SC26-4941 • High Level Assembler for z/OS, z/VM, and z/VSE Licensed Program Specifications, GC26-4944 • High Level Assembler for z/OS, z/VM, and z/VSE Installation and Customization Guide, SC26-3494 The currently available product publications for High Level Assembler for z/OS, z/VM, and z/VSE Toolkit Feature are: • High Level Assembler for z/OS, z/VM, and z/VSE Toolkit Feature Interactive Debug Facility User's Guide, GC26-8709 • High Level Assembler for z/OS, z/VM, and z/VSE Toolkit Feature User's Guide, GC26-8710 • High Level Assembler for z/OS, z/VM, and z/VSE Toolkit Feature Installation and Customization Guide, GC26-8711 • High Level Assembler for z/OS, z/VM, and z/VSE Toolkit Feature Interactive Debug Facility Reference Summary, GC26-8712 The currently available product publications for High Level Assembler for Linux on zSeries are: • High Level Assembler for Linux on System z User's Guide, SC18-9611 HLASM publications are available online at the HLASM web site: http://www.ibm.com/software/awdtools/hlasm/ Acknowledgments I am grateful to many people who have helped make this material more reliable and readable: • Friends and colleagues at SHARE have offered advice (and corrections) during and after presentations. • Abe Kornelis ([email protected]) provided many helpful suggestions and caught many inaccuracies. ii A++: Using HLASM's Macro Facility Contents Conditional Assembly and Macros ................................. 1 Why is the Conditional Assembly Language So Useful? ..................... 2 Why is the Conditional Assembly Language So Interesting? ................... 3 Part 1: The Conditional Assembly Language ........................... 4 Evaluation, Substitution, and Selection ................................ 6 Variable Symbols . 7 Declaring Variable (SET) Symbols ................................. 9 Subscripted Variable Symbols .................................. 10 Created Variable Symbols .................................... 10 Assigning Values to Variable Symbols: SET Statements ...................... 12 Substitution . 13 Evaluating Arithmetic Expressions: SETA ............................ 14 SETA Statements vs. EQU Statements ............................. 16 Evaluating and Assigning Boolean Expressions: SETB ..................... 17 Evaluating and Assigning Character Expressions: SETC .................... 19 Character Expressions: String Concatenation ......................... 21 Character Expressions: Substrings ................................ 22 Character Expressions: String Lengths ............................. 24 Conditional Expressions with Mixed Operand Types ...................... 25 Internal Conditional-Assembly Functions .............................. 26 Functions Using Logical-Expression Format ........................... 27 Arithmetic-Valued Functions Using Logical-Expression Format .............. 28 Character-Valued Functions Using Logical-Expression Format ............... 29 Functions Using Function-Invocation Format .......................... 30 Internal Type-Conversion Functions .............................. 31 Converting from Arithmetic Data to Character Value Types ................ 32 Converting from Character Values to Arithmetic Values ................... 33 Converting to and from Decimal Character Data ....................... 34 Converting Among Bit, Byte, and Hexadecimal String Data ................ 36 Validity-Testing Functions . 37 Character-Valued String Functions ............................... 38 Arithmetic-Valued String Functions .............................. 39 External Conditional-Assembly Functions ............................ 40 Statement Selection: Conditional Assembly Control Flow .................... 41 Sequence Symbols . 42 ANOP Statement . 43 The AGO Statement ........................................ 43 The Extended AGO Statement ................................. 44 The AIF Statement ......................................... 45 The Extended AIF Statement .................................. 46 Displaying Symbol Values and Messages: The MNOTE Statement ............... 47 Examples of Conditional Assembly ................................. 48 Example 1: Generate Bytes with Values 1-N ........................... 48 Example 3: Generating System-Dependent I/O Statements ................... 51 Conditional Assembly Language Eccentricities ........................... 52 Conditional Assembly Language Special Topics .......................... 53 Comments on Substitution, Evaluation, and Re-Scanning .................. 53 Logical Operators in SETA, SETB, and AIF Statements .................... 55 Part 2: Basic Macro Concepts ................................... 56 What is a Macro Facility? ....................................... 57 Macros and Subroutines ...................................... 57 Benefits of Macro Facilities ..................................... 58 The Macro Concept: Fundamental Mechanisms .......................... 59 Text Insertion . 60 Text Parameterization and Argument Association ........................ 61 Text Selection . 62 Contents iii Macro Call Nesting ......................................... 63 Macro Definition Nesting ...................................... 65 The Assembler Language Macro Definition ............................. 67 Macro-Instruction Definition Example .............................. 67 Macro-Instruction Recognition Rules ............................... 68 Macro Expansion, Generated Statements, and the MEXIT Statement ............ 69 Macro Comments and Readability Aids ............................... 70 Example 1: Define Equated Symbols for Registers ......................... 71 Macro Parameters and Arguments .................................. 72 Macro-Definition Parameters . 73 Macro-Instruction Arguments . 74 Macro Parameter-Argument Association ............................. 76 Example 2: Generate a Sequence of Byte Values (BYTESEQ1) ................. 78 Macro Argument Attributes and Structures ............................. 79 Macro-Instruction Argument Properties: Type Attribute .................... 81 Length, Integer, and Scale Attributes ............................... 81 Defined Attribute . 82 Macro-Instruction Argument Properties: Count Attribute ................... 82 Macro-Instruction Argument Properties: Lists and Number Attributes ............ 83 Macro-Instruction Argument Lists and Sublists ........................ 84 Macro-Instruction Argument Lists and the &SYSLIST Variable Symbol .......... 86 Summary of Attribute References ................................. 87 Global Variable Symbols ....................................... 88 Variable Symbol Scope Rules: Summary ............................. 89 Macro Debugging Techniques .................................... 91 Macro Debugging: The MNOTE Statement ........................... 91 Macro Debugging: The MHELP Statement ........................... 92 Macro Debugging: The ACTR Statement ............................ 94 Macro Debugging: The LIBMAC Option ............................ 95 Macro Debugging: The PRINT MCALL Statement ...................... 96 IBM Macro Libraries ........................................ 97 Macro Special Topics ......................................... 97 Macro-Instruction Recognition: Details ............................ 98 Macro-Definition Encoding ..................................... 98 Nested Macro Definitions ..................................... 100 Constructed Keyword Arguments ................................ 101 Macro Parameter Usage in Model Statements .......................... 102 Macro Argument Lists and Sublists: Details .......................... 103 Inner-Macro Sublists . 104 Part 3: Macro Techniques .................................... 106 Macro Techniques Case Studies .................................