|
|
Labels and
Macro Files Assembler Coding Examples http://www.simotime.com |
| When technology complements business | Copyright © 1987-2010 SimoTime Enterprises All Rights Reserved |
The creation and usage of labels within a mainframe assembler program is usually an easy task. One of the challenges in larger programs is to create unique labels. This was a problem with the early assembler compilers that had a limit of eight character names. With today's assembler compiler this has been increased to 64 characters.
The task of maintaining unique labels presented a bigger problem when using macros that generated code that included branch instructions. There are various techniques used to solve this problem and each has its own advantages and disadvantages.
This sample program is written entirely in mainframe assembler and will run as an MVS batch job on an IBM mainframe or as a project with Micro Focus Mainframe Express (MFE) running on a PC with Windows (refer to http://www.microfocus.com).
|
||||||||||
|
|
||||||||||
|
Mainline Program | |||||||||
|
|
||||||||||
|
Expanded macro code using a predefined label. | |||||||||
|
|
||||||||||
|
Expanded macro code using a generated label. | |||||||||
|
|
||||||||||
|
Expanded macro code using no labels. | |||||||||
|
|
||||||||||
|
Expanded macro code with alignment considerations | |||||||||
|
|
||||||||||
|
||||||||||
The following is the mainframe JCL (SIMLABJ1.JCL) required to run the mainline program. This will run on an IBM mainframe with MVS or on the PC using Micro Focus Mainframe Express.
//SIMLABJ1 JOB SIMOTIME,ACCOUNT,CLASS=1,MSGCLASS=0,NOTIFY=LRSP1 //* ******************************************************************* //* This program is provided by: * //* SimoTime Enterprises, LLC * //* (C) Copyright 1987-2010 All Rights Reserved * //* * //* Web Site URL: http://www.simotime.com * //* e-mail: helpdesk@simotime.com * //* ******************************************************************* //* //* Text - 370 Assembler, Sample use of labels //* Author - SimoTime Enterprises //* Date - January 01, 1997 //* //* This 370 Assembler program provides different techniques for //* generating unique labels or avoiding the use of labels within //* expanded macro code. //* //* This set of programs will run on a mainframe under MVS or on a //* Personal Computer with Windows and Micro Focus Mainframe Express. //* //* ******************************************************************* //* Step 1 This is a single step job. //* //SIMLABS1 EXEC PGM=SIMLABA1 //STEPLIB DD DSN=SIMOTIME.DEMO.LOADLIB1,DISP=SHR //*
The following is the mainframe assembler source code (SIMLABA1.MLC) for the mainline program that incorporates the use of the macro files to demonstrate the various ways to create label names or avoid creating label names within a macro.
SIMLABA1 CSECT
***********************************************************************
* This program is provided by: *
* SimoTime Enterprises, LLC *
* (C) Copyright 1987-2010 All Rights Reserved *
* *
* Web Site URL: http://www.simotime.com *
* e-mail: helpdesk@simotime.com *
***********************************************************************
* *
* This program illustrates techniques used in macro coding to *
* avoid creating labels or attempt to generate unique labels for *
* macro generated code. *
* *
* This program will run an an IBM Mainframe using MVS or a PC using *
* Micro Focus Mainframe Express, version 2.5 or later (MFE) with *
* the Assembler Option. *
* *
* Created: 1992/06/01, Simmons *
* Changed: 1992/06/01, Simmons, no changes to date... *
* *
***********************************************************************
*
BALR 12,0
USING *,12
***********************************************************************
* Macro generated code that uses specific labels. *
* *
* The advantage to this approach is that it is simple and easy *
* to understand. *
* *
* The disadvantage of this approach is that it may only be used *
* once in a program. A second use of this macro in the same program *
* will cause a duplicate label error. *
***********************************************************************
SIMLABM1
*
***********************************************************************
* Macro generated code that creates and uses generated labels. *
* *
* The advantage to this approach is the macro may be used more *
* than once in the same program. *
* *
* The disadvantage to this approach is that it attempts to create *
* unique labels but there is a possibility that a label may be *
* generated that is the same as another label used in the program. *
* *
* Another disadvantage is that it uses &SYSNDX that provides a *
* four digit number that is incremented. If the macro is used more *
* that once in a program and the second use of the macro is placed *
* before the original use of the macro then the name will be *
* changed because the number portion will be incremented. *
* *
* Also, the labels that are generated will appear in the symbol *
* table and may be confusing for the individual that uses the macro. *
***********************************************************************
SIMLABM2
*
***********************************************************************
* Macro generated code that avoids using labels. *
* *
* The advantage of this approach is that it does not use any labels. *
* *
* The disadvantage to this approach is that it may be confusing since *
* the branch target is define as a numeric offset. *
* *
* Also, care must be used when inserting additional code between the *
* branch instruction and the branch target. *
***********************************************************************
SIMLABM3
*
***********************************************************************
* Macro generated code with alignment considerations. *
* *
* It is never that easy. Let's take a look at a realistic example. *
* This program will pass a quoted text string to the macro. It is *
* the macro's responsibility to maintain halfword alignment. *
* *
* This is easy to do as long as the quoted text string is an even *
* number of characters. However, if the quoted text string is an odd *
* number of characters the macro must do a little extra work. *
* *
* The following illustrates the techniques used to maintain the *
* halfword alignment. The SR 15,15 instruction will be on a halfword *
* boundary for both an even and odd length message. *
***********************************************************************
SIMLABM4 'SIMLABM4, ALIGNMENT CONSIDERATIONS, EVEN'
*
SIMLABM4 'SIMLABM4, ALIGNMENT CONSIDERATIONS, ODD'
*
***********************************************************************
SR 15,15 * Set Return Code to Zero.
BR 14 * Return to Caller
*
END
Using explicit names in the mainline code creates code that is simple and easy to understand. Using explicit labels in expanded macro code has the same advantage being that it is simple and easy to understand. The disadvantage of this approach is that the macro can only be used once in a program. A second use of this macro in the same program will cause a duplicate label error. The following macro (SIMLABM1.MAC) uses explicit, hard-coded label names.
MACRO
SIMLABM1
.**********************************************************************
.* This macro is provided by: *
.* SimoTime Enterprises, LLC *
.* (C) Copyright 1987-2010 All Rights Reserved *
.* *
.* Web Site URL: http://www.simotime.com *
.* e-mail: helpdesk@simotime.com *
.**********************************************************************
.*
.* The following BAL instruction will branch around the Define Constant
.* (DC) that follows the instruction.
.*
.* The branch target label is explicitly defined.
.*
.* This macro may only be used once in a program. A second use
.* would cause a duplicate label error message.
.*
BAL 1,HARDROCK * Branch Target is specific label.
DC AL2(4+32,0)
DC CL32'SIMLABM1, USE A SPECIFIED LABEL.'
DS 0H * Maintain halfword alignment
HARDROCK SVC 35
.*
MEND
The advantage to this approach is the macro may be used more than once in the same program. The disadvantage to this approach is that it attempts to create unique labels but there is a possibility that a label may be generated that is the same as another label used in the program.
Another disadvantage is that it uses &SYSNDX that provides a four digit number that is incremented. If the macro is used more that once in a program and the second use of the macro is placed before the original use of the macro then the name will be changed because the number portion will be incremented.
Also, the labels that are generated will appear in the symbol table and may be confusing for the individual that uses the macro. The following macro (SIMLABM2.MAC) uses generated label names.
MACRO
SIMLABM2
.**********************************************************************
.* This macro is provided by: *
.* SimoTime Enterprises, LLC *
.* (C) Copyright 1987-2010 All Rights Reserved *
.* *
.* Web Site URL: http://www.simotime.com *
.* e-mail: helpdesk@simotime.com *
.**********************************************************************
.*
.* The following BAL instruction will branch around the Define Constant
.* (DC) that follows the instruction.
.*
.* The branch target label is generated by concatenating the literal
.* value of "ZLRS" with the numeric value supplied by $SYSNDX.
.*
.* This is an attempt to create and use a unique label within the
.* generated code. Once again, this is an attempt and in larger
.* programs the possiblity of generating a duplicate label increases.
.*
BAL 1,ZLRS&SYSNDX * Branch Target ZLRS plus &SYSNDX; DC AL2(4+32,0)
DC CL32'SIMLABM2, USE A GENERATED LABEL.'
DS 0H * Maintain halfword alignment
ZLRS&SYSNDX SVC 35
.*
MEND
The advantage of this approach is that it does not use any labels. The disadvantage to this approach is that it may be confusing since the branch target is define as a numeric offset. Also, care must be used when inserting additional code between the branch instruction and the branch target. The following macro (SIMLABM3.MAC) avoids the use of label names.
MACRO
SIMLABM3
.**********************************************************************
.* This macro is provided by: *
.* SimoTime Enterprises, LLC *
.* (C) Copyright 1987-2010 All Rights Reserved *
.* *
.* Web Site URL: http://www.simotime.com *
.* e-mail: helpdesk@simotime.com *
.**********************************************************************
.*
.* The following BAL instruction will branch around the Define Constant
.* (DC) that follows the instruction.
.*
.* The *+4 item takes the current address of the BAL instruction
.* location and increments the branch target address by four.
.*
.* The second +4 increments past the control information.
.*
.* The +44 then increments the branch target address by forty-four,
.* the length of the message text..
.*
.* Note: some instructions require halfword alignment so the length
.* of the DC should always be an even number.
.*
BAL 1,*+4+4+44 * Branch around literal.
DC AL2(4+44,0)
DC CL44'SIMLABM3, NO LABELS SPECIFIED OR GENERATED. '
SVC 35
.*
MEND
Once again, notice the the length of message text in the above example is an even number of bytes. This will maintain the halfword alignment for the SVC instruction. The following example will show how to handle halfword alignment for message text that may not maintain alignment.
It is never that easy. Let's take a look at a realistic example. The program (SIMLABA1) will pass a quoted text string to the macro. It is the macro's responsibility to maintain halfword alignment.
This is easy to do as long as the quoted text string is an even number of characters. However, if the quoted text string is an odd number of characters the macro must do a little extra work. The following macro (SIMLABM4.MAC) avoids using label names and will maintain halfword alignment.
MACRO
SIMLABM4 &MSG
.**********************************************************************
.* This macro is provided by: *
.* SimoTime Enterprises, LLC *
.* (C) Copyright 1987-2010 All Rights Reserved *
.* *
.* Web Site URL: http://www.simotime.com *
.* e-mail: helpdesk@simotime.com *
.**********************************************************************
.*
.* This macro will accept a quoted text string as a parameter.
.* This macro will calculate the length of the quoted text string
.* and maintain halfword alignment for the SVC 35 instruction. If
.* the quoted text string is an odd number of bytes then a pad
.* character is added to maintain the alignment.
.*
&MSGLEN SETA K'&MSG-2
&ALIGN SETA (K'&MSG-2)/2*2
AIF (&ALIGN NE &MSGLEN).ALIGNME
.*
.* The following BAL instruction will branch around the control
.* information and message text.
.*
BAL 1,*+4+4+&MSGLEN * Branch around literal.
DC AL2(&MSGLEN+4)
DC AL2(0)
DC C&MSG
SVC 35 * Maintain halfword alignment
AGO .END
.*
.ALIGNME ANOP
BAL 1,*+4+4+&MSGLEN+1 * Branch around literal and pad.
DC AL2(&MSGLEN+4)
DC AL2(0)
DC C&MSG
DC CL1' ' * Pad for alignment
SVC 35 * Maintain halfword alignment
.*
.END ANOP
MEND
In the world of programming there may be many different approaches to solving a problem. The approach is influenced by the following items:
| 1. | The design and business objectives | |
| 2. | Company standards | |
| 3. | Individual styles and preferences. | |
| 4. | Maintainability by someone other than the original author. |
The objective of this sample program is to provide insight into some of the approaches that may be used when writing macro code that will generate assembler code that contains branch instructions.
The choice of which approach is best suited to a particular environment is a decision that should be made by the programmer solving the problem.
Permission to use, copy, modify and distribute this software for any commercial purpose requires a fee to be paid to Simotime Enterprises. Once the fee is received by SimoTime the latest version of the software will be delivered and a license will be granted for use within an enterprise, provided the SimoTime copyright notice appear on all copies of the software. The SimoTime name or Logo may not be used in any advertising or publicity pertaining to the use of the software without the written permission of SimoTime Enterprises.
Permission to use, copy, modify and distribute this software for a non-commercial purpose and without fee is hereby granted, provided the SimoTime copyright notice appear on all copies of the software. The SimoTime name or Logo may not be used in any advertising or publicity pertaining to the use of the software.
SimoTime Enterprises makes no warranty or representations about the suitability of the software for any purpose. It is provided "AS IS" without any express or implied warranty, including the implied warranties of merchantability, fitness for a particular purpose and non-infringement. SimoTime Enterprises shall not be liable for any direct, indirect, special or consequential damages resulting from the loss of use, data or projects, whether in an action of contract or tort, arising out of or in connection with the use or performance of this software.
I prefer using explicitly defined labels in the mainline code. The advantage to this approach is that it is simple and easy to understand. If the label is the target of a branch instruction then code may be inserted between the branch instruction and the target and the branch integrity is maintained.
I prefer avoiding the generation of labels in macro code whenever possible. This approach avoids the possibility of creating duplicate labels and does not add labels to the symbol table. Also, if explicit labels are used the macro will be limited to a single use within a program.
This sample program is provided by Larry Simmons. He may be reached at larry.simmons@simotime.com
Check out The Assembler Connection for more examples of mainframe Assembler coding techniques and sample code.
Check out The SimoTime Library for a wide range of topics for Programmers, Project Managers and Software Developers.
To review all the information available on this site start at The SimoTime Home Page .
If you have any questions, suggestions or comments please call or send an e-mail to: helpdesk@simotime.com
Founded in 1987, SimoTime Enterprises is a privately owned company. We specialize in the creation and deployment of business applications using new or existing technologies and services. We have a team of individuals that understand the broad range of technologies being used in today's environments. This includes the smallest thin client using the Internet and the very large mainframe systems. There is more to making the Internet work for your company's business than just having a nice looking WEB site. It is about combining the latest technologies and existing technologies with practical business experience. It's about the business of doing business and looking good in the process. Quite often, to reach larger markets or provide a higher level of service to existing customers it requires the newer Internet technologies to work in a complementary manner with existing corporate mainframe systems. Whether you want to use the Internet to expand into new market segments or as a delivery vehicle for existing business functions simply give us a call or check the web site at http://www.simotime.com
| Return-to-Top |
| Copyright © 1987-2010 SimoTime Enterprises All Rights Reserved |
| When technology complements business |