Professional Documents
Culture Documents
Legac-e Education
Module 1 2 3 4 5 6 7 8 9 10 11 12 13 14
Title Assembler Introduction Data Areas Beginning and Ending Basic Decision Making Moving data around storage Non-VSAM queued I/O macros Load and Store Register contents DSECTs and Getting Storage More Decision Making Binary Integer Arithmetic Decimal Arithmetic Bit Manipulation Handling Sub-routines VSAM I/O macros
Assembler Instructions with page reference Machine Instructions Mnemonics with page reference Macros used, with page reference
Legac-e Education
Objectives
At the completion of this course, students will know and understand how to use the IBM Assembler Programming Language. All students will be able to: Explain the assembly process Explain the general syntax and structure of the language Demonstrate the ability to start and end programs correctly Select and use appropriate instructions for moving data between registers and storage Select and use appropriate instructions for moving data around storage Use appropriate instructions to alter the logic flow of a program. Perform binary integer arithmetic Perform decimal arithmetic Perform bit manipulation Execute non-VSAM queued technique I/O macros. Pass control between sub-routines Perform VSAM ESDS I/O operations
Legac-e Education
Course documentation
All Legac-e designed to intended to material by course. Education course documentation is complement the course, and is not be used as stand alone reference those who have not attended the
This course is designed and produced by KMS-IT Limited. If you require more information about our Legac-e Educations services, please contact: Legac-e Education 228 Abbeydale Road South, Dore, Sheffield, South Yorkshire, UK. SL17 3LA Telephone (National) 0114 262 0933 Telephone (International) +44 114 262 0933 E-mail Website courses@legac-e.co.uk www.legac-e.co.uk
Legac-e Education
All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, photographic, or otherwise, without the prior permission of the copyright owners. Copyright Legac-e Education 2004, 2006 All registered or unregistered trademarks referenced in this material are the property of their respective owners.
Legac-e Education
Legac-e Education
This is Version 2 of this document, produced in January 2006. This material has been produced by, and is the property of KMS-IT Limited, trading as Legac-e Education, irrespective of the elearning provider. Payment of a course fee entitles the subscriber to access to a single copy of both hardcopy and online material for the sole use of the subscriber. Copying of any of the material is prohibited except with the express permission of the authors.
Legac-e Education is a trade name of KMSIT Limited, whose registered address is: 228 Abbeydale Road South Dore Sheffield S17 3LA South Yorkshire UK Tel: +44 (0)114 262 0933 E-mail: enquiries@kmsitltd.co.uk KMS-IT Limited is registered in England and Wales, No 3767263
Legac-e Education
Additional documentation ______________________________________________ 4 Documentation location ________________________________________________ 4 Source code syntax ____________________________________________________ 6
Label _______________________________________________________________________6 Operation ___________________________________________________________________6 Operands ___________________________________________________________________8 Comments __________________________________________________________________8 Continuation _________________________________________________________________8
Practical example _____________________________________________________ 30 Multiple base registers ________________________________________________ 32 Instruction Notation ___________________________________________________ 34
Legac-e Education
Introduction
The first module of the "Assembler Programming Workshop" sets the scene in which the IBM Assembler Language operates. The main topics covered are: Documentation sources Source code syntax Assembly Process General Purpose Registers Relocatable addressability
Page 1
Legac-e Education
The definitions of these statement types are spread across a number of manuals, some of those relevant to z/OS are listed opposite. Instructions to the assembler SC26-4940 - High Level Assembler Language Reference Machine code mnemonics z/Architecture Principles of Operation manual (SA22-7832) describes the actual instructions and how they work. Data area declarations SC26-4940 - High Level Assembler Language Reference Macro instructions There may be a variety of manuals depending upon the type of macro required. The most common macro manuals are: SC26-7408 DFSMS Macro Instructions for Data Sets.
Page 2
Legac-e Education
Source Code
Mnemonic Machine Instructions. (See Principles of Operation SA22-7832) Data Definitions. (See High Level Assembler Language Reference SC26-4940)
AP
CLC
LM
DC
GET
DS
DC B
Macros. (See DFSMS Macro Instructions for Data Sets. C L OS SC26-7408) E Instructions to the Assembler. (As per Data Definitions above.)
E OP
START
RG TO L
END
11
Page 3
Legac-e Education Additional documentation These manuals may also be useful. For supervisor service macros such as CALL, LINK, STORAGE etc, two manuals will prove useful: z/OS MVS Programming: Assembler Services Reference, Vol. 1 (SA22-7606) z/OS MVS Programming: Assembler Services Reference, Vol. 2 (SA22-7607) If running on non-z/architecture and/or OS/390: ESA/390 Principles of Operation (SA22-7201) if running a machine other than a z/8nn or z/9nn. OS/390 DSFSMS/MVS Macro Instructions for Data Sets (SC26-7337) OS/390 MVS Programming: Assembler Services Reference (GC28-1910) Documentation location It is reasonable to assume that each installation would have its own copy of the relevant documentation. Product licensing normally provides for one hard-copy, and a soft-copy CD. If the documentation cannot be found or additional copies are required, it is useful to note that nearly all manuals are in Adobe Acrobat (.PDF) format and are obtainable from the IBM WEB site. The foil opposite indicates the link process to find the manual library on the WEB.
Page 4
Legac-e Education
Documentation location
www.ibm.com Products & Services Servers - Enterprise Library Select system environment
13
Page 5
Legac-e Education Source code syntax The rules governing assembler source code date from the 1960s when source code was input via punched cards. In some ways the rules are similar to those which applied to JCL at that time, especially with regard to catalogue procedures. Essentially each source statement is an 80-byte record, with columns 73-80 reserved for sequence numbers. Statements comprise 5 areas, i.e. Label Operation Operands Comments
Label The label field if required begins in column 1, and can be up to 8 characters long. If a label is not required the label area must be blank. Labels can be composed of alphanumeric characters or national symbols, but cannot start with a number. Operation This will be separated from the label field and operands field by blanks. The operation will be one of: A machine code mnemonic An instruction to the assembler A macro instruction name
Convention has it that the operation field will start in column 10.
Page 6
Legac-e Education
MYPGM
SAVE REGISTERS
Operation is mandatory and has a blank either side of it. Label is optional, if coded it must begin in column 1. If omitted column 1 must be blank. A name cannot exceed 8 characters. Name can consist of Alphanumeric & National characters.
Copyright Legac-e Education, 2004, 2005 14
Page 7
Legac-e Education Operands The number and type of operands will vary according to the operation. Machine code mnemonics may have up to three operands. Macro instructions may have many operands depending upon the complexity of the macro function. Operands will be separated by commas, and the first blank in the operands field will be treated as the end of the operands. Where possible convention dictates that operands start in column 16. Comments To aid understanding of the code, particularly from a maintenance perspective it is recommended that comments are liberally applied throughout the assembler source. There may be installation standards pertinent to comments, if not a comment can start in any column but are often found from either column 35 or 40 onwards. Continuation There will be occasions, invoking macros for instance, when all the operands may not fit within the 71 bytes available. Statements can be continued by coding a non-blank character in column 72, and starting the remaining operands in column 16.
Page 8
Legac-e Education
Continuation
80 Characters or bytes in length
SYSIN
DCB
DSORG=PS,DDNAME=SYSIN,MACRF=GM, * LRECL=80,EODAD=QUIT
15
Page 9
Legac-e Education
Assembly process
Overview The diagram opposite illustrates the process of compiling (or assembling) source code into an executable program. The three steps represented by the middle column of the diagram are: Assembly (or compile) Program Bind (sometimes known as Link-Edit) Execution (or GO stage)
Page 10
Legac-e Education
Assembly Process
(SYSIN) Souce Code Assembly (PGM= ASMA90) (SYSPRINT) Assembly Listing
(SYSLIB) Sub-routines
6
Page 11
Legac-e Education Assembly - Step 1 This is usually the first step, although CICS programs may require a preprocessor step ahead of this. The aim of this step is to convert the input source code to machine code format. While this step produces machine code, it does not produce executable code. Inputs to the assembly step will be: SYSIN SYSLIB - primary input, the location of the source code to be compiled. - Macro or copy book libraries required by the assembly.
Outputs from the assembly step will be: SYSPRINT SYSLIN - Listing of the assembled source - Object module to be input to the program binder
Ideally a condition code of zero, i.e. STEP WAS EXECUTED COND CODE 0000, will be issued by this step. Any condition code greater than 4 must be investigated. A condition code of 4 may not be serious, it may simply be warnings from embedded macros. The DD statement definitions can be checked in "z/OS Sample Assembly Procedure" later in this module, which contains the z/OS 1.3 assembly procedure as supplied by IBM.
Page 12
Legac-e Education
Assembly Results
Input + A listing with diagnostics. Macro Expansions & XREF Object code: ESD Machine Code Data Constants. This is not executable.
Copyright Legac-e Education, 2004, 2005 7
Page 13
Legac-e Education Program Bind - Step 2 Program Bind is the modern term for what was historically known as the LinkEdit step. The function of this step is to produce an executable routine. This process includes the resolution of any external references, i.e. calls or links to other modules, which may form part of a larger program. The entry point of the program will also be established by this process. Inputs to the program binder step will be: SYSLIN SYSLIB Anyname - Primary input, the location of the source code to be compiled - Libraries searched for implicit includes (unless PARM=NCAL) - Own library explicitly mentioned on an INCLUDE statement
Outputs from the program binder step will be: SYSLMOD SYSPRINT SYSUT1 - Library to contain executable program - Listing of the bound program plus input control statements - Work area
Ideally a condition code of zero, i.e. STEP WAS EXECUTED COND CODE 0000, will be issued by this step. Any condition code greater than 4 must be investigated. The DD statement definitions can be checked in "z/OS Sample Assembly Procedure" later in this module, which contains the z/OS 1.6 assembly procedure as supplied by IBM.
Page 14
Legac-e Education
Page 15
Legac-e Education Executable code - Step 3 This is the resultant module or program produced by the Program Binder, and stored somewhere on the system. Where the module (program) is stored and how it is invoked will be dependent upon its usage. Utility programs, such IEBGENER, IEBPTPCH, and IEFBR14 typically reside in the default system load library called SYS1.LINKLIB. Normal application batch modules or programs are likely to reside in a private load library, and will usually be invoked via a JCL EXEC statement. Application programs are often located at run time by including JOBLIB, or STEPLIB DD statements in the job or job step. These DD statements are not required however if the private libraries are added to member LNKLSTnn in SYS1.PARMLIB. (This member constructs the logical concatenation to SYS1.LINKLIB). If the module or program has a special function, i.e. it may be an exit to a system product, or a user-written supervisor call (SVC) it will need to reside an appropriate system area, such as the Link Pack Area (LPA). Member IEALPAnn of SYS1.PARMLIB defines the libraries, which constitute the LPA concatenation. To be LPA eligible modules require special attributes such as being reentrant, or RENT in Program Binder terms. Such programs cannot modify themselves and if they need to store or amend data, that data has to be outside of the module itself.
Page 16
Legac-e Education
Executable Code
Typically stored in system load library like:
SYS1.LINKLIB
Page 17
Legac-e Education
Page 18
Legac-e Education
31-bit addressing
64-bit addressing
27
Page 19
Legac-e Education Register conventions Within the assembler programming arena a convention has been established for register usage. This convention is almost universal, although some IBM system routines do not use register 12 as their base register. The convention is: R0 R1 R13 R14 R15 - used for passing a single parameter - used for passing a parameter list - contains the address of the register save area - contains the return address from a called sub-routine - contains the entry address of a called sub-routine
Irrespective of the above convention any register can be used for any purpose, although not following the convention will invite trouble if either implicit or explicit calls to other routines are made. Note that some instructions, such as TRT, can corrupt registers. Note also that the use of register zero may be restricted by some instructions and result in a no-operation condition. (This is not a failure as the program will continue to run.)
Page 20
Legac-e Education
Register Conventions.
0 1
Pass single parameter Addr of Parameter List
8 9 10 11 12 13 14 15
Base Register Address of Save Area Return Address Entry Address
28
Page 21
Legac-e Education
Relocatable Addressability
If programs were not relocatable they would always occupy the same area of storage. Managing such an environment would either significantly restrict the number of concurrent program executions, or increase the maintenance overhead when programs and operating systems changed. Relocatability allows a module or program to be loaded into different storage locations at different times, yet function as intended. Relocatability requires that each storage address used within a program be broken into two components: Base register Displacement
This combination, described in more detail in a moment, will definitely apply to the module itself, and may also be used as a technique to access areas of storage beyond the addressing boundaries of the module. In high level languages such as COBOL and PL/I this relocatable concept is transparent to the programmer, but this is not the case in Assembler.
Page 22
Legac-e Education
Page 23
Legac-e Education Addressability components As mentioned earlier relocatability requires that each storage address used within a program be broken into two components: Base register Displacement
Base register This is the anchor for relative addressing and logically this register contains the address of the first byte of storage used for subsequent relative addressing. In simple terms, for a program the base register points to a location toward the start of the program, with the instructions and data areas within the program being referenced via displacements relative to the address in the base register. The base register will be identified by a value in the range 0 to 9 or A to F, as there are only sixteen General Purpose Registers available. This is discussed in the next topic. Displacement The displacement is the relative offset to be added to the address in the base register to locate the particular area of storage. Remember that the base register points to the first byte and hence the first byte is at offset zero. The maximum offset value is 4095, or hexadecimal FFF.
Page 24
Legac-e Education
Addressability Components
All instructions which access memory (storage) will have one or more components in the form:
BDDD
A number in the range 0 4095 (cannot be greater than XFFF), which is the offset from the base.
19
Page 25
Legac-e Education An internal representation The foil opposite illustrates how a particular MoVe Character (MVC) instruction has been assembled. The first byte, D2, is the machine operation code for the MVC instruction. The second byte, 07, is the length, minus 1, of the field to be moved. The next two bytes hold the address of the target field in BDDD format. The last two bytes hold the address of the source field in BDDD format.
Page 26
Legac-e Education
An internal representation
This represents a MoVe Character (MVC) instruction as it might appear after assembly.
D2 07 C A30 C 420
Second operands displacement, X420 beyond the address in Register 12. Second operands base register. Register 12.
20
First operands base register. Register 12. First operands displacement, XA30 beyond the address in Register 12.
Page 27
Legac-e Education Establishing addressability Establishing addressability requires two actions, which are relevant at two separate times: Assembly time Run time
Assembly time At assembly time it is necessary to inform the assembler which register is to be used as the base register. The assembler also needs to know what the initial displacement is. These two requirements are resolved with the USING statement. Run time At run time the system needs to know where in storage the code or data area resides. The BASR instruction is usually used to establish the base for a program or module.
Page 28
Legac-e Education
Program addressability - 1
The programmer must select a GPR to act as the base register for addressability. Convention is to use GPR 12.
Sets IC to zero. START 0 BASR 12,0 USING *,12 MVC IN(8),B Puts address of next instruction into GPR 12.
21
Page 29
Legac-e Education Practical example The diagram opposite illustrates how the system calculates storage addresses by using the combination of base register and displacement. The big limitation of course is the maximum displacement of X'FFF', which might imply that a program could not be larger than 4096 bytes in size.
Page 30
Legac-e Education
Program addressability - 2
BASR 12,0 D207CA30C420 MVC PTIME,MTIME
X620
PTIME DC CL8
F1F27AF0F87AF0F0
4040404040404040
22
Page 31
Legac-e Education Multiple base registers To cater for large modules or programs, especially those which cannot be sub-divided into discrete modules, multiple base registers can be used. Opposite is a piece of code demonstrating how multiple base registers can be set up. In this instance 3 base registers are being established which allows the program to be 12K in size, (4096 times 3).
Page 32
Legac-e Education
Page 33
Legac-e Education Instruction Notation The illustration opposite is included as an indication of how other documentation might discuss or present instruction formats. The 'Principles of Operation' manual usually has diagrams of this type as part of the definition of each instruction. This is not however indicative of how instruction would necessarily be coded.
Page 34
Legac-e Education
Instruction notation
MVC d1(L1,b1),d2(b2) OP L b1 d1 b2 d2 (SS)
Page 35
Legac-e Education Potential source formats This illustration offers two examples of how instructions might be coded. At the top of the illustration is the sample machine code for the MVC instruction used in earlier examples. If the two storage areas used by the instruction are outside of the current module, then it might be necessary to code the MVC instruction in the form: MVC 2608(8,12),1056(12)
If however the two storage areas used by the instruction reside within the current module, it is easier to assign labels to those storage areas, and use the labels in the instruction thus: MVC PTIME,MTIME
The later is arguably more readable than the former, and hence more easily understood.
Page 36
Legac-e Education
MVC 2608(8,12),1056(12)
The same instruction, in non-relocatable source form.
MVC PTIME,MTIME
The same instruction, in relocatable source form.
Copyright Legac-e Education, 2004, 2005 25
Page 37
Legac-e Education
Page 38