Assembler Book

454
ASSEMBLY LANGUAGE PROGRAMMING PART - 1 STUDENT NOTE BOOK MAINTEC COMPUTERS PRIVATE LIMITED

description

Assembler reference

Transcript of Assembler Book

Page 1: Assembler Book

ASSEMBLY LANGUAGE

PROGRAMMINGPART - 1

STUDENT NOTE BOOK

MAINTEC COMPUTERS PRIVATE LIMITED

Page 2: Assembler Book

ASSEMBLY LANGUAGE

PROGRAMMINGPART - 2

STUDENT NOTE BOOK

MAINTEC COMPUTERS PRIVATE LIMITED

Page 3: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL.Course Materials may not be reproduced in whole,

or in part without the prior written permission of MCPL

Contents

Course Description…………………………………………………

Agenda ………………………………………………………………..

Units

Unit 1. Computer System Concepts…………………………….1-11.1 Computer System Concepts……………………………………… 1-1

Objectives………………………………………………………. 1-1Computer System Concepts……………………………………. .1-2Assembly Language Programming………………………………1-4Organization………………………………………………………1-5Assembling your Assembler Language Program & Link-Editing. 1-6Language Compatibility…………………………………………..1-7Relati onship of assembler to Operating System………………….1-8Operating System…………………………………………………1-9Relationship of Assembler and Loader………………………… 1-10Typical Output Process……………………………………………1-11Processing Modes…………………………………………………1-12Relationship of Program Components…………………………….1-13BITS and BYTES……………………………………………… 1-15Memory Location and Address………………………………….. 1-16Contents of BYTES.………………………………………………1-17Machine Language Instruction format……………………………1-18Program Location Counter………………………………………..1-19Registers………………………………………………………… .1-20Representation of data in Memory………………………………..1-21Character Codes…………………………………………………..1-22Binary and Hexadecimal Integers…………………………………1-23Number System …………………………………………………..1-24

Page 4: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL.Course Materials may not be reproduced in whole,

or in part without the prior written permission of MCPL

Position Notation Decimal Number System………………………1-25Binary Numbering……………………………………………….. 1-28Decimal Numbering……………………………………………… 1-29Conversion of Decimal to Binary…………………………………1-30Second Method for converting numbers of Binary……………….1-32Number Representation…………………………………………..1-33Binary Integers……………………………………………………1-3432-Bit Signed Binary Integers…………………………………….1-35Signed Binary Integer Arithmetic – Overflow & carries –part 1…1-36Signed Binary Integer Arithmetic – Overflow & carries –part2….1-37Unsigned Binary Integer Arithmetic…………………………… ..1-38Decimal Integers………………………………………………….1-39Floating – Point Numbers…………………………………………1-40Conversion of Positive integer from one base to another base……1-41

Unit 2. Fundamentals of Assembly Language………………….2-12.1 Fundamentals of Assembly Language……………...…………….2-1

Objectives…………………………………………………2-1Statement Format…………………………………………2-2Formats for Instructions and Directive……………………2-4Valid Symbols…………………………………………….2-5Invalid Symbols…………………………………………..2-6Statement Format Variations………………..…………….2-7Source Module Requirement-1……………...…………….2-9Source Module Requirement-2…………..……………….2-10Source Module Requirement-3……………………………2-11Executable vs. Non-Executable Statements……………….2-12Object Module…………………………………………..…2-13Input and Output Operations………………………………2-14OS I/O Macros……….……………………………………2-15Sample Program Using Files………………………………2-16DOS I/O Macros………………………………………… 2-18Sample Program for DOS……………………………….. 2-20ANSI Carriage-Control Characters……………………... 2-21

Page 5: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL.Course Materials may not be reproduced in whole,

or in part without the prior written permission of MCPL

Assembly Listings………………………………………….2-22

Unit 3. Instructions and Address………………………………….3-13.1 Instructions and Address….………….…………………………….3-1

Objectives……....………………………..…………………3-1Addresses……..…………………………………………….3-2Schematic Representation of Memory………..…………….3-3Schematic Diagram of the 16 General Register…..………...3-4Registers……..………………………………………………3-5Base Displacement Address……………………………...…3-6Instructions..………………………………………………....3-7Memory Location Counter (MLC)…………………………..3-8Machine Language Instruction Format……………………...3-9Assembly Language Operand Formats……..……………...3-10Examples for each Formats……..………………………….3-11RS Format…………………………………………………3-12SS1 Format…………………………………………………3-13Implicit Length…………………………………………….3-14The BALR – Using Sequence…………………………..…3-15Mnemonic Opcodes…………………………………… ...3-16

Unit 4. Basic Operations: Looping and Arrays………………….4-14.1 Basic Operations: Looping and Arrays…………………………….4-1

Objectives……………………………………………………4-1Basic Operations, Looping and Arrays…………………..…4-2Types of Constants for DC Directive……………………….4-3The DS Directive……………………………………………4-4Subdivisions…………………………………………………4-5Equivalence Constants (EQU)………………………………4-6Relocatable and Absolute Constants………………………..4-7Control Sections…………………………………………….4-8Source Module………………………………………………4-9Sample Program to Print the sum of two Binary integers….4-10Program to print the sum of two unsigned Decimal Integer.4-12The LA Instructions………………………………………..4-15

Page 6: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL.Course Materials may not be reproduced in whole,

or in part without the prior written permission of MCPL

The BXH and BXLE Instructions………………………….4-16Printing Nonnegative Integers……………………………..4-17Allocating Memory Areas………………………………….4-18Conversion from Binary to Character representation ……..4-19Reading Nonnegative Integer Input Data………………….4-20Allocating memory Areas………………………………….4-21Conversion from Character form to Binary………………..4-22

Unit 5. Integer Arithmetic…………………………………………5-15-1 Integer Arithmetic …………… …………………………………5-1

Two’s Compliment Arithmetic……………………… …..5-2Arithmetic Instruction… ………………………… ……..5-3Subtraction………………………………………… . … 5-4Multiplication ………………………………………...… .5-5Division………………………………………………. ….5-6Branching Instructions………………………………….…..5-7Comparison…………………………………… …….……5-8Complement Instructions …………………… … …….…..5-9Byte Operations……………………………..……….…….5-19Moving Bytes………………………………………………5-21Comparison of Bytes………..…………………………….5-22Shifting Bits………………………………………………..5-26Logical Shifts ……………………………………………...5-28Altering Bits………………………………………………..5-29Boolean Instructions on IBM 360 and 370-Systems ………5-31File Status Informations . ………………………………..5-32Testing Bits ………………………………………………..5-33The BC Instruction …………………….. …………………5-35Changing Sign and Generating Absolute Values ………….5-38

Unit 6. Constants and Data Areas……………..………………….6-16.1 Constants and Data Areas…………………………………………..6-1

Objectives……………………………………………………6-1Constants…………………………………………………….6-2Relocatable and Absolute Constants………………………...6-3

Page 7: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL.Course Materials may not be reproduced in whole,

or in part without the prior written permission of MCPL

Run-Time Constants…………………………………………6-4Types of Constants………………………………………..…6-5Defined Constants (DC)……………………………………..6-6DC Operand Subfield Format………………………………..6-7Value – Based Constants…………………………………….6-8Literals……….………………………………………………6-9Self – Defining Terms……………………………………...6-10Assembly – Time Constants………………………………..6-11Memory Location Symbol (*) ……………………………..6-12Equivalence Constants……..……………………………...6-13Value to Tedious to Compute by hand…………………….6-14Value can Change if Program is changed…………………6-15Value used Symbolically …………………………………..6-16Symbolic Register Addresses & Symbolic Displacements...6-17Symbolic register Addresses……………………………….6-18Invalid use of EQU…………………………………………6-19Relocatable vs. Absolute Constants………………………..6-20Data Areas …………………………………………………6-21Boundary Alignment and Length of an Area………………6-22Boundary alignment ……………………………………….6-23Forced and Natural alignment……………………………...6-24

Unit 7. Byte and String Manipulations7.1 Byte and String Manipulations……………………………………7.1

Character Constants ……………………………………….7-3Copying Bytes ……………………………………………..7-5Copying Bytes to and from Registers …………………….7-6Copying Bytes from one area of Memory to another …….7-8Comparing Bytes ………………………………………….7-9Comparing Bytes when one of the Strings is in a register…7-10Comparing Bytes when both Strings are inMemory locations……………………………..…………… 7-

11

Page 8: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL.Course Materials may not be reproduced in whole,

or in part without the prior written permission of MCPL

Determining the result of a String comparison……………7-12String processing examples …………………………….….7-13Destructive Overlap …………………………………….….7-15Non Destructive Overlap …………………………………..7-17Substring Operations ………………………………………7-22String-Editing Delete Procedure …………………………..7-24The Execute Instruction ……………………………… …7-26CLCL and MVCL Instructions ……………………… ….7-27CLCL Instruction …..……………………………… …..7-28CLCL Loop ………………………………………………..7-30MVCL ……………………………………………………..7-31TR and TRT Instructions ………………………………….7-33General Descriptions ………………………………………7-34

Unit 8. Bit Manipulations………………………………………….8-18.1 Bit manipulations……………………………………………...… . 8-1

Objectives……………………………………………….… 8-1Bit Manipulations……………………………………….… 8-2Shifting Bits…………………………………………….… 8-3Arithmetic Shift Instruction………………………….… …8-4Arithmetic Shifts………………………………………. ….8-5Logical Shifts………………………………………….… ..8-7Altering Bits……………………………………………… .8-9Use of Bits as Indicators………………………………….. 8-10Bit Variations………………………………………………8-11Boolean Operations………………………………………..8-12Boolean OR Operation ……………………………………8-13Boolean AND Operation…………………………………..8-14The Boolean Exclusive – OR Operation…………………..8-15Testing Bits………………………………………………..8-16Test Under Mask…………………………………………..8-17Test and Set………………………………………………..8-18Condition Code…………………………………………….8-19Condition Code Value……………………………………..8-20BC and BCR Mask Field…………………………………..8-21

Page 9: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL.Course Materials may not be reproduced in whole,

or in part without the prior written permission of MCPL

Condition Code settings for Non privileged Instructions….8-22Integer Operations………………………………………….8-23Byte Operations…….…………………………………..…..8-24Bit Operations………………………………………………8-25

Decimal……………………………………………...8-26Floating Point………………………………………..8-27Miscellaneous………………………………………..8-28

Non Privileged Instructions that do not set Condition Code.8-29Bit Manipulation Examples…..…………………………….8-30Status Byte………………………………………………….8-31Definitions for a file – Status Byte…………………………8-32Use of a Status World………………………………………8-33Testing or Resetting Bit N………………………………….8-34Setting or Inverting Bit N…………………………………..8-35Conversion of HEX digits to EBCDIC…………………….8-36Translate from Decimal to Binary………………………….8-37Convert HEX digits to EBCDIC Codes……………………8-38Translating a Non-Negative Integer fromEBCDIC to Binary…………………………………………8-39

Unit 9. Macros………………………………………………………9-19.1 Macros………………………………………………………………9-1

Objectives……………………………………………………9-1Macro Definition…………………………………………….9-2Macro – Prototype Statement………………………………..9-3Macro - Header Statement ………………………………….9-4A Sample Macro……………………………………………..9-5A Macro’s Definition…………….………………………….9-6Example 1……………………………………………………9-7Use of Control directives…………………………………….9-8Return Macro Definitions……………………………………9-9MEXIT Directive…………………………………………..9-10VSAM Processing – Assembler……………………………9-11Creating ACB’s and RPL’s ………………………………..9-12ACB MACRF Parameter…………………………………..9-13RPL OPTCD Parameter …………………………………..9-14

Page 10: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL.Course Materials may not be reproduced in whole,

or in part without the prior written permission of MCPL

Assembler Error Handling…………………………………9-15

Unit 10. Sequential Organization…………………………………10-110.1 Sequential Organization…………………………………………10-1

Objectives………………………………………………….10-1Sequential Organization ….……………………………….10-2The System Input and Output data set…………………….10-3SYSIPT and SYSLST in DOS System……………………10-4Processing fields in a Logical record……………………...10-5Processing variable – Length Records…………………….10-7Move Mode………………………………………………..10-8Locate Mode………………………………………………10-9Printer Output……………………………………………..10-10Title……………………………………………………….10-11Date and Time Macros……………………………………10-12Dormitory Room Master File……………………………..10-13Transaction record Format………………………………..10-14

Page 11: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL.Course Material may not be reproduced in whole

or in part without the prior written permission of MCPL

Unit 11. Indexed Sequential Organization………………… 11-1

Indexed Sequential Organization……………………………….…… 11-1Objectives………………………………………………….. 11-1Indexed Sequential Organization……………………………… 11-2Difference OS and DOS…………………………………… 11-3Queued Indexed Sequential Access Method(QISAM)…….. 11-4QISAM vs. QSAM…………………………………………. 11-5DSORG and MACRF Parameters …………………………. 11-6Basic Indexed Sequential Access Method………………….. 11-7Indexed Sequential Access Method………………………… 11-8Space Allocation……………………………………………. 11-11Space Allocation for ISDS in OS Systems…………………. 11-12Space Allocation in DOS Systems………………………….. 11-15Adding Records to an Indexed Sequential data set…………. 11-16Space Requirements………………………………………… 11-17Creating an Indexed Sequential Data Set…………………… 11-18Principal DCB Parameters………………………………….. 11-19Principal DTFIS Parameters………………………………… 11-20Fixed Length Record Format……………………………….. 11-21Variable – Length Record Format………………………….. 11-22Update in Sequential Mode…………………………………. 11-23Sequential Mode in OS Systems……………………………. 11-24Sequential Mode in DOS Systems………………………….. 11-25OS Random – Mode Processing …………………………… 11-26DOS Random – Mode Processing………………………….. 11-27Updating in Random Mode…………………………………. 11-28

Page 12: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL.Course Material may not be reproduced in whole

or in part without the prior written permission of MCPL

Unit 12. VSAM (Virtual Storage Access Method)…………12-1

VSAM (Virtual Storage Access Method)……………………….. … 12-1Objectives…………………………………………………… 12-1VSAM (Virtual Storage Access Method)…………………… 12-2VSAM Datasets……………………………………………….. 12-3ESDS: Entry Sequenced Data Set…………………………… 12-4RRDS: Relative record Data Set…………………………….. 12-5KSDS: Key Sequenced Data Set…………………………….. 12-6VSAM Building Blocks……………………………………… 12-7RBA’s and Control Interval Formats…………………….…... 12-8AMS Command Summary…………………………………… 12-11Access Method Services………………………………….….. 12-14Data Components, Index Components and Clusters…………… 12-15VSAM Macro Summary………………………………….….. 12-16Relationship of JCL and VSAM Macros…………………….. 12-20ACB Macro Parameter……………………………………….. 12-21RPL Macro Parameters………………………………………. 12-25Keywords for Advanced Applications……………………….. 12-26OPTCD – Options……………………………………………. 12-27Define Commands……………………………………………. 12-29Define Cluster………………………………………………… 12-30Cluster Options……………………………………………….. 12-31Define Cluster Parameters……………………………………. 12-32The REPRO Command………………………………….……. 12-34Loading a VSAM Data Set……………………………………. 12-36JCL Control for Alternate Index………………………………. 12-38

Page 13: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL.Course Material may not be reproduced in whole

or in part without the prior written permission of MCPL

Unit 13. Assembler Concepts……..……………..…………… 13-1

Assembler concepts…..…………………………….……………….. 13-1Objectives…………………………………………………… 13-1Assembler Input and Output…………………………………… 13-2Two – Pass Assembler…….………………………………… 13-3Assembler tables and File usage..…………………………… 13-4Fundamentals of the Assembly Process.……………………. 13-5Assembler Processing Requirements…..……………………. 13-6Opcode table…………………………….…………………… 13-7Directive table……………………………..…………… …… 13-9Symbol table…………………………………………………. 13-10Literal Table………………………………………………….. 13-11Base – register table………………………………………….. 13-12Intermediate File……………………………………..……….. 13-13

Assembler processing Logic – Pass1…………………………. 13-14Assembler processing Logic – Pass 2………………………… 13-15The Object module………………………………………. ….. 13-16Table Searching………………………………………….. ….. 13-17Linear Searching…………………………………………. …. 13-18Binary Search…………………………………………….. …. 13-19Linear vs. Binary Search Time ………………………….. ….. 13-21Sorting Tables……………………………………………. ….. 13-22Straight Insertion sort………………………………………… 13-23Other Sort Techniques………………………………………… 13-24Cross Reference………………………………………….. ….. 13-25Cross – Reference List Structure……………………………… 13-26

Page 14: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL.Course Material may not be reproduced in whole

or in part without the prior written permission of MCPL

Unit 14. Internal subroutines…………………………………….. 14-1

Internal subroutine………………………………………………………. 14-1Objectives………………………………………………………. 14-1Internal Subroutines…………………………………………… 14-2Terminology…………………………………………………… 14-3Linkage………………………………………………………… 14-4Address Constants………………………………………… …. 14-5Parameters and Registers……………………………………… 14-6Examples of internal Subroutine parameters …………………. 14-7Modularization…………………………………………….. …. 14-8Multiple Base Registers……………………………………….. 14-9

Unit 15. External Subroutines…………………………………… 15-1

External Subroutines……………………………………………………. 15-1Objectives………………………………………………….…… 15-1Terminology and Linkage Requirements…………………. ….. 15-2Addressing and Address Constants……………………….. ….. 15-3Linkage Conventions …………………………………………. 15-5Passing Parameter Address through register .. ……………. …. 15-6Passing Values of parameters …………………………….. ….. 15-7Restoring Registers When Returning from a Subroutine…. …... 15-8Comments on the Linkage Conversion……………………. ….. 15-9ENTRY, EXTRN, COM, and DSECT Directives…………. … 15-10Common Addresses: COM……………………………………. 15-11

Page 15: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL.Course Material may not be reproduced in whole

or in part without the prior written permission of MCPL

Unit 16. Noninteger Arithmetic Introductory Concepts………..16-1

Introductory Concepts……………………………………………..……. 16-1Objectives………………………………………………………. 16-1A Question of Accuracy……………………………………….. 16-2Conversion from one base to another………………………….. 16-3Representation of mixed Numbers…………………………….. 16-4Floating – Point Representation……………………………….. 16-5Overflow, Underflow and Significance Errors………………… 16-6

Unit 17. Packed – Decimal Operations……………………………17-1

Packed – decimal Operations…………………………………..… 17-1Objectives ……………………………………………………… 17-1Packed decimal operations………………………………………17-2Data Formats………………………………………………….. 17-3Instruction Formats……………………………………… ……. 17-4Arithmetic Operations…………………………………………. 17-5Zero and Add Packed …………………………………………. 17-6Add Packed (AP) ……………………………………………… 17-7Subtract Packed (SP) ……………………………………………17-8Multiply Packed(MP).…………………………………………. 17-9Divide Packed (DP) …………………………………………… 17-10Comparisons ……..…………………………………………….. 17-11

Page 16: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL.Course Material may not be reproduced in whole

or in part without the prior written permission of MCPL

Unit 18. Floating - Point Operations……………………………..18-1

Floating – Point Operations……………………………………….. 18-1Objectives………………………………………………………. 18-1Floating- Point Operation……………………………………… 18-2Assembly Language Representation…………………………… 18-3Floating – Point Instructions…………………………………… 18-4Load and Store Operations……………………………………. 18-5Arithmetic Operations…………………………………….. ….. 18-6Error Condition……………………………………………….. 18-7Conversion to and form Floating – Point format……………… 18-8Comparing and testing of Floating – Point……………….. ….. 18-9

Unit 19. Cosmetic Directives………………………………………19-1

Cosmetic Directives……………………………………………………….. 19-1Objectives………………………………………………….. …. 19-1Definition Of Directives 19-2EJECT, Title and Space…………………………………….. … 19-3PRINT………………………………………………………. … 19-4OPSYN, ISEQ………………………………………………….. 19-5ICTL……………………………………………………………. 19-6

Page 17: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL.Course Material may not be reproduced in whole

or in part without the prior written permission of MCPL

Unit 20. Pseudo – OPS

Pseudo – OPS……………………………………………………………………...20-1Objectives……………………………………………………… 20-1Control Sections………………………………………………. 20-2CSECT…………………………………………………………. 20-3START…………………………………………………….. ….. 20-4ORG……………………………………………………….. ….. 20-5LTORG……………………………………………………. … 20-6END……………………………………………………….. …. 20-7DSECT ……………………………………………………. …. 20-8COM……………………………………………………………. 20-9

Unit 21. Conditional Assemblies……………………………….….21-1

Conditional assemblies…………………………………………….…… 21-1Objectives……………………………………… …………… 21-1Conditional assemblies………………………… …………… 21-2Sequence Symbols…………………………………………… 21-3Assembly Variables and their Scope…………………………. 21-4Global and Local Scope of Assembly Variables……………… 21-5Conditional Assemblies: AIF,AGO,ANOP…………………… 21-6System Variable Symbols…………………………………….. 21-7Arithmetic Boolean and Character Expressions………………. 21-8Additional Capabilities………………………………………… 21-9

Page 18: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL.Course Material may not be reproduced in whole

or in part without the prior written permission of MCPL

Unit 22. I/O Hardware Concepts………………………………….22-1

I/O Hardware Concepts…………………………………………………. 22-1Objectives……………………………………………………… 22-1Magnetic Tape Concept……………………………………….. 22-2Effect of block size on tape transfer time……………………… 22-4Magnetic Disks………………………………………………… 22-5Count data Format : track utilization forIBM 3330 disk System…………………………………………. 22-6Effect Block size and gap size on attainabletrack capacity in IBM 3330……………………………………. 22-7Data transfer overhead for IBM 3330 Disk System…………… 22-8Data Record ……………………………………………………. 22-9

Page 19: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 1.Computer System Concepts 1-1

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL.

UNIT 1. COMPUTER SYSTEM CONCEPTS

OBJECTIVES :

Assembly language programming.

Operating syst ems.

Hardware.

Representation of data in memory.

Binary and hexadecimal int egers.

Page 20: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 1.Computer System Concepts 1-2

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL.

COMPUTER SYSTEM CONCEPTS

Hardware

Software

Program

Machine language

Programming language

Source module

Instructions

Figure 1-1. Computer system concepts

NOTES:

Hardware refers to a computer system’s electronic, electromagnetic, andelectromechanical components: in short, it’s physical equipment.

Software consists of the computer programs, procedures, rules, and documentation usedin the operation of a computer system.

Page 21: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 1.Computer System Concepts 1-3

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL.

Program or computer program means a sequence of actions and conditions written insuch a wayThat they may either be processed directly by hardware or be translated into a form thatmay be processed directly by the hardware.

A program that can be processed directly by the hardware is known as a machinelanguage program.

A program that can be translated into machine language is said to be written in acomputer programming language.

An assembly language program consists of the statement that processed by a programknown as assembler. The statements are collectively called the source code, or sourcemodule.

A significant position of an assembly language program consists of statements thatrepresent the detailed operations- known as instructions- that the hardware is capable ofexecuting.

An instruction is a symbolic representation of a single machine language operation thatwill be executed by the hardware at run time. A directive is a request to assembler toperform a function other than translating instructions into machine language.

Page 22: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 1.Computer System Concepts 1-4

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL.

ASSEMBLY LANGUAGE PROGRAMMING

Object module

Assembly time

Load time

Run time

Figure 1-2. Assembly language programming.

NOTES:

The object module contains the numeric instructions and data formats that constitute themachine language representation of the source module statements.

When the assembler is processing a programmers source module, it is the assemblerprogram that is being executed by the hardware, not the programmer’s. The period oftime during which this happens is known as assembly time.

When a object module is being processed by the loader, it is the loader program that isbeing executed, not the programmer’s. This is known as load time.

The period of time during which the programmer’s program is being executed by theprogram is known as run time.

Page 23: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 1.Computer System Concepts 1-5

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL.

ORGANIZATION

Serial channel paths Parallel channel paths

Fig 1- 3: Logical structure of an ESA/390 system with two CPUs.

NOTES:Logically a system consists of a main storage, one or more central processing units(CPUs), a channel subsystem and I/O devices. I/O devices are attached to the channelsubsystem through control units. ETR is an external time reference. The maximumnumber of sub-channels is 65536.

ETR

CPU

MAINSTORAGEEXPANDE

DSTORAGE

CPU

CHANNEL SUBSYSTEM

DYNAMICSWITCH

DYNAMICSWITCH

CU CUCU CU CU CU

Page 24: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 1.Computer System Concepts 1-6

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL.

Assembling your Assembler Language Program and Link-editing

Figure 1-4 Assembler language program and link-editing

NOTES:

Your program becomes the source module that is input to the assembler. The assembleroutput is the object module. The Linkage editor processes the object module to give theload Module which is loaded into main storage.

SOURCEMODULE

HIGH LEVELASSEMBLER

MESSAGES &LISTINGS

OBJECTMODULE

LINKAGEEDITOR

LOADMODULE

Page 25: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 1.Computer System Concepts 1-7

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL.

LANGAUGE COMPATIBILITY

Figure 1-5 language compatibility

NOTES:

Migration from Assembler H V2 or DOS/VSE Assembler to High Level Assemblerwill require an analysis of existing assembler language programs to ensure that they donot contain Macro instructions with names that conflict with High Level Assemblersymbolic operation codes, SET symbols and variable symbols that conflict High LevelAssembler system variable symbols.

HLA supports assembly of programs using Extended Architecture Instructions and ESAinstructions.

A generated object program using 370-XA/ESA/370 instructions can only be run on a370-XA/ESA/370 mode processor.

ASSEMBLER HVERSION 2

HIGH LEVELASSEMBLER

DOS/VSEASSEMBLER

MACRO SETSYMBOLSVariableSYMBOLSX

Page 26: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 1.Computer System Concepts 1-8

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL.

RELATIONSHIP OF ASSEMBLER TO OPERATING SYSTEM.

Figure: 1-6 Relationship of assembler to operating system

NOTES:

The operating systems provide the Assembler with services for assembling a sourcemodule and running the assembled object module as a program.

MVS/ESA MVS/XA

VSE/ESA

HIGH LEVELASSEMBLER

MVS/ESA VM/XA

Page 27: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 1.Computer System Concepts 1-9

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL.

OPERATING SYSTEM

OS Vs DOS

In many IBM 360 and 370 computers, the operating systemis known as OS; in others it is DOS.

Figure : 1-7 Operating system

NOTES:

In IBM 360 and 370, the master control program is known as the operating system.

OS is essentially more complex and more versatile than dos.

Page 28: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 1.Computer System Concepts 1-10

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL.

Relationship of assembler and loader.

Figure 1-8. Relationship of loader and assembler

NOTES :

Source module is input data processed by the assembler.

The loader processes the object module one step further in order to prepare it forexecution by the hardware.

AssemblerProgramexecuting

LoaderProgramexecuting

User’sProgram

executingSource

Module

Objectmodule

listing

Assemblytime

Loadtime

Runtime

Page 29: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 1.Computer System Concepts 1-11

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL.

TYPICAL OUTPUT PROCESS

User program executing MAIN MEMORY

22SECONDARY MEMORY

DescriptionOf data

Operating system1. process that occur when a file is opened2. processes that occur when a write operation is performed

Figure 1-9. Typical output processes.

NOTES :

Two mechanisms for communicating with operating system: (I) by means of job controllanguage (jcl) statements and (2) by means of instructions.

The principal functions of jcl statements are to identify the user and the user’s accountingparameters, to initiate and terminate jobs, to describe files and request certain activitiesrelated to files.

Job is a unit of work such as assembling , loading, and running a program that is to beperformed by the computer system.

File is a set of related data that is treated as a unit and is identified by name.

The process of reading data is known as input , that of writing data as output.

DCB for output

Data area for output

System data area

System control area

Output data

Jcl statements

111

2

Page 30: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 1.Computer System Concepts 1-12

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL.

PROCESSING MODES

PROBLEM MODE

SUPERVISOR MODE

Figure 1-10 Processing mode.

NOTES :

When a user’s program is being run, the hardware, or more precisely , the centralprocessing unit is in what is known as problem mode; this means that only thoseinstructions that can not be used to affect the system integrity are allowed to be executed

When the operating system is being run, the central processing unit is said to be insupervisor mode, in which all the instructions of the computer can be executed.

Since input and output instructions are among those that can be used to affect systemintegrity , they can be executed in supervisor mode and are therefore known as privilegedinstructions.

Page 31: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 1.Computer System Concepts 1-13

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL.

RELATIONSHIP OF PROGRAM COMPONENTS

Figure 1-11. Relationship of program component.

NOTES :

Main memory contains the operating system and any other program that is beingexecuted by the hardware. It contains data and control information required by theoperating system and the programs that are being executed.

The central processing unit (CPU) contains electronics required to interpret and executemachine language instructions, to control the transfer of data and programs into and outof main memory, and to detect the various errors as they arise.

Central processing unit(CPU)

Main memory

I/oDevices

I/oProcessor

I/oProcessor

SecondaryMemory

Page 32: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 1.Computer System Concepts 1-14

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL.

The i/o (input/output) processors, called data channels in IBM systems , contain theelectronics required to transmit data between main memory and input /output devices ,and between main memory and secondary memory.

Secondary, or auxiliary, memory serves as storage space for data and for programs whenthey are not been executed. Secondary memory commonly consists of magnetic tapes,disks, and drums.

Input devices generate signals required for the transmission of the data into main memoryfrom sources external the computer system.

Output devices receive signals transmitted from main memory for use outside thecomputer system.

Page 33: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 1.Computer System Concepts 1-15

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL.

BITS AND BYTES

Bit number 0 1 2 3 4 5 ……… k-2 k-1

K bits

In a unit of information consisting of k consecutive bits , the bits are usually numberedfrom 0 to k-1, starting at high order bit position.

Figure 1-12. Bits and bytes.

NOTES :

The fundamental unit of information in main memory is the binary digit ,or bit , whichmay be either a 0 or a 1. All data and programs are represented as sequences of bits.

The term byte is used to denote a small number of consecutive bits.

The term word is generally used to denote a some what a larger number of consecutivebits.

Page 34: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 1.Computer System Concepts 1-16

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL.

MEMORY LOCATION AND ADDRESS

Byte address 0 1 2 3 4 5 ……… N-2 N-1

N bytes

In a one megabyte memory there are approximately one million byte locations – N = 220

= 1,048,576.

Figure 1-13. Memory location and address.

NOTES :

A byte consists of 8 bits. A word consists of 32 bits.

A half word consists of 16 bits (2 bytes) , and a double word consists of 64 bits (8 bytes) .

Each byte in a main memory is said to occupy a location, or physical position, inmemory, and each location is identified by a numeric name called its address.

Page 35: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 1.Computer System Concepts 1-17

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL.

MACHINE LANGUAGE INSTRUCTION FORMAT

Format of machine language instruction is

Opcode operand

Opcode field identifies the particular instruction to be executed by the CPU, e.g.ADD, SUBTRACT. Operand field identifies either the address of the data to be operated on by theinstruction or the data itself.

Figure: 1-14. Machine language instruction format.

NOTES :

The CPU executes instructions that it obtains from main memory and, in doing so ,frequently processes data that is also obtains from main memory. The instructions anddata are represented in machine language.

Machine language is numeric language.

In many instructions, two items of data is represented in operand field, and someinstructions three are represented. These are known as two operand or three operandinstructions respectively.

Page 36: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 1.Computer System Concepts 1-18

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL.

PROGRAM LOCATION COUNTER

CPU’s execute only one instruction at a time. At any instant, the address of thenext instruction to be executed is contained in a program element known asprogram location counter (PC) .

The PC is part of the program status word (PSW) , which records variousinformation about the instantaneous state of running program .

Figure 1-15. Program location counter.

NOTES :

The address in the PC is initially set by the operating system to refer to the firstinstruction in a program, but once program execution is under way, the CPU controls theaddress in the PC.

When an instruction is obtained from memory, the CPU anticipates that the nextinstruction will be obtained from the next sequential location in memory.

Page 37: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 1.Computer System Concepts 1-19

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL.

REGISTERS

Registers are special memory elements designed to provide faster access to datathan is possible through main memory.

Registers contribute substantially to the speed with which a program can beexecuted.

Figure 1-16 Registers

NOTES :

In addition to fetching instructions and data directly from main memory, the CPU andmain memory often are interfaced to one- another through registers.

Registers are specifically designed to be used by the CPU for various arithmetic andlogical operations.

Registers are more expensive than the main memory elements, there are far fewerregisters than main memory locations in a computer system.

Page 38: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 1.Computer System Concepts 1-20

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL.

REPRESENTATION OF DATA IN MEMORY

Data are represented as one or more sequences of bits. The bit sequences that are usedgenerally depend on how the data to be processed by the CPU.

Fig 1-17. Representation of data in memory.

NOTES :

A different representation is used for numbers that participate in arithmetic processesthan is used for numbers that participate in non-arithmetic processes. An example of anumber used in an arithmetic process is the mathematical constant pi = 3.14159…… Anexample of a number used in non-arithmetic process is a telephone number, such as 555-1346.

All data that are transmitted between computer’s main memory and external input oroutput devices are almost invariably transmitted in a form known as character data.

Page 39: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 1.Computer System Concepts 1-21

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL.

CHARACTER CODES

ASCII – American National Standard Code for InformationInterchange

EBCDIC – Extended Binary-coded Decimal InterchangeCode

Figure 1-18. Character codes.

NOTES :

ASCII is a 7-bit code, giving 128 possible character representation.

EBCDIC is used in IBM devices and computer systems, as well as the computer systems.

Page 40: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 1.Computer System Concepts 1-22

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL.

BINARY AND HEXADECIMAL INTEGERS

In the binary number system, only two digits are used in the representation ofnumbers: 0 and 1.

In the hexadecimal system, there are sixteen digits, represented by the symbols0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F. the first ten symbols have their usual meaning;the remaining six represent the values ten through fifteen when used ashexadecimal digits.

Figure 1-19. Binary and hexadecimal integers.

NOTES :

Calculations involving address are of critical importance in assembly languageprogramming, and almost such calculations are based on binary systems.

The range of integers that can be represented in computer systems is not infinite andattempts to generate an integer whose value is outside the allowable range usuallyproduce erroneousResults.

Page 41: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 1.Computer System Concepts 1-23

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL.

NUMBER SYSTEM

Programming in assembler language requires a working knowledge of threedifferent number systems:

BINARY HEXADECIMAL DECIMAL

Not only will you be expected to count in all three number systems, but also toperform arithmetic in any of them, and to convert numbers represented in one form toanother. In addition, because negative signed binary integers are represented internally intwo's complement notation; you must be able to make the necessary transformationswhen examining the contents of binary fields.

Figure: 1-20 Numbering system

NOTES:

Page 42: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 1.Computer System Concepts 1-24

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL.

POSITION NOTATION DECIMAL NUMBER SYSTEM

Figure 1-21 Numbering system

NOTES:The decimal number system will be discussed first because it is more familiar.

The decimal number system, which takes its name from the Greek dekas (group of 10),has 10 digits - 10 unique symbols or characters that can be used when representing anumber. The digits are 0,1,2,3,4,5,6,7,8, and 9. Every number in the decimal system iscomprised of one or more of these digits. The value that each digit contributes to thenumber depends on its position in that number. In this positional notation a particulardigit has a value equal to that digit multiplied by the base of that number system raised toa power that reflects its relative position in the number. (Power of a number are the resultof multiplying the base of the number system times itself that number of times)

The 0,1, and 2 in the previous example are called exponents. An exponent of 1always results in the number itself.

Page 43: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 1.Computer System Concepts 1-25

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL.

POSITION NOTATION DECIMAL NUMBER SYSTEM (CONT..)

Remember that a number having an exponent of 0 always results in a value of 1:

Figure: 1-22 Numbering system

NOTES:

Another term to learn at this point is what's called the expanded form in which anumber is shown as the sum of the values contributed by each of its digits. The decimalnumber 743 in its expanded form would be :

One last process to consider while was we are still working in the familiardecimal number system is the simple process of counting. In counting we advancethrough the range of symbols or digits in the system until the range is exhausted. We thencarry 1 to the next, more significant, position and start through the range again. In the

Page 44: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 1.Computer System Concepts 1-26

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL.

decimal system, we count from 0-9; once 9 is reached, we carry 1 to the tens positionsand begin over with 0 in the units position. This process is the same regardless of thenumber system in which we are counting.

POSITION NOTATION DECIMAL NUMBER SYSTEM (CONT..)

Figure: 1-23 Numbering system

NOTES:

Because of its importance in modern computer systems, a programmer shouldacquire a working knowledge and understanding of the binary number system. As in thedecimal system, the value of a particular digit in a binary number is a reflection theposition of that digit in the number. Binary means base 2.

Page 45: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 1.Computer System Concepts 1-27

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL.

BINARY NUMBERING

The binary number 101101 in expanded form is:

Figure 1-24 Binary number

NOTES:

Thus the number 101101 in the binary number system is equivalent to (representsthe same value as) the decimal number 45. Whatever we have done is to use theexpanded form of binary to convert the binary number to its decimal equivalent. In fact,the digit equivalent of a number to its decimal equivalent. In fact, the decimal equivalentof a number in any base can be obtained by multiplying each digit by its positional valueand summing the results. Try converting the following to their decimal representation.

Page 46: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 1.Computer System Concepts 1-28

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL.

DECIMAL NUMBERING

Subscripts indicate the base of a number, with no subscript indicating a decimalnumber.

Respectively, your answers should be:

Figure: 1-25 Decimal numbering

NOTES:

Page 47: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 1.Computer System Concepts 1-29

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL.

CONVERSION OF DECIMAL TO BINARY

Figure 1-26 Conversion of decimal numbers to binary

NOTES:

There are two ways to convert a decimal number to a binary number. The firstway is the multiple-division method. The number to be converted is divided repeatedlyby the value of the base of the number system to which the conversion is being made.The division operation is repeated on the quotient until the quotient finally reaches 0. Theremainder from the first division operation is used as the digit in the rightmost (least-significant) position in the resultant binary number; the remainder from the second

Page 48: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 1.Computer System Concepts 1-30

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL.

division operation becomes the next digit, and so on, until the evaluation is complete. Forexample, converting the decimal number 45 to binary takes the following series ofdivision operations:

CONVERSION OF DECIMAL TO BINARY (CONT..)

Thus 45 and 1011012 are equivalent. Convert the following decimal values to binary:

see if you get:

Figure 1-27 Conversion of decimal to binary

NOTES:

Page 49: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 1.Computer System Concepts 1-31

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL.

SECOND METHOD FOR CONVERTING DECIMAL NUMBERS TO BINARY

A second method for converting decimal numbers to binary utilizes a table of the powersof 2.

Figure 1-28 Second method of conversition

NOTES:

Page 50: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 1.Computer System Concepts 1-32

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL.

NUMBER REPRESENTATION

Binary integers

Signed binary integers

Unsigned binary integers

Decimal integers

Floating point numbers

Conversion examples

Figure:1-29 Number representation

NOTES:

Page 51: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 1.Computer System Concepts 1-33

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL.

BINARY INTEGERS

+ 26 0000 0000 0001 1010

Invert 1111 1111 1110 0101

Add 1 0001

- 26 1111 1111 1110 0110

Figure 1-30 Binary system

NOTES :Positive binary integers have a zero in sign bit position.Negative binary integers have a one in sign bit program and are denoted in two’scompliment form.

Page 52: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 1.Computer System Concepts 1-34

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL.

32-Bit Signed Binary Integers

2147483647 = 0111 1111 1111 1111 1111 1111 1111 1111

65536 = 0000 0000 0000 0001 0000 0000 0000 0000

1 = 0000 0000 0000 0000 0000 0000 0000 0001

0 = 0000 0000 0000 0000 0000 0000 0000 0000

-1 = 1111 1111 1111 1111 1111 1111 1111 1111

-65536 = 1111 1111 1111 1111 0000 0000 0000 0000

-2147483647 = 1000 0000 0000 0000 0000 0000 0000 0001

-2147483648 = 1000 0000 0000 0000 0000 0000 0000 0000

Figure 1-31. 32-bit signed binary integers

NOTES :The signed binary integer is a weighted code, negative numbers are represented in two’scomplimented form.

Page 53: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 1.Computer System Concepts 1-35

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL.

Signed Binary Integer Arithmetic – Overflow and carries – part 1

Ex 1: +57 = 0011 1001 Ex 2: +57 = 0011 1001+35 = 0010 0011 -35 = 1101 1101----- ------ ------- ---- ------ -----

92 = 0101 1100 +22 = 0001 0110----- ------ ------ ---- ------ ------

No overflow

Ex : 3 + 35 = 0010 0011 Ex :4 + 57 = 0011 1001-57 = 1100 0111 + 92 = 0101 1100

----- ------- ------- ----- ------ -------22 = 1110 1010 +149 = *1001 0101----- ------- ------- ------ ------ -------

Ex : 5 Ex : 6

-57 = 1100 0111 -57 = 1100 1011-35 = 1101 1101 -92 = 1010 0100----- ------ ------ ----- ------ -------92 = 1010 0100 -149 = * 0110 1011----- ------ ------ ----- ------ ------

Figure 1-32. Signed Binary Integer Arithmetic – Overflow and carries

NOTES :

Page 54: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 1.Computer System Concepts 1-36

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL.

Signed Binary Integer Arithmetic – Overflow and carries – part 2

Ex Overflow Carry into leftmost position Carry out

1 & 3 No No No

2 &5 No Yes Yes

4 Yes Yes No

6 Yes No Yes

Figure 1-33 Signed Binary Integer Arithmetic – Overflow and carries

NOTES :

Page 55: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 1.Computer System Concepts 1-37

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL.

Unsigned Binary Integer Arithmetic

Ex 1: 57 = 0011 100135 = 0010 0011

---- ------ ------92 = 0101 1100

- --- ------ -------

Ex 2: 57 = 0011 1001221 = 1101 1101

----- ------ ------278 = *0001 0110

- --- ------ -------

Figure 1-34 Unsigned Binary Integer Arithmetic.

NOTES :A carry out of the left most bit position may or may not imply an overflow, depending onthe application.

Page 56: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 1.Computer System Concepts 1-38

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL.

Decimal Integers

Packed format

Zoned format

Decimal Value Packed form Zoned Form+ 123 12 3C F1 F2 C3

or or123 F F1 F2 F3

-4321 04 32 1D F4 F3 F2 D1-7 7 D D7

Figure 1-35 Decimal Integers

NOTES :

The decimal digits are in BCD with the values 0-9 encoded as 0000-1001. The sign isrepresented as 1100 (C Hex) for plus and 1101 (D Hex) for minus.

Page 57: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 1.Computer System Concepts 1-39

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL.

Floating – Point Numbers

Short floating –point NumberS Characteristic 6- Digit Fraction0 1 8 31

Long floating –point Number

S Characteristic 14-digit Fraction0 1 8 63

Extended Floating-Point Number

High-order PartS High-order

characteristicLeftmost 14 digits of28-digit Fraction

0 1 8 63Lower-order Part

S Low-order characteristic Rightmost 14 digits of28-digit Fraction

64 72 127

Figure:1-36 Floating point number

N0TES:

Page 58: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 1.Computer System Concepts 1-40

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL.

A floating-point number has two signs: One for the fraction and one for the exponent.The fraction sign, which is also the sign of the entire number, is the leftmost bit of eachformat (0 for plus, 1 for minus). The exponent sign is obtained by expressing theexponent in excess-64 notation that is, the exponent is added as a signed number to 64.The resulting number is called the characteristic.

CONVERSION OF POSITIVE INTEGERS FROM ONE BASE TO ANOTHER BASE

The method of converting a positive integer from its representation in one base to itsrepresentation in another depends on each number system the competitions are performedin .

Conversion from base 10 to base 218 = 10010

Conversion from base 16 to base 1012 = 18

Conversion from base 10 to base 1618 = 12

Figure 1-37 Conversion of positive integers from one base to another base

NOTES :

Page 59: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 1.Computer System Concepts 1-41

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL.

Page 60: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit2.Fundamentals of Assembly Language Page 2 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

1

UNIT 2: FUNDAMENTALS OF ASSEMBLY LANGUAGE

OBJECTIVES:

STATEMENT FORMATS

STATEMENT FORMAT VARIATIONS

SOURCE MODULE REQUIREMENTS

INPUT AND OUTPUT OPERATIONS

ASSEMBLY LISTINGS

Page 61: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit2.Fundamentals of Assembly Language Page 2 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

2

STATEMENT FORMAT

General format for all statement

The format used for comment statements

The format used for instructions and directives.

Figure 2-1. Statement formats

NOTES :

The general format is designed to accommodate the constraints imposed by an 80 columninput line.

Page 62: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit2.Fundamentals of Assembly Language Page 2 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

3

STATEMENT FORMATS

Comment statement format1 71 72 73 80

Comment filed Identification

Comment ContinuationIndicator

Format for instructions and directives.1 9 15 39 72 80name opcode operand comment identification

Continuation

Figure 2-2 Statement format

NOTES:

The first column of a comment statement begins with an asterisk (*); continuationcolumn 72 contains any nonblank character for continuation onto next line. Eachcontinuation line begins in position 16.

Name field. When the first character in main field is not blank, the name field mustconsist of from one to eight characters followed by a blank.

Opcode field. The opcode field must contain availed assembly language code of fromone to five alphabetic characters that identifies one of the instructions of directives thatexist in the language.

Operand field. The format of the operand field depends on whether the opcode fielddesignates an instruction or a directive, and it also depends on which instructions ordirective is specified.

Page 63: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit2.Fundamentals of Assembly Language Page 2 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

4

FORMAT FOR INSTRUCTIONS AND DIRECTIVE

Format for instructions and directives

1 9 15 39 72 80name opcode operand comment identification

Continuation

Figure 2-3. Formats for instructions and directives

NOTES:

Continuation field. The statement may be extended over two or more lines by means ofthe continuation field. If the continuation field contains any none blank character, thenfollowing line will be assumed to be a continuation of the line whose continuation field isnon blank.

Each continuation line must be in position sixteen called the continuing position.

Identification field. Its purpose is twofold: (1.) to identify the source module in whichthe statement appears and (2) to record the sequential position of the statement within thesource module.

Page 64: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit2.Fundamentals of Assembly Language Page 2 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

5

VALID SYMBOLS

Example of valid symbols

QA101LOOPFOUNDREP 12# 1CONTINUE@ HERE$###2

Figure 2-4. Valid symbols

NOTES :

Page 65: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit2.Fundamentals of Assembly Language Page 2 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

6

INVALID SYMBOLS

Example of invalid symbols:

3 first character not a letter101AF(1)LOOP 1 parentheses not among the allowable charactersLOOP.1 blankLOOP-1 periodENCOUNTER to many characters : maxmum 8

Figure 2-5. Invalid symbols.

NOTES :

Page 66: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit2.Fundamentals of Assembly Language Page 2 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

7

STATEMENT FORMAT VARIATRIONS

Standard fixed format

Free format

Figure 2-6. Statement format variations

NOTES:

The field positions for the statement format are said to be in the standard fixed format ofthe IBM 360 and 370 assembly language.

Other characteristics of standard fixed format include the following:

Page 67: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit2.Fundamentals of Assembly Language Page 2 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

8

Any field that is omitted must be blank.

All none blank fields must be left justified within the field boundaries and be fieldwith trailing blanks.

Positions 9,15 and 39 must be blank.

Information of the operand or / and comment fields of one line of a statement maybe continued on the following line, provided that the continuation field contains anonblank character.

Free format permits longer operands than can fit in the fixed position 16 through 38;alternately, it permits comments to be started before position 14. It permits one to indentthe opcode and operand fields.

In both standards fixed format or standard free format, the positions of the continuationand identification fields remain fixed in positions 72 and 73-80,respectively; and thebeginning, ending, and continuing positions remain fixed in positions 1,71,and 16,respectively.

Page 68: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit2.Fundamentals of Assembly Language Page 2 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

9

SOURCE MODULE REQUIREMENT - 1

Except for comment statements, which may be placed anywhere in a source module, thefirst statement of the source module should be these:

Name field opcode operand

Modname CSECTSTM 14, 12, 12 (13)BALR 12, 0

This symbol USING *, 12Used as name ST 13, SAVE +4Of the source LA 13, SAVEmodule

Figure : 2-7 Source module requirements

NOTES:

Page 69: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit2.Fundamentals of Assembly Language Page 2 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

10

SOURCE MODULE REQUIREMENT - 2

The last executable statement of source module should be

NAME FIELD OPCODE OPERAND

Exit name L 13, SAVE+4LM 14, 12, 12 (13)BR 14

Any valid symbol

Figure 2-8. Source module requirements

NOTES :

Page 70: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit2.Fundamentals of Assembly Language Page 2 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

11

SOURCE MODULE REQUIREMENT- 3

The last executable statement of source module should be

NAME FIELD OPCODE OPERAND

Save DS 18FEND

This symbol must be SAVE

Figure 2-9 Source module requirements

NOTES:

Page 71: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit2.Fundamentals of Assembly Language Page 2 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

12

EXECUTABLE VS. NON-EXECUTABLE STATEMENTS

Instructions are known as executable statements. Some directives are also executablestatements.

Other directives are called non-executable statements.

Figure 2-10. Executable vs. non-executable statements

NOTES:

Instructions are translated into machine language by the assembler and executed at runtime by the hardware.

Page 72: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit2.Fundamentals of Assembly Language Page 2 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

13

OBJECT MODULE

If the object module size is greater than 4096 bytes it may not run properly.

Figure 2-11. Object module size

NOTES:

All executable statements and those non-executable statement that defined constants anddata areas, are assembled into object module that can be loaded into main memory andexecuted at run time.

Page 73: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit2.Fundamentals of Assembly Language Page 2 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

14

INPUT AND OUTPUT OPERATIONS

Macros for input output operations

OPEN

CLOSE

DCB

PUT

DS

DC

Figure 2-12. Input output operations

NOTES:

The OPEN, CLOSE, GET and PUT macros are directives that cause the assembler togenerate the instructions needed to request that the corresponding operations to beperformed by the operating system.

The areas of memory to be used for the input and output data must be reserved by thedefined storage (DS) and define constants (dc) directives.

There must be DCB macro associated with each file that is used in a program, the DCBmacro informs the operating systems how you intend to use the file.

Page 74: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit2.Fundamentals of Assembly Language Page 2 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

15

OS I/O MACROS

Input file

Symbol 1 DCB DSORG =-----, MACRF = (---), XDDNAME = SYSIN, EODAD = Symbol2, XRECFM =-----, LRECL = ---, BLKSIZE = ---

Printer file

Symbol 1 DCB DSORG = ---, MACRF = (---), XDDNAME = SYSPRINT, RECFM=---, XLRECL = ---, BLKSIZE = ------

Figure: 2-13 OS I/O macros

NOTES:

The input file parameters DSORG = PS for a sequential file, MACRF = (GM) for a GETmacro. DDNAME = SYSIN for the standard system input file. The parameter EODADnames the symbol of the statement to which control is to be transferred when the end-of-file condition is reached. The RECFM parameter describes the type of records, which iseither FB or VB. LRECL is for logical record length and BLKSIZE parameter stands forblock size for storing records. The printer file parameter has MACRF = (PM) for putmacro. RECFM = FBA which says that records are of fixed length and ANSI carriagecontrol character will be used for printer line spacing.

Page 75: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit2.Fundamentals of Assembly Language Page 2 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

16

SAMPLE PROGRAM USING FILES

Sample assembly language program for OS.

DEMO CSECTSTM 14, 12, 12(13) STANDARD ENTRY TO PROGRAMBALR 12, 0USING *, 12ST 13, SAVE +4LA 13, SAVEOPEN (INDCB, (INPUT)) OPEN INPUT DATA STREAM FILEOPEN (OUTDCB, (OUTPUT)) OPEN PRINTER OUTPUT FILE

10LOOP MVC INAREA,=80C’ BLANK OUT ‘INAREA'GET INDCB, INAREA READ DATA INTO 'INAREA'MVI OUTCARR, C' ' SET SINGLE-PACE CONTROL CHARMVC OUTLINE (80), INAREA COPY DATA TO OUTPUT LINE AREAPUT OUTDCB,OUTAREA WRITE DATA FROM 'OUTAREA'B IOLOOP CONTINUE UNTIL END-OF-FILE

FINISH CLOSE (INDCB) CLOSE INPUT FILECLOSE (OUTDCB) CLOSE OUTPUT FILE

EXIT L 13, SAVE+4 STANDARD EXIT FROM PROGRAMLM 14, 12, 12(13)BR 14

INDCB DCB DSORG=PS, MACRF=(PM), DDNAME=SYSIN, EODAD=FINISH XRECFM=FB, LRECL=80,BLKSIZE=4080

OUTDCB DCB DSORG=PS, MACRF=(GM), DDNAME=SYSPRINT, XRECFM=FBA, LRECL=133,BLKSIZE=3990

INAREA DS CL80 80 BYTES FOR AN INPUT RECORDOUTAREA DS OCL133 133 BYTES FOR A PRINTER LINE…OUTCARR DC CL1 ' ' 1 BYTE FOR CARRIAGE CONTROL CHAROUTLINE DC CL132 ' ' 132 BYTES FOR DATA TO BE PRINTEDSAVE DS 18F

END

Page 76: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit2.Fundamentals of Assembly Language Page 2 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

17

DOS I/O MACROS

Input fileSymbol 1 DTFCD DEVADDR = _______, IOAREA1=_________, X

WORKA=____, EOFADDR=_____, BLKSIZE= _____

Printer fileSymbol 1 DTFPR DEVADDR=______, IOAREA1=________, X

WORKA=______, CTLCHR=______, XBLKSIZE==______

Figure: 2-14 DOS I/O mode

NOTES:

DTF stands for define the file.

The input file parameter DEADDR is coded as DEVADDR=SYSIPT for reading fromthe standard system input device. The IOAREA1= symbol parameter identifies the areainto which each input record will be read. WORKA=YES indicates that after the inputdata has been read, it will be available to your program in the “work area” whose name isspecified in the GET macro. The EOFADDR = parameter names the symbol of thestatement to which control is to be passed on reaching the end-of-file condition. Forprinter file DEVADDR=SYSLST for writing to the standard listing device.IOAREA1=______ identifies the area from which each output record will be written.WORKA = yes means that the output line will be created in the work area whose name isspecified in the PUT macro. CTICHR=ASA means than an ANSI carriage-controlcharacter will be used for printer line-spacing. The first byte of every record is a ANSIcontrol character and the remaining 132 bytes contain the character to be printed.

Page 77: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit2.Fundamentals of Assembly Language Page 2 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

18

The ANSI Carriage –control character and their functions are

ANSI function

C‘ ’ single spacing

C‘ 0 ’ double spacing

C‘ __’ Triple spacing

C‘ | ’ skip to new page

C‘ + ’ suppress spacing

Page 78: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit2.Fundamentals of Assembly Language Page 2 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

19

SAMPLE PROGRAM FOR DOSDEMO CSECT

BALR 12, 0 STANDARD ENTRY TO PROGRAMUSING *, 12LA 13, SAVEOPEN INDTF OPEN INPUT DATA STREAM FILEOPEN OUTDTF OPEN PRINTER OUTPUT FILE

IOLOOP MVC INAREA, =80C ' ' BLANK OUT 'INAREA'GET INDTF, INAREA READ DATA INTO 'INAREA'MVI OUTCARR, C ' ' SET SINGLE-SPACE CONTROL CHARMVC OUTLINE, INAREA COPY DATA TO OUTPUT LINE AREAPUT OUTDTF, OUTAREA WRITE DATA FROM 'OUTAREA'B IOLOOP CONTINUE UNTIL END-OF-FILE

FINISH CLOSE INDTF CLOSE INPUT FILECLOSE OUTDTF CLOSE OUTPUT FILE

EXIT EOJ STANDARD EXIT FROM PROGRAMINDTF DTFCD DEVADDR=SYSIPT, IOAREA1=INBUF, WORKA=YES, X

EOFADDR=FINISH, BLKSIZE=80OUTDTF DTFPR DEVADDR=SYSLST,IOAREA1=OUTBUF,WORKA=YES, X

CTLCHR=ASA, BLKSIZE=133INAREA DS CL80 80 BYTES FOR INPUT 'WORKA'INBUF DS CL80 80 BYTES FOR INPUT "IOAREA"OUTAREA DS OCL133 133 BYTES FOR PRINTER 'WORKS'OUTCARR DC CL1 ' ' 1 BYTE FOR CARRIAGE CONTROL CHAROUTLINE DC CL132 ' ' 132 BYTES FOR DATA TO BE PRINTEDOUTBUF DS CL133 133 BYTES FOR PRINTER " IOAREA1"SAVE DS 9D

END

Page 79: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit2.Fundamentals of Assembly Language Page 2 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

20

ANSI CARRIAGE-CONTROL CHARACTERS

The ANSI carriage-control characters and their functions are these:

ANSI character function action

C’ ‘ (blank) single spacing: print on the next available line

C’0’ (zero) double spacing: leaves one blank line before printing

C’-‘ (minus) triple spacing: leave two blank lines before printing

C’1’ (one) skip to new page: print on first line of next page

C’+’ (plus) suppress spacing: print without advancing the paper

Figure 2-15 ANSI carriage-control.

NOTES:

These characters are in the standard character set of the computer, but when they are inthe first position of the print line they are not printed; instead they cause the printer toadjust the paper position before printing the line.

Page 80: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit2.Fundamentals of Assembly Language Page 2 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

21

ASSEMBLY LISTINGS

The appearance of the assembly listing can be enhanced by using the followingsimple assembly language directives:

EJECT – starts a new page on the listing

TITLE – puts a title line at the beginning of each page

SPACE – inserts one or more blank lines on a page

PRINT NOGEN, NODATA – limits the amount of detail printed

Figure 2-16 Assembly listing.

NOTES:

The assembler produces a listing of your program that shows the machine languagetogether with your source language statements and indicates what (if any) errors havebeen detected during the assembly process.

The listing also includes an index of the name field symbols defined in the sourcemodule.

The index is known as the cross-reference list (XREF). It is very useful when debuggingand modifying programs. It identifies the statement in which each symbol is defined andthe statement in which each is used.

The cross-reference list also gives the value of each symbol and the length of theinstruction or data field that the symbol is associated with.

Page 81: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit3.Instructions and Address Page 3 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

1

UNIT 3: INSTRUCTIONS AND ADDRESSES

OBJECTIVES :

ADDRESSES

INSTRUCTIONS

MACHINE LANGUAGE FORMATS

ASSEMBLY LANGUAGE FORMATS

THE BALR-USING SEQUENCE

MNEOMONIC OPCODES

Page 82: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit3.Instructions and Address Page 3 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

2

ADDRESSES

First byte of memory last byte of memory

0 1 2 3 4 5 6 7 8 9 A B C

Byte addressFFFFFF

byte address FFFFFE

Figure 3-1 Addresses

NOTES:

Each byte in the memory is referred to by its address.A memory address is an unsigned integer in the range 0 through 2 N-1 where 2n is thetotal number of bytes available in memory, , i.e. , the memory’s capacity.

Memory addresses are written in hexadecimal notation.

Page 83: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit3.Instructions and Address Page 3 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

3

SCHEMATIC REPRESENTATION OF MEMORY

Addresses of 0 1st double wordfull , double & 4Half words 8

C

FFFFFC last byte last full word

Last half word

Figure 3-2. Representation of memory

NOTES:A full word is any four consecutive bytes in which the address of the first byte is anumber exactly divisible by 4.

In a half word, the address of the first byte is exactly divisible by 2.

In a double word, the address of the first byte is exactly divisible by 8.

The first byte of the full word is said to be at the full word boundary.

Half word and double word boundaries are at the beginning byte of each half and doubleword, respectively.

Page 84: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit3.Instructions and Address Page 3 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

4

SCEMATIC DIAGRAM OF THE 16 GENERAL REGISTER

REGISTER ADDRESS

DECIMAL HEXA DECIMAL

0 0 BIT # 31 IS THE1 1 LEAST SIGNIFICANT,or2 2 LOW-ORDER, bIT3 3 IN EACH REGISTER4 45 56 67 78 89 910 A11 B12 C13 D

. 14 E15 F

32-BIT PER REGISTER

Figure 3-3 Schematic diagrams of 16 registers

NOTES:

There are 16 general-purpose registers in the IBM 360 and 370 systems, and each isreferred to by an address that is an unsigned integer in the range from 0 to 15. Eachregister contains 32 bit. The left most bit are the most significant, or high –order, bits of aregister: the right –most bits are the least significant, or low-order, bits. The 32-bitquantity in a register is often called the contents of that register.

Page 85: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit3.Instructions and Address Page 3 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

5

REGISTERS

16 GPRS

Each 32 bit

Numbered as 0 to 15

Base-displacement form of address used for XA / ESA

Figure: 3-4 Registers

NOTES:

Using the base-displacement form of addressing 16 bits are used to represent a 24 bitaddress.

Page 86: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit3.Instructions and Address Page 3 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

6

BASE DISPLACEMENT ADDRESS

B D

B = Base register address (4 bits)D = Displacement (12 bits)

M = Contents of base register + Displacement

M = Base address displacement= Effective address

Figure-3-5 Base displacement register

NOTES:The 16 bits that are used to represent a memory address do not represent a single integer;they represent two integers, each with a different purpose. One of the integers is 4 bitslong and designates the address of a register known as the base register.The other integer is 12 bits long and represents an adjustment factor known as thedisplacement.This 16-bit representation of a memory address is known as the base-displacement formof that address.At run time, base displacement form of an address is translated by the central processingunit (CPU) into a 24-bit memory address.

M is known as the effective address generated from the base-displacement address.

Page 87: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit3.Instructions and Address Page 3 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

7

INSTRUCTIONS

Each machine language instruction consists of a certain number of bytes. The number ofbytes comprising an instruction is known as the instruction’s length. In manycomputers, length of all instructions is same.In some computers the length of an instruction depends on type of instruction it is.We speak of a variable-length instruction set in latter case and fixed-length instructionset in former.The IBM systems 360 and 370 have a variable-length instruction set.The use of a variable-length instruction set, though apparently more complex than use ofa fixed-length set, has one significant advantage,

. The number of bytes required for any instruction is just sufficient to provide only theinformation required in that instruction. This results in an overall saving of memory spacein a program.

In fixed-length sets, the length used for all instructions is the length needed by theinstructions that contain the most information. This can result in unusable memory space.

Figure: 3-6 Instructions

NOTES:

Page 88: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit3.Instructions and Address Page 3 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

8

MEMORY LOCATION COUNTER (MLC)

The assembler maintains a counter, called the memory location counter whose initialvalue is 0.

Memory address assigned address assigned length ofLocation = to an = to preceding + precedingCounter instruction instruction instruction

Address assigned = memory location = address assigned toTo a symbol counter instruction identified

By that symbol

Figure 3-7. Memory location counter

NOTES:

The assembler maintains a list of all symbols defined in an assembly language program,together with the address values it has assigned to them. This list is known as theassemblers symbol table.

Page 89: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit3.Instructions and Address Page 3 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

9

MACHINE LANGUAGE INSTRUCTION FORMAT

Instruction Type Machine Language Instruction Format Instruction lengthNo .of bytes no. of bits

RR 2 16

0 8 12

RX 4 32

0 8 12 16 20

RS 4 32

0 8 12 16 20

SI 4 32

0 8 16 20

S 4 32

0 16 20

SS1 6 48

0 8 16 20 32 36

SS2 6 48

0 8 12 16 20 32 36

Figure: 3-8 Machine language instruction format

NOTES:

The opcode is 1 byte and operand can be 1, 3 or 5 bytes in length. There are sevendifferent instruction formats namely RR, RX, RS, SI, S, SS and SS2. The S format isavailable on IBM 370 machines only.

OPCODE R1 R2

OPCODE R1 X2 B2 D2

OPCODE R1 R2 B3 D3

OPCODE I 2 B1 D1

OPCODE B1 D1

OPCODE L B1 D1 B2D2

OPCODE L1 L2 B1 D1 B2D2

Page 90: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit3.Instructions and Address Page 3 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

10

ASSEMBLY LANGUAGE OPERAND FORMATS

Instruction Type Operand Format

RR Explicit R1, R2RX Explicit R1, D2(X2, B2)

R1, D2 (,B2)R1, D2(X2)R1, D2

Implicit R1, S2 (X2)R1, S2

RS Explicit R1, R2, D3(B3)Implicit R1, R2, S3

SI Explicit D1 (B1), I2Implicit S1, I2

S Explicit D1 (B1)Implicit S1

SS1 Explicit D1(L, B1), D2(B2)Implicit S1, S2Mixed D1( L, B1), S2

S1 (L), D2 (B2)S1 (L), S2S1, D2 (B2)

SS2 Explicit D1 (L1,B1), D2(L2,B2)Implicit S1, S2Mixed D1 (L1, B1), S2(L2)

D1 (L1, B1), S2S1 (L1),S2 (L2)S1 (L1), S2S1, S2 (L2)S1(L1), D2(L2,B2)S1, D2 (L2, B2)

Figure: 3-9 Operand format

NOTES:

1. When the index field X2 is omitted, X2 =0.2. I2 field is one byte long and is used for storing immediate data.3. L, L1, L2 are the length fields and are represented by a number that is one less than

that used in assembly language.

Page 91: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit3.Instructions and Address Page 3 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

11

EXAMPLES FOR EACH FORMAT

Eg 1: RR Format

Machine language Assembly Language

OP R1, R2

AR 5, 6

Eg 2: RX FormatMachine Language Assembly Language

OP R1, D2 (X2, B2)

A 8, 4 (10, 11)

Figure: 3-10 Format examples

NOTES:

X2 is omitted has a value of zero and is denoted as OP R1, D2 (, B2). A comma denotesthe absence of X2.

OP R1 R2

1A 56

OP R1 X2 B2D2

5A 8 A B004

Page 92: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit3.Instructions and Address Page 3 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

12

RS FORMAT

OP R1, R2, D3 (B3)

SRA 7, 4 (10)

Eg 4: SI Format

OP D1 (B1), I 2

CLI 32 (12), X‘ 30 ’

Figure: 3-11 RS format

NOTES:

Considering the RS format R1, R2, D3 (B3), the second operand, R2, is not written inassembly language and not used in machine language. In the above Eg 3 R1 denotesregister to be shifted and D3 (B3) specifies number of positions to be shifted.

OP R1 R2 B3D3

8A 7 0 10004

OP I2 B1 D1

95 30 C020

Page 93: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit3.Instructions and Address Page 3 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

13

SS1 FORMAT

Machine Language Assembly Language

OP D1 (L, B1), D2 (B2)

CLC 64 (5, 12) 200(12)

Eg : 6 SS2 Format

OP D1(L1, B1), D2 (L2,B2)

0 8 12 16 20 32 36

F8 ZAP B(8), A(4)

Figure: 3-12 SS1 format

NOTES:

SS1 type instruction is used to compare bytes at one memory location with those atanother. SS2 type instruction is used to compare L1 number of bytes starting frommemory address designated by B1, D1 with L2 number of bytes starting at B2, D2.

OP L B1 D1 B2D2

D5 04 C 040 C0C8

OP L1 L2 B1 D1 B2D2

F8 8 4 C 040 C0C8

Page 94: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit3.Instructions and Address Page 3 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

14

IMPLICIT LENGTH

A 3, Z

OP R1 X2 B2 D2

Memory address base impliedRepresented by Z = address + displacement

Opcode operandUSING A, R

Implied = memory - base addressDisplacement address of Z

Figure: 3-13 Implicit Length

NOTES:The USING directive is used at assembly time and must occur before any statement inthe source module that contains an operand for which an implied displacement must becalculated. If memory address of Z = 80 A & Base address is 6, then implieddisplacement = 80A – 6 = 804.

5A 3 0 ??

Page 95: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit3.Instructions and Address Page 3 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

15

THE BALR – USING SEQUENCE

BALR R1, R2

BALR 12, 0USING *, 12

Eg: SAMP1 CSECTSTM 14, 12, 12 (13)BALR 12, 0USING *, 12ST 13, SAVE + 4LA 13, SAVE

Implied Displacement = Memory addressrepresented symbolically - Base addressby SAVE + 4

4 FE = (500 + 4) - 006for the instruction ST 13, SAVE + 4

Figure: 3-14 Blar sequence

NOTES:

Page 96: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit3.Instructions and Address Page 3 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

16

MNEMONIC OPCODES

The letters used in the opcodes are designed to help you remember each opcode and itspurpose.

For this reason the opcode are said to be mnemonic, from Greek words meaning mindfuland remember

Figure: 3-15 Mnemonic Opcode.

NOTES:

Page 97: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 4.Basic Operations: Looping and Arrays Page 4 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

1

UNIT 4: BASIC OPERATIONS: LOOPING AND ARRAYS

OBJECTIVES:

Addition of two binary integers

Binary integer constants and memory allocation

Addition of integer arrays

Aspects of loop controls

Page 98: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 4.Basic Operations: Looping and Arrays Page 4 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

2

BASIC OPERATIONS, LOOPING AND ARRAYS

Defining Constants Defining Storage

Define constant (DC) directive

Name field Opcode Operand

Any symbol DC One or moreOr blank sub-fields, separated

by comma

DC operand sub-field components

Optional

Required

Figure: 4 – 1 Basic operations

NOTES:

The DC directive is used to denote constants in various forms. The duplicator denotesthe number of consecutive representations of the constant. The modifier can be a lengthscale or exponent modifier.

DC FL1‘ 50’

This generates a 1-byte binary integer representation of 50.

Eg: DC FS10‘ 8’

This generates a full word binary integer representation of 3 x 2 10 = 3072

Duplicator Type ModifierConstant

Page 99: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 4.Basic Operations: Looping and Arrays Page 4 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

3

TYPES OF CONSTANTS FOR DC DIRECTIVE

Type code meaning Example

F (full word) F‘8’Binary Integer

H Binary Integer H‘ 8’(Half word)

C Text or characters C‘Hello’E Floating Point E‘ 8.3’

(Short form)D Floating point D‘ 8.3’

(Long form)L Floating Point L‘8.3’

(Extended form)X Hexadecimal X‘ABC’P Decimal Numbers P‘8.5’

(Packed form)Z Decimal Numbers Z‘8.5’

(Zoned form)B Bit sequence B‘1001’A Address (internal) A (Symbol)V Address (External) V (Symbol)

Figure: 4-2 DC directives

NOTES:

Each character is converted to its 8-bit EBCDIC representation. The characters are storedin consecutive bytes. For D format the maximum approx. is 7.2 x 1075 with about 16-digit accuracy. For E format the maximum approx. is 7.2 x 1075 with about 7-digitaccuracy. For L format the max approx. is 7.2 x 1075 with about 32-digit accuracy. ForP format each digit is converted to a 4 bit binary integer and decimal point is ignored.For Z format each digit is converted to its 8-bit EBCDIC form.

Page 100: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 4.Basic Operations: Looping and Arrays Page 4 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

4

THE DS DIRECTIVE

Name Opcode Operand

a symbol, or blank DS one or more sub-fields,separated by commas

Required

Optional

Eg 1 DATE DS 2 CL 8

ModifierType

Duplicator

Eg 2: MVC DATE(10),=C‘09/10/1998’MVC DATE,=C‘09/10/1998’

DATE DS 2CL10

Figure: 4 – 3 DS directives

NOTES:

The DS directive is used to reserve an area of memory for future data. If the length fieldis omitted when specifying a symbolic address in an SS1 or SS2 instruction, the assembleruses the length attribute of that symbol.

Duplicator Type ModifierConstant

Page 101: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 4.Basic Operations: Looping and Arrays Page 4 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

5

SUB DIVISIONS

DATE DS 0CL10MONTH DS CL2

DS CDAY DS CL2

DS CYEAR DS CL4

2 1 2 1 4

10

COBOL EQUIVALENT

01 DATE.02 MONTH PIC XX.02 PIC X.02 DAY PIC XX.02 PIC X.02 YEAR PIC XXXX.

Figure: 4 –4 Sub divisions

NOTES:

Subdivisions are convenient for defining areas within an area. In the above exampleDATE and MONTH both will have the same address.

MONTH DAYYEAR

Page 102: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 4.Basic Operations: Looping and Arrays Page 4 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

6

EQUIVALENCE CONSTANTS (EQU)

Eg 1 MLC EQU *Eg 2 MSG1 DC C‘ MAINTEC COMPUTERS’

RESULT EQU * - MSG1Eg 3 T1 DC F‘1’

DC F‘2’DC F‘3’

T2 EQU * - T1Eg 4 ST DS CL1

ON EQU X‘FF’OFF EQU X‘00’

.

.CLI ST, ON CLI ST, X‘FF’BE PUTON BE PUTON

Invalid use of EQU

EX1 EQU * - EX2EX2 DC C‘HELLO’

Figure: 4 –5 Equivalence constants

NOTES:

EQU directive is to define a value for a symbol. This value cannot be changed in theprogram. The EQU does not cause any bytes to be generated on the object module. Theassembler at assembly time uses the constant defined by the EQU directive.

Page 103: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 4.Basic Operations: Looping and Arrays Page 4 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

7

RELOCATABLE AND ABSOLUTE CONSTANTS

Valid absolute constants : -A, A+B, A-B, A*B, A/B, (A+B)/C, R-S

Valid relocatable constants : R+A, R-A, R+(S-T), R-(S-T),-R

Invalid constants : R + S, R*S, R/S, R+(S-A)

Where R,S and T are non-negative re-locatable constants,

A, B and C are absolute constants.

Figure: 4-6 Relocatable and absolute constants

NOTES:

An assembly language constant consists of an algebraic expression of one or more terms.Each item is re-locatable if it is used to represent a memory address, if not it is anabsolute term. The value of an absolute term remains unchanged during run time andassembly time whereas the value of a re-locatable term may change from assembly timeto run time.

Page 104: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 4.Basic Operations: Looping and Arrays Page 4 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

8

CONTROL SECTIONS

SOURCE MODULE OBJECT MODULE

ExecutableControl section

ReferenceControl section

Input output

Figure: 4-7 Control sections

NOTES:

There are 2 types of control sections namely executable control section and referencecontrol section. An executable control section consists of instructions, constants and dataareas whereas a reference control section consists of directives only. The assemblerkeeps a separate memory location counter for each control section in the source module.

ACSECT

BDSECT

C COMEND

Executablesection A

Dummyreference

Section B

Commonreferencesection C

Page 105: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 4.Basic Operations: Looping and Arrays Page 4 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

9

SOURCE MODULE

07FC

0

328800

CSECT

Name field Opcode Operand

Any symbol CSECT blankOr blank

START

Name field Opcode Operand

Any symbol START blank orOr blank a self defining term

Figure: 4-8 Source module.

NOTES:

CSECT specifies the beginning of any executable control system in a source module.Symbol in the name field of a CSECT is considered to be entry point for the CSECT; itcan be referred as an external symbol from another source module. START specifies thebeginning of the first executable control section in a source module. The STARTpseudo-op cannot be used to resume an executable control section. The value of the self-defining term in the operand (if present) designates the initial value for the memorylocation counter of the control section. If the operand is blank, the initial value is zero.

A CSECT.

..

B DSECT

A CSECT

END

Page 106: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 4.Basic Operations: Looping and Arrays Page 4 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

10

SAMPLE PROGRAM TO PRINT THE SUM OF TWO BINARY INTEGERS

* PRINTEX CSECT* This program will compute the sum of two binary integers* Convert the sum to a 10-byte character form suitable for* Printing and print the result.* The conversion process used is valid only for nonnegative* Integers. i.e. the sum in this process is printed as a 10-digit* Number without punctuating commas, with leading zeroes* Printed as zeroes, and with the sign not printed.* The integers used to compute the sum are defined within the* PROGRAM: they are not read as input data.

STM 14, 12, 12 (13) STANDARD ENTRYBALR 12,0

USING *, 12ST 13,SAVE+4LA 13,SAVEOPEN (PRINTER, (OUTPUT)) OPEN THE PRINTER OUTPUT

FILE* ADD

L 3,X COMPUTE THE SUM OF THEINTEGERS

A 3, Y AT SYMBOLIC ADDRESSES X &Y, AND

ST 3, Z STORE THE SUM AT SYMBOLICADDRESS* CONVERT

L 5, Z COPY THE SUM INTOREGISTERS

CVD 5,BCD CONVERT IT TO BCD FORMUNPK SUM, BCD CONVERT THAT TO EBCDICOI SUM+9, X ‘F0’ ELIMINATE SIGN CODE IN

LOW-ORDER

Page 107: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 4.Basic Operations: Looping and Arrays Page 4 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

11

* PRINTPUT PRINTER, LINE WRITE THE SUM, TOGETHER

WITH TEXT, ONTO THE PRINTER.* EXIT

CLOSE (PRINTER)L 13, SAVE+4 STANDARD EXITLM 14,12,12(13)BR 14

* INTEGER CONSTANTS, AND AREA RESERVED FOR THEIR SUMX DC F’437’ BINARY REPRESENTATION OFDECIMAL +437Y DC F’562’ BINARY REPRESENTATION OFDECIMAL +562Z DS F BINARY SUM, TO BE CONVERTED TOEBCDICBCD DS D 8 BYTES RESERVED ON DOUBLE-WORD* AREA RESERVED FOR 132-BYTE PRINT LINELINE DS 0CL132 BEGINNING AND LENGTH OF LINE

DC CL7‘ ’ COLS 1 – 7 BLANKDC C‘THE SUM IS ’

SUM DS CL10DC CL104‘ ’

** DATA CONTROL BLOCK FOR OUTPUT TO PRINTERPRINTER DCB DSORG=PS, MACRF=(PM), DDNAME-SYSPRINT, X

RECFM=FB, LRECL=132, BLKSIZE=4092* REQUIRED STATEMENTS :SAVE DS 18F

END

NOTES:

The program computes the sum of 2 positive binary integers and converts the sum to a10-byte character form for printing.

Page 108: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 4.Basic Operations: Looping and Arrays Page 4 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

12

PROGRAM TO PRINT THE SUM OF TWO UNSIGNED DECIMAL INTEGER

RDPRT CSECT

* THIS PROGRAM READS TWO NON-NEGATIVE INTEGERS FROM A DATACARD THAT IS IN* THE INPUT DATA STREAM, COMPUTERS THEIR SUM, AND PRINTS THERESULT IN A* SINGLE LINE ON THE PRINTER.THE INPUT DATA IS ASSUMED TO BEREPRESENTED AS* 10-BYTE UNSIGNED DECIMAL INTEGERS, WITH EITHER LEADING ZEROESOR LEADING* BLANKS.* THE SUM IS PRINTED AS A 10-BYTE UNSIGNED DECIMAL INTEGER, WITHLEADING* ZEROES PRINTED AS ZEROES.

STM 14, 12, 12(13) STANDARD ENTRYBALR 12, 0USING *, 12ST 13, SAVE+14LA 13, SAVE

* OPEN INPUT AND OUTPUT FILESOPEN (TRANS,(INPUT) CARDS FROM INPUT DATA STREAMOPEN (PRINTER,(OUTPUT) PRINTER IS SYSOUT

* READ ONE DATA CARDGET TRANS, CARD INPUT AREA IS ‘CARD’

CONVERT EACH NUMBER TO 32-BIT BINARYPACK BCD,INT1 FIRST INTEGER IS AT ‘INT1’CVB 5, BCD ITS 32-BIT BINARY INTEGER

FORM ISSTORED AT ‘X’.

PACK BCD,INT2 SECOND INTEGER IS AT ‘INT2’.CVB 5,BCD ITS 32-BIT BINARY INTEGER FORM ISST 5, Y STORED AT ‘Y’.

Page 109: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 4.Basic Operations: Looping and Arrays Page 4 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

13

COMPUTE THE SUM, AND STORE BINARY INTEGER RESULT AT ‘ Z ’.

L 3, X COMPUTE THE SUM OF THEINTEGERS GIVEN

A 3, Y AT SYMBOLIC ADDRESSES X & Y,AND

ST 3, Z STORE THE SUM AT SYMBOLICADDRESS Z.

CONVERT THE SUM TO UNSIGNED 10-BYTE CHAR, FORM WITH LEADINGZEROES.

L S, Z PUT THE SUM IN A REGISTERCVD 5, BCD CONVERT IT TO BINARY-

CODED DEC.UNPK SUM,BCD CONVERT THAT TO CHAR (EBCDIC)OI SUM+9, X ‘FO’ ELIMINATE SIGN CODE

* PRINT THE RESULTPUT PRINTER, LINE

EOJ CLOSE (PRINTER) CLOSE ALL FILESCLOSE (TRANS)L 13, SAVE+14 STANDARD EXITLM 14,12,12(13)BR 14

* AREAS RESERVED FOR TWO BINARY INTEGERS AND THEIR SUMX DS F BINARY REPRESENTATION OF INTEGER AT ‘INT1’Z DS F SUM OF ‘X’ AND ‘Y’ INTEGERS

* AREA RESERVED FOR INTERMEDIATE BINARY-CODED DECIMALREPRESENTATIONBCD DS D SAME AREA USED FOR ALL CONVERSIONS* AREA RESERVED FOR 80-BYTE INPUT CARDCARD DS OCL 80 BEGINNING AND LENGTH OF AREA

DS CL5 COLS 1 – 5 UNUSEDINT1 DS CL10 6 – 15 FIRST 10-BYTE DECIMAL INTEGER

DS CL5 16 – 20 UNUSEDINT2 DS CL10 21 –- 30 SECOND 10-BYTE DECIMALINTEGER

DS CL50 31 – 80 UNUSED

Page 110: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 4.Basic Operations: Looping and Arrays Page 4 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

14

* AREA RESERVED FOR 132-BYTE PRINT LINELINE DS OCL132 BEGINNING AND LENGTH OFLINE

DC CL7‘ ’ COLS 1- 7 BLANKDC C‘THE SUM IS ’ 8 – 18 EXPLANATORY TEXT

SUM DS CL10 19 – 28 10 BYTE SUMDC CL104‘ ’ 29 – 132 BLANK

TRANS DCB DSORG-PS, MACRF-(GM), DDNAME-SYSIN,EODAD-EOJ, X

RECFM=FB, LRECL-80,BLKSIZE=4080PRINTER DCB DSORG=PS,MACRF=(PM),DDNAME=SYSPRINT,

XRECFM=FB,LRECL=132,BLKSIZE=4092

REQUIRED STATEMENTS

SAVE DS 18FEND

NOTES:

The program uses instructions such as PACK to convert from Zoned to BCD form andCVB convert form BCD form to Binary integer form. The resulting sum is printed as a10 byte unsigned decimal integer.

Page 111: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 4.Basic Operations: Looping and Arrays Page 4 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

15

THE LA INSTRUCTION

General form

1. LA R1, S22. LA R1, D23. LA R1, D2 (X2)4. LA R1, D2(X2, B2)

Eg 1: LA 5,WEg 2: LA 5,4Eg 3 : LA 5,4 (5)Eg 4 : LA 5,4 (5, 6)

Figure: 4-9 LA Instructions

NOTES:

Eg 1: Is used to initialize register 5 with an implicit memory address.Eg 2: Is to initialize register 5 with a displacement of 4.Eg 3: Is to use register 5 as a counter and add a displacement of 4 to the contents of

register 5.Eg 4: Is to add a displacement of 4, and contents of register 6 to the contents of

register 5.

Page 112: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 4.Basic Operations: Looping and Arrays Page 4 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

16

THE BXH AND BXLE INSTRUCTION

Explicit form : BXH R1, R2, D3 (B3)BXLE R1, R2, D3 (B3)

Implicit form : BXH R1, R2, S3BXLE R1, R2, S3

Eg :

L 9, LIMITL 8, INCRL 7,=F‘0’

Loop L 3,X(7)A 3,Y(7)ST 3,Z(7)BXLE 7, 8, LOOP

Figure: 4-10 BXH and BXLE instruction

NOTES:

BXLE 7,8, LOOP means add the increment which is contents of register 8 to the indexthat is in register 7 and compare the sum to the limit that is in register 9. If the sum isless than or equal to the limit then branch to symbol called LOOP otherwise do notbranch.

Page 113: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 4.Basic Operations: Looping and Arrays Page 4 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

17

PRINTING NONNEGATIVE INTEGERS

Binary vs. Character data

Conversion of binary integer to character

Allocating a memory area

Figure 4 - 11 Printing nonnegative integers

NOTES:

Integer data used for arithmetic purposes are represented in the binary numbersystem, where as all data transmitted between memory and most input and outputdevices are in character format.

In the IBM 360 and 370 systems, EBCDIC character format is used. To print aninteger that is represented in binary form in memory, it must first be converted to itscharacter form.

The sequence of instructions must be used to converts a binary integer to itsrepresentation as a decimal integer in character form. The instructions (DS and DCdirectives) are also used to allocating memory areas for the characters that are to beprinted.

Page 114: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 4.Basic Operations: Looping and Arrays Page 4 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

18

ALLOCATING MEMORY AREAS

To define the beginning and length of a printed line :

LINE DS 0CL 132 Used when carriage control omitted.LINE DS 0CL 133 Used when carriage control included.

To reserve space for an integer that consists of n characters including oneposition for the sign :

Symbol DS CLn n is an unsigned decimal integer andsymbol is any valid name field symbol.

To define text that is to be printed on the line:

DC C’…’ The three dots represent any text characters otherthan an apostrophe (‘) or an ampersand (&) .

To assign m blanks to unused print positions :

DC CLm’ ‘ m , an unsigned decimal integer, and is thenumber of consecutive blanks to be printed;the apostrophes enclose a single blank.

Figure 4 - 12 Allocating memory area.

NOTES :

The number of print positions per line is usually 132 for high speed printers.

To allocate a memory area sufficient to accommodate any printed line , 132 bytes ofmemory must be reserved for the entire line, some of these bytes must be allocatedfor the integers . that are to printed, others for any text that is also to be printed, andthe remainder for blanks that fill out the line.each such allocation will designate theprint position that are to be used.

Page 115: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 4.Basic Operations: Looping and Arrays Page 4 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

19

CONVERSION FROM BINARY TO CHARACTER REPRESENTATION

Four Conversion Instructions :

L 5 , Z COPY THE BINARY INTEGER INTO A REGISTERCVD 5 , BCD CONVERT IT TO BCD FORMUNPK SUM ,BCD CONVERT THAT TO CHARACTER FORMOI SUM+9,X’F0’ ELIMINATE THE SIGN CODE IN LOW-ORDER DIGIT

Binary representation of 12 :

0000 0000 0000 0000 0000 0000 0000 1100

character representation of 12 :

1111 0001 1111 0010

Figure: 4 – 13. Conversion from binary to character

NOTES :

The address of the binary integer must be specified in the second operand of theLoad(L) instruction.The address of the ten-byte memory area that is allocated for the characterrepresentation of the number must be specified in the first operand of the UNPKinstruction.

The address of the low-order byte of the ten-byte character area must be specified inthe first operand of the OI instruction.

The address of the area reserved for the intermediate binary coded decimalrepresentation must be specified in the second operand of both the CVD and theUNPK instructions.

Page 116: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 4.Basic Operations: Looping and Arrays Page 4 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

20

READING NONNEGATIVE INTEGER INPUT DATA

PACK Instruction

CVB

PACK – CVB

CVD – UNPK

Figure: 4 – 14 Reading non - negative integer input data

NOTES :

The PACK instruction converts from character form to binary coded decimal(BCD),and the converts to binary(CVB) converts from BCD to 32-bit binary integer form.

The PACK – CVB sequence , the counter part of the CVD –UNPK sequence used forprinting.

The character form of the decimal integer occupies exactly ten positions ,rightjustified with either leading zeroes or leading blanks. Its sign is omitted; it is assumedto be nonnegative.

Page 117: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 4.Basic Operations: Looping and Arrays Page 4 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

21

ALLOCATING MEMORY AREAS

The Directives required to allocate memory area for the data :

CARD DS 0CL80 DEFINE BEGINNING AND LENGTH OF CARD

DS CL5’ ‘ RESERVE 5 BYTES FOR UNUSED POSITIONS

INT DS CL10 10 BYTES FOR CHARACTER FORM OF INTEGER

DS CL65’ ‘ 65 BYTE POSITION FOR REMAINDER OF CARD

Figure: 4 - 15 Memory allocating area

NOTES :

Page 118: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 4.Basic Operations: Looping and Arrays Page 4 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

22

CONVERSION FROM CHARACTER FORM TO32-BIT BINARY INTEGER FORM

THREE INSTRUCTIONS ARE REQUIRED FOR CONVERSION :

PACK BCD , INT CONVERT FROM CHAR. TO BCDCVB 5 , BCD CONVERT THAT TO 32-BIT BINARY IN REGISTER 5ST 5 , X STORE THE BINARY FORM AT SYMBOLIC ADDRESS XTHE SYMBOLIC ADDRESS INT:

INT DS CL10 RESERVE 10 BYTES FOR THE CHARACTER FORRM

THE SYMBOLIC ADDRESS BCD :

BCD DS D RESERVEV 8 BYTES ON A DOUBLE WORD BOUNDARY

THE SYMBOLIC ADDRESS X :

X DS F RESERVE ONE FULL WORD FOR A BINARY INTEGER

Figure: 4 – 16 Conversion

NOTES :

The address of the 10-byte memory area that is allocated for the input characterrepresentation of the number must be specified in the second operand of the PACKinstruction.

The address of the area reserved for intermediate BCD representation of the numbermust be specified in the first operand of the PACK instruction and in the secondoperand of the CVB instruction.

The address of the area reserved for the binary integer must be specified in the secondoperand of the ST instruction.

Page 119: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 5. Integer Arithmetic 5 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

1

UNIT 5 :INTEGER ARITHMETIC

OBJECTIVES:

Two’s complement arithmetic

Addition, subtraction, multiplication, division

Conditional branches

Comparing integers

Two – dimensional arrays

Changing sign and generating absolute values

Page 120: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 5. Integer Arithmetic 5 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

2

TWO’S COMPLEMENT ARITHMETIC

. Representation of binary integers:b0,b1,b2…..bk-1, where b0 is used to designate the sign bit.

b0 = 0 for positive integer and b0=1 for negative integers.

Sign-magnitude form

Decimal binary decimal binary+0 0000 -0 1000+1 0001 -1 1001+2 0010 -2 1010+3 0011 -3 1011+4 0100 -4 1100+5 0101 -5 1101+6 0110 -6 1110+7 0111 -7 1111

Figure: 5 – 1 Two’s compliment

NOTES :

The value of each integer b0,b1,b2,b3 can be computed as

(1-2b0 )

The term integer arithmetic includes several types of instructions that operate on full-word and half-word binary numbers: copying data into and out of a register; addition,subtraction, multiplication and division of two binary integers; changing sign, andgenerating the absolute value of a binary integer; testing for positive, negative, or zeronumeric result; and comparing two binary integers algebraically.

Page 121: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 5. Integer Arithmetic 5 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

3

ARITHMETIC INSTRUCTION

Addition Condition codesInstruction 0 1 2 3A, AR, AH result was zeroAl, ALR result was zero

With no carryOut of sign bitPosition

Result = -veResult was not zeroWith no carry outOf sign position

Result = +veResult was zeroWith a carry outof sign bitposition

OverflowResult wasZero with acarry out ofsign bitposition.

Eg 1: Reg 5 = F’15’

A 5,=F‘15’ Before : 0000 0030 0000 000FAfter : 0000 003F 0000 000F

Eg 2:Reg 8 Reg 9

AR 8, 9 Before: 0000 0001 0000 0010After : 0000 0011 0000 0010

Eg 3:Reg 8 = H’5’

AH 8, =H’5’ Before : 0000 0040 0005After : 0000 0045 0005

Figure: 5-2 Arithmetic Instructions

NOTES:

Condition code stores the status of each add instruction after execution.

Page 122: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 5. Integer Arithmetic 5 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

4

SUBTRACTION

Instruction Condition CodesInstruction 0 1 2 3S, SR, SHSl, SLR

Result = 0 Result = -veResult was notzero with nocarry out ofsign bit position

Result = +veResult was zerowith a carry outof sign bitposition

Overflow resultwas not zerowith a carry outof the sign bitposition.

Eg 1:Reg 5 =F’10’

S 5, = F‘10’ Before: 0000 0030 0000 000AAfter: 0000 0026 0000 000A

Reg 8 Reg 9Eg 2:

SR 8, 9 Before : FFFF FFFF 0000 1000After : FFFF FFFF 0000 1001

Reg 8 =H‘80’Eg 3:

SH 8, =H‘80’ Before : 0000 0008 0050After : FFFF FFB8 0050

Figure 5-3 Subtractions

NOTES:

If the result after subtraction is negative then the result is in two’s complement form.

Page 123: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 5. Integer Arithmetic 5 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

5

MULTIPLICATION

even register odd register

Before :

After :

Eg 1 SR 4,4 even-odd pairL 5,=F‘3’ Reg 4 Reg 5M 4,=F‘2’ Before : 0000 0000 0000 0003

After : 0000 0000 0000 0006

Eg 2SR 6,6L 7,=F‘65536’ Reg 6 Reg 7MR 6, 7 Before : 0000 0000 0001 0000

After : 0000 0001 0000 0000

Eg 3L 9,=F‘3’ Reg 9MH 9,=H‘5’ Before : 0000 0003

After : 0000 000F

Figure: 5 –4 Multiplication

NOTES:

While using M and MR instructions, Multiplicand must always be in an odd-numberedregister. The product is 64-bit signed integer that occupies two consecutive registers(called even-odd pair).

Some NumberMultiplicand

64 – bit product

Page 124: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 5. Integer Arithmetic 5 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

6

DIVISION

even-odd register pair

even numbered odd numberedRegister register

Before

After

Eg 1 L 7, = F‘9’ Reg 6 Reg 7L 6, = F‘0’ Before : 0000 0000 0000 0009D 6, = F‘2’ After : 0000 0001 0000 0004

Eg 2 L 9, = F‘150’ Reg 8 Reg 9 Reg10

L 8, = F‘0’ Before : 0000 0000 0000 0096 FFFFFFD4

L 10,=F‘-40’ After : 0000 001E FFFF FFFD FFFF FFD4DR 8, 10

Figure 5 –5 Division

NOTES:

While using the D & DR instructions the dividend is a 64-bit integer. Divisor could bestored in any register. The remainder is stored in the even-numbered register and thequotient is stored in the odd-numbered register.

64 bit dividend

32-bit remainder 32-bit quotient

Page 125: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 5. Integer Arithmetic 5 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

7

BRANCHING INSTRUCTIONS

Eg 1:

L 5, M1M 4, M2LTR 5,5BM NEGTBZ ZEROB POS

Figure 5 –6 Branching Instructions

NOTES:

The conditional branch instructions do not set the condition code. They only test it. TheLTR instruction sets the condition code according to whether register R1 is zero, negativeor positive. Before testing, the LTR instruction first copies the contents of R2 to R1.

BZ BNZ BM BNM BP BNP

LTR R1,R2

Page 126: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 5. Integer Arithmetic 5 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

8

COMPARISON

RELATED BRANCH INSTRUCTIONS

Opcode Meaning

BE N1 = N2BNE N1 N2BL N1 < N2BNL N1 N2BH N1 > N2BNH N1 N2

Eg 1 Eg 2:L 5, Z L 3, ZC 5,=F‘6’ L 4,=F‘6’BE EQ CR 3, 4BH HIGH BNH LORE

B GTEg 3 L 3, Z

CH 3,=H‘ – Z’BNE NEQ

Figure 5 – 7 Comparison

NOTES:

One of the two numbers to be compared must be in a register and the other number canbe in a register or memory location. None of the numbers are affected by the compareinstruction.

INSTRUCTION CONDITION CODE

0 1 23C, CR, CH N1 = N2 N1 < N2 N1 > N2------

Page 127: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 5. Integer Arithmetic 5 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

9

COMPLEMENT INSTRUCTIONS

Reg 5

Eg 1 LCR 5,5 before : 0000 0002

After : FFFF FFFE

Eg 2: LCR 5, 6 Reg 5 Reg 6

Before : 1234 5678 8000 0000

After : 8000 0000 8000 0000

Eg 3:LPR 5, 4 Reg 4 Reg 5

Before :FFFF FFFA 0000 00AB

After : FFFF FFFA 0000 0006

Eg 4: LPR 4, 5 Reg 4 Reg 5

Before : FFFF FFFA 0000 00AB

After : 000 00AB 0000 00AB

CONDITION CODEInstruction 0 1 2 3

LCR result = 0 result = -ve result= +ve overflow

LPR result = 0 ------- result=+ve overflow

LNR result = 0 result = -ve ------- -----------

Page 128: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 5. Integer Arithmetic 5 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

10

Eg 5: LNR 4,5 Reg 4 Reg 5

Before : FFFF FFFA 0000 00AB

After : FFFF FF55 0000 00AB

Eg 6: LNR 5, 4 Reg 4 Reg 5

Before : FFFF FFFA 0000 00AB

After : FFFF FFFA FFFF FFFA

Figure: 5-8 complement instruction

NOTES:

The LCR instruction loads the two’s complement of a register. The LNR instruction isused to load the negative absolute value of a number. The LPR instruction is used to loadthe positive absolute value of a number.

Page 129: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 5. Integer Arithmetic 5 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

11

Sample programs using arrays.

* THIS PROGRAM ADDS INTEGERS STORED IN AN ARRAY

* REQUIRED STATEMENTS*START CSECT

STM 14,12,12(13)BALR 12,0USING *,12ST 13,SAVE+4

* WTO 'FIRST STEP'LA 13,SAVEOPEN (FILE,(OUTPUT))

** ADDITION OF THE TWO INTEGERS*S LA 8,ARRAY

L 9,NSR 10,10

ADD A 10,0(8)LA 8,4(8)BCT 9,ADDST 10,Z

** CONVERSION OF BINARY O/P TO EBCDIC*CONVERT L 5,Z

CVD 5,BCDUNPK SUM,BCDOI SUM+9,X'F0'PUT FILE,OUTRECCLOSE FILE

*L 13,SAVE+4LM 14,12,12(13)BR 14

** DATA CONTROL BLOCK FOR WRITING THE O/P*FILE DCB DSORG=PS,MACRF=(PM),DDNAME=SYSOUT,

RECFM=FB,LRECL=80,BLKSIZE=8000*

Page 130: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 5. Integer Arithmetic 5 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

12

*** DEFINING THE CONSTANTS USED IN THE PROGRAMZ DS FN DC F'10'ARRAY DC F'1,2,3,4,5,6,7,8,9,10'OUTREC DS 0CL80

DC CL25' THE SUM OF ARRAY IS'SUM DS CL10

DC 45C' 'BCD DS D*** REQUIRED STATEMENTS* DS 0DSAVE DS 18F

Page 131: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 5. Integer Arithmetic 5 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

13

* THIS PROGRAM ADDS FINDS AVERAGE OF AN ARRAY** REQUIRED STATEMENTS

START CSECTSTM 14,12,12(13)BALR 12,0USING *,12ST 13,SAVE+4

* WTO 'FIRST STEP'LA 13,SAVEOPEN (FILE,(OUTPUT))

* AVERAGE OF THE INTEGERS*S LA 8,ARRAY

L 9,NSR 11,11

ADD A 11,0(8)LA 8,4(8)BCT 9,ADDST 11,ZM 10,=F'1'D 10,NST 11,QUOTST 10,REM

** CONVERSION OF BINARY O/P TO EBCDIC*CONVERT L 5,Z

CVD 5,BCDUNPK SUM,BCDOI SUM+9,X'F0'PUT FILE,OUTREC1L 6,QUOTCVD 6,BCDUNPK Q,BCDOI Q+9,X'F0'PUT FILE,OUTREC2L 7,REM

Page 132: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 5. Integer Arithmetic 5 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

14

CVD 7,BCDUNPK R,BCDOI R+9,X'F0'

PUT FILE,OUTREC3CLOSE FILE

*L 13,SAVE+4LM 14,12,12(13)BR 14

** DATA CONTROL BLOCK FOR WRITING THE O/P*FILE DCB DSORG=PS,MACRF=(PM),DDNAME=SYSOUT,

RECFM=FB,LRECL=80,BLKSIZE=8000**** DEFINING THE CONSTANTS USED IN THE PROGRAMZ DS FN DC F'3'QUOT DS FREM DS FARRAY DC F'1,2,3'OUTREC1 DS 0CL80

DC CL25' THE SUM OF ARRAY IS'SUM DS CL10

DC 45C' 'OUTREC2 DS 0CL80

DC CL25' THE QUOTIENT IS'Q DS CL10

DC 45C' 'OUTREC3 DS 0CL80

DC CL25' THE REMAINDER IS'R DS CL10

DC 45C' 'BCD DS DSAVE DS 18F

Page 133: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 5. Integer Arithmetic 5 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

15

* THIS PROGRAM MULTIPLIES EACH INTEGER IN AN ARRAY BY ACONSTANT

* REQUIRED STATEMENTS*START1 CSECT

STM 14,12,12(13)BALR 12,0USING *,12ST 13,SAVE+4

* WTO 'FIRST STEP'LA 13,SAVEOPEN (SNAPDCB,(OUTPUT))SNAP DCB=SNAPDCB,ID=1,STORAGE

=(START1,SAVE),PDATA=(PSW,REGS)OPEN (FILE,(OUTPUT))

** AVERAGE OF THE INTEGERS*S LA 8,ARRAY

L 9,NL 3,CONST

MULT SR 10,10L 11,0(8)MR 10,3ST 11,ZST 10,Y

** CONVERSION OF BINARY O/P TO EBCDIC*CONVERT L 5,Z

CVD 5,BCDUNPK SUM,BCDOI SUM+9,X'F0'SNAP DCB=SNAPDCB,ID=2,PDATA=(PSW,REGS), X

STORAGE=(START1,SAVE)

PUT FILE,OUTREC1L 6,YCVD 6,BCDUNPK Q,BCD

OI Q+9,X'F0'

Page 134: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 5. Integer Arithmetic 5 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

16

PUT FILE,OUTREC2LA 8,4(8)BCT 9,MULTCLOSE FILECLOSE SNAPDCB

L 13,SAVE+4LM 14,12,12(13)BR 14

** DATA CONTROL BLOCK FOR WRITING THE O/P*FILE DCB DSORG=PS,MACRF=(PM),DDNAME=SYSOUT,

RECFM=FB,LRECL=80,BLKSIZE=8000*SNAPDCB DCBDSORG=PS,MACRF=(W),RECFM=VBA,BLKSIZE=1632,LRECL=125,

DDNAME=SNAPSHOT*** DEFINING THE CONSTANTS USED IN THE PROGRAMZ DS FY DS FCONST DC F'2'N DC F'5'ARRAY DC F'1,2,3,4,2147483647'OUTREC1 DS 0CL80

DC CL25' THE VALUE IN R11 IS'SUM DS CL10

DC 45C' 'OUTREC2 DS 0CL80

DC CL25' THE VALUE IN R10 IS'Q DS CL10

DC 45C' 'BCD DS DSAVE DS 18F

Page 135: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 5. Integer Arithmetic 5 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

17

* THIS PROGRAM COUNTS THE NUMBER OF POSITIVE INTEGERS INAN ARRAY* REQUIRED STATEMENTS

START1 CSECTSTM 14,12,12(13)BALR 12,0USING *,12ST 13,SAVE+4

* WTO 'FIRST STEP'LA 13,SAVEOPEN (SNAPDCB,(OUTPUT))SNAP DCB=SNAPDCB,ID=1,STORAGE=(START1,SAVE),

XPDATA=(PSW,REGS)

OPEN (FILE,(OUTPUT))**S LA 8,ARRAY

L 9,NPOSCHK L 11,0(8)

LTR 11,11BNP LOOPCTLA 10,=F'1'

LOOPCTL LA 8,4(8)BCT 9,POSCHKST 10,POSCTR

** CONVERSION OF BINARY O/P TO EBCDIC*CONVERT L 5,POSCTR

CVD 5,BCDUNPK SUM,BCDOI SUM+9,X'F0'SNAP DCB=SNAPDCB,ID=2,PDATA=(PSW,REGS),

XSTORAGE=(START1,SAVE)

PUT FILE,OUTREC1CLOSE FILECLOSE SNAPDCB

Page 136: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 5. Integer Arithmetic 5 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

18

L 13,SAVE+4LM 14,12,12(13)BR 14

** DATA CONTROL BLOCK FOR WRITING THE O/P*FILE DCB DSORG=PS,MACRF=(PM),DDNAME=SYSOUT, X

RECFM=FB,LRECL=80,BLKSIZE=8000*SNAPDCB DCBDSORG=PS,MACRF=(W),RECFM=VBA,BLKSIZE=1632,LRECL=125,

DDNAME=SNAPSHOT*** DEFINING THE CONSTANTS USED IN THE PROGRAMPOSCTR DS FN DC F'11'ARRAY DC F'-1,-2,-3,-4,-5,0,1,2,3,4,5'OUTREC1 DS 0CL80

DC CL50'NUMBER OF POS NUMBERS IN THE ARRAY IS'SUM DS CL10

DC 20C' 'BCD DS DSAVE DS 18F

Page 137: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 5. Integer Arithmetic 5 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

19

BYTE OPERATIONS

Register

0 8 16 24

Mask

Eg 1: Reg 8 mem locn 500

IC 8, A Before : 01 02 03 04 A1 A2 A3 A4

After : 01 02 03 A1 A1 A2 A3 A4

Reg 4 mem loc 400

Eg 2: STC 4, Z Before : 01 02 03 04 A1 A2 A3 A4

After : 01 02 03 04 04 A2 A3 A4

Opcode Type

IC RXSTC RXICM RSSTCM RS

Page 138: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 5. Integer Arithmetic 5 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

20

Eg 3: ICM 6, X’A’, A Reg 6 mem loc. 500

Before : 01 02 03 04 A1 A2 A3 A4

After : A1 02 A2 04 A1 A2 A3 A4

Eg 4: STCM 4, ‘0011’, Z Reg 4 mem loc. Z

Before : 01 02 03 04 A1 A2 A3 A4After : 01 02 03 04 03 04 A3 A4

Figure 5-9 Byte

NOTES:

Set of bytes can be copied from memory to register and vice-versa. The ICM andSTCM instructions are available on the IBM 370 only and not on the IBM 360. Thenumber of bytes that are inserted or stored is equal to the number of 1’s in the 4-bitmask. The relative position of the bytes in the register is dependent on the position of bit1’s in the mask. A one-to-one correspondence from left to right is used.

1 0 10

Page 139: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 5. Integer Arithmetic 5 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

21

MOVING BYTES

Location ZEg 1: MVI Z+3, C ‘!’ in hexadecimal in characters

Before : D4 E3 C5 C3 M T E CAfter : D4 E3 C5 5A M T E !

Eg 2: MVC Z(4), Y mem loc 500 (Z) mem locn 800Before : S T U D F A R MAfter : F A R M F A R M

Eg 3: MVC Z+1(3), Z mem locn 500Before : G O O D

After : G G G GEg 4: MVCIN Z+3(4), Y mem locn 500 (Z) mem locn (Y) 1000

Before : T H A T S H O PAfter : P O S H S H O P

Figure 5-10Moving Bytes

NOTES:

The MVCL and MVCIN instructions are available on the IBM 370 only and not on theIBM 360. The MVC instruction has a length field which specifies the number of bytesthat are to be copied. In Eg 3 the sending field 500-502 overlaps receiving field 501-503. In the MVCIN instruction memory location Y is the sending field and memorylocation Y is the sending field and memory location Z is the receiver.

Opcode Type

MV1 SIMVC SS1MVC IN SS1MVCL RR

Page 140: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 5. Integer Arithmetic 5 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

22

COMPARISON OF BYTES

OPCODE

Condition Code

Instruction 0 1 2 3

CL, CLC, CLR S1 = S2 S1<S2 S1>S2 ----CLCL, CLI, CLM

Relative Conditional Branch instructions are

Figure 5-11 Comparison Of Bytes

NOTES:

CLCL instruction is available only on IBM 370 and not on IBM 360. SI is the firststring and S2 is the second string.

Opcode Type

CL RXCLR RRCLM RSCLI SICLC SSICLCL RR

BE BNE BL BNL BH BNH

Page 141: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 5. Integer Arithmetic 5 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

23

Sample program segment to replace the question mark symbols in agiven text with periods.

LA 4, TEXTLA 5, LEN

CMP CLI 0(4), C ‘?’BNE NXTMVI 0(4), C‘.’

NXT LA 4, 1(4)BCT 5, CMP...

TXT DC C ‘How? WHEN? WHY?’LEN EQU * - TEXT

Figure 5-12 Sample programs

NOTES:

The program uses register 4 to store the address of TEXT and register 5 to store thelength of the TEXT. The string TEXT is searched for the question mark and replacedwith period.

Page 142: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 5. Integer Arithmetic 5 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

24

Sample program segment to find the first comma or blank and compute the lengthof the string preceding it.

LA 4, textLA 5, LEN

CMP CLI 0(4),C ‘,’BE DONECLI 0(4), C‘ ’BE OVERLA 4, 1(4)BCT 5, CMP

OVER LA 4, LENSR 4, 5

EXIT STH 4, POSIT..

TEXT DC C‘ FIRST COMMA, OR BLANK’LEN EQU * - TEXTPOSIT DS H

.

.

Figure 5-13 Sample programs

NOTES:

The assembler calculates the difference of two addresses ,the starting byte and the bytefollowing last byte to compute the length of the string.

Page 143: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 5. Integer Arithmetic 5 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

25

Program segment to compare a 5- byte string with a string in a table.

LA 4, TABLELA 5, ELEMTS

REPEAT CLC 0 (5,4), STRBE EXITLA 4, 5(4)BCT 5, REPEATSR 4, 4

EXIT ST 4, POSIT...

STR DC CL5‘STOP’TABLE DC CL5‘END’

DC CL5‘HERE’DC CL5‘STOP’

ELEMTS EQU (* - TABLE) / 5POSIT DS F

.

.

.

Figure 5 –14 Program segment

NOTES:

The TABLE contains elements. ELEMTS contains number of entries in the TABLE.STR contains the string to be searched. If the string is not found then zero is stored inPOSIT. If the string is found then the address of the matching string is stored.

Page 144: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 5. Integer Arithmetic 5 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

26

SHIFTING BITS

ARITHMETIC SHIFT LOGICAL SHIFT

Reg 9Eg 1 : SRA 9, 31 Before : 0001 0001 0001 0001 0001 0001 0001 0001

After : 0000 0000 0000 0000 0000 0000 0000 0000

Eg 2: SRA 8,5 Reg 8Before : 1111 1111 1111 1111 1111 1010 1010 1000

After : 1111 1111 1111 1111 1111 1110 1101 0101

Eg 3: Propagation of sign bitsSLA 4,4 (10)

Reg 10: 0000 0000 0000 0000 10001000

Displacement : 0000 00000100

00 1100

Reg 4

Before : 1111 1010 1111 1000 0000 0111 0000 0110

After : 0000 0000 0111 0000 0110 0000 0000 0000

Opcode Type

SRA, SLA RSSLDA, SRDA RS

Page 145: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 5. Integer Arithmetic 5 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

27

Eg 4 : Reg 6 Reg 7SRDA 6, 3 Before : 1A 1B 1C 1D 1E 1F 10 11

After : 03 43 63 83 A3 C3 E2 02

Eg 5 : SLDA 6, 11 Before : 1A 1B 1C 1D 1E 1F 10 11

After : 58 ED E8 F0 F8 80 88 00

Figure 5-14 Shifting bits

NOTES:

In an arithmetic shift the sign bit of a register or register pair is treated differently fromthe other, bits and the condition code has a value which denotes the status of the result.In a logical shift the sign bit is treated as similar to any other bit and the condition codeis not set.

Page 146: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 5. Integer Arithmetic 5 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

28

LOGICAL SHIFTS

SRL,

Reg 8SRL 8, 5 Before : 1111 1111 1111 1111 1111 1111 1010 0100

After : 0000 0111 1111 1111 1111 1111 1111 1101

SLL 8, 4(10) Reg 10 : 0000 0000 0000 0000 1000 1000Displacement : 0000 0000 0100

00 1100Reg 8

Before : 0000 1001 0000 1000 0000 0111 0000 0110After : 1000 0000 0111 000 0110 0000 0000 0000

SRDL 6, 3 Reg 6 Reg 7Before : 1A 1B 1C 1D 1E 1F 10 11After : 03 43 63 83 A3 C3 E2 02

SLDL 6, 11 Reg 6 Reg 7Before : 1A 1B 1C 1D 1E 1F 10 11After : D8 E0 E8 F0 F8 80 88 00

Figure 5-15 Logical shifts

NOTES:

When the contents of a register or register pair are shifted X bits to the right then X rightmost bits are lost and zeros are inserted into the X left - most positions. The sign bit istreated as any other bit. The condition code is not set.

Opcode Type

SRL, SLL, SRDL, SLDL RS

Page 147: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 5. Integer Arithmetic 5 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

29

ALTERING BITS

0 1 2 3

OPEN I/O TYPE EOF

0 1 2 3 4 5

Open I / O Type EOF

BIT VALUE COMMENT

OPEN 0 File not open1 File open

I / O 0 If open, file is used for input only1 If open, file is used for output only.

TYPE 0 Sequential file1 indexed sequential file

EOF 0 File has not reached end-of-file1 File has reached end-of-file

Page 148: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 5. Integer Arithmetic 5 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

30

Figure 5 – Alternating system

NOTES:

BIT VALUE COMMENTS

OPEN 0 File not open1 File open

I / O 00 No meaning01 Opened for input only10 Opened for output only11 Opened for input & output

TYPE 00 No meaning01 Sequential10 indexed sequential11 direct

EOF 0 not end-of-file1 end-of-file

Page 149: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 5. Integer Arithmetic 5 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

31

Boolean Instructions on IBM 360 and 370-systems

Figure 5-16 Boolean Instructions

NOTES:

The OR, AND and EXCLUSIVE –OR instructions are used to alter bits. Theconditional branch instructions following boolean instructions are BZ, BZR, BNZ,BNZR.

Opcode Type Location of mark Locn of

O, N, X RX Memory Register(Second operand) (First operand)

OR, NR, XR RR Register (second Operand) Register (Firstoperand)

OX, NI, XI SI Immediate data field Memory (Firstoperand)

(Second operand)OC, NC, XC SS, L byte memory L bytememory

(Second operand)(First operand)

Page 150: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 5. Integer Arithmetic 5 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

32

FILE STATUS INFORMATION

FILESTAT DC B’0000 0000’OPEN EQU B’1000 0000’I O EQU B’0110 0000’IOIN EQU B’0010 0000’IOOUT EQU B’0100 0000’IOINOUT EQU B’0110 0000’TYPE EQU B’0001 1000’TYPSAM EQU B’0000 1000’TYPISAM EQU B’0001 0000’TYPBDAM EQU B’0001 1000’EOF EQU B’0000 0100’USAGE1. OI FILESTAT, OPEN2. OI FILESTAT, TYPISAM3. TM FILESTAT, IOOUT

BO OUTPUTTM FILESTAT, IOINBO INPUT.

4. TM FILESTAT, IOINOUTBO BOTH

Figure 5-17 File status

NOTES:

Usage 1. When file is opened set open bit to 1.2. If the file opened is an indexed sequential file then set isam bit to 1.3. Check if file is opened for input or output.4. Check of file is opened both for input & output.

Page 151: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 5. Integer Arithmetic 5 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

33

TESTING BITS

Assembly language format Machine Language formatOpcode operandTM D1 (B1), I2

TM S1, I 2

Implied DisplacementBase Register

Related Conditional Branch Instructions are

TEST AND SET

Assembly Language format Machine Language format

TS D1 (B1)TS S1

0 8 16

Space not used by TS

TS = TM BYTE, B‘ 10000000’MVI BYTE, B‘ 11111111’

Figure 5-18 Testing Bits

NOTES:

TM instruction tests up to 8 bits at once without altering the bits that are tested. TSinstruction tests only 1 bit, the sign bit and then sets all bits in the tested byte to 1. TSinstruction is use in a program that controls the use of non sharable resources.

91 I 2 B1D191 I 2

BZ BOBM

93 B1D1

93

Page 152: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 5. Integer Arithmetic 5 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

34

Eg 1 TM CHQ, X ‘FO’Mask Byte = 1111 0000

Assumed target byte = 1010 1111BM will branch whereas BO & BZ will not branch

Eg 2 TM CHQ, X‘OF’

Mask Byte = 0000 1111Assumed target byte = 1010 1111

BO will branch whereas BM and BZ will not branch

Eg 3 TM CHQ, B‘ 0101 0000’Mark Byte = 0101 0000

Assumed target byte = 1010 1111BZ will branch whereas BM and BO will not branchEg 4

TS CHQ CHQBefore : 0111 1000After : 1111 1111

BZ will branch whereas BNZ will notEg 5 TS CHQ CHQ

Before : 1000 0000After : 1111 1111

BNZ will branchBZ will not

NOTES:

BM means branch on mixed zeroes and onesBZ means branch on zerosBO means branch on ones.

Page 153: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 5. Integer Arithmetic 5 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

35

THE BC INSTRUCTION

RX format for BC RR format for BCR

Mask field of BC & BCR

CC = 0 CC = 1 CC = 3

CC = 2Mask field Comment

1000 If condition code = 0, BC & BCR will branch1100 If condition is 0 or 1, BC & BCR will branch0000 Whatever the condition BC & BCR will not

will not branch (no-op instruction)

USAGE BC 8, FOUND = BE FOUND

Assembly language format Machine Language format

BC M1, D2 (X2, B2)

0 8 12 16 20BC 8, FOUNDBE FOUND

Mask

Figure 5-19 BC instruction

OP M1 X2 B2D2

OP M1R2

47 M1 X2 B2D2

47 8 0

Page 154: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 5. Integer Arithmetic 5 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

36

NOTES:

The condition code settings are 2 bit, therefore condition codes can have a value of0, 1, 2 or 3.

ASM1 CSECTSTM 14,12,12(13)BALR 12,0

USING *,12ST 13,SAVE+4LA 13,SAVEOPEN (OUTFILE,(OUTPUT))MVC DATE1+2(2),D1MVC DATE2+2(2),D2MVC COMP+2(2),=C'60'CLC DATE1,COMPBH HIGH1BL LOW1

HIGH1 MVC DATE1(2),=C'19'L 2,DATE1B SUB1

LOW1 MVC DATE1(2),=C'20'L 2,DATE1

SUB1 CLC DATE2,COMPBH HIGH2BL LOW2

HIGH2 MVC DATE2(2),=C'19'L 3,DATE2B FIRST

LOW2 MVC DATE2(2),=C'20'L 3,DATE2

FIRST MVC OUT1,DATE1PUT OUTFILE,OUTLINE1MVC OUT3,DATE2PUT OUTFILE,OUTLINE2C 2,DATE2BH HIGHBL LOW

HIGH MVC OUT5,=C'DATE1'PUT OUTFILE,OUTLINE3B EXIT

LOW MVC OUT5,=C'DATE2'PUT OUTFILE,OUTLINE3

Page 155: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 5. Integer Arithmetic 5 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

37

EXIT CLOSE OUTFILEL 13,SAVE+4LM 14,12,12(13)BR 14

OUTFILE DCBDSORG=PS,MACRF=(PM),DDNAME=SYSOUT,RECFM=FB,LRECL=80,X

BLKSIZE=8000D1 DC CL2'00'D2 DC CL2'98'DATE1 DS CL4DATE2 DS CL4COMP DS CL4OUTLINE1 DS 0CL80

DC CL20'FIRST DATE IS 'OUT1 DS CL4OUT2 DC CL56' 'OUTLINE2 DS 0CL80

DC CL20'SECOND DATE IS 'OUT3 DS CL4OUT4 DC CL56' 'OUTLINE3 DS 0CL80

DC CL20'LARGEST DATE IS 'OUT5 DS CL5OUT6 DC CL56' 'SAVE DS 18F

Page 156: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 5. Integer Arithmetic 5 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

38

CHANGING SIGN AND GENERATING ABSOLUTE VALUES

Opcode Meaning Type

LCR LOAD COMPLEMENT FROM REGISTER RRCopies the negative of V2 i,e its two’s complementinto the register occupied by V1;the result replacesV1.

LPR LOAD POSITIVE ABSOLUTE VALUES RRFROM REGISTERCopies the positive absolute value of V2 into theregister occupied by V1;the result replaces V1.

LNR LOAD NEGATIVE ABSOLUTE VALUE FROM RRREGISTERCopies the negative absolute value of V2 into theregister occupied by V1; the result replaces V1.

Figure 5-20 Changing sign and generating absolute values

NOTES:

V1 , V2 are the operands.

The nature of the result may be determined by use of the conditional branch instructionslike BZ, BNZ, BM, BNM , BP and BNP.

Page 157: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 5. Integer Arithmetic 5 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

39

The condition code for LCR instruction :If result = 0 , condition code = 0If result = - ve , condition code = 1If result = +ve , condition code = 2If result = overflow condition code = 3

The condition code for LPR instruction :If result = 0 , condition code = 0If result = - ve , condition code = nullIf result = +ve , condition code = 2If result = overflow condition code = 3

The condition code for LPR instruction :If result = 0 , condition code = 0If result = + ve , condition code = 1If result = +ve , condition code = nullIf result = overflow condition code = null

Page 158: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 6.Constants and Data Areas Page 6 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

1

UNIT 6: CONSTANTS AND DATA AREAS

OBJECTIVES:

Relocatable and absolute constants

Runtime constants

Assembly time constants

Data areas

Boundary alignments

Page 159: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 6.Constants and Data Areas Page 6 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

2

CONSTANTS

Run-time constants

Assembly-time constants

Absolute constants

Relocatable constants

Data areas

Address boundary

Figure: 6-1 Constants.

NOTES:

In assembly language, the source module can have two types of constants; Constantsused by the program at run time, constants used by the assembler at assembly time.

To differentiate the runtime constants and assembly time constants, all constants areclassified as being either relocatable or absolute.Data Areas are memory locations that are defined by DS directives for specific type ofdata.

The beginning address of the each runtime constants and data area is known as addressboundary.

Page 160: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 6.Constants and Data Areas Page 6 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

3

RELOCATABLE AND ABSOLUTE CONSTANTS

ABSOLUTE Constants are independent of the program memory locationRELOCATABLE Constants are dependent on the program memorylocation.

RELOCATABLE Constants are MAIN MEMORY Addresses.CONSTANT consists of an Algebraic expression containing one or moreterms.

EXAMPLES:

Let R, S, T are non-negative Relocatable constants. A, B, C are absoluteconstants.

Valid absolute constants: -A, A+B, A-B, A*B, A/B, (A+B)/C, R-SValid Relocatable constants: R+A, R-A, R+(S-T), R- (S-T), -RInvalid constants: R+S, R*S, R/S, R+(S-A)

Figure: 6-2 Relocatable and absolute constants

NOTES:

Any algebraic combination of two absolute terms or the difference between twoallocatable terms is an absolute constant. If an absolute term is added to or subtractedfrom relocatable term is a relocatable constant.

Page 161: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 6.Constants and Data Areas Page 6 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

4

RUN-TIME CONSTANTS

RUN-TIME Constants can be specified by two ways:

By means of DC Directive

As VALUE-BASED Constants by use of ‘literals’ or ‘self-definingterms

RUN-TIME Constants occupy memory location when programbeing executed.

‘Type’ determines representation.

Figure: 6-3 Run-time constants

NOTES:

Run-time constants are represented by sequences of bits in memory.

EX:The integer +3 is represented as;

0000 0000 0000 0000 0000 0000 0000 0011

The floating point representation of +3 :

0100 0001 0011 0000 0000 0000 0000 0000The character representation of the 3 is ;

1111 0011

Page 162: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 6.Constants and Data Areas Page 6 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

5

TYPES OF CONSTANTS

ASSEMBLY LANGUAGE FORTRAN COBOL

TEXT Enclosed in quotes USAGE IS DISPLAYBinary Integers INTEGER(full word interger) USAGE IS COMPFloating -point

Single precision REAL USAGE IS COMP-1Double precision DOUBLE PRECISION USAGE IS COMP-2

Decimal ---- USAGE IS COMP-3Hexadecimal ---- ------

Binary Digits ---- ------

Address Program names Program namesVariable names elementary, groups

Record namesStatement labels Paragraph, sections

Figure: 6-4 Types of constants

NOTES:

Representation of the constant in memory contains no indication of what type of constantit is.

Page 163: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 6.Constants and Data Areas Page 6 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

6

DEFINED CONSTANTS (DC)

By using Define Constant (DC) directive we can generate themachine language constants.

DC Directive format:

Name field Opcode Operand

Any symbol DC One or more sub fields,Or separated by commas

Blank

Figure: 6-5 Defined constants (DC)

NOTES:

Each use of the DC directive is written in the single assembly language statement.Comments, continuation and the identifications are also present with the Name fieldopcode and the operand. But those are optional.Each specification of the constant must be preceded by the type code identifying the formin which the constant is being specified.

Page 164: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 6.Constants and Data Areas Page 6 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

7

DC OPERAND SUBFIELD FORMAT

DC OPERAND SUBFIELD COMPONANT:

Required

Duplicator Type Modifier Constant

Optional

Figure 6-6. Dc operand sub field format

NOTES:

Page 165: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 6.Constants and Data Areas Page 6 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

8

VALUE -BASED CONSTANTS

Two types of value-based constants. Used to create data at run time.

Literals

Self-defining terms

Figure: 6-7. Value -based constants

NOTES:

The value-based constant allows the programmer to specify a constant in an operandwithout having to define that constant else where in the program.

Page 166: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 6.Constants and Data Areas Page 6 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

9

LITERALS

Required

= Duplicator Type Modifier Constant

optiona l

Statement1 FCON DC F ‘1’Statement2 L 5,FCONStatement3 L 5, =F ‘1’

Figure: 6-8 Literals

NOTES:

A literal is a symbolic representation of a constant to which the assembler assignsaddress. When single constant is needed in the operand of certain instructions, theprogrammer can use a literal to designate that constant without having to define theconstant with a DC directive.

The literal can’t be used to designate a register address in any instruction, to specify theimmediate data or mask field in any instruction, or to specify the length fields (L, L1, L2)in any instruction. They can, however, are specified in the second operand of any load,Add, Subtract, Multiply, Divide and Move an instruction that is not an RR or SIinstructions.

Page 167: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 6.Constants and Data Areas Page 6 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

10

SELF-DEFINING TERMS

SELF-DEFINING TERMS :

Type of Method of Comments ExamplesTerm representation

Decimal Unsigned decimal Maximum, 3Integer integer OS: 2 31-1 12

Binary B’ ‘ Maximum, B’0001’Integer binary digits OS: 32 bits B’11’

DOS :25 bits B ‘1011’Hexa X ‘ ‘ Maximum, X’5A’Decimal hexadecimal OS:8 hex digit X’6D’Integer digits DOS: 6 hex digit X’5100’Sequence C’ ‘ Maximum, C’Z’Of text text OS: 5 char C’CAT’Characters character DOS:3 char C’A=B’

Figure : 6-9 Self-defining terms

NOTES:

A self defining term is an absolute constant that can be written 5 ways. Those aredecimal integer, Binary integer and hexadecimal integer, sequence of text characters.

The assembler substitutes its 5-bit binary representation.

Page 168: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 6.Constants and Data Areas Page 6 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

11

ASSEMBLY-TIME CONSTANTS

Do not occupy memory locations in user program.

Assembly-time constants:

User defined symbols

Assembly language itself

Memory location symbol (*)

EQU directive

Figure: 6-10 Assembly-time constants

NOTES:

The symbol (*) is used as assembly time constant , is the memory location symbol

Assembly time constants those represented by the symbols that are the part of theassembly language itself and those represented by user defined symbols.

Page 169: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 6.Constants and Data Areas Page 6 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

12

MEMORY LOCATION SYMBOL (*)

Memory address determination

Addressassociatedwith a = Address Number of bytesstatement associatedgenerated or with the Reserved by thePreceding statement preceding statement statement

Figure : 6-11 Memory location symbol ( * )

NOTES:

The value of the memory location symbol depends on the statement in which it is used.

Page 170: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 6.Constants and Data Areas Page 6 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

13

EQUIVALANCE CONSTANTS

EQU directive

Used to define a value for symbol

Format is same as dc directive format

Value of operand is 006

HERE EQU *

Figure : 6-12 Equivalence constants

NOTES:

EQU directive provides an easy means of changing the value of the assembly timeconstant.

We can use EQU directive any number of times in the program.

EQU does not cause any bytes to be generated in the object module.

The symbol HERE is assigned the current value of memory location symbol. The value isnot known in advance by the programmer. HERE is the relocatable constant it representsthe memory location.

Page 171: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 6.Constants and Data Areas Page 6 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

14

VALUE TOO TEDIOUS TO COMPUTE BY HAND

MSG1 DC C ‘ SAMPLE USE OF THE EQU.’

TLNG1 EQU * -MSG1

Figure : 6-13 Value too tedious to compute by hand

NOTES:

TLNG1 is assigned the value computed by subtracting the value that was assigned to thesymbol MSG1.

If the text value changed by the programmer the value TLNG1 is automatically changedwhen the program is reassembled.

The TLNG1 is an absolute constant , since it equals the difference of two relocatableconstants.

Page 172: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 6.Constants and Data Areas Page 6 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

15

VALUE CAN CHANGE IF PROGRAM IS CHANGED

TABLE2 DC F ‘1’DC F ‘2’DC F ‘3’DC F ‘4’DC F ‘5’

TLNG2 EQU *-TABLE2 (value of TLNG2 is 20)TABLE2 DC F ‘1’

DC F ‘2’DC F ‘3’DC F ‘4’DC F ‘5’DC F ‘6’ (new statement added)

TLNG2 EQU *-TABLE2 (value of TLNG2 is 24)

Figure : 6-14. Value can change if program is changed

NOTES:

In first table the TLNG2 value is 20 ie number of bytes reserve for the above table ofintegers ( 4 bytes ).

It is compute by the assembler by using the EQU directive.

If the statements are added to or deleted from the TABLE2 table the value of the TLNG2will be recomputed by the assembler.

Page 173: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 6.Constants and Data Areas Page 6 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

16

VALUE USED SYMBOLICALLY

STATUS DS CL1 device status byteOFF EQU X’00’ device is offON EQU X’FF’ device is on.

CLI STATUS , ONBE POWERON

THIS IS EQUIVALENT TO WRITINGCLI STATUS, X’FF’BE POWERON

STATUS DS CL 1 device status byteOFF EQU X’00’ device is offON EQU X’OF’ device is on but not in useINUSE EQU X’FF’ device is on but being used.

CLI STATUS, ONBE POWERON

CAN BE WRITTEN ASCLI STATUS,X’OF’BE POWERON

Figure : 6-15. Value used symbolically

NOTES:

The use of ON has two advantages, each use of on will be recorded in the cross-reference listing by the assembler and the change can be made to the value of ON withouthaving to change any statements in the program except the EQU that defines ON.

It is the good practice to use symbols that are equated to self-defining terms.

Page 174: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 6.Constants and Data Areas Page 6 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

17

SYMBOLIC REGISTER ADDRESSES AND SYMBOLIC DISPLACEMENTS

OFFSET EQU 12

STM 14,12,12(13)

AND

STM 14,R12,OFFSET(R13)

Figure: 6-16. Symbolic register addresses and symbolic displacements

NOTES:

So far we defined self-defining terms by symbolically. Similar advantage can be gainedfrom symbolically defining the address of general registers and the value of thedisplacement constant.

Page 175: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 6.Constants and Data Areas Page 6 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

18

SYMBOLIC REGISTER ADDRESSES

R0 EQU 0R1 EQU 1R2 EQU 2R3 EQU 3R4 EQU 4R5 EQU 5R6 EQU 6R7 EQU 7R8 EQU 8R9 EQU 9R10 EQU 10R11 EQU 11R12 EQU 12R13 EQU 13R14 EQU 14R15 EQU 15

Figure : 6-17. Symbolic register addresses

NOTES:

Page 176: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 6.Constants and Data Areas Page 6 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

19

INVALID USE OF EQU

SPLNG EQU * - SPCHARSPCHAR DC C’@#$%c&&*()+-=;;?/,.’

SPCHAR DC C’@#$%c&&*()+-=;;?/,.’SPLNG EQU * - SPCHAR

Figure : 6-18. Invalid use of EQU.

NOTES:

In the first definition the EQU is an invalid attempt to define the SPLNG as the numberof characters in the SPCHAR constant.

The reason the first is invalid and the second is valid is that all the symbols appearing inthe operand of EQU directive must have been defined prior to their appearance in theoperand.

Page 177: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 6.Constants and Data Areas Page 6 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

20

RELOCATABLE VS ABSOLUTE CONSTANT

L 4,Y IMPLICIT: USES IMPLIED BASE REGISTERLA 5,Y IMPLICIT: USES IMPLIED BASE REGISTERLA 6,W IMPLICIT: USES IMPLIED BASE REGISTERLA 7,Z EXPLICIT: SAME AS LA 7 , 4(0,0)L 8,Z EXPLICIT: SAME AS L 8 , 4(0,0)…

Y DC F’4’ Y IS A RELOCATABLE CONSTANT (A SYMBOLICADDRESS)Z EQU 4 Z IS AN ABSOLUTE CONSTANTW EQU Y W IS A RELOCATABLE CONSTANT (EQUAL TOAN ADDRESS)

Figure : 6-19 Relocatable vs. Absolute constant

NOTES:

The instruction L8, Z would load the contents of the location whose address is 000004;i.e. it does not load the value of Z, it loads the contents of Z. on the other hand the LA 7,Zinstruction loads.

Page 178: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 6.Constants and Data Areas Page 6 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

21

DATA AREAS

Define Storage (DC) DirectiveGeneral format is :

Name Opcode Operand

Symbol One or more sub fieldsor blank DC separated by comma

DS Operand sub field component:Required

Duplicator Type Modifier Constant

Optional

Figure : 6- 20. Data Areas

NOTES:

DS directive is used to reserve the area of memory for future data. This directive causes adesignated amount of memory space to be reserved in the program but don’t place anydata into the reserved area.

EX for sub field component:

Date DS 2 C LB ModifierType

Duplicator

Page 179: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 6.Constants and Data Areas Page 6 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

22

BOUNDARY ALIGNMENTS AND LENGTH OF AN AREA

Length Type code Constant Boundary Lengthmodifier Alignment

Length Any valid Either no constant Byte boundary Determine viamodifier Type code or any validLength modifier is used constant in the operand

B,C,P,X,Z Any valid constant Byte boundary Determine by No constantsByte boundary Constants 1

Lengthmodifier

H OR Y Either no constants half word boundary

OR Any valid constants2

Is not used in operand

E,F,A,Q ,S Either no constant full word boundary

OR Any valid constants4

D OR L Either no constant double word boundary

OR Any valid constants8

Figure : 6-21. Boundary alignments and length of an area

NOTES:

Page 180: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 6.Constants and Data Areas Page 6 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

23

BOUNDARY ALIGNMENT

DS 0H Half word boundary

DS 0F Full word boundary

DS 0D Double word boundary

Figure : 6-22. Boundary alignment

NOTES:

The most straight forward way to force alignment to the desired boundary for anyconstant or data area is to immediately precede the DC or DS directive that defines itwith one of these three statements.

DS 0HDS 0FDS 0D

EX:

DC X’80000000’

DS 0FDC X ‘80000000’

Page 181: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 6.Constants and Data Areas Page 6 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

24

DS 0D

FORCED AND NATURAL ALIGNMENT

LOCTN OBJECT CODE SOURCE STATEMENT

001000 DS 0F FORCE ALIGNMENT TO FULL WORD001000 80 DC X’80 1-BYTE CONSTANT001004 00000001 DC F’1’ 4-BYTE CONSTANT, ON FULL-WD BDY001008 DS CL25 25-BYTE RESERVED0010028 DS 0D FORCED ALIGNMENT TO DBL-WD BDY0010028 F1F2F3 DC F’F1F2F3’ 3-BYTE CONSTANT00102C 0002 DC H’2’ 2-BYTE CONSTANT,ON HALF WORD BDY001030 DS 18F 18 FULL WORD RESERVED001078 C5D5C4 DC C ‘END’ 3-BYTE CONSTANT,ON BYTE BDY00107B FF DC X’FF’ 1-BYTE CONSTANT,ON BYTE BDY

Figure : 6-23. Forced and natural alignment

NOTES:

Page 182: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 7. Byte and String Manipulation 7-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

UNIT 7: BYTE AND STRING MANIPULATIONS

OBJECTIVES: -

Character constants

Copying bytes

Comparing bytes

Determining the result of a string comparison

String-processing examples

Sub string operations

The execute instruction

The CLCL and MVCL instructions

The TR and TRT instructions

Page 183: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 7. Byte and String Manipulation 7-2Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

BYTE AND STRING MANIPULAITON

The word byte refers to any addressable 8-bit quantity. Asequence of bytes is called a string.

The number of bytes in string called string length.

Copying bytes, comparing two sequence of bytes, and searching asequence of bytes

Figure 7-1 Byte and String Manipulations

NOTES:

Byte-manipulation instructions have three general characteristics. 1All byte-manipulation instructions operate on two strings. One of thestrings in memory; the other may be in memory or in a register, dependingon the instruction itself.2 All byte-manipulation instructions require that the number of bytes beingoperate on the length of the strings be specified either explicitly or implicitly.3 All the byte manipulation instructions described in this chapter treat bytes as 8-bit nonalgebraic quantities: the high-order bit is not considered to be a sign bit butis treated in the same way as the other bits.

Page 184: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 7. Byte and String Manipulation 7-3Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

CHARACTER CONSTANTS

C-Type Constants

C-Type DC Directive

Length Modifier

Figure: 7-2 Character constant

NOTES:

To define data constant as a sequence of characters, we use the C data-type code. Thiscode may be used in DC directive in literals and in self-defining terms. One byte isalways allotted for each specified character. The maximum number of characters thatcan be specified for a single DC or literal constant is 256.

When the length modifier Ln specifies fewer bytes than are needed to contain thebinary representation of the data constant given in a C-type DC directive, theassembler deletes characters from the right. This is called truncation on the right.

When the length modifier Ln specifies more bytes than are needed to contain thebinary representation of the data constant given in a C-type DC directive, theassembler adds blank characters on the right to fill the length that was specified. Thisis called padding with blanks.

Page 185: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 7. Byte and String Manipulation 7-4Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

COPYING BYTES

Copying bytes to and from Registers

Copying bytes from one Area Memory to another

Figure : 7-3 Copying Bytes

NOTES :

There are two sets of byte copying instructions:1 copy bytes from memory into a register or from a register into memory2 copy bytes from one area of memory to another area .The former are calledINSERT and STORE instructions, respectively, the latter are called MOVEinstructions.

Page 186: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 7. Byte and String Manipulation 7-5Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

COPYING BYTES TO AND FROM REGISTERS

Opcode Meaning Type

IC INSERT CHARACTER RXCopies 1 byte from memory into the8 right-most bits of a register, without

altering the other bits in that register.

STC STORE CHARACTER RXCopies 1 byte – the 8 right-most bitsof a register---- into Memory.

ICM INSERT CHARACTERS UNDER MASK RSCopies N bytes, n<4, from memory into aregister. The Number of bytes copied and theirrelative positions in the Register are specifiedin the second operand of the instruction.

STCM STORE CHARACTERS UNDER MASK RSCopies N bytes, n<4, from register intomemory. The Number of bytes copied andtheir relative positions in the Register arespecified in the second operand of the instruction.

Figure 7-4 Copying Bytes to and from Registers

NOTES:

Note that the ICM and STCM instructions are available on the IBM 370, but not on theIBM 360. The letter M in these instructions refers the fact that the second operand of theICM and STCM constitutes a mask rather than a register address or a length.

Page 187: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 7. Byte and String Manipulation 7-6Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

COPYING BYTES TO AND FROM REGISTERS (contd..)

4-bit register

0 8 16 24

4-bit mask

Figure : 7-5 Copying Bytes to and from Registers

NOTES:

The mask is 4-bit field that has a dual purpose. First, the number of bytes that are insertedor stored is equal to the number of 1’s in 4-bit mask. And second, the relative position ofthe bytes in the register is determined by the relative position of the 1’s in the mask , thecorresponding being from left to right,one for one.

Page 188: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 7. Byte and String Manipulation 7-7Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

COPYING BYTES FROM ONE AREA OF MEMORY TOANOTHER

Opcode Meaning Type

MVI MOVE IMMEDIATE S1Copies 1 byte from 12 field of MVIInstruction to memory

Location designated by first operand.

MVC MOVE CHARACTERS SS1

MVCIN MOVE INVERSE SS1

Copies L bytes, L<=256, from memorylocation designated By second operandto memory location designated by first

operand.(L = value of length field in firstoperand..)

MVCL MOVE CHARACTERS LONG RRCopies L bytes, L<=224, from memorylocation designated by Bits 8-31 of thegeneral register specified in the secondoperand Operand to memory locationdesignated by bits 8-31of the Generalregister specified in the first operand.

(L = value of Length field associated withthe first operand.)

Figure : 7-6 Copying Bytes From one Area of memory to Another

NOTES:Note that the MVCL and MVCIN instructions are available on the IBM 370 but not onthe IBM 360. The MVCIN instruction is available as a special feature rather than as astandard instruction on most IBM 370 systems. MVCIN can copy from 1 to 256 bytesfrom one location to another. The sending location’s address is specified in the secondoperand field, and the receiving location’s address and length are specified in the firstoperand field.

Page 189: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 7. Byte and String Manipulation 7-8Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

COMPARING BYTES

Logical quantity and Arithmetic quantity

Comparing Bytes when One of the Strings is in a Register

Comparing Bytes when Both strings are in memory location

Figure: 7-7 Comparing Bytes

NOTES:

In comparing any two bytes, the contents of each byte are treated as unsigned 8-bitnumbers. An unsigned quantity such as a byte contents is called logical quantity, whereassigned quantities such as integers are arithmetic quantities.

Page 190: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 7. Byte and String Manipulation 7-9Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

COMPARING BYTES WHEN ONE OF THE STRINGS IS INA REGISTER

Opcode Meaning Type

CL COMPARE LOGICAL RXCompares two 4-byte strings: first stringis in the register Designated by the firstoperand. Second string is in the Memorylocation designated by the second operand.

CLR COMPARE LOGICAL REGISTER RRCompares two 4-byte strings: first string isin the register Designated by the firstOperand. Second string is in the Register

Designated by the operand.

CLM COMPARE LOGICAL UNDER MASK RSCompares two N-byte strings, n >= 4; firststring is in the Register designated by thefirst operand. Second string is in The memory

location designated by the second operand.

Figure : 7-8 Comparing Bytes when one of the string s is in a Register.

NOTES:To emphasize this distinction, all byte comparison instructions begin with theletter CL, meaning compare logical.The CLM instruction is available on the IBM 370 but not on the IBM 360.The letter M in this instruction refers to the fact that the second operandis a mask.The CLM mask functions in a manner similar to that in the ICM andSTCM instructions .

Page 191: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 7. Byte and String Manipulation 7-10Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

COMPARING BYTES WHEN BOTH STRINGS ARE INMEMORY LOCATIONS

Opcode Meaning Type

CLI COMPARE LOGICAL IMMEDIATE SICompares two 1-byte strings: first string isin the memory Location designated by thefirst operand. Second string is in theImmediate data field of the instruction itself.

CLC COMPARE LOGICAL CHARACTERS SS1Compares two N-byte strings, N<=256: firststring is in the register Designated by thefirst operand. Second string is in the Registerdesignated by the operand.

CLCL COMPARE LOGICAL CHARACTERS LONG RRCompares two possibly unequal-length strings,Maximum Length = 224 –1; first string andsecond string is in the memory Locationdesignated by 8-31 bits of the general registers.

Figure : 7-9 Comparing Bytes both strings are in Memory locations.

NOTES:The CLCL instructions are available on the IBM 370 but not theIBM360.

Page 192: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 7. Byte and String Manipulation 7-11Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

DETERMINING THE RESULT OF A STRINGCOMPARISON

Opcode Meaning Type

BE Branch if v1 equals v2 v1 = v2

BNE Branch if v1 is not equal to v2 v1 = v2

BL Branch if v1 is less than v2 v1 < v2

BNL Branch if v1 is not less than v2 v1 >= v2

BH Branch if v1 is higher than v2 v1 > v2

BNH Branch if v1 is not higher than v2 v1<= v2

Figure : 7-10 Determining The Result of a String Comparison

NOTES:

Whenever compare instruction is used, the results of the comparison may be determinedby means of a condition branch instruction. The same conditional branch instructionsused in determining the result of algebraic comparison are used in determining the resultof string comparison. Each of this six instructions is written with only one operand field.That field designates the address of the instruction to which a branch is made if thecondition being tested is true.If the condition is not true, then no branch ismade,instead,execution of the program continues with the instruction that immediatelyfollows the conditional branch instruction.

Page 193: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 7. Byte and String Manipulation 7-12Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

STRING PROCESSING EXAMPLES

Consider the following elementary but typical string-handling tasks:

Fill an area of memory with blank spaces. Search a string for all occurrences, if any, of the exclamation point

character “!”; replace each occurrence with the period “.”. Search a string for the first occurrence of either a blank or a

comma and determine how many characters in the string precededthe first blank or comma that was found.

Compare an arbitrary 5-byte string with the “END “ to see if it isequal to it or not.

Compare an arbitrary 5-byte string with an each of three 5-bytestrings “END “, “STOP”, “FINIS” and determine which, if any,of these it is equal to.

Figure : 7-11 String Processing Examples

NOTES:The key aspect of these instruction is that they allow a programmer to deal

with strings of arbitrary length , provided their length is known at that time aprogram is written.

Page 194: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 7. Byte and String Manipulation 7-13Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

EXAMPLE 1. FILL AN AREA WITH BLANKS

1 MVI Temp, C’ ’ PUT A BLANK INTO FIRST BYTE2 * OF AREA NAMED ‘TEMP’3 MVC TEMP+1(79), TEMP PROPAGATE BLANK INTO

REMAINDER4 * 79 POSITIONS OF ‘TEMP’ AREA

.

.

.5 TEMP DS CL80 RESERVE 80 BYTES FOR TEMP

.

.

.

Figure : 7-12 Fill an area With Blanks

NOTES:Either of the following two MVC instruction will copy 80 blanks into thearea named TEMP:

MVC TEMP(80),BLANKS EXPLICIT LENGTH FIELDMVC TEMP, BLANKS LENGTH FIELD IMPLIED

To fill an area of memory with blanks, two things must be known: (1) the address of thearea and (2) the number of bytes in the area, i.e., the area’s length. The address can bewritten either symbolically or in base-displacement form. The area’s length, an unsignedinteger, can be written symbolically or numerically, or can be omitted and implied by thelength attribute of the area.

Page 195: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 7. Byte and String Manipulation 7-14Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

DESTRUCTIVE OVERLAP

80 –byte area reserved for TEMP

Overlap Area

Sending area

Receiving area

Destructive overlap

Figure : 7-13 Destructive Overlap

NOTES:

The fig illustrates the concept of destructive overlap, created by an MVC when twoconditions exist simultaneously: (1) the sending area designated by the second operandoverlaps the receiving area designated by the first operand, and (2) the first byte of thereceiving area is with in the sending area.

Page 196: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 7. Byte and String Manipulation 7-15Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

DESTRUCTIVE OVERLAP (CONT….)

Temp area1

Arbitrary data

Arbitrary data

Arbitrary data

….

All blanks

All blanks

2

Figure : 7-14 Destructive Overlap

NOTES:

The above figure represents the sequence of the execution of the two instructions.

In the 1 represents the MVI blank into first byte.

2. Represents MVC propagates first byte in 79 distinct steps, successively replacing thesending area bytes, one at a time, before they are copied into the receiving area.

Page 197: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 7. Byte and String Manipulation 7-16Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

NONDESTRUCTIVE OVERLAP

Overlap Area

Sending area

Receiving area

Figure :7-15 Non Destructive Overlap

NOTES:

The method of Propagation illustrated here can be useful, it can also be disastrous if theprogrammer is unaware of the destructive overlap potential of the sending and receivingfields. If the first byte of the receiving area is not within the sending area, destructiveoverlap cannot occur. If in this situation, the areas partially overlap, they are said tooverlap nondestructively.

Page 198: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 7. Byte and String Manipulation 7-17Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

EXAMPLE 2. REPLACE EXCLAMATION POINTS WITHPERIODS

1 * INITALIZATION2 START LA 4, STRING R4=ADDR OF FIRST BYTE OF STRING3 LA 5, LENGTH R5=LENGTH OF STRING4 * SEARCH FOR ALL EXCLAMATIION POINTS5 COMPARE CLI 0(4), C’, ’ COMPARE CURRENT BYTE TO ‘!’6 BNE NEXTIF NOT EQUAL, ATTEMPT NEXT BYTE7 MVI O(4), C’ ‘ IF EQUAL, ATTEMPT NEXT BYTE8 * LOOP CONTROL9 NEXT LA 4,1(4) R4 = ADDR OF NEXT BYTE OF STRING10 BCT 5, COMPARE DECR STR LNG BY 1,REPEAT LOOP11 * END OF PROCEDURE

.

.

.12 STRING DC C’TEST! WILL IT WORK? YES!’13 LENGTH EQU *--STRING

Figure : 7-16 Replace Exclamation Points with Periods

NOTES:

The BCT instruction in statement 10 Reduces the loop control counter by 1.If thereduction is non zero , the BCT branches to the statement named COMPARE to continuethe search .If the counter reaches 0 no branch will make.

Page 199: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 7. Byte and String Manipulation 7-18Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

EXAMPLE 3. FIND FIRST COMMA OR BLANK IN ASTRING AND COMPUTE LENGTH

1 * INITIALIZATION2 START LA 4, STRING R4=ADDR OF FIRST BYTE OF STRING3 LA 5, LENGTH R5=LENGTH OF STRING4 * SEARCH FOR FIRST BLANK OR COMMA5 COMPARE CLI 0(4), C ‘,’ COMPARE CURRENT BYTE TO COMMA6 BE DONE IF COMMA, TERMINATE SEARCH7 CLI 0(4),C’ ‘ IF NOT, COMPARE TO BLANK8 BE DONE IF BLANK, TERMINATE SEARCH9 * LOOP CONTROL10 LA 4,1(4) R4=ADDR OF NEXT BYTE OF STRING11 BCT 5,COMPARE DECR STR LNG BY 1,REPEAT LOOP12 * COMPUTE NUMBER OF BYTES PRECEDING THE BLANK ORCOMMA13 DONE LA 4.LENGTH ORIGINAL LENGTH MINUS REMAINING14 SR 4,5 LENGTH IS RESULT DESIRED15 * END OF PROCEDURE16 EXIT STH 4,POSIT R4=LENGTH UP TO COMMA OR BLANK17 STRING DC C’FIND COMMA, OR BLANK’18 LENGTH EQU *-STRINGASSBLRCOMPUTES #BYTES IN STRING19 POSIT DS H HALF-WORD FOR PTR TO ‘ ‘ OR ‘,’

Figure : 7-17 Find First comma or Blank in a String And Compute Length

NOTES:

This solution is similar to that of Example 2. The differences are that: (1) the search isterminated either when a comma or blank is found or when there are no more bytes to beexamined, and (2) when the search is terminated, the number of bytes that precede thefirst comma or blank is calculated and stored in the location named POSIT. It alwaysrequires at least two types of statements to examine a string: the first is a comparison, thesecond is a conditional branch determining the results of the comparison.

Page 200: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 7. Byte and String Manipulation 7-19Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

EXAMPLE 4. COMPARE 5-BYTE STRING TO C’END

1 CLC COMMAND(5),STRING COMPARE 5-BYTE STRINGS

2 BE FOUND BRANCH IF EQUAL..

3 STRING DS CL5 5-BYTE AREA RESERVED FOR STRING

4 COMMAND DC CL5’END’ ‘END’ IS PADDED ON RIGHT...

Figure : 7-18 Compare 5-Byte String to c’ End

NOTES:

Both strings are in memory and are of length greater than four, the CLC instruction isused. If the string lengths were greater than 256, or if the strings were of unequal length,the CLCL instruction would have to be used instead of the CLC.

Page 201: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 7. Byte and String Manipulation 7-20Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

COMPARE 5-BYTE STRING WITH STRINGS IN A TABLE

1 * INITIALIZTION2 START LA 4,TABLE R4=ADDR OF FIRST ENTRY IN TABLE3 LA 5,TABLE R5=NUMBER OF ENTRIES4 * COMPARE STRING TO EACH ENTRY (STRING LENGTH IS 5)5 LOOK CLC 0(5,4),STRING COMPARE CURRENT ENTRY TO STRING6 BE EXIT TERMINATE PROCEDURE WHEN FOUND7 * LOOP CONTROL8 LA 4,5(4) IF NOT FOUND, ADV TO NEXT ENTRY9 BCT 5,LOOK DECR #ENTRIES BY 1,REPEAT LOOP10 * END OF PROCEDURE WHEN SEARCH IS COMPLETE, EITHER11 SR 4,4 R4=0 IF NOT FOUND IN TABLE, OR12 EXIT ST 4,POSIT R4=ADDR OF ENTRY THAT WAS FOUND

.13 STRING DS CL5 S-BYTE AREA RESERVED FOR STRING14 TABLE DC CL5’END’ TABLE WITH 3 5-BYTE ENTRIES15 DC CL5’FINIS’16 DC CL5’STOP’17 ENTRIES EQU (*-TABLE)/5 ASSBLR COMPUTES NO.ENTRIES18 POSIT DS F FULL-WD FOR ADDR OF FOUND ENTRY

Figure : 7-19 Compare 5-Byte String With Strings in a Table

NOTES:A table is a set of related items stored in a memoryAn item in a table is almost always called a Table entryThe number of entries in a table depends on length of each entry and amount of spaceavailable for the table.There are three entries given in the statement 14 through 16. But, instead of using thenumber three in the program, Statement 17 lets the assembler calculate the number andassign it to the symbol ENTRIES.Statements 5,8, and 12 require comment. Statement 5 compares the 5-byte string locatedat the current table-entry address given in Register 4 with the 5-byte string located at thesymbolic address STRING. Statement 8 increments the table-entry address in Register4by five (the length of each table entry) so that the second iteration of the loop willexamine the second entry, and the third iteration will examine the third entry.

Page 202: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 7. Byte and String Manipulation 7-21Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

SUBSTRING OPERATIONS

EXAMPLE:

T: ‘A NOT SO TYPICAL STRING NAMED T’S: ‘NOT SO’S1: ‘VERY’S2: ‘UNUSUAL BUT RATHER’

Figure : 7-20 Substring Operations

NOTES:We frequently need to be able to determine if a given substring, say S, exists within some

string T. among the operations we may wish to perform on S are those of deleting eachoccurrence of S from T; replacing S by another string S1; or of inserting a string S2, immediatelyfollowing S in T.

Three operations illustrated for above example as follows1. Deleting S from T would a new string,

TNEW: ‘ A TYPICAL STRING NAMED T ’

2. Replacing S in T by S would yield this new String.

TNEW: ‘ A VERY TYPICAL STRING NAMED T’

3. Inserting S2 immediately following S in T

TNEW: ‘A NOT SO UNUSUAL BUT RATHER TYPICAL STRING NAMED T

Page 203: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 7. Byte and String Manipulation 7-22Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

SUBSTRING OPERATIONS (CONT….)

Pseudocode for string-editing procedures DELETE, REPLACE andINSERT.

STRING-EDIT:

REPEAT UNTIL number of remaining comparisons <= 0

IF current sub string in t = sTHEN

IF operation = replaceCopy s1 to current position in TNEW;Increase length of TNEW by length of S1;Adjust current position in TNEW by length of S!;

ELSEIF operation = insertTHEN

Copy s followed by s2 to current position in TNEW;Increase length of TNEW by length of S plus length f s2;

Adjust current position in TNEW by length of s plus length of s2:END IF;

END IF;{ The following steps are done for all three operations }Adjust current position in T by length of S;Reduce number of remaining comparisons by length of S;

ELSE {current sub string of T did not match s}Copy one character from current position in TTo current position in TNEW;

Increase length of TNEW by 1;Adjust current position in TNEW by +1;Adjust current position in T by +1;Reduce the number of remaining comparisons by 1;END IF;END UNTIL;Copy remaining character (if any) from T to TNEW

And increase length of TNEW accordingly;EXIT STRING_EDIT.

Figure: 7-21 Substring operations

Page 204: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 7. Byte and String Manipulation 7-23Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

STRING-EDITING DELETE PROCEDURE.

* THE FOLLOWING STATEMENTS CAN BE USED TO DELETE EACH OCCURRENCE OF AN ** ARBITRARY-LENGTH SUBSTRING S FROM ANOTHER STRING T.* THE RESULT IS STORED AT SYMBOLIC ADDRESS ‘TNEW’ .* THE LENGTH OF T IS GIVEN AS A HALF-WORD BINARY INTEGER AT * N’.* THE LENGTH OF S IS A HALF-WORD BINARY INTEGER AT ‘M’.* THE LENGTH OF THE RESULTING STRING ‘TNEW’ DEPEDS ON THE *NUMBER* OCCURRENCES OF S IN T. THIS LENGTH IS COMPUTED OF* AND STORED AS A HALF-WORD BINARY INTEGER AT ‘NN’.* THE GIVEN STRINGS S AND T ARE NOT ALTERED. THEIR LENGTHS *ARE* RESTRICTED TO BE LESS THAN OR EQUAL TO 256 , AND *GREATER THAN 0.

* INITIALIZTIONSLA 1,S R1 = ADDR OF SLA 2,T R2 = ADDR OF CURRENT POSITION IN TLA 9,TNEW R9 = ADDR OF CUR. POSITION IN TNEWLH 10, =H’0’ R10=COMPUTED LNG OF TNEW (INITIALLY 0)LH 3, N R3 = NUMBER OF COMPARISONS

REMAINING TOSH 3, M BE MADE. INITIALLY, EQUAL TO

AH 3, =H ‘1’ N – ( M – 1)BNP MOVE IF N < M THEN MAKE NO COMPARISONS

LH 4, M R4 = LENGTH OF S, MINUS 1SH 4,=H’1’ +1 IS SUBTRACTED FOR EX INSTR

* COMPARES TO SUBSTRING OF SAME LENGTH IN T

LOOP EX 4,COMPARE COMPARISON OF M BYTESBE EQUAL BRANCH IF SUBSTRING S IS FOUND

NOTEQUAL MVC 0(1,9),0(2) COPY ONE CHAR FROM T TO TNEWAH 10, =H’1’ INCR LNG OF TNEW BY +1LA 9,1(9) ADJ CUR POSIT IN TNEW BY +1LA 2,1(2) ADJ CUR POSIT IN T BY +1BCT 3,LOOP REDUCE #REMAINING COMPARISONS BY +1B MOVE IF NO MORE COMPAISONS, GO COPY REST OF T

Figure : 7-22 Byte and String Manipulations

Page 205: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 7. Byte and String Manipulation 7-24Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

STRING-EDITING DELETE PROCEDURE (CONT…)

*DELETE OPERATION AVOIDS MOVING S FROM T TO TNEW

EQUAL AH 2,M ADJ CUR POSITION IN T BY LENGTH OF SSH 3,M REDUCE # REMAINING COMPARISONS BY LNG OF SBP LOOP if more comparisons remain, do them

* COPY REMAINING CHARACTER (IF ANY) FROM T TO TNEW

MOVE LA 5,T COMPUTE # CHARACTERS REMAINING IN T, BYAH 5,N SUBTRACTING CUR. POSIT. IN T FROM ADDRSR 5,2 OF FIRST BYTE BEYOND TBNP NOMORE NO MORE CHARS IF S OCCUPIED LAST MAR 10,S BYTES OF T. OTHERWISE, INCR LNG OFSH 5, =H’1’ TNEW, AND PREPARE TO MOVE REMAININGEX 5,MOVEX CHARS TO TNEW VIA EX INSTR

NOMORE 5TH 10,NN STORE COMPUTED LENGTH OF TNEW

T DS CL256 SPACE FOR MAX LENGTH T STRINGS DS CL256 SPACE FOR MAX LENGTH S STRINGTNEW DS CL256 SPACE FOR MAX LENGTH TNEW STRINGN DS H SPACE FOR LENGTH OF T ( 0<LNG<256)M DS H SPACE FOR LENGTH OF S (0<LNG < = 256)NN DS H SPACE FOR LENGTH OF TNEW

FOLLOWING ARE TARGET INSTRS FOR EX INSTRUCTIONS IN ABOVEPROCEDURECOMPARE CLC 0(0,1),0(2) R1=ADDR OF S: R2 = CUR POSIT INT

MOVE MVC 0(0,9),0(2) R9 = CUR POSIT IN TNEW ; R2 = POSITIN T

Figure: 7-23 String Editing-Delete Procedure

NOTES:

Page 206: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 7. Byte and String Manipulation 7-25Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

THE EXECUTE INSTRUCTION

Opcode operand

EX R1, D2 (X2, B2)

Address of target instructionDesignated by second operand

Figure: 7-24 Execute Instruction

NOTES:

When executed at run time, it causes the CPU to execute another instruction, called”target” instruction, located at the address given in the second operand field of the EXinstruction.One of the main uses of the EX instruction depends on its capability for effectively butnot actually changing the second byte (bits 8-15) of the target instruction is executed.This capability makes it possible to vary the length-field contents of SS1 and SS2instructions and to vary the mask-field contents RS and SI instructions.

Page 207: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 7. Byte and String Manipulation 7-26Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

CLCL AND MVCL INSTRUCTIONS

Compare Logical Characters Long (CLCL)

Move Logical Character Long (MVCL)

Figure: 7-25 CLCL and MVCL Instructions

NOTES:

To compare CLCL and MVCL are so named both of these instructions, the number ofbytes operated on is not restricted to be less than or equal to 256,as is the case of CLCand MVC.In CLCL and MVCL the number of bytes can be from 0 to 224 - 1The CLCL and MVCL are designed as RR –type instructions.

Page 208: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 7. Byte and String Manipulation 7-27Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

CLCL INSTRUCTION

OPCODE OPERANDCLCL R1, R2

Reg R1 Reg R1 + 1

1100 Reg R2 Reg0 8 31 0 8 31

1-byte padding character

0 8 31 0 8 31first string

Reg R2 Reg R2 + 1

0 8 31 0 8 31Second string

1-bytepadding character

Figure: 7-26 CLCLNOTES:

The execution of CLCL instructions utilizes two even-odd pairs of registers.Even odd register pair is specified by its even-numbered register address. For the CLCLinstruction one register pair contains address and length of one of the strings to becompared, while the other register pair contains the address and length of the other string.For the CLCL instructions the length of two strings need not to be same.

The String address and lengths as well as the padding character must be loaded into theregisters before the CLCL is executed. The string specified by the first operand field (R1)is determined to be equal, less than, or greater than the string specified by the secondoperand string field.

Address length

Address length

Page 209: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 7. Byte and String Manipulation 7-28Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

CLCL LOOP

Using CLCL within a loop

Figure: 7-27 CLCL LOOP

NOTES:

The contents of two pair of registers are altered during the execution of theinstruction.If the result of the comparison is that the two strings are not equal , the lengthand address fields of each register pair identify the bytes that caused theunequal result.

One consequence of the register alterations just described is that if the CLCL isto be used in a loop, the length fields must be reloaded before each executionof the CLCL, and, depending on the locations of the strings being compared,the address fields may also have to be reloaded into the registers

Page 210: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 7. Byte and String Manipulation 7-29Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

MVCL

Opcode operand

MVCL R1,R2

Reg1 Reg1+1

0 8 310 8 31

Receiving field

Reg2 Reg 2 +1

Figure : 7-31 MVCL

0 8 310 8 31

Specification for sending field 1-byte padding character

Figure: 7-28 MVCLNOTES:

The MVCL Instruction, like the CLCL instruction, utilizes two even-odd pairs of registersduring its execution. The MVCL and the meaning of the contents of the register pairs aresimilar to CLCL.

The number of bytes specified by the length field in Register R1+1 is copied intothe Receiving field, beginning at the address designated in Register R1. The bytes arecopied from the sending field, starting from the address designated in Register R2.if thesending field length is less than the receiving field length, the remaining bytes of thereceiving field are filled with the padding character.If the receiving field length isspecified as zero,no bytes are copied.

Address length

Address length

Page 211: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 7. Byte and String Manipulation 7-30Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

TR AND TRT INSTRUCTIONS

The TR and TRT instructions are used to help reduce the size andrunning time of programs that perform the following types of recurringstring operations:

Replacing some, but not necessarily all, bytes in a string with otherpredetermined bytes and

Searching a string from left to right for the first occurrence of anyone of some predetermined set of bytes.

Figure : 7-29 TR and TRT Instructions

NOTES:

The TR instruction can be used in any situation where it is desirable to replace certainbytes in a string with other byes.

The TRT instruction can be used in any situation where we want to find one of anumber of different characters in a string.

Page 212: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 7. Byte and String Manipulation 7-31Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

GENERAL DESCRIPTION

Argument String

Function String

Length of Argument String

Length of Function String

Opcode Operand

TR D1(L,B1), D2(B2)TRT D1(L,B1), D2(B2)

Argument FunctionString string

Figure : 7-30 General Description

NOTES:

Both the TR and TRT instructions operate on two strings. One string is called theargument string and the other is called the function string. The bytes in the argumentstring are generally not known to the programmer, for it is the bytes in the argumentstring that are replaced by the action of the TR and searched by the action of the TRT.The programmer knows the bytes of the function string; the desired result can beachieved by the TR or TRT instructions.

In the TR and TRT instructions, the argument string and its length are designated by thefirst operand and the function string is designated by the second operand. The length ofthe function string, which is usually 256 bytes, is not specified in either instruction.

Page 213: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 8. Bit Manipulations 8-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

UNIT 8 : BIT MANIPULATIONS

OBJECTIVES :

Shifting Bits

Altering Bits

Testing Bits

The Condition Code

Bit Manipulation Examples

Page 214: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 8. Bit Manipulations 8-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

BIT MANIPULATIONS

Bit Manipulations includes several types of instructions that operate on one ormore consecutive Bits

1. Shifting a bit sequence to the right or left

2. Altering individual bits

3. Testing individual bits

4. Testing the condition code

Figure 8-1 Bit Manipulations

NOTES:

The concept of a byte or character string, a sequence of consecutive bits is called a BitString.

The Bit String is usually used to refer to a sequence of bits.

Page 215: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 8. Bit Manipulations 8-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

SHIFTING BITS

Arithmetic Shifts

Logical Shifts

Figure 8-2. Shifting Bits

NOTES:

In Arithmetic Shifts, the sign bit of the register or register pair is treated differently fromother bits, and the condition code will be set to reflect the nature of the result.

In Logical Shifts, the sign bit is treated in the same manner as all other bits, and thecondition code is not set.

Page 216: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 8. Bit Manipulations 8-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

ARITHMETIC SHIFT INSTRUCTIONS

The four Arithmetic shift instructions are

Opcode meaning Type

SRA Shift Right Single Arithmetic RS

SLA Shift Left Single Arithmetic RS

SRDA Shift Right Double Arithmetic RS

SLDA Shift Left Double Arithmetic RS

Figure 8-3. Arithmetic Shift Instructions.

NOTES:

The 32-bit quantity in the register designated by the first operand is arithmetically shiftedright(or left) N bit positions.

The 64-bit quantity in the even-odd register pair designated by the first operand isarithmetically shifted right (or left) N bit positions.

When the contents of a register or register pair are shifted N bits to the right, the N right-most bits are lost, and the sign bit (bit 0) that existed before the shift began is insertedinto each of the N left-most vacated positions, i.e., into bit positions 1 through N. Thesign bit itself remains unchanged.

When the contents of a register or register pair are shifted N bits to the left, zeroes areinserted into the N right-most vacated positions, the N left-most bits (not including thesign bit) are lost, and condition code 3 – the overview indicator – is set if a bit valuedifferent from that of the sign bit was among those that were lost. The sign bit itselfremains unchanged.

Page 217: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 8. Bit Manipulations 8-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

ARITHMETIC SHIFTS

Reg 9Eg 1 : SRA 9, 31 Before : 0001 0001 0001 0001 0001 0001 0001 0001

After : 0000 0000 0000 0000 0000 0000 0000 0000

Eg 2: SRA 8,5 Reg 8Before : 1111 1111 1111 1111 1111 1010 1010 1000

After : 1111 1111 1111 1111 1111 1110 1101 0101

Eg 3: Propagation of sign bitsSLA 4,4 (10)

Reg 10: 0000 0000 0000 0000 10001000

Displacement : 0000 00000100

00 1100

Reg 4

Before : 1111 1010 1111 1000 0000 0111 0000 0110

After : 0000 0000 0111 0000 0110 0000 0000 0000

Eg 4 : Reg 6 Reg 7SRDA 6, 3 Before : 1A 1B 1C 1D 1E 1F 10 11

After : 03 43 63 83 A3 C3 E2 02

Eg 5 : SLDA 6, 11 Before : 1A 1B 1C 1D 1E 1F 10 11

After : 58 ED E8 F0 F8 80 88 00Figure 8-4. Arithmetic Shifts

NOTES:

In an arithmetic shift the sign bit of a register or register pair is treated differently fromthe other, bits and the condition code has a value which denotes the status of the result.

Page 218: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 8. Bit Manipulations 8-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

In a logical shift the sign bit is treated as similar to any other bit and the condition codeis not set.

Page 219: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 8. Bit Manipulations 8-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

LOGICAL SHIFTS

Logical Shifts are used in conjunction with other bit – and byte-manipulation toseparate or join sequences of bits.

Opcode Meaning Type

SRL Shift Right Single Logical RS

SLL Shift Left Single Logical RS

SRDL Shift Right Double Logical RS

SLDL Shift Left Double Logical RS

Figure 8-5. Logical Shifts

NOTES:

When the contents of a register or register pair are shifted N bits to the right, the N right-most bits are lost, and zeroes are inserted into the N left-most vacated positions.

When the contents of a register or register pair are shifted N bits to the left, the N leftmost bits are lost, and zeroes are inserted into the N right-most vacated positions.

Regardless of the nature of the result of a logical shift instruction, the condition code isnot set.

Page 220: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 8. Bit Manipulations 8-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

LOGICAL SHIFTS

SRL,

Reg 8SRL 8, 5 Before : 1111 1111 1111 1111 1111 1111 1010 0100

After : 0000 0111 1111 1111 1111 1111 1111 1101

SLL 8, 4(10) Reg 10 : 0000 0000 0000 0000 1000 1000Displacement : 0000 0000 0100

00 1100Reg 8

Before : 0000 1001 0000 1000 0000 0111 0000 0110After : 1000 0000 0111 000 0110 0000 0000 0000

SRDL 6, 3 Reg 6 Reg 7Before : 1A 1B 1C 1D 1E 1F 10 11After : 03 43 63 83 A3 C3 E2 02

SLDL 6, 11 Reg 6 Reg 7Before : 1A 1B 1C 1D 1E 1F 10 11After : D8 E0 E8 F0 F8 80 88 00

Figure 8-6. Logical Shifts.

NOTES:

When the contents of a register or register pair are shifted X bits to the right then X rightmost bits are lost and zeros are inserted into the X left - most positions. The sign bit istreated as any other bit. The condition code is not set.

Opcode Type

SRL, SLL, SRDL, SLDL RS

Page 221: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 8. Bit Manipulations 8-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

ALTERING BITS

The Assembly Language Programs use the individual bits in a bit string to representstatus information. This type of information can be used to control the flow of a programand to keep succinct record of events that occur during the execution of a program.

Bit position: 0 1 2 3

OPEN TYPE I/O EOF

Figure: 8-7. Altering Bits.

NOTES:

Page 222: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 8. Bit Manipulations 8-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

USE OF BITS AS INDICATORS

Each bit in this bit string has a value of 0 or 1. These values could imply the status of afile as follows.

Bit Value Meaning

OPEN bit 0 = file not opened1 = file opened

I/O bit 0 = if opened, file is used for input only1 = if opened, file is used for output only

TYPE bit 0 = sequential file1 = indexed sequential file

EOF bit 0 = file has not reached end-of-file1 = file has reached end-of-file

Figure 8-8. Use of bits as indicators.

NOTES:

Page 223: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 8. Bit Manipulations 8-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

BIT VARIATIONS

Bit position: 0 1 2 3 4 5

OPENI/O TYPE EOF

The bits could have following meaning: BIT ValueMeaning

OPEN BIT 0 = file not opened1 = file opened

I/O BITS 00 = no meaning01 = opened for input only10 = opened for output only11 = opened for input and output

TYPE BITS 00 = none of the standard types01 = sequential10 = indexed sequential11 = direct

EOF BIT 0 = not yet end-of- file1 = end-of-file

Figure 8-9. Bit operators.

NOTES:In general, n consecutive bits will provide 2 n possible meanings.

There are two instructions that test bits, the test under mask (TM) and test and set (TS)instructions.

Page 224: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 8. Bit Manipulations 8-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

BOOLEAN OPERATIONS

AND

OR

EXCLUSE-OR

Figure 8-10. Boolean Operators.

NOTES:

The Boolean operations OR, AND, EXCLUSIVE-OR have three characteristics incommon:

1. They operate on two bit strings, each of same length.

2. Only one of the bit strings, the target, is altered. The other bit string, the mask, selectsthe individual bits that are to be altered in the target bit string. Each bit in the mask thatis a ‘1’ selects the correspondingly positioned bit in the target, regardless of whether thattarget bit is a ‘0’ or a ‘1’.

3. The Mask bit string is matched, bit for bit, with the target bit string: each bit in themask operates on the corresponding bit in the target. The sign bit is not given any specialtreatment.

Page 225: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 8. Bit Manipulations 8-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

THE BOOLEAN OR OPERATION.

Mask Bit Target Bit Resulting Bit

0 0 0 mask bit = 0target bit unchanged

0 1 1------------------------------------------------------------------------------------------------

1 0 1 mask bit = 1target bit is set to 1

1 1 1

Figure 8-11. The Boolean OR Operation.

NOTES:

The Boolean OR operation sets the selected target bits to1, regardless of what theprevious values of those bits were.

Page 226: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 8. Bit Manipulations 8-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

THE BOOLEAN AND OPERAION

Mask Bit Target Bit Resulting Bit

0 0 0 mask bit = 0target bit reset to 0

0 1 1

-----------------------------------------------------------------------------------------------

1 0 0 mask bit = 1target bit unchanged

1 1 1

Figure 8-12. The Boolean AND Operator.

NOTES:

The Boolean AND operation preserves the value of the selected target bits and resets theremaining bits to zero, regardless of what the previous values of those bits were.

Page 227: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 8. Bit Manipulations 8-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

THE BOOLEAN EXCLUSIVE-OR OPERATION

Mask Bit Target Bit Resulting Bit

0 0 0 mask bit = 0target bit unchanged

0 1 1

1 0 1 mask bit = 1target bit reversed

1 1 0

Figure 8-13. The Boolean EXCLUSIVE-OR Operation.

NOTES:

The Boolean EXCLUSIVE-OR operation reverses the value of the selected target bits :If a selected bit was 0, it is set to 1; if it was 1, it is reset to 0.

Page 228: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 8. Bit Manipulations 8-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

TESTING BITS

Two instructions test individual bits to determine whether their values are 0 or 1. Both ofthese test the bits of a byte in memory.

The Two instructions that test individual bits in a byte are

1. Test under Mask (TM)

2. Test and Set (TS)

Figure 8-14. Testing Bits.

NOTES:

TM is the more generally useful of the two. It tests up to 8 bits at once, without alteringthe bits that are tested.

TS tests only one bit- The higher order or “sign” bit of a byte – and then sets all the bitsin the tested byte to 1.

Page 229: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 8. Bit Manipulations 8-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

TEST UNDER MASK

The TM is an SI- type instruction:

Assembly language format machine language format

Opcode operand opcodeoperand

TM D1(B1), 12

0 8 16 20

TM S1, 12

implieddisplacement

implied base register

Figure 8-15. Test under Mask.

NOTES:

The 8 bits in the 12 mask field correspond, one for one, left to right, with 8bits in thetarget byte(addressed by the first operand field). Each 1-bit in the mask causes thecorresponding bit in the target byte to be selected for testing. Each 0-bit in the maskcauses the corresponding bit in the target byte not to be selected for testing.

The result of the TM instruction can be determined by means of conditional branchinstructions:BZ Branch if Zeroes

Branches if all tested bits are 0’s, or if all mask bits are 0’sBO Branch if Ones

Branches if all tested bits are 1’sBM Branch if Mixed Zeroes and Ones

Branches if some tested bits are 0’s and the other tested bits are 1’s.

91 12 B1 D1

91 12

Page 230: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 8. Bit Manipulations 8-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

TEST AND SET

The TS is an S-type instruction: It requires only a single operand field. As shown below,no mask is necessary because the TS always tests the high-order bit of a byte.

Assembly language format machine language format

Opcode operandTS D1 (B1)

TS S10 8 16

space reserved but impliedunused in the TS displacement

implied base register

Figure 8-16. Test and Set

NOTES:

The result of the test made by the TS instruction can be determined by means ofconditional branch instructions:

BZ Branch if ZeroBranches if the tested bit had a value of 0

BNZ Branch if Not ZeroBranches if the tested bit had a value of 1

93 B1 D1

93

Page 231: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 8. Bit Manipulations 8-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

CONDITION CODE

The condition code is a hardware indicator that records the nature of results of certaininstructions. The indicator consists of only two bits, only four possible conditions canbe coded. These are known as condition code settings.

00 = Condition Code 0

01 = Condition Code 1

10 = Condition code 2

11 = Condition Code 3

Figure 8-17. Condition Code

NOTES:

The setting of the condition code can be examined and its value determined by twoinstructions designed for this purpose .

1.Branch on Condition (BC)

2.Branch on Condition via Register (BCR)

Page 232: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 8. Bit Manipulations 8-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

CONDITION CODE VALUE

The condition code value when either of these instructions is executed determineswhether or not the branch is made. The BC or BCR instruction determine with setting orsettings of the Condition code will cause a branch.

RX format for BC instruction RR format for BCR

Mask field of BC & BCR

Right-most bit denotescondition code 3

third bit denotes condition code 2second bit denotes condition code 1

left-most bit denotes condition code 0

Figure 8-19. Condition code value.

NOTES:

OP M1 X2 B2 D2 OP M1 R2

Page 233: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 8. Bit Manipulations 8-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

BC AND BCR MASK FIELD

Mask field Meaning

1000 if the condition code is 0, the BC & BCR will branch

1100 if the condition code is 0 or 1, the BC & BCR will branch

1010 if the condition code is either 0 or 2, the BC & BCR will branch

0011 if the condition code is either 2 or 3, the BC & BCR will branch

1111 whatever the condition code setting is, the BC & BCR willbranch (thereby constituting an unconditional branch).

0000 Whatever the condition code setting is, the BC & BCR will notbranch(thereby constituting a so-called “no-op”, or no operation,instruction).

Figure 8-19. BC & BCR Mask field.

NOTES:

The variations are created by different values of the mask field and offen called ExtendedMnemonics .

Extended mnemonics are used so that we need not remember the appropriate mask field.For example, the instruction

BE FOUNDIs identical to the instruction

BC 8, FOUND

Page 234: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 8. Bit Manipulations 8-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

CONDITION CODE SETTINGS FOR NONPRIVILEGED INSTRUCTIONS

Integer Operations

Byte Operations

Bit Operations

Decimal

Floating Point

Miscellaneous

Figure 8-20. Condition code settings for Nonprivileged Instructions

NOTES:

Page 235: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 8. Bit Manipulations 8-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

INTEGER OPERATIONS

Instruction condition condition code 1 condition code2 condition code 3code 0

Add A,AR,AH result is 0 result is negative result is positive operation genera-Subtract S,SR,SH ted an overflow

Add AL,ALR result is 0, result is not 0, result is 0, result is not 0,Subtract SL,SLR With no carry with no carry with carry with carry

(AL,ALR)only

Compare C,CR,CH both operands first operand less first operandAre equal than second greater than - - -

SecondLoad LCR result is 0 result is negative result is positive overflow

generatedLNR result is 0 result is negative - - - - - -LPR result is 0 - - - result is positive overflow

generatedLTR result is 0 result is negative result is positive - - -

Shift SLA,SLDA, result is 0 result is negative result is positive overflowGeneratedSRA,SRDA result is 0 result is negative result is positive - - -

Figure 8-21. Integer Operations.

NOTES :

Page 236: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 8. Bit Manipulations 8-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

BYTE OPERATIONS

Instruction condition condition code 1 condition code2 conditioncode 0 code 3

Insert ICM all inserted bits 0, 1st inserted bit is 1 1st inserted bit is - - -Or all mask bits 0 0 but not all are 0

Compare CL, both operands are 1st operand less 1st operand greaterCLR,CLC,CLI equal than second than second - - -

CLCL operands are 1st operand less 1st operand greaterequal, or have than second than second - - -zero lines

CLM bytes selected are 1st operand field 1st operand fieldequal or mask bits less than second greater than second - - -are all zero

Copy MVCL first operand 1st operand length 1st operand length destructivelength equals less than second greater than second overlap(nosecond operands bytes copied)

Translate TRT all argument bytes one or more argu- such stopped ontested all function ment bytes not last argument byte - - -bytes 0 tested

Figure 8-22. Byte Operations.

NOTES:

Page 237: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 8. Bit Manipulations 8-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

BIT OPERATIONS

Instruction condition condition code 1 condition code2 conditioncode 0 code 3

AND N,NC,NI, result is 0 result is not 0 - - - - - -NR

OR O,OC,OL, result is 0 result is not 0 - - - - - -OR

EXCL-OR X, result is 0 result is not 0 - - - - - -XC,XI,XR

TEST TM all selected bits 0 some set bits are all selectedor all mask bits 0 0 and some bits - - - bits are one’s

are 1

TS left most bit of left most bit oftested byte is 0 tested byte is 1 - - - - - -

Figure 8-23. Bit Operations

NOTES:

Page 238: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 8. Bit Manipulations 8-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

DECIMAL

Instruction condition condition code 1 condition code2 conditioncode 0 code 3

Add AP,ZAP result is 0 result is negative result is positive operation gene-Subtract SP ted an overflolw

Compare CP both operands first operand less first operand great -------------Are equal than second er than second

Shift SRP result is zero result is negative result is positive overflowgenerated

Figure 8-25. Bit Operations

NOTES:

Page 239: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 8. Bit Manipulations 8-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

FLOATING POINT

Instruction condition condition code 1 condition code2 conditioncode 0 code 3

Add AE,AER, mantissa of result is negative result is positiveAD,ADR,AU, result is 0 - - -

AUR,AW,AWRAXR

Subtract SE,SER mantissa of result is negative result is positive ------SD,SDR,SU, result is 0

SUR,SWR,SXR

LoadLCER,LCDR result mantissa result is negative result is positive --------

is 0.LNER,LNDR result mantissa result is negative -------- ------

is 0.LNPR,LPDR result mantissa I-------------- result is positive ----------

is 0.LTER,LTDR result mantissa result is negative result is positive -------------

Is0.

Compare CE, both operands first operand less first operandCER,CD,CDR are equal than second greater than -------

second

Figure 8-25. Bit Operations

NOTES:

Page 240: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 8. Bit Manipulations 8-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

MISCELLANEOUS

Instruction condition condition code 1 condition code2 conditioncode 0 code 3

Compare CS, compared oper- compared operandsAnd swap CDS ands equl,second not equal,first is --------- ----------

one is replaced replaced

Set pgm SPM (the condition code is set to the value of bits 2 and 3 of theMask designated register)

Store STCK clock in set state clock in not-set clock in error clock in stopp-clock state state ed state or

not-operational

Editing ED, last edited field last edited field is last edited fieldEDMK is 0. negative is positive ---------------

Figure 8-26. Bit Operations

NOTES:

Page 241: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 8. Bit Manipulations 8-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

NONPRIVILEGED INSTRUCTIONS THAT DO NOT SET CONDITION CODE.

Branches Branch and link BAL BALR BAS BASRBranch on Condition BC BCRBranch on Count BCT BCTRBranch on Index BXH BXLE

Integer Multiply M MR MHOperations Divide D DR

Load L LM LHStore ST STM STH

Byte Copy IC STC STCM MVC MVI MVCINoperations Translate TR

Bit Shift Logical SRL SRDLoperations SLL SLDL

Decimal Multiply MPOperations Divide DP

Copy MVN MVO MVZ

Floating-point Multiply ME MER MD MDR MXD MXDROperations MXR

Divide DE DDR DD DDRHalve HER HDRRound LRER LRDRLoad LE LER LD LDRStore STE STD

Miscellaneous Decimal-binaryOperations Conv. CVB CVD

Decimal-EBCDICConv. PACK UNPK

Execute EXLoad Address LAMonitor Call MCSupervisor Call SVC

Figure 8-27. Nonprivileged instructions that do not set the condition code.

NOTES:

Page 242: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 8. Bit Manipulations 8-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

BIT MANIPULATION EXAMPLES

Bit Manipulation Instruction

1. Shift Instructions

2. Boolean Instructions

3. TM Instructions

4. The Conditional Branch Instructions

Figure 8-28. Bit manipulation examples

NOTES:

The shift instructions is used as a succinct method of multiplying and dividing by powersOf two, enable a program to separate and link adjacent bit strings.

The Boolean instructions enable a program to isolate bits, to set individual bits to 0 or1,and to reverse the settings of bits.

The TM instruction provides an easy method for testing the values of individual bits,facilitating the use of status indicators and switches.

The BC & BCR operations underlie the conditional branch instructions without whichdecisions could not be made by programs.

Page 243: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 8. Bit Manipulations 8-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

STATUS BYTE

The Instantaneous status of a file is to be recorded in a single status byte, as follows:

Bit name Bit position within byte Value of bits meaning

OPEN 0 0 = file is closed1 = file is opened

IO 1,2 00 = no meaning01 = opened for input only10 = opened for output only11 = opened for input and output

TYPE 3,4 00 = none of the standard types01 = sequential10 = Index sequential11 = direct

EOF 5 0 = not yet end-of-file1 = end-of-file

bit position 0 1 3 5 6

bit meaning

Figure 8-29. Status Byte.

NOTES:

The whole byte is used for the status information, even though there are two unused bitsin the byte. This serves two purposes.1. It leaves a little room for defining other status bits at a later time.

2. It facilitates use of the bit manipulation instructions that can only address of wholebyte.

OPEN IO TYPE EOF

Page 244: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 8. Bit Manipulations 8-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

DEFINITIONS FOR A FILE –STATUS BYTE

1 * File status information

2 FILESTAT DC B’00000000’ FILE STATUS INITIALLY 0’S

3 OPEN EQU B’10000000’ BIT 0 0=CLOSED, 1=OPEN

4 IO EQU B’01100000’ BIT 1,2 FOR I/O STATE:

5 IO IN EQU B’00100000’ 01= INPUT ONLY

6 IO OUT EQU B’01000000’ 10= OUTPUT ONLY

7 IO INOUT EQU B’01100000’ 11= INPUT & OUTPUT

8 TYPE EQU B’00011000’ BIT 3,4 FOR FILE TYPE

9 TYPSAM EQU B’00001000’ 01=SEQTL (SAM)

10 TYPISAM EQU B’00010000’ 10=INDEXED (ISAM)

11 TYPBDAM EQU B’00011000’ 11=DIRECT (BDAM)

12 EOF EQU B’00000100’ BIT 5 0=NOT EOF, 1=EOF

Figure 8-30. Definitions for a file-status byte.

NOTES:Examples of using status bytes:When the file is opened OI FILESTAT, OPEN SET OPEN BIT TO ‘1’If the file is opened as an indexed sequential file

OI FILESTAT, TYPISAM SET ISAM BIT TO ‘1’If it is necessary to determine whether the file is opened for output or input

TM FILESTAT, IOOUT SEE IF OUTPUT BIT IS ‘1’BO OUTPUT BRANCH IF IT IS ‘1’TM FILESTAT, IOIN SEE IF INPUT BIT IS ‘1’BO INPUT BRANCH IF IS ‘1’

. . . . . . . . . . . . . . . .OUTPUT EQU * file is opened for output

.INPUT EQU * file is opened for input

Page 245: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 8. Bit Manipulations 8-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

USE OF A STATUS WORD

several bytes in the manner described as a full word or several fullwords. To use the full words the following techniques are used Setting

Testing

Resetting

Inverting

Figure 8-31. Use of a status word.

NOTES:

Sometimes 8 bits are not used to enough to represent the status of a situation, for that weuse several bytes in the manner of as a full word or several full words.

In each bit corresponds to a terminal, the bits are numbered from left to right0,1,2,3,….,31, and these numbers correspond to the terminal numbers.

Each bit records the state of one terminal: if bit N is 0, then terminal N is not in use; ifthe bit N is a 1, then terminal N is being used.

Page 246: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 8. Bit Manipulations 8-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

TESTING OR RESETTING BIT N

To test or reset the Nth bit in the status word, that word can be placed intoa register and the Nth bit isolated from the other bits. The isolation is achieved bySHIFT and AND instructions

LH 2, BITN R2= VALUE OF N

L 3, STATUS R3= STATUS WORD

SLL 3, 0(2) MOVE BIT N TO POSITION 0

N 3, PATTERN SET ALL BUT BIT # 0 TO ‘0’

Figure 8-32. Testing or Resetting Bit N

NOTES:

It is assumed that BIT N is the half word location that has the value of N, that status isthe location of the status word, and that pattern is a location that contains a one bit andposition 0 and 0 bits everywhere else.

PATTERN DC X ‘8 0 0 0 0 0 0’

Once bit N is in position 0, it is isolated by the AND instruction using the pattern word.At this point, bit N is in an known position. It can be easily tested, reset, set, or inverted.

Page 247: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 8. Bit Manipulations 8-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

SETTING OR INVERTING BIT N

To set bit N to 1, these statements are suffice:

LH 2, BITN R2=VALUE OF NL 3, PATTERN R3= ‘1’ IN POSITION # 0SRL 3, 0 ( 2 ) MOVE ‘ 1 ‘ TO POSITION # NO 3, STATUS ‘OR’ THE STATUS BITS INTO R3,ST 3, STATUS PUT RESULT BACK INTO STATUS WORD

To invert bit N, from 0 to 1 or vice versa these statements are suffice:

LH 2, BITN R2= VALUE OF NL 3, PATTERN R3= ‘ 1 ‘ IN POSITION # 0SRL 3, 0 ( 2 ) MOVE ‘1’ TO POSITION # NX 3, STATUS REVERSE BIT # N, PRESERVE OTEHRSST 3, STATUS PUT RESULT BACK INTO STATUS WORD

Figure 8-33. setting or inverting Bit N

NOTES:

Trace these situations for two different cases:

(1) in which the Nth bit is originally 0(2) in which the Nth bit is originally 1

Page 248: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 8. Bit Manipulations 8-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

CONVERT HEX DIGITS TO EBCDIC CODES

To convert hex digit or line printer ,the digit must be represented in the EBCDICcharacter scheme.

1 * THE SET OF STATEMENTS GENERATES EIGHT CONSECUTIVE BYTES IN2 * EBCDIC CODE FORMAT CORRESPONDING TO EIGHT CONSECUTIVE3 * HEX DIGITS4 * THE HEX DIGITS ARE ASSUMED TO BE IN THE FULL WORD NAMED5 * ‘DIGITS’6 * THE EBCDIC BYTES ARE PLACED IN THE AREA NEAMED ‘RESULT’7 LA 1, EBCDIC R1= ADDR OF EBCDIC CODE TABLE8 LA 2, RESULT R2= ADDR OF FIRST RESULT BYTE9 L 3, =F ‘ 8’ R3= LOOP-CONTROL COUNTER10 L 7, DIGITS R7= HEX DIGITS11 * GENERATE AN EBCDIC BYTE12 NEXT LH 6, = H’ 0’ R6 IS CLEARED, THEN NEXT HEX13 SLDL 6, 4 DIGIT IS SHIFTED INTO IT, AND14 LA 8, 0 ( 6, 1 ) IS USED TO COMPUTE ADDR OF15 MVC 0 (1,2), 0(8) CORRESPONDING EBCDIC CODE16 * LOOP - CONTROL17 LA 2, 1(2) ADJUST ADDR TO NEXT RESULT BYTE18 BCT 3, NEXT REPEAT TILL EIGHT DIGITS DONE

.19 DIGITS DS F HEX DIGITS(FULLWORD) TO BE CONV20 RESULT DS CLB AREA FOR RESULT BYTES21 EBCDIC DC C’0123456789ABCDEF’ EBCDIC CODES FOR HEX DIGITS

.

.Figure 8-34. Convert hex digits to EBCDIC codes

NOTES:

Page 249: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 8. Bit Manipulations 8-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

CONVERSION OF HEX DIGITS TO EBCDIC

32 BITSHEX DIGITS:

EBC-DIC

64 BITS

HEX DIGITS:

EBC-DIC

Figure 8-35. conversion of hex digits to EBCDIC

NOTES:

In this example, the goal is to convert a sequence of eight arbitrary hex digits into theirEBCDIC codes.

Two things should be noticed in this solution:1. The use of the double logical left shift in the statement 13 in the previous slide to

isolate a hex digit in a register and simultaneously position the next hex digit for itseventual isolation

2. The use of the LA instruction in Statement 14 to compute the address of the correctEBCDIC byte, based on the numeric value of the hex digit.

0 1 2 3 4 5 6 7

F 0 F 1 F 2 F 3 F 4 F 5 F 6 F 7

8 9 A B C D E F

F 8 F 9 C 1 C 2 C 3 C 4 C 5 C 6

Page 250: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 8. Bit Manipulations 8-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

TRANSLATE FROM DECIMAL TO BINARY

Whenever a data enter a computer’s memory from an I/O device such asa terminal or acard reader, they are stored in which the device transmitted. This type of format is theEBCDIC code scheme.

In EBCDIC format, the number 1358 is represented as a 4-byte quantity whose hexrepresentation is

1 3 5 8and whose binary representation is

Figure 8-36. Translate from decimal to binary

NOTES:

1.The so-called zone bits 1111 of the EBCDIC scheme must be removed for each digit.

2.The remaining bits of each digit, i.e., the bits that represent each digit in binary form,must be multiplied by the appropriate power of 10.

3.each of the product in step 2 must be added together to form the binary integer result.

F1 F3 F5 F8

1111 0001 1111 0011 1111 0101 1111 1000

Page 251: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 8. Bit Manipulations 8-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

TRANSLATING A NON-NEGATIVE INTEGER FROM EBCDIC TO BINARY

1 * THIS SET OF STATEMENTS TRANSLATES F NONNEGATIVE INTEGER2 * FROM ITS EBCDIC REPRESENTATION TO ITS FULL-WORD BINARY3 * REPRESENTATION4 *5 * THE EBCDIC REPRESENTATION IS ASSUMED TO BE EIGHT BYTES LONG,6 * RIGHT JUSTIFIED, BEGINNING AT SYMBOLIC ADDRESS ‘INT10’. IT MAY7 * HAVE LEADING ZEROES OR LEADING BLANKS8 *9 * THE RESULTING BINARY REPRESENTATION WILL BE STORED AT ‘INT2’10*11* INITIALIZATION12 LA 2,INT10X R2 = ADDR OF LOW-ORDER BYTE13 LA 3,P10 R3 = ADDR OF TABLE OF 10 * * N14 LH 4, =H’ 8 ‘ R4 = MAX # DIGHTS TO BE TRANSLATED15 LH 5, =H’ 0 ‘ R5 =ACCUMULATED RESULT (INITIALLY

ZERO)16 *17 NEXT CLI 0(2), X’F0’ IF CURRENT BYTE VALUE NOT BETWEEN18 BL DONE 0 AND 9 ( IN EBCDIC) THEN A LEADING19 CLI 0(2), X’F9’ BLANK HAS BEEN REACHED20 BH DONE21 * MULTIPLY CURRENT DIGIT BY 10 * * N :22 IC 7, 0 (2) PUT EBCDIC DIGIT INTO ODD-NUMBERED23 N 7,PATTERN REGISTER, AND REMOVE ITS ZONE BITS.24 M 6, 0 (3) THEN MPY BY CURRENT POWER OF 10, AND25 AR 5, 7 ADD PRODUCT TO RESULT IN REG 5.26 *27 SH 2, =H’+1’ FOR LOOP CONTROL, ADJUST BYTE ADDRESS28 AH 3, =H’+4’ TO NEXT DIGIT, AND TABLE ADDR TO NEXT29 BCT 4, NEXT 10 * * N; THEN REPEAT UP TO EIGHT TIMES.30 *31 DONE ST 5, INT2 SAVE RESULTING BINARY INTEGER

.

.32 INT2 DS F BINARY INTEGER RESULT (FULL WORD)33 INT10 DS CLB EIGHT EBCDIC DIGITS, RIGHT- JUSTIFIED34 INT10X EQU * - 1 ADDR OF LEAST. SIGNIFICANT EBCDIC DIGIT35 PATTERN DC X’0000000F’ MASK PRESERVES RIGHT-MOST FOUR BITS36 *37 P10 DC F’1,10,100,1000’ TABLE OF POWERS OF 10, I.E.

Page 252: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 8. Bit Manipulations 8-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

38 DC F’1E4,1E5,1E6,1E7’ 10 * * N FOR N = 0, 1, 2, . . . . , 7

Figure 8-37. Translating a nonnegative integer from EBCDIC to binaryNOTES:

Page 253: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 8. Bit Manipulations 8-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

Page 254: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 9. Macros Page 9-Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

1

UNIT 9 : MACROS

OBJECTIVES :

A sample macro

Defining macros

Use of control directives

VSAM processing - assembler

Creating ACDS and RPLS

ACD MACRF parameter

RPL OPTCD parameter

Assembler error handling

Page 255: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 9. Macros Page 9-Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

2

Macro Definition

The set of statements that a macro represents must be defined beforethe macro can be used in a source module.some macros,such as GET andPUT I/O macros,are defined by system programmers and may be used byany assembly language programmers.

A Macro is an opcode that represents a set of one or more assemblylanguage instructions, directives, or other macros. It is a kind of high-levelextension of assembly language.

Figure : 9-1 Macro Definition

NOTES:

Page 256: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 9. Macros Page 9-Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

3

MACRO - PROTOTYPE STATEMENT

Figure : 9-2 Macro-prototype statement

NOTES:

The second statement of the definition must describe the name, opcode andoperand fields of the macro.

This statement is termed as prototype statement or at times the model statement.

Each positional parameter is represented by a variable symbol and each keywordparameter is represented by a variable symbol followed immediately by an equal sign.

Name Field Opcode Operand

Variable Macro's List of positionalSymbol or name and/or keywordBlank parameters

MACRO - PROTOTYPE STATEMENT

Page 257: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 9. Macros Page 9-Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

4

MACRO - HEADER STATEMENT

Figure : 9-3 Macro - header statement

NOTES:

The first statement of the macro definition must be a MACRO directive, termed asHeader-Statement.

The definition of a macro can be included in the source module in which it isinvoked, or placed in a separate file that's accessible to the assembler while it isassembling that source module.

Name Field Opcode Operand

Blank MACRO Blank

MACRO - HEADER STATEMENT

Page 258: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 9. Macros Page 9-Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

5

A SAMPLE MACRO

Example: A macro named ADD with the following propertyopcode operand

ADD X , Y

Whenever the statement is written in a source module,the effect isequivalent to these three statements:

L 5 , XA 5 , YST 5 , X

We can also write it asADD ALPHA , BETA

the effect is equivalent to these three statements:L 5 , ALPHAA 5 , BETAST 5 , ALPHA

Figure : 9-4 A sample Macro

NOTES :

The add macro such that we write any two valid symbols in place of ALPHA andBETA.

It always causes Register 5 to be used,so that the previous number in that register isreplaced by the result of the ADD macro.

There must be exactly two symbols in the operand and,they must designate full-wordintegers.

The number whose address is represented by the second symbol is added to the numberwhose address is represented by the first symbol;the sum is stored at the addressrepresented by the first symbol.

Page 259: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 9. Macros Page 9-Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

6

A MACRO'S DEFINITION

Figure 9-5 A Macro's definition

NOTES:

A = An optional variable symbol designating the namefield.

B = The macro name or opcode

C = Specifications of the operand

X = An optional sequence symbol identifying the MEND statement.

Header

Prototype

Body

Trailer

A MACRO'S DEFINITION

MACRO

A B C

X M E N D

Page 260: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 9. Macros Page 9-Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

7

EXAMPLE 1

Figure 9-6 example 1

NOTES:

The MACRO ADD processes two variables 'A' & 'B'.

'A' is loaded into the register 5.

'B' is added to the contents of Register 5.

The third instruction stores the contents of register 5 to A.

MACRO

&L ADD &A, &B

&L L 5, &AA 5, &BST 5, &A

MEND

EXAMPLE 1

Page 261: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 9. Macros Page 9-Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

8

USE OF CONTROL DIRECTIVES

The statements in the body of a macro’s definition can include any of thecontrol directives.

GBLx , SETx , AIF , AGO , ANOP

RETURN Macro:

The meaning of the RETURN macro is Return to the calling programafter restoring all registers except the registers (if any) designated in theoperand.

The exceptions can only be Register 0,Register 15,or both Register 0and Register 15.Thus there are four essential different ways to invoke theRETURN macro:

RETRN restores all registersRETRN 0 , 15 restores all but R15 and R0RETRN 15 restores all but R15RETRN 0 restores all but R0

Figure : 9-7 Return Macro

NOTES:

Each of the invoking statements will cause the assembler to generate the correspondingexpansion for the return sequence.

Page 262: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 9. Macros Page 9-Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

9

RETURN MACRO DEFINITIONS

1.The prototype statement (line2) identifies the name of the RETRN macro and thevariable symbols whose values can be specified when the RETRN macro is invoked.

2. The statements in the body of the definition are processed at assembly time each timethe RETRN macro is invoked. It is during this assembly time processing of the definitionthat the assembler generates the expansion. The expansion is not executed until run time.

Statement no Statement Explanation

3 AIF (‘&R1’ EQ ‘’).R1 This determines whether the firstoperand field is present.If not,assembler skips to statementidentified by the sequence symbol.

4 AIF ((‘&r1’ NE ‘0’) AND (‘&R1’ NE ‘15’)).RERRWhen the first operand field ispresent, this determines whetherits value is acceptable.

5 AIF (‘&R2’ EQ ‘’).R3 When the first operand is presentand its value is either 0 or 15,thisdetermines whether the secondoperand is present. If it is not,theassembler skips to statementidentified by the sequence symbol

6 AIF ((‘&R2’ NE ‘0’) AND (‘&R2’ NE ‘15’)).RERRThis determines whether theValue in the second operand isis acceptable.

7 AGO .R2 When both operands are presentand valid, the assembler skips tostatement identified by thesequence symbol.

Figure : 9-8 Return macro definitions

NOTES:

Page 263: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 9. Macros Page 9-Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

10

MEXIT Directive

The MEXIT directive instructs the assembler to stop its assembly-time processing of the RETRN macro. This directive is equivalent to anunconditional skip(AGO) to the MEND directive.

Syntax:

Name field Opcode Operand

Sequence symbol MEXIT Blankor

Blank

MNOTE Directive

The MNOTE directive specifies a message that is printed on thelisting and a severity code.

Syntax:

Name field Opcode Operand

Sequence symbol MNOTE n,’……’or

Blank

Severity code Character string,to be printed onthe listing

Figure : 9-9 Directives

NOTES:

Page 264: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 9. Macros Page 9-Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

11

VSAM PROCESSING - ASSEMBLER

Figure 9-10 Vsam processing - Assembler

NOTES:

The ACB macro identifies the data set, type of processing and basic options. OPEN/CLOSE connect/disconnect application programs and the data set defined in

the ACB. RPL macros define a request and specify the processing options for the request (e.g.

DIR or SEQ access; LOC or MVE mode). A RPL identifies the data set to which therequest is directed by naming the ACB macro that defines the data set.

Request macros initiate a request and point to the RPL that defines the request.

ACB MACRO RPL MACRO

REQUEST MACROS

VSAM PROCESSING - ASSEMBLER

OPENmacro

Access methodControlBlock

DataSet

RequestParameterList

CLOSEmacro

GETPUTPOINTERASE

Page 265: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 9. Macros Page 9-Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

12

CREATING ACBs AND RPLs

Figure 9-11 Creating acbs and rpls

NOTES:

GENCB generates a control block when the program is executed rather than whenthe program is assembled.

The use of GENCB means that programs would not require reassembly with anew version of VSAM.

GENCB allows you to generate multiple ACBs or RPLs.

The instructions path length is longer with GENCB than with an explicit ACB orRPL macro.

MACROS PROCESSED MACROS PROCESSEDAT ASSEMBLY TIME AT EXECUTION TIME

CREATING ACBs AND RPLs

ACBRPL

GENCB ACBGENCB RPL

Page 266: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 9. Macros Page 9-Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

13

ACB MACRF PARAMETER

Figure 9-12 ACB MACRF parameter

NOTES:

NIS / SIS

NIS (Normal insert strategy) is the default insert strategy. Splits occur in the middleof control intervals.

SIS (Sequential insert strategy) is helpful for mass sequential insertions. Splits occurat the point of record insertion.

FILEA ACB ….MACRF = (processing option list)….

MACRF ADR I CNV I KEY Record or CI accessPROCESSING DIR I SEQ I SKP Access modeOPTIONS IN I OUT Input or Output

NIS I SIS Insert strategy

ACB MACRF PARAMETER

Page 267: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 9. Macros Page 9-Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

14

RPL OPTCD PARAMETER

Figure: 9- 13 RPL OPTCD parameter

NOTES:

ASSEMBLER ERROR HANDLING

RPLA RPL …. OPTCD = (request option list)…..

ADR I CNV I KEY Record or CI accessRPL DIR I SEQ I SKP Access modeREQUEST FWD I BWD Forward or BackwardOPTIONS LOC I MVE LOCATE or MOVE mode

NSP I NUP I UPD Retrieval for UPDATE NOUPDATE

RPL OPTCD PARAMETER

Page 268: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 9. Macros Page 9-Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

15

Figure 9-14 Assembler Error Handling

NOTES:

When an OPEN / CLOSE or request macro completes, VSAM always places a returncode in register 15 indicating success or failure.

The application program must check the return code.

The corresponding VSAM reason code can be accessed using the SHOWCB macro.

The MVS/DFP Macro Instruction reference contains a list of reason codes that an errorhandling routine might interrogate.

KEYED - SEQUENTIAL RETRIEVAL (FORWARD)

INPUT ACB MACRF=(KEY, SEQ, IN)

RETRVE RPL ACB=INPUTAREA=IN,AREALEN=100,OPTCD =(KEY, SEQ,SYN,NUP,MVE )

B LOOPERROR …

IN DS CL100

ASSEMBLER ERROR HANDLING

LOOP GETRPL=RETRVE

LTR 15, 15BNZ ERROR

Page 269: Assembler Book

STUDENT NOTE BOOK

© Copyright MCPL. Unit 10. Sequential Organization 10-Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

1

UNIT 10: SEQUENTIAL ORGANIZATION

OBJECTIVES:

The system input and output data sets

Processing fields in a logical record

Processing of variable length records

Printer output

Dormitory room master file

Transaction record format

Page 270: Assembler Book

STUDENT NOTE BOOK

© Copyright MCPL. Unit 10. Sequential Organization 10-Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

2

SEQUENTIAL ORGANIZATION

Initialization phase

Main processing phase

End-of-data phase

Figure 10-1 Sequential organization

NOTES:

The processing of Sequential data sets always involves at least in three distinct phases.Initialization Phase: each data set opened and perhaps the first record is read. Mainprocessing phase: each record is processed according to whatever criteria are appropriateto the problem.

End-of–data phase: the last output record remaining in main memory has to written andthe data sets must be closed.

Page 271: Assembler Book

STUDENT NOTE BOOK

© Copyright MCPL. Unit 10. Sequential Organization 10-Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

3

THE SYSTEM INPUT AND OUTPUT DATA SETS

SYSIN AND SYSOUT IN OS SYSTEMS

The DD statements for SYSIN and SYSOUT are

For SYSIN: / / SYSIN DD *For SYSOUT: / /SYSPRINT DD SYSOUT = A

The values coded for block size for IBM 3330 disk system for SYSIN and SYSOUT

For SYSIN: RECFM=FB, LRECL=80,BLKSIZE= 4080 (51 records per block)RECFM=VB, LRECL=84,BLKSIZE= 4036 (48 records per block)

For SYSOUT: RECFM=FB, LRECL=132,BLKSIZE= 4092 (31 records per block)RECFM=VB, LRECL=136,BLKSIZE= 4084 (30 records per block)

Figure 10-2. SYSIN and SYSOUT in OS Systems.

NOTES:

The SYSIN data set is a sequential data set created by the operating system. A specialForm of the DD statement, either DD * or DD DATA, identifies the SYSIN data.

Like SYSIN, the SYSOUT data set is a sequential data set created by the operatingSystem. It is identified on a DD statement by the parameter SYSOUT =. NeitherSPACE = nor DISP = can be specified for SYSOUT.

To designate the block size for SYSIN and SYSOUT, choosing a value consistent withthe device characteristics. Some computer installations use default values of block sizesfor both these data sets. You should determine what block sizes should be specified atyour computer installation. Unless stated otherwise, the above values will be coded.

Page 272: Assembler Book

STUDENT NOTE BOOK

© Copyright MCPL. Unit 10. Sequential Organization 10-Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

4

SYSIPT AND SYSLST IN DOS SYSTEM

The SYSIPT data set needs no job control statements unless it is assigned to a deviceother then the system card reader. For card reader, the data records described by theDTFCD Macro simply follow the // EXEC command for the program that records thosedata.

The simple form of the DTFCD Macro is as follows:

DTFNAME DTFCD DEVADDR=SYSIPT, WORKA=YES, OAREA1=INBUF,EOFADDR=EOJ, DEVICE=22540

Figure 10-3. SYSIPT and SYSLST in DOS System

NOTES:

The above code specifies that SYSIPT data records will be read from an IBM 2540 cardreader, with a single I / O buffer named INBUF, and that the name of the user’s end-of-file routine is EOJ. Move mode is used due to the WORKA = YES parameter.

Page 273: Assembler Book

STUDENT NOTE BOOK

© Copyright MCPL. Unit 10. Sequential Organization 10-Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

5

PROCESSING FIELDS IN A LOGICAL RECORD

MOVE MODEExample for move mode

CARD DS CL80 RESERVE 80 POSITIONS FOR INPUTRECORD

ORG CARD SET MEMORY LOCATION COUNTERTO ‘CARD’

DS CL4 COLUMNS 1 - 4 UNUSEDNAME DS CL40 COLUMNS 5 - 44 FOR STUDENT NAME

DS CL1 COLUMN 45 UNUSEDCOURSE DS CL 10 COLUMNS 46–55 FOR COURSE TAKEN

DS CL 1 COLUMN 56 UNUSEDGPA DS CL4 COLUMNS 57– 60 FOR GPA (AS ‘X.XX’)

ORG SET MEM LOC CTR TO FIRST BYTEBEYOND ‘CARD’

Figure 10-4. Processing fields in a logical record

NOTES :

Page 274: Assembler Book

STUDENT NOTE BOOK

© Copyright MCPL. Unit 10. Sequential Organization 10-Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

6

PROCESSING FIELDS IN A LOGICAL RECORD (contd…)

LOCATE MODE :

Example for locate mode

CARD DSECT BEGIN DUMMY SECTIONNAMED ‘CARD’

DS CL4NAME DS CL40

DS CL1 SAME AS IN ABOVE MOVEMODE DEFINITIONS

COURSE DS CL10DS CL1

GPA DS CL4EG2 CSECT RESUME CONTROL SECTION

NAMED ‘EG2’

Figure 10-4. Processing fields in a logical record

NOTES :

To process fields with in a logical record in locate mode, a DSECT defining the logicalrecord fields must be established at assembly time. A dummy base register that points tothe beginning of the DSECT area must also be established by means of a USINGdirective at assembly time, and the logical record address received from the GET Macroshould be loaded in to the dummy base register at run time.

Page 275: Assembler Book

STUDENT NOTE BOOK

© Copyright MCPL. Unit 10. Sequential Organization 10-Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

7

PROCESSING VARIABLE – LENGTH RECORDS

Using the RDW

Move Mode

Locate Mode

Figure 10-4: Processing variable length records

NOTES:

Processing variable length records, the length of a record is not necessarily known until itis processed at run time. The record length can be obtained at run time from the recorddescriptor word. Once the record length is obtained, the record can be moved with anExecute instruction.

The logical record area must be defined to include the record descriptor word (RDW). Atthe least, the area should begin on a half-word boundary, to make the count field in theRDDW accessible to LH and STH instructions.

The Ds directive that defines the area with a DS OH directive:

DS OHCARD DS CL84

Page 276: Assembler Book

STUDENT NOTE BOOK

© Copyright MCPL. Unit 10. Sequential Organization 10-Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

8

MOVE MODE

To process variable-length records in move mode can be codelike this:

COPYLOOP GET TRANSIN, CARD OBTAIN A LOGICAL RECORDLH 10,CARD LOAD RECORD LENGTH FROM RDWSH 10, =H ’ 1 ‘SUBT +1 FOR EXECUTE INSTREX 10, VMVC MOVE RECORD FROM INPUT TO OUTPUTPUT TRANSOU, LINE AREAS, AND PUT IT INTO OUTPUTB COPYLOOP BUFFER. THEN GETNEXT RECORD.

VMVC MVC LINE ( 0 ), CARD MVC FOR VAR-LNG MOVE...

TRANSIN DCB . . . , RECFM=VB, LRECL=84, BLKSIZE =4096TRANSOU DCB . . . ,RECFM=VB, LRECL= 136, BLKSIZE=4084

*TRANSIN DFTCD . . ., RECFORM= VARUNB, BLKSIZE =84*TRANSOU DFTPR . . . , RECFORM=VARUNB, BLKSIZE = 136*INBUF DS CL94

* DS CL136DS 0H

CARD DS CL84DS 0H

LINE DC CL136 ‘

Figure 10-5. Move Mode

NOTES:

Page 277: Assembler Book

STUDENT NOTE BOOK

© Copyright MCPL. Unit 10. Sequential Organization 10-Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

9

LOCATE MODE

COPYLOOP GET TRANSIN OBTAIN ADDRESS OF LOGICAL RECORDLR 9, GREG USE REG 9 TO SAVE INPUT RECDD ADDRMVC VRECL,0(9) GET LENGTH FROM RDW IN I /O BUFFERLH 10, VRECL LOAD RECD LNG FROM HALF-WORD AREASH 10, =H ‘ 1 ‘ SUBT + 1 FRO EXECUTE INSTREX 10, VMVC MOVE RECORD FROM INPUT TO OUTPUTPUT TRANSOU AREAS, AND OBTAIN ADDRESS OF NEXTLR 8, PREG OUTPUT RECORD. SAVE THIS IN REG 8B COPYLOOP AND THEN GET NEXT INPUT RECD ADDR.

VMVC MVC 0 ( 0, 8), 0 (9) MVC FOR VAR-LNG MOVE.VRECL DS H HALF WORD FOR RECORDLENGTH

Figure 10-6. Locate mode

NOTES:

In locate mode, the process of obtaining the record length should be modified. TheRecord length must be obtained from the record descriptor word (RDW) of the logicalRecord, i.e., from the first 2 bytes of the logical record area.

The general case of blocked records (RECFM =VB or RECFORM = VAR BLK ) eventhough The DOS SYSIPT and SYSLST files do not permit blocked records. The samemethod can be used for any file(DOS or OS ) in which blocked records are permitted.The method Consists of moving the first 2 bytes of the RDW to a temporary area that isaligned on a half-word boundary, so that the LH (Load Half Word) instruction can beused whether we have An IBM 360 or IBM 370.

Page 278: Assembler Book

STUDENT NOTE BOOK

© Copyright MCPL. Unit 10. Sequential Organization 10-Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

10

PRINTER OUTPUT

Printer output : Page and Line spacing ;Date and Time macros

Carriage control

Title lines

Figure 10-7. Printer output

NOTES:

The first character of each logical record written to the system out put data set can beused to control printer line-spacing. The most common space-control functions are tosingle space, double space, triple space, suppress spacing and skip to new page. Controlcharacter is simply one of the 256 EBCDIC characters. There are two different sets ofcontrol characters, ANSI and IBM machine code characters.

In OS , the choice of control character set is designated in the RECFM=parameter of theDCB macro. The ANSI set is designated by letter ‘A’, the IBM set by letter ‘M’:RECFM=FBA or VBA, or RECFM=FBM or VBM.

Page 279: Assembler Book

STUDENT NOTE BOOK

© Copyright MCPL. Unit 10. Sequential Organization 10-Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

11

TITLE

The logical record area for the title could be defined asTITLE DS CL133 SPACE FOR TITLE LINE

ORG TITLE BEGIN REDEFINITION FOR FIELDSDC X’F1’ ANSI CTL CHAR FOR TOP OF NEW

PAGEDC CL14’ ’ BLANKS TO CENTER THE TITLE

*FOLLOWING IS SOME APPROPRIATE TITLE,WITH TRIALINGBLANKS

DC CL90’ LISTING OF SYSIN DATA’MONTH DS CL2 SPACE FOR TWO-DIGIT MONTH

DC C’/’DAY DS CL2 TWO-DIGIT DAY OF MONTH

DC C’/’YEAR DS CL2 TWO-DIGIT YEAR

DC CL11’ ‘ SPACING FOR READABILITYDC C’PAGE’

PAGE DC CL4’ ‘ UPTO FOUR-DIGIT PAGE NO.ORG

Figure 10-8. Title

NOTES:

The title line must be printed each time the line-number counter reaches the limitestablished for number of lines per page. A logical record area must be defined to includethe title space for the date and page number, and the top of page control character.

A page-number counter must be maintained and converted to EBCDIC format each timea new page is to be started.

Page 280: Assembler Book

STUDENT NOTE BOOK

© Copyright MCPL. Unit 10. Sequential Organization 10-Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

12

DATE AND TIME MACROS

The TIME Macro

Date and Time in OS

Opcode Operand

TIME blanks

The COMRG and GETIME Macros

Date and Time in DOS

Opcode Operand

GETIMECOMRG

Figure 10-9. Date and Time macros

NOTES:

To obtain the date and time in DOS two separate macros are needed, GETIME andCOMRG GETIME macro returns the time of day in register 1 as a signed packed –decimal number.

The COMRG macro returns the address of the date rather than the date itself. The addressis returned in register 1, and the field that points to is known as communication region ,of which the first 8-bytes contain calendar date in EBCDIC format , stored as mm/dd/yy.

Page 281: Assembler Book

STUDENT NOTE BOOK

© Copyright MCPL. Unit 10. Sequential Organization 10-Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

13

DORMITORY ROOM MASTER FILE

Column 4 : 1-byte transaction code

Cols 8-11:4-byte dorm abbreviation

Cols 16-19:4-byte room no.Cols 62-70:std-id

Cols 21-60 : stud-name

1 4 8 12 16 21 60 62 71 80

Figure 10-10. Dormitory room master file

NOTES:

The information to be maintained for each dorm room is the dorm identity and roomnumber, and the names of the students who are assigned to that room. Since the data setwill contain the information that we want to know and maintain about dorm roomcapacity is known as master file.

The data set used to create or update the master file is known as transaction file. Toprocess the master file as a sequential data set, we require that its logical records be insome useful sequence and that the logical records of the transaction file be in the samesequence. The dorm field in each record is thus referred to as the major field forsequencing and the room number field as the minor field.

Each dormitory is identified by a one-to four –character abbreviation, all of which beletters. Each dormitory room number consists of one to four letters or digits.

Page 282: Assembler Book

STUDENT NOTE BOOK

© Copyright MCPL. Unit 10. Sequential Organization 10-Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

14

TRANSACTION RECORD FORMAT

CODE MEANING

1. Add a record for this dorm and room number to theMaster file

2. Add the student identified in this transaction recordto the master file record identified by the dorm androom number field given in the transaction.

3. Delete the student identified in this transaction recordFrom the master file record.

4. Delete the master file record that is identified by theDorm and room number in the transaction.

Figure 10-11. Transaction record format

NOTES:

Page 283: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-Course Material may not be reproduced in whole or in part

Without the prior permission of MCPL.

1

UNIT 11: INDEXED SEQUENTIAL ORGANIZATION

OBJECTIVES:

Space Allocation

Creating an Indexed sequential Data set

Updating in Sequential mode

OS Random-mode Processing consideration

DOS Random-mode Processing Consideration

Updating in random mode

Page 284: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-Course Material may not be reproduced in whole or in part

Without the prior permission of MCPL.

2

INDEXDED SEQUENTIAL ORGANIZATION

Queued Indexed Sequential Access Method (QISAM)

Basic Indexed Sequential Access Method (BISAM)

Indexed Sequential Access Method (ISAM)

Figure 11-1. Indexed Sequential Organization

NOTES:

Page 285: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-Course Material may not be reproduced in whole or in part

Without the prior permission of MCPL.

3

DIFFERENCES BETWEEN OS AND DOS

OS Supports QISAM and BISAM .

DOS Supports ISAM only.

Major differences between OS and DOS :

The way in which I/O error communicated to the user’s program

From the operating system.

The way in which buffers are allocated.

The way in which buffers are used by the GET,PUT,READ and

WRITE Macros.

The way in which space allocated by the job control language

Statement.

Figure: 11-2 Differences of OS and DOS.

NOTES:

Page 286: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-Course Material may not be reproduced in whole or in part

Without the prior permission of MCPL.

4

QUEUED INDEXED SEQUENTIAL ACCESS METHOD (QISAM)

Used to create an Indexed Sequential Data Set in OS.

Used to update records in place via PUTX in UPDAT Mode.

Used to add the records to end of the data set via PUT inEXTEND Mode.

Figure 11-3. Queued indexed sequential access method (QUISAM)

NOTES:

QISAM is access method used to create the indexed sequential data sets, update therecords, insert the records and delete the Records from sequential data set.

The processing steps used with QISAM are similar to QSAM but Some significantdifferences between them.

Page 287: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-Course Material may not be reproduced in whole or in part

Without the prior permission of MCPL.

5

QISAM vs. QSAM

QISAM sequential processing can begin at any arbitrary record in the

data set.

The record processing begins must be identified by it’s key.

Specified in a set location (SETL) macro before invoking GET macro.

In order to stop retrieval from one section before beginning a new

section of the data set, we simply invoke the End SETL (ESETL)

macro.

QISAM records can be deleted when updating in place. This is

accomplished by using the first byte of each logical record as a delete

flag.

Figure 11-4. QISAM vs. QSAM

NOTES:

Page 288: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-Course Material may not be reproduced in whole or in part

Without the prior permission of MCPL.

6

DSORG AND MACRF PARAMETERS

The DSORG parameter must always be coded as DSORG = IS forQISAM.

Move mode or locate mode buffering can be used

INPUT Mode the MACRF Parameter

Figure 11-5. Dsorg and macrf parameters

NOTES:

The RECFM, LRECL, and BLKSIZE parameters should be coded only when creatingthe data set, not when updating or retrieving from it.

Move mode or locate mode buffering can be used , but the other buffering optionsavailable with QSAM processing – data mode, substitute mode , and exchange bufferingare not permitted with QISAM

When retrieving record in INPUT mode, we must specify in the MACRF Parameterwhether or not the SETL macro will be used by coding MACRF=(GM,SK) or (GL,SK)

Page 289: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-Course Material may not be reproduced in whole or in part

Without the prior permission of MCPL.

7

BASIC INDEXED SEQUENTIAL ACCESS METHOD

Used to update or retrieve the records but not to create anIndexed Sequential Dataset.

Deleted records

Synchronization

Open Macro

DCB Parameters

Figure 11-6. Basic indexed sequential access method

NOTES:

Page 290: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-Course Material may not be reproduced in whole or in part

Without the prior permission of MCPL.

8

INDEXED SEQUENTIAL ACCESS METHOD

Create an Indexed Sequential File.

Extend an Indexed Sequential File.

Update a file in Sequential Mode.

Update a file in Random Mode.

Figure 11-7. Indexed sequential access method

NOTES:

We must use WRITE macro with IOAREAl = buffer area and specify IOROUT = LOADin the DTFIS macro.

Follow the OPEN macro with a SETFL(Set File Load Mode) macro and precede theCLOSE macro with an ENDFL (End SETFL) macro.Record must be written in ascending key sequence.

To create a file: //DLBL dtfname ,’filename’,date,ISC,……..

Page 291: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-Course Material may not be reproduced in whole or in part

Without the prior permission of MCPL.

9

INDEXED SEQUENTIAL ACCESS METHOD

Create an Indexed Sequential File.

Extend an Indexed Sequential File.

Update a file in Sequential Mode.

Update a file in Random Mode.

Figure 11-8. Indexed sequential access method

NOTES:

To add records in ascending key sequence beyond the previous last record of the file, usethe procedure and parameters as when creating the file.

Difference between creating and extending is indicated in a user’s program it specified inthe //DLBL JCL statement.

To create a file: //DLBL dtfname ,’filename’,date,ISC,……..

To extend a file: //DLBL dtfname ,’filename’,date,ISE,……..

Page 292: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-Course Material may not be reproduced in whole or in part

Without the prior permission of MCPL.

10

INDEXED SEQUENTIAL ACCESS METHOD

Create an Indexed Sequential File.

Extend an Indexed Sequential File.

Update a file in Sequential Mode.

Update a file in Random Mode.

Figure 11-9.Indexed Sequential Access Method.

NOTES:

In sequential Mode, we can choose between updating in place and general updatingprocedures.

Updating in place is restricted to changing data field contents(but not the key field), and isspecified via IOROUT=ADDRTR and TYPEFLE = SEQNTL in the DTFIS macro.

It uses GET and PUT macro to retrieve a record and to write a record respectively. Inrandom mode, generalized updating is permitted by specifying

IOROUT = ADDRTR and TYPEFLE = RANDOM.

New records can be inserted in their proper key-sequenced position without creating anew file. There is no provision for deleting records in random mode

Page 293: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-Course Material may not be reproduced in whole or in part

Without the prior permission of MCPL.

11

SPACE ALLOCATION

Prime Data Area

Independent overflow Area

Cylinder Index Area

Figure 11-10. Space allocation

NOTES:

Secondary memory space for an indexed sequential data set is generally allocated in threedistinct areas: the prime data area, the independent overflow area and the cylinder indexarea.

In OS systems , the space allocation depend on the SPACE= parameter of the DDstatement is coded.

In DOS systems , the space allocation is done by //EXTENT statements.

Page 294: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-Course Material may not be reproduced in whole or in part

Without the prior permission of MCPL.

12

SPACE ALLOCATION FOR ISDS IN OS SYSTEMS

DD statements Arrangement of Areas

p// ddname DD DSNAME=dsname,// DISP=(NEW,KEEP),// SPACE=(CYL,(P),,CONTIG) ……… …// DCB=(DSORG=IS),……….

p//ddname DD DSNAME=dsname,// DISP=(NEW,KEEP) ,// SPACE=(CYL,(P, ,X), ,CONTIG) ………………// DCB=DSORG=IS,…………

X

Figure 11-11. Space allocation for ISDS in OS systems

NOTES:

Fig1: Prime area = P cylinders with index at its end ; partially used index cylinders usedfor independent overflow.

Fig2: Prime area = P cylinders with X cylinders as embedded index; partially used indexcylinders are independent overflow areas.

Page 295: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-Course Material may not be reproduced in whole or in part

Without the prior permission of MCPL.

13

SPACE ALLOCATION (CONTINUED…)

DD statements Arrangement of Areas

p

// ddname DD DSNAME=dsname(prime),// DISP=(NEW,KEEP),// SPACE=(CYL,(P), ,CONTIG) ……… …// DCB=(DSORG=IS),……….// DD DSNAME=dsname(OVFLOW),// DISP=(NEW,KEEP),// SPACE=(CYL,(W), , CONTIG), W// DCB=*.ddname,…..

p w//ddname DD DSNAME=dsname(prime),// DISP=(NEW,KEEP) ,// SPACE=(CYL,(P, ,X), ,CONTIG) ………………// DCB=DSORG=IS,…………// DD DSNAME=dsname(OVFLOW),// DISP=(NEW,KEEP),// SPACE=(CYL,(W), ,CONTIG), X// DCB=*.ddname,…..

Figure 11-11. Space allocation for isds in os systems

NOTES:

FIG1: prime area = p cylinders; independent overflow areas = w cylinders with index atit’s end.

FIG2: prime area = p cylinders with x cylinders as embedded index;Independent overflow area = w cylinders.

Page 296: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-Course Material may not be reproduced in whole or in part

Without the prior permission of MCPL.

14

SPACE ALLOCATION (CONTINUED…)

DD statements Arrangement of Areas

p

// ddname DD DSNAME=dsname(INDEX),// DISP=(NEW,KEEP),// SPACE=(CYL,(X), ,CONTIG) ……… …// DCB=DSORG=IS,……….// DD DSNAME=dsname(PRIME),// DISP=(NEW,KEEP),// SPACE=(CYL,(P), , CONTIG), X// DCB=*.ddname,…..

P//ddname DD DSNAME=dsname(INDEX),// DISP=(NEW,KEEP) ,// SPACE=(CYL,(X), ,CONTIG) ………………// DCB=DSORG=IS,…………// DD DSNAME=dsname(PRIME),// DISP=(NEW,KEEP),// SPACE=(CYL,(P), ,CONTIG), W X// DCB=*.ddname,…..// DD DSNAME=dsname(OVFLOW),DISP=(NEW,KEEP),// SPACE = (CYL,(W), ,CONTIG),DCB=*.ddname….

Figure 11-12 Space allocation for isds in os systems

NOTES:

Fig1: prime area = p cylinders: index area = x cylinders, with partially usedIndex cylinders used as independent overflow area.

Fig2: prime area = p cylinders: index area = x cylinders : independent overflow area = wcylinders.

Page 297: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-Course Material may not be reproduced in whole or in part

Without the prior permission of MCPL.

15

SPACE ALLOCATION IN DOS SYSTEMS

/ /DLBL dtfname,’filename’,date.isc

/ /EXTENT , ,4,0,a,n -- Optional master index area.

/ /EXTENT , ,4,1,b,r -- Required cylinder index area.

/ /EXTENT , ,1,2,c,s -- Required prime data area.

/ /EXTENT , ,2,3,d,t -- Optional independent overflow area.

extent type Relative track number where spaceallocation begins.

Extent seq# Number of consecutive tracks in thespace allocation.

Figure 11-13. Space allocation in dos system

NOTES:

Page 298: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-Course Material may not be reproduced in whole or in part

Without the prior permission of MCPL.

16

ADDING RECORDS TO AN INDEXED SEQUENTIAL DATA SET

Track0 primeTrack260 1

480 track2

Track-index track

Track1Key data block 120 180 230230 110

Prime data tracks(one block per track)

Track2key data block 380 405 425 FF 480480 340

Track18

Overflow track

Figure 11-14. Adding records to an indexed sequential data set

NOTES:

Records existing before addition of new records – assuming one block/track with 5records/block and record 480 flagged for deletion

Page 299: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-Course Material may not be reproduced in whole or in part

Without the prior permission of MCPL.

17

SPACE REQUIREMENTS

For the IBM 3330 system the track capacity formula is

13165Number of blocks per track =

191 + KL + DL

Index space requirements.

Prime space requirements.

Number cylinder for prime data =C = N/(M*P) = (L*R)/(B*M*P).

Figure 11-15. Space requirements

NOTES:

KL - Key Length.DL - Data Block Length.L - Logical record length.B - Block Size.R - Estimated Number Records.N - Number prime data Blocks required = (L*R)/B.M - Blocks per Tracks.P - Prime data tracks per cylinder.

Page 300: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-Course Material may not be reproduced in whole or in part

Without the prior permission of MCPL.

18

CREATING AN INDEXED SEQUENTIAL DATA SET

Block size.

Maximum possible block size for IBM 3330 isDL = (13165/3) – (191 + KL)

= 4197 – KL.

DCB Parameters.

DTFIS Parameters.

Figure 11-16. Creating an indexed sequential data set

NOTES:

To create an Indexed Sequential Data Set :

The length and position of the key field must be the same in all logical records of thedata set.

Some DCB parameters and DTFIS parameters are required.

Page 301: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-Course Material may not be reproduced in whole or in part

Without the prior permission of MCPL.

19

PRICIPAL DCB PARAMETERS

Parameter Meaning

BLKSIZE=n block size of n bytes including 4 bytes for block descriptor word.CYLOFL=c c tracks in each prime data cylinder for overflow area.DDNAME=ddname DD statement that describes data set.DSORG=IS specifies that organization is indexed sequential.KEYLEN=k length of the key field in each record is kLRECL=m m bytes in each logical record.

{(PM)} PM for PUT macro in move modeMACRF={(PL)} PL for PUT macro in locate mode.NTM= t if the cylinder index requires more than t tracks then master index

will be created.OPTCD=…… OPTCD=I specifies that independent overflow area is to be used.

OPTCD=L specifies that delete flag option will be used.OPTCD=M specifies that master index is to be created.OPTCD=Y specifies that cylinder overflow areas are to be used.

{(FB)} Fixed length recordsRECFM={(VB)} Variable length recordsRKP=p p is the relative position of the first byte in the key field.

Figure 11-17 Principal dcb parameters

NOTES:

BLKSIZE,CYLOFL,KEYLEN,LRECL,NTM,OPTCD,RECFM And RKP can only bespecified when creating an indexed sequential data set. They cannot be specified whenupdating or retrieving from the data set.

Page 302: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-Course Material may not be reproduced in whole or in part

Without the prior permission of MCPL.

20

PRINCIPAL DTFIS PARAMETERS

PARAMETER MEANING

CYLOFKL=c c tracks in each primary data cylinder for overflow area.DEVICE = device# device # is the identity assigned by IBM to the unit that

contains the prime data area.DSKXTNT=x x extents have been allocated including all index, overflow

and prime data extents.HINDEX = device# device # is the identity assigned by IBM to the unit that

contains the high level index.IOAREAL=buffer name name of the i/0 buffer area for file creation.KEYLEN=k k bytes is the length of the key in each record.KEYLOC=p p is the relative position of the first byte in the key field.

Where p=1 designates the first byte position in the record.MSTIND=YES specifies that master index is to be used.NRECDS=n n is the number of records in a data block.

{ FIXBLK } blocked fixed length recordsRECFORM={----------- }

{ FIXUNB}unblocked fixed length recordsRECSIZE=m m bytes in each logical record so block size = m*n.WORKL=work area name name of logical record area used for file creation.

Figure 11-18. Principal dtfis parameters

NOTES:

Page 303: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-Course Material may not be reproduced in whole or in part

Without the prior permission of MCPL.

21

FIXED –LENGTH RECORD FORMAT

Byte 0 - 1: byte deletes flagBytes 1 - 4: 4-byte dorm abbreviation}Bytes 5 - 8: 4 byte room number} record key field

| Space used whether needed or not |

Figure 11-19. Fixed –length record format

NOTES:

Student name(40 bytes)

Id(9)

Student name(40 bytes)

Id(9)

Page 304: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-Course Material may not be reproduced in whole or in part

Without the prior permission of MCPL.

22

VARIABLE – LENGTH RECORD FORMAT

Bytes 0-3: 4-byte RDW

Byte 4: 1 byte delete flag

Bytes 5-8: 4- byte dorm abbreviation

Bytes9-12: 4 byte room number

Bytes 13-14: 2 byte count

Student name(40 bytes)

Id(9)

Student name(40 bytes)

Id(9)

| Space not used unless needed

Figure 11-20. Variable – length record format

NOTES:

Page 305: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-Course Material may not be reproduced in whole or in part

Without the prior permission of MCPL.

23

UPDATING IN SEQUENTIAL MODE

The possible updating actions in sequential mode are:

Add records to the end of the data set.

Change or delete some of the data in the existing records.

Insert new records with proper sequence with in the dataset.

Delete one or more records in the existing data set.

Figure 11-21. Updating in sequential mode

NOTES:

Inserting new is not usually performed sequentially because new records cannot beinserted into an existing data set using sequential mode which requires overflow area.

Page 306: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-Course Material may not be reproduced in whole or in part

Without the prior permission of MCPL.

24

SEQUENTIAL MODE IN OS SYSTEMS

The various modes are:

EXTENDINGOpen the data set in EXTEND mode.DISP=(MOD,KEEP) in DD statement.

UPDATINGSpecify the MACRF parameter in DDstatement and use PUTX macro.

DELETINGOPTCD=L andMove X’FF in to the delete-flag and rewritethe record.

Figure 11-22. Sequential mode in OS systems

NOTES:

Page 307: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-Course Material may not be reproduced in whole or in part

Without the prior permission of MCPL.

25

SEQUENTIAL MODE IN DOS SYSTEMS

The various modes are:

EXTENDINGTo create a data set code ISC in //DLBLstatement.To update or extend code ISE in //DLBLstatement.

UPDATINGSETFL and ENDFL are not used forupdating.PUT macro is used to rewriting an updatedrecord.

DELETINGMove X’FF in to the first byte of the recordthere is no delete flag.

Figure 11-23. Sequential mode in DOS systems

NOTES:

Page 308: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-Course Material may not be reproduced in whole or in part

Without the prior permission of MCPL.

26

OS RANDOM – MODE PROCESSING

DYNAMIC BUFFERING

READ And WRITE MACROS

MACRF parameter

I/O synchronization

INVALID key conditions

Figure 11-24. Os random – mode processing

NOTES:

Include the BUFNO=parameter in DCB macro.

For read a record READ macro is READ KU.

For rewrite a record WRITE macro is WRITE K.

For new record WRITE macro is WRITE KN.

Page 309: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-Course Material may not be reproduced in whole or in part

Without the prior permission of MCPL.

27

DOS RANDOM MODE PROCESSING

BUFFERING

READ And WRITE MACROS

DTFIS Parameters

I/O synchronization

INVALID key conditions

Figure 11-25. DOS random mode processing

NOTES:

The buffer used for adding new records is indicated by the IOAREAL=parameter.IOAREAR=parameter indicates buffer used for retrieving and updating existing records.WORKR=parameter indicates logical record work area.

Page 310: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-Course Material may not be reproduced in whole or in part

Without the prior permission of MCPL.

28

UPDATING IN RANDOM MODE

INITILIZATIONThe file is opened and the first transaction recordis read.

MAIN PROCESSINGMove the key of the current transaction record tothe area that is designated by the key addressparameter in an OS read or write macro and by theKEYARG=parameter in DOSDTF macro.

END-OF-DATA

INVALID KEY

Figure 11-26 Updating in random mode

NOTES:

Page 311: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

UNIT 12: VSAM (VIRTUAL STORAGE ACCESS METHOD)

OBJECTIVE: Access Method Services

Basic I/O macros

Loading a VSAM Data set

Updating an Entry-Sequenced Data Set

Updating a Key-sequenced Data Set

Alternate Indexes

Page 312: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -2Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

VSAM (VIRTUAL STORAGE ACCESS METHOD)

Figure 12 -1 VSAM (virtual storage access method)

NOTES:

The Virtual Storage Access Method has been designed for several purposes;It isintended as a replacement for OS and DOS Indexed Sequential Access Methods(QISAM,BISAM;ISAM).

It may also be used instead of the OS and DOS Sequential Access Methods (QSAM,BSAM;ISAM).It can used in DataBase Management Applications such as IBM’sInformation Management System (IMS).

The Access Method Services Utility Program (AMS) provides means of creating VSAMData Sets, and the VSAM I/O provides a variety of processing option.

Page 313: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -3Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

VSAM DATASETS

VSAM provides support for three types of Datasets.

Entry-Sequenced Data Sets (ESDS)

Key-Sequenced Data Sets (KSDS)

Relative Record Data Sets (RRDS)

Figure 12-2 VSAM datasets

NOTES:

Page 314: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -4Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

ESDS: ENTRY SEQUENCED DATA SET

RECORD1 RECORD2 RECORD3 UNUSEDSPACE

RDF

RDF

CIDF

RECORD1 RECORD2 RECORD3UNUSEDSPACE

RDF

RDF

RDF

CIDF

Figure 12-3 ESDS

NOTES:

ESDS records are stored in a data set in the sequence in which they are presented to theoperating system. In this sense the sequencing of ESDS records is analogous to that ofsequential data-set records

ESDS has only a data component it contains fixed length or variable length records. Newrecords are only added at the end of the dataset, existing records can never be deleted, butthey can be updated.

Access Methods:1. Sequential Access2. Direct Access by means of relative byte address (RBA)

Page 315: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -5Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

RRDS: RELATIVE RECORD DATA SET

CI 0

SLOT1 SLOT2 SLOT3 SLOT4

CI 1

SLOT1 SLOT2 SLOT3 SLOT4

CI 2

SLOT1 SLOT2 SLOT3 SLOT4

Figure 12-4 RRDS

NOTES:

RRDS consists of a number of preformatted fixed-length slots. each slot has a uniquerelative record number, and the slots are sequenced by ascending relative recordnumber.

Each record occupies a slot, and is stored and retrieved by relative record number(RRN).

Access Methods:1. Sequential Processing

2. Skip-Sequential Processing

3. Direct Processing by means of relative record number (RRN)

Page 316: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -6Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

KSDS: KEY-SEQUENCED DATA SET

Index component

Data component

Figure 12-5 KSDS

NOTES:

KSDS has a data and an index component, it contains fixed length and variable lengthrecords.

KSDS records are stored in a data set in ascending key sequence.The key field that controls sequencing is known as the primary Key field.

In this sense the primary key and sequencing of KSDS data records are analogous tothose of indexed sequential data set records.Access Methods:

1. Sequential Access2. Direct Access by means of key3. Skip sequential access

IS1

IS2 IS3

SS SS6

SS1

SS2

SS3

SS4

CA1 CA2 CA3 CA4 CA5 CA6CI 1

CI 2

CI 3

CI 4

CI 1

CI 2

CI 1

CI 2

CI 1

CI 2

CI 1

CI 2

CI 1

CI 2

Page 317: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -7Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

VSAM BUILDING BLOCKS

Physical block All physical block can contain Last physical blocklogical records and unused space also contains CI info

…..

Control Interval

Control IntervalTrack1

Track2 PB Control Area

(M<=19) Tracks

Figure 12-6 VSAM building blocks

NOTES:

LR = Logical RecordA logical record is a unit of information used to store data in a VSAM data set.

CI = Control IntervalVSAM uses CI s to contain records. Whenever record is retrieved from DASD, the entireCI containing the record is read into VSAM I/O buffer in virtual storage.

CA = Control AreaThe CI’S in a VSAM data set are grouped together into fixed-length contiguous areas ofdirect storage called CA’S.A VSAM data set is composed of one or more CA’s.

LR LR LR

LR LR LR

LR

LR

LR LR

LRLR

Page 318: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -8Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

RBA’S AND CONTROL INTERVAL FORMATS

Cidf3

1 2 3 n RDFnRDF3

L1 L2 L3 Ln Rdf2 Rdf1UNUSEDSPACE

LOGICAL RECORDS CONTROL INFORMATION

CONTROL INTERVAL

Figure 12-7 RBA and CI ‘s

NOTES:

Page 319: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -9Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

RBA’S AND CONTROL INTERVAL FORMATS (CONT..)

CIDF=CONTROLINTERVALDEFINITION FIELD

2 2

L U

TOTAL LENGTH OF RECORDS LENGTH OF UNUSEDSPACE

1 THRU n 1 2

X’00’ Lk

RDFk = RECORD DEFINITIONFIELD FOR RECORD K

LENGTH OF RECORD K

Figure 12-8 RBA and CI’s continue..

NOTES :

Page 320: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -10Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

RBA ‘S AND CONTROL INTERVAL FORMATS (CONT…)

3 3X’04’

X’08’

L1 L2 L3 L2 Ln 3 3 3

1 2 3n

RDFn RDF RDF RDF1CIDF

2RDF’Sm CONSECUTIVE RECORDSEACH OF LENGTH L2

Figure 12-9 RBA and CI’s continue..

NOTES:

VSAM always uses the RBA to determine a record’s location in a dataset. But except incertain advanced applications of VSAM, RBA’s are not normally needed by userprograms to access records.

m L2

Page 321: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -11Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

AMS COMMAND SUMMARY

General usage

DEFINE Creates a catalog entry for a VSAM object

DELETE Deletes one or more VSAM objects and theircatalog entries

LISTCAT List information contained in a VSAM catalog

PRINT Prints the contents of a VSAM data set or of a sequentialor Indexed-sequential data set

REPRO Copies a VSAM or sequential or indexed sequential data setInto another catalog

VERIFY Verifies and corrects certain information about a data set ina catalog

Figure 12-10 AMS command summary.

NOTES:

AMS is the VSAM Utility program, executable under the name IDCAMS in both OSand DOS systems. The most important of its functions are :

It defines VSAM catalogs and data sets and allocates space for them.

It loads VSAM data sets from the input data stream and from other NON-VSAM datasets.

It prints the contents of VSAM catalogs and data sets

Page 322: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -12Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

AMS COMMAND SUMMARY (CONT..)

Special Usage

ALTER Changes catalog information about a VSAM object thatwas previously defined

BLDINDEX Initially loads a newly defined alternate index

CHKLIST List tape data set that were open at the time acheckpoint was taken (OS only)

CNVTCAT Converts OS catalog entries into VSAM VSAM catalogentries (OS only)

EXPORT Unloads a VSAM base cluster or alternate index ,together with its catalog entry, onto a movablestorage volume; alternatively, copies a user catalog ontoa movable volume and then disconnects that catalog fromthe system’s master catalog

Figure 12-11 AMS command summary continue.

NOTES:

Page 323: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -13Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

AMS COMMAND SUMMARY (CONT..)

EXPORTRA Unloads data sets whose catalog entries aredamaged, using the information about the dataset that is in the catalog recovery area instead ofthe information in the catalog itself.

IMPORT Defines and loads a data set or catalog that hadbeen unloaded via EXPORT

IMPORTRA Reconstructs a data set that had been unloaded viaEXPORTRA, by redefining it and reloading it

LISTCRA Lists the contents of a catalog recovery area and(optionally) compares it with the contents of theassociated catalog

RESETCAT Adjusts information in a catalog to be consistentwith that which is in its associated catalog recoveryarea and in the VTOC

Figure 12-12 AMS command summary continue

NOTES:

Page 324: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -14Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

ACCESS METHOD SERVICES (AMS)

There are several consideration of overriding importance when using AMS:

1. Every computer system that supports VSAM must have exactly one master catalogthat is created by AMS for the entire system .The master catalog is usually definedby the system administrator and will not be considered here .

2. Every VSAM user data set must be described either in the master catalog orin a user catalog that is created by AMS. For various reasons (e.g. ,Increasedprocessing efficiency and easier transportability to other computer systems), auser catalog should be used for this purpose rather than the master catalog .

3. There can be no more than one user catalog per storage volume ( e.g. ,oneper disk pack ). Like the master catalog , user catalogs are ordinarily defineby a system administrator rather than by a programmer.

4. No two VSAM data sets that are listed in the same catalog can have thesame data set name indeed , no two VSAM objects that are listed in thesame catalog can have the same name

The names of VSAM objects must contain from 1 to 44 characters, of whichthe first must be a letter (A through Z, and @,#,$) and the others can be lettersor digits.

Names longer than 8 characters must be segmented by periods into groups of 8,or fewer letters and digits (e.g.,VSAM.DATA.SET).

Consecutive periods are not permitted , and the last character of a name cannotbe a period. The portion of a name consisting of period and all characters tothe left that period is known as a qualifier; names containing qualifiers areknown as qualified names.

Page 325: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -15Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

DATA COMPONENTS, INDEX COMPONENTS, AND CLUSTERS

CONTROL AREA

Figure 12 –13 Data component and Index component.

NOTES:

Like the logical records in a control intervals the entries in a index record are stored inascending prime key sequence.

The imbedded index sequence set (the lowest level index) contains the highest key and apointer for each control interval that contains data in the control area that the sequence setpertains to.

Each higher-level index contains the highest key and the pointer for each of theimmediately lower-level indexes that pertain to.

CDC

AAA

BDEABC

XYZ

EFG

WXY

CRABRO DAB

XAB

XYZUSAKLAEFGCDC

BDE CDCBRO XYZ

XAB

WXY

EFG

DAB

CRA

XYZKLA

CONTROL

INTERVAL

Page 326: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -16Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

VSAM MACRO SUMMARY

Nonexecutable Control Block Macros

ACB Generates an access-method control block at assembly timeEXLST Generates a list of exit-routine addresses at assembly timeRPL Generates a request parameter list assembly time

Executable Control Block Macros

GENCB Generates the same information that an ACB, EXLST,or RPL macro does so at run time rather than assembly time

MODCB Modifies the contents of any of the control blocks that weregenerated by ACB,EXLST,RPL, or GENCB

SHOWCB Obtains the contents of one or more fields of any control block

TESTCB Tests the contents of any one of the fields in a control block

Figure 12-14 VSAM Macro summary

NOTES:

As in sequential and indexed sequential assembly language I/O programming, VSAM I/Oprogramming is accomplished via macros.

Types of Macros:1. Request Macros2. Control Block Macros

Control Block Macros are used to create, modify, obtain or test selectedfields of the control blocks.

The control blocks themselves are similar in purpose to the DTFxx areasin DOS and the DCP areas in OS systems.

The provided information is used at run time by the operating system. Theinformation generated by the ACB, RPL and EXLST macros in bothDOS and OS systems.

Page 327: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -17Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

VSAM MACRO SUMMARY (CONT….)

Request Macros for General Use

CHECK Waits for completion of an asynchronous I/O request

CLOSE Disconnects a program from a data set

ENDREQ Terminates an asynchronous I/O request

ERASE Deletes a record from a key-sequenced or relative-record data set

GET Retrieves a record from a data set

OPEN Connects a program to a data set

POINT Positions a data set at a designated record or class ofrecords

PUT Stores a record into a data set

Figure 12-15 VSAM Macro summary continue.

NOTES:

Request Macros are designed to be executed at run time.

They initiate actions such as opening a dataset and retrieving and updating records.

Page 328: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -18Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

VSAM MACRO SUMMARY (CONT..)

Request Macros For Advanced Applications

BLDVRP Builds a VSAM resource pool

DLVRP Deletes a VSAM resource pool

GETIX Retrieves a specified index control interval (OS only)

MRKBFR Marks a buffer for output, or to release it fromexclusive control or shared status (OS only)

PUTIX Stores a specified index control interval (OS only)

Figure 12-16 VSAM Macro summary continue.

NOTES:

Page 329: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -19Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

VSAM MACRO SUMMARY (CONT..)

SCHBFR Searches a buffer for an RBA with in specified ranges(OS only)

SHOWCAT Retrieves information from a VSAM catalog

VERIFY Ensures that the end-of-data information contained inthe catalog for a specific data set is accurate (OS only)

WRTBFR Writes a deferred buffer or (in OS only) writes abuffer that was marked for output via MRKBFR.

Figure 12-17 VSAM Macro summary continue.

NOTES:

Page 330: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -20Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

RELATIONSHIP OF JCL AND VSAM MACROS

//DLBL dname,’filename’, ,VSAM ddname DD DSN = dsname,….

acbname ACB …,DDANME = dname,EXLST = existname,….

rplname RPL ….ACB = acbname,…

existname EXLST …

OPEN (acbname)

GETPUT RPL = rplnameEtc

Figure 12-18 Relationship of JCL and VSAM Macro.

NOTES:

Page 331: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -21Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

ACB MACRO PARAMETER

General format : acbname ACB keyword1 = value1…..keywordn = valuen

KEYWORDS COMMONLY USED

AM =VSAM States that the access method is VSAM

DDNAME = dname DDname identifies the associated JCLstatement

MACRF = (macrf-options) Specifies options for run-time processing

KEYWORD FOR ERROR HANDLING

EXLST = existname Identifies this ACB’s EXLST macro

MAREA = addressnames an area to receive OPEN/C error messagesMLEN = length Specifies length of the MAREA area

Figure 12-19 ACB macro parameter

NOTES:

Page 332: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -22Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

ACB MACRO PARAMETER (CONT…)

KEYWORD FOR BUFFERSBUFND = n1 n1 = # I/O buffers used for data

component CisBUFNI = n2 n2 = # I/O buffer used for index

components CisBUFSP = s s = maximum number of bytes for

all data and index buffersSTRNO = n3 n3 = max number of request

required concurrent data-setpositioning

BSTRNO = n4 n4 = # strings accessing the basecluster of the path

Keywords for catalogsPASSWD = address Names a field that contains the

highest-level password requiredfor type of access specified inMACRF

CATALOG = NO | YES Specifies whether catalog is beingOpened as a catalog (YES) or as adataset(NO); default is NO

CRA = SCRA | UCRA Requests system or user storage beUsed when processing a catalogrecovery area

Figure 12-20 ACB Macro summary continue.

NOTES:

The ACB Macro must be referred to when opening and closing a VSAM data set.

The Basic option specified in an ACB are these : The identity of an OS DD statement orDOS DLBL statement that in turn identifies the VSAM data set to be processed and theiranticipated logical record accessing modes.

The other options may be specified in an ACB are the buffer space requirements forreading and writing CONTROL INTERVALS and the address of the EXLST Macro thatpertains to this ACB. If needed password also can be specified.

Page 333: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -23Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

ACB MACRO PARAMETER (CONT..)

MACRF-Options For Data Set Access

KEY | ADR | CNV Keyed addressed, or control-intervalAccess

SEQ | DIR | SKP Sequential, direct or skip-sequentialAccess

IN | OUT IN means retrieval only; OUT meansLoading or updating

NRM | AIX NRM means process the objectnamed by DDNAME = ; AIX meansProcess the alt index whose path isnamed by DDNAME =

NRS | RST NRS: not a reusable data set, or elsedo not set high-RBA to zero; RST:reset high-RBA of reusable data setto zero

Figure 12-21 ACB Macro summary continue

NOTES:

Page 334: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -24Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

ACB MACRO PARAMETER (CONT…)

Macrf-options for performance improvement

NUB | UBF Whether or not user programManages use of I/O buffers

NFX | CFX Whether or not buffers and controlblocks are swappable

NCI | ICI Whether or not to use improvedControl-interval processing

NIS | SIS whether or not to split control

Macrf-options for shared resources

NSR | LSR |GSR Non shared locally shared orGlobally shared resources

NDF | DFR nondeferred or deferred writingOf shared buffers

DDN | DSN Shared control blocks are based onddnames / dsnnames

Figure 12-22 ACB Macro summary continue

NOTES:

Permission to process a VSAM data set must be requested at run time by an OPENmacro.

The macro must in turn specify the address of an ACB macro by describes the anticipatedprocessing requirement.

All the accessing mode that are going to used while the data set is being processed mustbe specified in the ACB macro.

Page 335: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -25Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

RPL MACRO PARAMETERS

General format rpl name RPL keyword1 = value1,….keywordn = valuen

Keywords commonly used

AM = VSAM States that the access method isVSAM

ACB = acbname Identifies the associated ACBControl block

AREA = areaname Identifies the work area for logicalRecords in move mode

AREALEN = m m is the length of work area, andshould be no less than the length of thelongest record to be processed

ARG = fieldname Identifies the field that contains thesearch key or RBA used in direct andskip-sequential access, and inpositioning

KEYLEN = k k is the length of the generic key usedwhen OPCTD = GEN

RECLEN = r r is the length of the record that PUTAdds or inserts

OPTCD = (optcd-options) Specifies options for run-timeprocessing

Figure 12-23 Rpl macro parameters

NOTES:

The RPL Macro must be referred to each time any macro other than the OPEN orCLOSE (or GENCP) is executed at run time.

The basic options specified in an RPL are these: the name of the ACB that the RPL isassociated with; the address and length of the I/O record work area; the record accessingmode to be used for a particular request; the address of the search argument fordirect accessing and for record positioning; and whether or not the request is forupdating a record.

Page 336: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -26Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

KEYWORDS FOR ADVANCED APPLICATIONS

TRANSID=i Is a number that identifies all the modifiedBuffers associated with a given transaction

ECB=address Identifies an event control block used withasynchronous

MSGAREA=address Names an area to receive physical I/O errormessages from VSAM

MSGLEN= length Specifies the length of the MSGAREA area;Must be >= 128

NXTRPL=address Specifies the address of the next RPL in a chainOf RPL’s

Figure 12-24 Keywords for advanced applications

NOTES:

Page 337: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -27Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

OPTCD-OPTIONS

KEY | ADR | CNV Keyed, addressed, or control-interval access

SEQ | DIR | SKP Sequential, direct, or skip-sequential access

MVE | LOC Move mode or locate mode

NUP | UPD | NSP Is not for update, is for update, or note sequentialposition

KEQ | KGE With keyed access, find the first record with akey that is either equal to, or greater than orequal to, the search key

FKS | GEN Specifies whether the search key is a full keyor a generic key

FWD | BWD Record accessing is either in the forward or thebackward direction; if BWD, then KEQ and FKSare assumed

Figure 12-25 OPTCD - OPTIONS

NOTES:

Defaults for all optcd-options are specified above as the first choice each group of twoare three options.

Page 338: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -28Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

OPTCD-OPTIONS (CONT…)

ARD | LRD ARD: record accessing is as specified in otherparameters; LRD: locate or retrieve the lastrecord in the data set (BWD)

SYN | ASY Synchronous or asynchronous accessing

NWAITX | WAITX Specifies whether or not to give control to theuser’s UPAD error-exit routine to synchronizeprocessing of shared resources

Figure 12-26 OPTCD – OPTIONS

NOTES:

Page 339: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -29Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

THE DEFINE COMMANDS

The AMS DEFINE command must be used to create a new catalog andmust be used to create an entry in an existing catalog for any VSAMobject.

There are seven variations of this command, corresponding to the sevenVSAM objects:

In full abbreviated

DEFINE MASTERCATALOG DEF MCAT

DEFINE USERCATALOG DEF UCATDEFINE SPACE DEF SPCDEFINE CLUSTER DEF CLDEFINE NONVSAM DEF NVSAMDEFINE ALTERNATEINDEX DEF AIXDEFINE PATH DEF PATH

Figure 12-27 The DEFINE Command.

NOTES:

The methods of space allocation that seem to the author to be appropriate for mostapplications consist of three steps:

1.Use the DEF UCAT command to allocate space for a user catalog

2.Use the DEF SPC command to allocate space to be shared by all VSAM clusters andalternate indexes that are define in that user catalog.

3.Use the DEF CL command to request space for a cluster and the DEF AIX command torequest space for an alternate index.

Page 340: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -30Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

DEFINE CLUSTER

General Format

DEFINE CLUSTER(cluster options) –DATA (data options) –INDEX (index options) –CATALOG (catalog options) –

Figure 12-28 DEFINE CLUSTER

NOTES:

Page 341: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -31Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

CLUSTER OPTIONS

NAME (entry name) Specifies the name of the cluster

VOLUME (volser) Identifies the volume where theCluster will reside

CYL (p s) |TRK (p s)|REC (p s) Specifies the amount of space to beAllocated; p is the primary allocation,the secondary

FILE (dname) Identifies the DD or DLBL statementlinked to the cluster

NONINDEXED | INDEXED NONINDEXED means it’s an ESDS;INDEXED means it’s a KSDS

NOREUSE | REUSE Specifies whether or not it is a“Reusable” data set

SUBALLOCATION|UNIQUE Specifies whether the data set shares aSuballocatable data space or is allotted

NOIMBED|IMBED (KSDS only) specifies whether or not toImbed the index sequence Set

Figure 12-29 Cluster options

NOTES:

Page 342: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -32Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

DEFINE CLUSTER PARAMETERS

Data options:

NAME(entryname) Specifies the name of the datacomponent

RECSZ(avg max) Specifies the average and maximumlength of data records

CISZ(size) Specifies the data component controlInterval size

KEYS(length offset) For KSDS only, specifies the length ofthe primary key and its displacementfrom the Beginning of a record.

FSPC(ci ca) For KSDS only, CI specifiesthe percent of space in each controlinterval and CA.The percent in each control area thatIs to be left free when the cluster isloaded

Figure 12-30 DEFINE CLUSTER parameters.

NOTES:

Page 343: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -33Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

DEFINE CLUSTER PARAMETERS (CONT..)

Index options(for KSDS only)

NAME (entryname) Specifies the name of the index component

CISZ( size) specifies the index component controlInterval size

Catalog options

CATALOGNAME / PASSWORD Identifies the name of the catalog in whichthe cluster is to be defined and specifies thepassword (if any) required to update the catalog;the slash / between catalogname and passwordmust be included if a password is specified

Figure 12-31 Define cluster parameters continue.

NOTES:

Page 344: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -34Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

THE REPRO COMMAND

For OS system

//STEP004 EXEC PGM= IDCAMS//STEPCAT DD DSN=SAMPLE.UCAT, DISP=SHR//NEWDD DD DSN=DORM.FILE,DISP=OLD//OLDDD DD VOL=SER=VOLB,UNIT=3330,DISP=(OLD,KEEP),// DSN=DORM.FILE,DSORG=PS,// DCB=(RECFM=FB,LRECL=106,BLKSIZE=4036)//SYSPRINT DD SYSPRINT=A//SYSIN DD *

REPRO INFILE(OLDDD) -OUTFILE(NEWSS)

/*

Figure 12-32 Repro command

NOTES:

The AMS REPRO command can be used to load a new VSAM data set with recordsobtained from a non-VSAM dataset.

The VSAM dataset that is loaded by REPRO must have been previously defined by theDEFINE command.

The sequential is the input to the REPRO command and the output is a KSDS cluster.

Page 345: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -35Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

THE REPRO COMMAND (CONT…)

For DOS systems

//DLBL OLDDD,’SEQTL.DORM.FILE’//EXTENT SYS020, , , ,50,130//ASSGN SYS020,DISK,VOL=VOLB,SHR//DLBL NEWDD,’DORM.FILE’, ,VSAM//EXTENT SYS010,VOLA//ASSGN SYS010,DISK,VOL=VOLA,SHR//EXEC IDCAMS,SIZE=AUTO

REPRO -INFILE (OLDDD -ENV (RECFM (FB) -

BLKSZ (4028) -RECSZ (106) -PDEV (3330) -) -

OUTIFLE (NEWDD)

/*

Figure 12-33 Repro command continue.

NOTES:

1. The only change required loading an ESDS cluster rather than a KSDS cluster isto change the job control statements that identify the cluster that is being loaded.

2. The cluster being must be identified in the JCL by its base cluster name, not by itsdata or index component names.

Page 346: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -36Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

LOADING A VSAM DATASET

1 CREATE CSECT2 . . . STANDARD ENTER NOT SHOWN3 *4 * INITIALIZATIONS5 *6 OPEN (MASTER) OPEN VSAM MASTER FILE7 LTR 15,15 SEE IF OPEN WAS SUCCESSFUL8 OPEN (TRANS, (INPUT)) IF NOT, TERMINATE,9 * DOS ********

10 * OPEN TRANS11 ****************12 GET TRANS,INAREA GET FIRST TRANSACTION RECORD13 BAL 14,CONSTRUCT BEGIN CONSTRUCTING FIRSTOUTPUT RECD 14 *15 * MAIN PROCESSING16 *17 READ GET TRANS,INAREA GET NEXT TRANS RECD18 *19 WRITE PUT RPL=LOADIT MOVE OUTPUT RECDTO OUTPUT BUFFER20 LTR 15,15 SEE IF ANY I/O ERRS21 BNZ EOJK IF SO, TERMINATE22 BAL 14,CONSTRUCT BEGIN CONSTRUCTING, NEXTOUTPUT RECD

Figure 12-34 Loading a VSAM dataset.

NOTES:

Page 347: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -37Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

LOADING A VSAM DATASET (CONT…)

23 *24 *25 * END-OF-DATA PROCESSING26 *27 EOJ PUT RPL=LOADIT MOVE LAST OUTPUT RECDTO OUTPUT BUF.28 EOJX CLOSE (MASTER) CLOSE ALL FILES29 CLOSE (TRANS)30 * DOS ********31 * CLOSE TRANS32 *******************33 STDXIT . . . STANDARD EXIT NOT SHOWN34 *35 * OS DCP AND DOS DTFCD FOR TRANS FILE ARE ALSO THE SAME ,AS ARE THE INPUT36 * RECORD AREAS FOR THE TRANS AND MASTER FILES. BUT OS DCPAND DOS DTCST37 * FOR MASTER FILE ARE REPLACED BY THIS VSAM ACB / RPL PAR38 *39 MASTER ACB

AM=VSAM,DDNAME=DORMS,MACRF=(ADR,SEQ,NUP,MVE)40 LOADIT RPL AM=VSAM,ACB=MASTER,RECLN=106,

AREA=OUTAREA,AREALEN=106,OPTCD=(ADR,SEQ,NUP,MVE)

41 *42 END

Figure 12-35 Loading VSAM dataset.

NOTES:

Page 348: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -38Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

JCL CONTROL FOR ALTERNATE INDEX

For OS systems://STEP006 EXEC PGM=IDCAMS

//STEPCAT DD DSN=SAMPLE.UCAT,DISP=SHR//AIXDD DD VOL=SER=VOLA,DISP=OLD,UNIT=3330//SYSPRINT DD SYSOUT=*//SYSIN DD *

For DOS systems//DLBL CLDD,’DORM.FILE’, , VSAM//EXTENT SYS010,VOLA//DLBL AIXDD,’DORM.FILE.AIX1’, , VSAM//EXTENT SYS010,VOLA//DLBL PATHDD,’DORM.FILE.PATH1’, , VSAM]//EXTENT SYS010,VOLA//ASSGN SYS010,DISK,VOL=VOLA,SHR//EXEC IDCAMS,SIZE=AUTO

Figure 12-36 JCL control for alternate index.

NOTES:

An Alternate Index enables records in an ESDS or KSDS base cluster to be identified andaccessed by key. The key is known as Alternate key, to distinguish it from the prime keyof KSDS cluster

Page 349: Assembler Book

Student Notebook

© Copyright MCPL. Unit 13. Assembly Concepts Page 13 -

Courses may not be reproduced in whole or in partWithout the prior written permission of MCPL.

1

UNIT 13: ASSEMBLER CONCEPTS

Objectives:

Fundamentals of the assembly process

Assembler tables

Assembler processing logic

The object module

Table searching

Sorting tables

Cross-references

Page 350: Assembler Book

Student Notebook

© Copyright MCPL. Unit 13. Assembly Concepts Page 13 -

Courses may not be reproduced in whole or in partWithout the prior written permission of MCPL.

2

ASSEMBLER INPUT AND OUTPUT

ddsss

Figure: 13-1 Assembler input and output

NOTES:

The machine language representation of source module is produced by the assembler andstored in an object module.

Assembler produces a listing that correlates the source and object module contents andprovides certain diagnostic information.

SourceModule

AssemblerProgram

Objectmodule

Listing

Page 351: Assembler Book

Student Notebook

© Copyright MCPL. Unit 13. Assembly Concepts Page 13 -

Courses may not be reproduced in whole or in partWithout the prior written permission of MCPL.

3

TWO – PASS ASSEMBLER

PASS 1: To determine the values of symbols.

PASS 2: To produce the object code.

EQU DIRECTIVES.

Figure 13-2. Two – pass assembler

NOTES:

The entire source module is processed twice in succession, statement by statement.

PASS 1 is a mechanism that assigns values to symbols and address to literals.

PASS 2 is a mechanism that creates the object module, the listing and relatedinformation.

For a two – pass assembler, a symbol must be defined prior to its occurrence in an EQU’soperand. The assembly processes depend on the information represented in tables. Someof these tables generated as part of the assembler source module, some at assembly time.

The two – pass assembler mechanism depicted in diagram and the tables will discussed inlater sections.

Page 352: Assembler Book

Student Notebook

© Copyright MCPL. Unit 13. Assembly Concepts Page 13 -

Courses may not be reproduced in whole or in partWithout the prior written permission of MCPL.

4

ASSEMBLER TABLE AND FILE USAGE

Figure: 13-3 Assembler table and file usage

NOTES:

SourceModule

PASS

1

PROCESSING

PASS

2

PROCESSING

Opcodetable

ESD

TXT

RLD

Listing

Directivetable

Symboltable

Baseregistertable

Literaltable

Intermediatefile

Objectmodule

Page 353: Assembler Book

Student Notebook

© Copyright MCPL. Unit 13. Assembly Concepts Page 13 -

Courses may not be reproduced in whole or in partWithout the prior written permission of MCPL.

5

FUNDAMENTALS OF THE ASSEMBLY PROCESS

Information requirements

Instructions and Directives

Values of symbols

Addresses of literals

Tables

Assembler processing requirements

Figure 13-4. Fundamentals of the assembly process

NOTES:

The assembler to carry out the process from the source module to object module it needs– descriptions of instructions and directives, determine and remember the value ofsymbols, identities and addresses of literals and base register and base address.

Table is a collection of data arranged in some order so that the data items are relativelyeasy to locate and process. the simplest form of the table is single – dimensional integerarray in which each integer is an entry of the table. Table entries contain more than onedata item; among the items is a key that identifies the entry.

Page 354: Assembler Book

Student Notebook

© Copyright MCPL. Unit 13. Assembly Concepts Page 13 -

Courses may not be reproduced in whole or in partWithout the prior written permission of MCPL.

6

ASSEMBLER PROCESSING REQUIREMENTS

Directives: CSECT, DSECT, ENTRY, EXTRN, USING, DROP,DC, DS, EQU, END

Data-type codes: C- , X- , F - , A- and V-

Procedures: SAVE + 4

Listing

Figure 13-5 Assembler processing requirements

NOTES:

Assembler is complex program written in assembley language that requires number ofstatements, instruction codes, instruction formats and base registers to handle the user’ssource module.

In IBM 360 and 370, there are 150 instruction codes, 50 directives, 7 instruction formatsand 15 data type codes. But frequently used are mentioned above.

Page 355: Assembler Book

Student Notebook

© Copyright MCPL. Unit 13. Assembly Concepts Page 13 -

Courses may not be reproduced in whole or in partWithout the prior written permission of MCPL.

7

OPCODE TABLE

Figure: 13-6 OPCODE table format

NOTES:

5bytesMnemonic opcodeopcode

EBCDICAAD

ADRAE

AERAHAL

ALRAP

1 byteMachineopcode hex

5A6A2A7A3A4A5A1EFA

1 ByteMask InstrField Hex Type

hex0 10 10 00 10 00 10 10 00 6

1 ByteInstr Flagslength hex binary10 00000010 00100001 00100010 00100001 00100010 00000010 00000001 00000011 010000

17F8

0 00 6XR

ZAP

01 00000011 010000

Page 356: Assembler Book

Student Notebook

© Copyright MCPL. Unit 13. Assembly Concepts Page 13 -

Courses may not be reproduced in whole or in partWithout the prior written permission of MCPL.

8

OPTCODE TABLE FORMAT (CONT.)

Instruction type: 0 = RR 2 = RS 4 = S1 = RX 3 = SI 5 = SS16 = SS2

Instruction length: 01 = 2 Bytes10 = 4 Bytes, 11 = 6 Bytes

Extended mnemonicStore clock

Extended precision floating pointFloating point

Packed decimalUnused bit

Figure : 13-7 Opcode table cont..

NOTES:

Opcode table describes the instructions will be defined for Assembley process.

Each Entry in the table consists 8-bytes that are divided into 5 items or Fields.

Mnemonic instruction code: 5-bytes key field. Entries are in ascending sequence by thevalue of this field.

Machine language opcode: 1-byte information of instruction’s type and length.

Mask field: defines conditional branch instructions.

Other information in a table represented by the 1-bit flag fields.

Page 357: Assembler Book

Student Notebook

© Copyright MCPL. Unit 13. Assembly Concepts Page 13 -

Courses may not be reproduced in whole or in partWithout the prior written permission of MCPL.

9

DIRECTIVE TABLE

Figure: 13-8 Directive table format

NOTES:

Directive table is used to process the directives and to determine the given characterstring represents a valid directive or not.

It contains the address of the routine within the assembler that process each directive.

Each directive has its own processing routine.

5 Bytes

MnemonicDirectiveC’ACTR’C’AGO’C’AIF’

C’ANOP’C’CNOP’C’COM’C’COPY’C’CSECT’

1100 C’CXD’

C’DC’

3 BytesAddress of processingroutine

AL3(DIRACTR)AL3(DIRAGO)AL3(DIRAIF)

AL3(DIRANOP)AL3(DIRCNOP)AL3(DIRCOM)AL3(DIRCOPY)AL3(DIRCSECT)

AL3(DIRCXD)AL3(DIRDC)C’TITLE’

C’USING’C’WXTRN’

AL3(DIRTITLE)AL3(DIRUSING)AL3(DIRWXTRN)

Page 358: Assembler Book

Student Notebook

© Copyright MCPL. Unit 13. Assembly Concepts Page 13 -

Courses may not be reproduced in whole or in partWithout the prior written permission of MCPL.

10

SYMBOL TABLE

8 bytes | 4 bytes | 2 bytes | 2 bytes | 1 byte | 1byteSymbol Value

Length attributeStatement numberControl section numberRelocatable / absolute indicator

Figure: 13-9 Symbol table

NOTES:

Page 359: Assembler Book

Student Notebook

© Copyright MCPL. Unit 13. Assembly Concepts Page 13 -

Courses may not be reproduced in whole or in partWithout the prior written permission of MCPL.

11

LITERAL TABLE

2 4 2 | variable length

Assembled lengthAddress

Figure: 13-10 Literal table format

NOTES:

A Literal is entered in to the Literal table, when it is obtained from an instruction’soperand field in PASS1.

Addresses are assigned to any literals in the table when an END or LSTORG directiveis processed.

In IBM 360 and 370 systems, the first address assigned to a literal is always on a Double-word boundary.

Source statmentStringlength

Page 360: Assembler Book

Student Notebook

© Copyright MCPL. Unit 13. Assembly Concepts Page 13 -

Courses may not be reproduced in whole or in partWithout the prior written permission of MCPL.

12

BASE – REGISTER TABLE

1 Byte | 3 Byte | 1 ByteBase address

Base register

Control section number

USING Base-address , base-register-1, base-register-2,…..

DROP Base-register-1, base-register-2,……..

Figure: 13-11 Base register table

NOTES:

The entries in the table reflect the information from the USING and DROP directives. Toallow for the designation of symbolic base registers and symbolic base addresses andentries are not made in this table until PASS2.

USING directive causes an entry to be made in the table for each base register designatedin its operand.

DROP directive causes entries to be deleted. To compute a base – displacement addresscorresponding to a relocatable symbolic address, the assembler chooses the base registerwhose base address is in the same control section as the symbolic address.

Page 361: Assembler Book

Student Notebook

© Copyright MCPL. Unit 13. Assembly Concepts Page 13 -

Courses may not be reproduced in whole or in partWithout the prior written permission of MCPL.

13

INTERMEDIATE FILE

1 3 1 3 | variable length

Control section member

C M D I eStatement type indicator

C = comment statement m = macro d = directive

I = instruction e = opcode error

Figure: 13-12 Intermediate table format

NOTES:

Each entry in the intermediate file is created in PASS1, PASS2. The sequence of theentries is the same as that of the statements in the source module.

Each entry contains a copy of a source module statement plus some additionalinformation determined in PASS1. It includes the MLC at the time the statement wasprocessed.

Source statementOp/direntryaddress

MLCType

Page 362: Assembler Book

Student Notebook

© Copyright MCPL. Unit 13. Assembly Concepts Page 13 -

Courses may not be reproduced in whole or in partWithout the prior written permission of MCPL.

14

ASSEMBLER PROCESSING LOGIC – PASS 1

The principal ideas in Pass 1 are:

Comment statements are processed by simply putting anappropriate entry on the intermediate.

Instructions must be aligned on a half-word boundary, literalsand name-field symbols must be placed in the appropriate tables,MLC must be increased by the instruction length.

Each directive has separate processing requirements.

Figure 13-13. Assembler processing logic – pass 1

NOTES:

Page 363: Assembler Book

Student Notebook

© Copyright MCPL. Unit 13. Assembly Concepts Page 13 -

Courses may not be reproduced in whole or in partWithout the prior written permission of MCPL.

15

ASSEMBLER PROCESSING LOGIC – PASS 2

The principal ideas in Pass 2 are:

The opcode and directive tables need not be searched becauseintermediate file consists information to describe the statementtype.

After creation of object code it is not directly written to the objectmodule instead it is placed in TXT table.

Out of ten directives only four is used they are END, DC, USINGand DROP.

The listing is created in pass 2 one line at a time as each statementis processed.

Address constants created by DC directives and literals areaccumulated in the RLD table to be written on the object moduleat the end of pass2.

Figure 13-14. Assembler processing logic – pass 2

NOTES:

Page 364: Assembler Book

Student Notebook

© Copyright MCPL. Unit 13. Assembly Concepts Page 13 -

Courses may not be reproduced in whole or in partWithout the prior written permission of MCPL.

16

THE OBJECT MODULE

ENTRIES:

External Symbol Dictionary Entries (ESD)

Object Code Entries or Text (TXT)

Relocation Dictionary Entries (RLD)

End Entry (END)

RELOCATION

LINKING

ESDID (External Symbol Dictionary Identification Number)

Figure 13-15. The object module

NOTES:

Page 365: Assembler Book

Student Notebook

© Copyright MCPL. Unit 13. Assembly Concepts Page 13 -

Courses may not be reproduced in whole or in partWithout the prior written permission of MCPL.

17

TABLE SEARCHING

Table search is mainly divided into two types:

Linear search

Binary search

Figure 13-16. Table searching

NOTES:

Table search is a processing technique to find the table entry. This search consists of twotypes linear search and binary search.

Page 366: Assembler Book

Student Notebook

© Copyright MCPL. Unit 13. Assembly Concepts Page 13 -

Courses may not be reproduced in whole or in partWithout the prior written permission of MCPL.

18

LINEAR SEARCH

LINEAR_SEARCH:

J := 1;REPEAT WHILE J <= Number of entries in table

IF search-key = key of Jth entry of tableTHEN

{key found in Jth entry}EXIT LINEAR_SEARCH;END IF;Increase J by 1;

END WHILE;{key not found}EXIT LINEAR_SEARCH.

Figure 13-17. Linear search

NOTES:

Linear search is start searching from the first one until the desired entry is found. Linearsearch is simple to implement but it is time-consuming when there are large number ofentries in the table. Linear search requires half the time of the entries that is if there are Nentries then average time is A(N/2).

Page 367: Assembler Book

Student Notebook

© Copyright MCPL. Unit 13. Assembly Concepts Page 13 -

Courses may not be reproduced in whole or in partWithout the prior written permission of MCPL.

19

BINARY SEARCH

BINARY_SEARCH:

{set initial group to entire table}LOWPT := 1; {first entry}HIPT := M; {number of entries in table}REPEAT WHILE LOWPT < HIPTMIDPT := integer portion of (LOWPT + HIPT)/2; {index of current middle}IF search_key = key of entry of table at position MIDPTTHEN

{key found in MIDPT entry}EXIT BINARY_SEARCH:ELSE

IF search_key < key of entry of table at position MIDPTTHEN

HIPT := MIDPT – 1; {use lower half of current group}ELSE

LOWPT := MIDPT + 1; {use upper half of current group)END IF;END IF;END WHILE;IF LOWPT = HIPTTHEN {one entry remains to be checked}IF search_key = key of remaining entry of tableTHEN

{key found in MIDPT =/- entry}EXIT BINARY_SEARCH;END IF;END IF;{key not found}EXIT BINARY_SEARCH.

Figure 13-18. Binary search

NOTES:

Page 368: Assembler Book

Student Notebook

© Copyright MCPL. Unit 13. Assembly Concepts Page 13 -

Courses may not be reproduced in whole or in partWithout the prior written permission of MCPL.

20

BINARY SEARCH (CONT…)

The binary search technique involves starting at the middle of the table and proceeding in

the following manner:

Determine, by comparing the search key to the key of the middle entry, whether the

sought-for entry is in the first half or last half of the table.

After determining appropriate area, examine the middle entry of that half, to determine

which of the two halves of that half is the appropriate area in which to look further.

Continue this process until the desired entry found or not found.

Page 369: Assembler Book

Student Notebook

© Copyright MCPL. Unit 13. Assembly Concepts Page 13 -

Courses may not be reproduced in whole or in partWithout the prior written permission of MCPL.

21

LINEAR vs. BINARY SEARCH TIME

A(N/2)

B(LOG2)/N

Figure: 13-19 Binary Vs Linear

NOTES:

For linear search, there are N entries, the average search time will be more A (N/2)Where A is a function of the speed of the computer and of the number and type ofinstructions used in each iteration of the search procedure.

The average search time using the Binary search technique B (log2/N)

Page 370: Assembler Book

Student Notebook

© Copyright MCPL. Unit 13. Assembly Concepts Page 13 -

Courses may not be reproduced in whole or in partWithout the prior written permission of MCPL.

22

SORTING TABLES

Internal sorting

External sorting

Straight insertion sort

Other sort techniques

Criteria for best sort

Figure 13-20 Sorting tables

NOTES:

Sorting involves rearrangement of entries into some prescribed order in the table.

The sorting is based on the some property of the each entry. Property is a value of one ormore fields of an entry.

All the entries that are to be sorted can fit in main memory through the processing called‘Internal sorting’.

The number of entries is so large that only a portion can be in main memory at on time,the rest being in secondary memory, the process is known as ‘external sorting’

There is no known best way to sort an arbitrary set of data in an arbitrary chosen system.The best situation would be one that used least amount of time and least amount ofmemory space. This is depending on the system, on the instructions used in thealgorithm, how many entries are to be sorted and how badly out of sequence.

Page 371: Assembler Book

Student Notebook

© Copyright MCPL. Unit 13. Assembly Concepts Page 13 -

Courses may not be reproduced in whole or in partWithout the prior written permission of MCPL.

23

STRAIGHT INSERTION SORT

INSERTION_SORT

REPEAT FOR j = 2 to nk = key from record jr = copy of record ji = j – 1{ i will be the position of the left of the inserted jth record }REPEAT WHILE ( I > 0) AND ( k < key from record j)

Move record i to record i+1Subtract 1 from i

END WHILEMove r to record i + 1

END FOREXIT-INSERTION_SORT

Figure 13-21 Straight insertion sort.

NOTES:

Page 372: Assembler Book

Student Notebook

© Copyright MCPL. Unit 13. Assembly Concepts Page 13 -

Courses may not be reproduced in whole or in partWithout the prior written permission of MCPL.

24

OTHER SORT TECHNIQUES

EXCHANGE TECHNIQUES: Which interchange pairs of entries thatare out of order until no more pairs exist in the table.

MERGE TECHNIQUES:

SELECTION TECHNIQUES: Which search for the smallest(or largest) entry, then for the next smallest (or largest), and soon.

DISTRIBUTION TECHNIQUES

Figure 13-21 Other sort techniques

NOTES:

Merge technique, which combine two or more already sequenced subset of entries toproduce a new sequenced subset and continue in this way until all the sequenced subsetshave been merged into one, which is the final sorted table.

Distribution technique, in which a portion of each is examined and the entries separatedinto subsets, one for each different value of key portion being examined. A differentportion of key is then used and the process repeated, maintain the order of the entries thatwas established by the previous distribution. Continue this process until the final portionof the key has been examined. The final subset produced consists of all the entries insequence.

Page 373: Assembler Book

Student Notebook

© Copyright MCPL. Unit 13. Assembly Concepts Page 13 -

Courses may not be reproduced in whole or in partWithout the prior written permission of MCPL.

25

CROSS – REFERENCES

SPACE CONSIDARATIONS:How many tables are there andhow much space should be reserved for each table.

LIST and PRINTERS

CROSS – REFERENCE LIST STRUCTURE

Figure 13-22 Cross – references

NOTES:

Cross – referenced information for a source module: the statement numbers of allstatements in which the symbol appears in an operand field, in order that they can beprinted at the end of PASS2.

To get this information would be to have one cross – reference table for each symbol.But it poses space consideration problems because we don’t know how many symbolsthere will be in a given source module until that module is processed.

To resolve these problems with a scheme called list.LIST is set of entries that may be scattered in memory, instead of being consecutive as ina table. Each list entry contains at least one field that is used in locating another entry ofthe list. The content of that field is called ‘Pointer’. POINTER can be an address or anyother number that can be used in calculating an address.

Page 374: Assembler Book

Student Notebook

© Copyright MCPL. Unit 13. Assembly Concepts Page 13 -

Courses may not be reproduced in whole or in partWithout the prior written permission of MCPL.

26

CROSS – REFERENCE LIST STRUCTURE

Statement numberin which symbol isreferenced

Pointer to nextentry for thissymbol

2 bytes 2 bytes

# 1 save

2 mainline

3 array1

4 arrayfld

5 a1

6 subr

Figure: 13-23 Cross-reference tables.

NOTES:

The entries would be place in cross – reference table in pass2 of the assembler when thecorresponding intermediate file is processed. The list structure has these properties.

Each entry consists of two fields of 2 bytes each.Statement number field: identifies the statement in which the cross – reference occurs.

Pointer field: identifies the next entry in the structure that contains the cross – referencefor the same symbol.

5

6

8

11

12

15

2

5

6

0

4

0

Page 375: Assembler Book

Student Notebook

© Copyright MCPL. Unit 13. Assembly Concepts Page 13 -

Courses may not be reproduced in whole or in partWithout the prior written permission of MCPL.

27

CROSS – REFERENCE LIST STRUCTURE (CONT…)

Suppose the assembler has determined the address of the symbol table entry for a symbolthat has been referenced in the operand of a source module statement.Then to make an entry in the cross – reference table, the following procedure may beused:

I.The pointer to the next available position in the cross – reference area is determined.II.If the reference counter field in the symbol table entry is zero, this is the first reference

for that symbol. Therefore, the pointer to the next available position is placed in both thefirst and last entry pointer fields, the reference counter is set to 1, and an entry made inthe cross – reference area with a pointer of zero.

III.If the reference counter in the symbol table entry is not zero, the pointer to the last cross –reference entry for that symbol tells the assembler where to insert the new pointer in thelist. The new entry is added in the first available position, and its pointer field set to zero.Both the reference counter and the last entry pointer fields in the symbol table entry areupdated accordingly.

The structure described for the cross – reference data is known as a ‘one – way list orFIFO (first – in, first - out)’.

Page 376: Assembler Book

STUDENT NOTE BOOK

© Copyright MCPL. Unit 14. Internal Subroutines Page 14-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

UNIT-14 INTERNAL SUBROUTINES

OBJECTIVES:

Terminology

Linkage

Address Constants

Parameters and Registers

Modularization

Multiple base Registers

Page 377: Assembler Book

STUDENT NOTE BOOK

© Copyright MCPL. Unit 14. Internal Subroutines Page 14-2Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

INTERNAL SUBROUTINES

Subroutines

Internal Subroutine

External Subroutine

Figure 14-1. Internal subroutines

NOTES:

Subroutine is a set of statements that may be used at one are more points in a computerprogram to perform some task of that request of that program.

An internal subroutine is one whose statements are contained within the requestingprogram at assembly time.

An external subroutine is one whose statements are assembled separately from therequesting program.

Alternative names for the concept of a subroutine are subprogram and procedure.

Page 378: Assembler Book

STUDENT NOTE BOOK

© Copyright MCPL. Unit 14. Internal Subroutines Page 14-3Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

TERMINOLOGY

Calling and called programs.

Program P. Program Q.

P calls Q

Q returns toP’s re-entry

Called Program point Calling Program

Sequence of Called Programs:

P Q RP calls Q Q calls R

Q returns R returnsto P to P to Q

Figure 14.2 Terminology

NOTES:

When a program requests that a subroutine perform its task, it is said to call thatsubroutine. The program making the request is known as the caller. The subroutinerequested to perform the task known as the called program.

The address of the first instruction executed by a subroutine when it is called is thesubroutine’s entry point. The address of the instruction to which a subroutine branchesis called is the subroutine’s entry point.

A closed subroutine is one written in such a way that a single copy of it is all that isrequired, no matter how many places it is used in a program.

Instructions andData of

Program P

Instructions andData of

Program Q.

Page 379: Assembler Book

STUDENT NOTE BOOK

© Copyright MCPL. Unit 14. Internal Subroutines Page 14-4Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

LINKAGE

Calling a Subroutine

Returning from a Subroutine

RR type Branches

BAL’s Rentry Register

Figure 14.3 Linkage

NOTES:

A closed subroutine can be called from any number of different places within in program,the caller has to be able to specify reentry point to which the subroutine will return. InIBM 360 and 370 systems, there are two instructions that do this: an RR-type Branch andLink via register(BALR), and an RX-type Branch and Link (BAL) instruction. The RR-type BALR instruction will be needed when calling external subroutines. To use BAL,the subroutine’s central point is specified symbolically in second operand:

BAL R1, SymbolBR instruction branches to the address contained in the register specified in its operand.

By using this instruction, a subroutine is able to branch to whatever re-entry point hadbeen loaded into that register by the caller. Symbolically given below.

BR R1The subroutine can return to the re-entry point via a BR or other RR-type branchinstruction provided both the BAL and the RR-type branch use the same register for there-entry point address.1

Page 380: Assembler Book

STUDENT NOTE BOOK

© Copyright MCPL. Unit 14. Internal Subroutines Page 14-5Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

ADDRESS CONSTANTS

Address is Basic to the use of Subroutines

1. If Z is defined in the name field of an instruction thenL’Z= 2,4 or 6.

(2, 4, or 6 bytes)

2. If Z is defined in the name field of a DC or DS directivecontaining a Length modifier Ln, then L’Z= n.

3. If Z is defined in the name field of a DC or DS directivenot containing a length modifier then L’Z is the length ofthe constant:

L’Z = 2 for H-type constantsL’Z = 4 for F-type constants etc.,

Figure 14.4 Address Constants

NOTES:

An A-type constant whose value is the value of L’Z is specified simply as A(L’Z).Address contains can contain more than one field separated by commas: forexample A (X, Y, Z) is a same as three consecutive full word address constants, the firstbeing A (X), the Second A (Y) and the third A (Z).

An address constant is a constant whose value is the value of an expression that cancontain one or more name-field symbols.In address constants, you use a left and right parenthesis rather than apostrophes toenclose the expression.

A (X) instead of A ‘X’

The length attribute of a symbol is the number of bytes that the assembler assign to thememory area associated with the symbol. Such as an instruction or a DC or DS directive.

Page 381: Assembler Book

STUDENT NOTE BOOK

© Copyright MCPL. Unit 14. Internal Subroutines Page 14-6Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

PARAMETERS AND REGISTERS

Actual parameters

Formal parameters

Figure 14.5 Parameters and Registers

NOTES:

The actual parameters are the ones that are specified by the caller when it calls asubroutine.

The formal parameters are the ones that are referred to from within the subroutine sothat the assembler can generate the instructions needed to access the actual parameters.

We need some way for the subroutine to know what its actual parameters are each time itis called. Two methods are given below.

1. The subroutine can specify symbolic address for its input data as well as for itsoutput results.

2. The caller can specify either the address or the value of the parameters when itcalls the subroutine, so that the subroutine doesn’t need to specify symbolicaddress.

Page 382: Assembler Book

STUDENT NOTE BOOK

© Copyright MCPL. Unit 14. Internal Subroutines Page 14-7Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

EXAMPLES OF INTERNAL SUBROUTINE PARAMETERS

INTERNAL SUBROUTINE with ASSEMBLY–TIMEParameters

INTERNAL SUBROUTINE with RUN – TIME Parameters

INTERNAL SUBROUTINE with ASSEMBLY – TIME andRUN-TIME Parameters

Figure 14.6 Examples of Internal Subroutine Parameters

NOTES:

Internal subroutine with assembly-time and run-time parameters.

Called via BAL 14, SKIP

PARAMETERS: STRING = ADDR OF STRING

R3 = ADDR OF RESULT

SKIP LA 3, STRING R3 = ADDR OF STRINGSKIPL CLI 0(3), C ‘ ‘ LOOK FOR BLANKS

BNER 14 RETURN WHEN NON-BLANK FOUNDLA 3, 1(3) ELSEE, ADVANCE TO NEXT CHARB SKIPL

Page 383: Assembler Book

STUDENT NOTE BOOK

© Copyright MCPL. Unit 14. Internal Subroutines Page 14-8Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

MODULARIZATION

TOP-DOWN DESIGN

LEVEL 0:

LEVEL 1:

LEVEL 2:

LEVEL 3:

LEVEL 4:

LEVEL 5:

Figure 14.7 Modularization

LEVEL 0: The top most levels solution is relatively easy: it just calls lower level routinesTo carry out the details.

LEVEL 1: The initialization task in this problem need only consists of opening twoFiles: in put data file and out put result file.

LEVEL 2: At this level, the task is convert a single hex in put integer, which is given inEBCDIC format, the task is accomplished in two steps:

1.Convert EBCDIC hex to internal binary format2.Convert internal binary to EBCDIC decimal format.

LEVEL 3 Our CVX and CVE subroutines are at LEVEL3 & the subroutines called by& Them—SKPBLK, HEXCHK, HEXCON—are at LEVEL 4

LEVEL 4

LEVEL 5: We can put the I / O data areas, DCB’s (or DTFs), and constants at LEVEL 5Which are the lowest levels in our organization.

Page 384: Assembler Book

STUDENT NOTE BOOK

© Copyright MCPL. Unit 14. Internal Subroutines Page 14-9Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

MULTIPLE BASE REGISTERS

Example of the using directive

Exactly range of4096 Reg 12

Bytes

Range ofExactly 4096 Reg 11

Bytes

Up to 4096 range ofBytes Reg 10

Figure 14.8 Multiple Base Registers

NOTES:

The Using directive,Opcode operand

USING B0, R0, R1, R2…. Rn

Where B0 = symbol whose value is assumed by the assembler to be the baseaddress in Register.Rx = address of any one of the general register.

MAIN CSECTSTM 14,12,12(13)BALR 12,0USING * , 12, 11, 10

BASE O L 11, BASE 1L 10 , BASE2B BEGIN

BASE1 DC A(BASE0 + 4096)BASE1 DC A(BASE0 + 8192)BASE1 ST 13, SAVE + 4

LA 13 , SAVE..

...

.SAVE DS 18F

END

Page 385: Assembler Book

STUDENT NOTE BOOK

© Copyright MCPL Unit 15. External Subroutines. Page 15 -1Courses may not be reproduced in whole or in part

Without the prior written permission of MCPL.

UNIT 15: EXTERNAL SUBROUTINES

Objectives:

Terminology and Linkage Requirements

Addressing and Address Constants

Linkage Conventions

Comments on the Linkage Conventions

External versus Internal Subroutines

ENTRY, EXTRN, COM, and DSECT Directives

Recursive Subroutines

Page 386: Assembler Book

STUDENT NOTE BOOK

© Copyright MCPL Unit 15. External Subroutines. Page 15 -2Courses may not be reproduced in whole or in part

Without the prior written permission of MCPL.

TERMINOLOGY AND LINKAGE REQUIREMENTS

Calling Program

Called Program

Entry Point

Reentry Point

Linkage Requirements

Calling Sequence

Linkage Conventions

Figure: 15-1 Terminology and Linkage Requirements

NOTES:When a Program requests that a subroutine perform a task, it is said to call thatSubroutine.The program making the request is known as the calling program, whereas the subroutinerequested to perform the task is known as the called program.

The address of the first instruction executed by a subroutine when it is called is known asthe subroutine’s entry point. Correspondingly, the address of the instruction to which asubroutine branches when it returns to a calling program is known as the callingprogram’s reentry point.

The Linkage requirements are:-1) Passing the values of the parameters,2) Passing the address of the reentry point and3) Branching to the entry point.

The mechanism by which these requirements are met is known as the calling sequence.

Page 387: Assembler Book

STUDENT NOTE BOOK

© Copyright MCPL Unit 15. External Subroutines. Page 15 -3Courses may not be reproduced in whole or in part

Without the prior written permission of MCPL.

ADDRESSING AND ADDRESS CONSTANTS

Assembly-Time versus Run-Time Address

Internal versus External Addresses

0 04 Program P’s 48 Instructions 8C And data C program Q’s

10 10 instructions14 14 and data

181C20

Np Nq

Addresses assigned by the assembler Addresses assigned by the assemblerto program P to program Q

Figure: 15-2 Memory Addresses assigned by the assembler.

NOTES:

Two programs may be assigned the same memory addresses at assembly time, there willbe no conflict when they are run because their respective addresses can be mapped intodifferent real memory address.

The addresses assigned to a program at assembly time are internal to that program. Theaddresses that are internal to one program are external to all other programs.

Page 388: Assembler Book

STUDENT NOTE BOOK

© Copyright MCPL Unit 15. External Subroutines. Page 15 -4Courses may not be reproduced in whole or in part

Without the prior written permission of MCPL.

ADDRESSING AND ADDRESS CONSTANTS (contd.)

Resolving Address Conflicts

Specifying external Addresses

048C1014

NpNp+4Np+8

Np+Nq+4

Figure: 15-3 Memory addresses in a load module.

NOTES:

The Linkage editor program has an intermediary roll between assembler and the loader. Itproduces what is known as a load module.

An External address Constant symbolically specifies an address that is in some otherprogram than the one in which it is specified.

Register 13 and Save area: The contents of Register 13 must be saved and since they willbe needed when restoring the other register contents, they had better be saved in an areafrom which they can be recovered prior to returning to the calling program.

Program P

Program Q

Page 389: Assembler Book

STUDENT NOTE BOOK

© Copyright MCPL Unit 15. External Subroutines. Page 15 -5Courses may not be reproduced in whole or in part

Without the prior written permission of MCPL.

LINKAGE CONVENTIONS

Figure: 15-4 Standard linkage convention.

NOTES:

Every Program, be it a called or calling program, begins and ends its execution in thesame manner.The value of the parameters and the address of the result areas are passed indirectlythrough register one.

P CSECTSTM 14,12,12(13)BALR 12,0USING *, 12ST 13,SAVE+4LA 13,SAVE

.

.

.LA 1,=A(X,Y,…)L 15, = V(Q)BALR 14,15.

PEXIT L 13,SAVE+4LM 14,12,12(13)

Q CSECTSTM 14,12,12(13)BALR 12,0USING *, 12ST 13,SAVE+4LA 13,SAVE

.

.

.LA 1, =A(X,Y,…)L 15, = V (Q)..

QEXIT L 13,SAVE+4BR 14,

Page 390: Assembler Book

STUDENT NOTE BOOK

© Copyright MCPL Unit 15. External Subroutines. Page 15 -6Courses may not be reproduced in whole or in part

Without the prior written permission of MCPL.

PASSING PARAMETER ADDRESS THROUGH REGISTER 1.

R1

Figure: 15-5 Passing parameter addresses through Register 1.

NOTES:

LA 1,=A(X,Y,Z,…)

ADDRESS OF TABLEOF PARAMETERADDRESSES

Addresses assigned to X

Addresses assigned to Y

Addresses assigned to Z

Area allocated for Z

Area allocated for X

Area allocated for Y

Page 391: Assembler Book

STUDENT NOTE BOOK

© Copyright MCPL Unit 15. External Subroutines. Page 15 -7Courses may not be reproduced in whole or in part

Without the prior written permission of MCPL.

PASSING VALUES OF PARAMETERS.

Parameter address table

Accessing the Parameter Address Table

Figue: 15-6 Passing values of parameters.

NOTES:

The Linkage convention’s method of passing parameter’s to an external subroutine isdifferent from that of internal subroutines. What is passed to an external subroutine is theaddress of the table., not the values of the parameters, not the addresses of theparameters, but the address of the table that contains the addresses of the parameters.

One of the first instructions that the subroutine will execute after it has stored the registercontents and the caller’s SAVE area address is one that will obtain one or more parameteraddresses from the table.For example, to copy the first parameter address into Register 2, this instruction issufficient: L 2,0(1)To copy the first two parameter addresses into register 2 and 3, respectively, these twoinstructions can be used: L 2,0(1)

L 3,4(1)Or this single instruction can be used: LM 2,3,0(1)

Page 392: Assembler Book

STUDENT NOTE BOOK

© Copyright MCPL Unit 15. External Subroutines. Page 15 -8Courses may not be reproduced in whole or in part

Without the prior written permission of MCPL.

RESTORING REGISTERS WHEN RETURNING FROM A SUBROUTINE.

To restore all registers: to restore all but register 15:

L 13, SAVE + 4 L 13, SAVE + 4LM 14, 12, 12(13) L 14,12(13)BR 14 LM 0, 12, 20(30)

BR 14

To restore all but register 0: to restore all but 0 and 15:

L 13, SAVE + 4 L 13,SAVE + 4LM 14, 15,12(13) L 14,12(13)LM 1,12,24(13) LM 1,12,24(13)BR 14 BR 14

Figure.15-7 Restoring registers when returning from a subroutine.

NOTES:

The act of restoring the calling program’s Register 0 and/or Register 15 contents wouldvoid the result and/or code that had been placed in those registers by the subroutine.Consequently, there are four cases to be considered when returning from a subroutine(mentioned above).

Page 393: Assembler Book

STUDENT NOTE BOOK

© Copyright MCPL Unit 15. External Subroutines. Page 15 -9Courses may not be reproduced in whole or in part

Without the prior written permission of MCPL.

COMMENTS ON THE LINKAGE CONVENTIONS.

Figure:- 15-8

NOTES:

1) A subroutine written in by one person can be called by a program written by someoneelse. If the subroutine’s method of return is clear to both persons, neither has toinvestigate the details of the other’s program.

2) The passing of parameters is done in a single consistent manner, whether the data andresults are integers, character’s, or of any other type or length.

3) If all compiler’s generate the same standard code for the equivalent of the subroutinecall and return operations, then programs written in Fortran, Cobol, and other high levellanguages can be interfaced to one another and to assembly language programs.

4) Benefits 1-3 are increased in importance when a person wishes to transfer a programfrom one computer installation to another, if the same conventional methods are used atboth sites.

Page 394: Assembler Book

STUDENT NOTE BOOK

© Copyright MCPL Unit 15. External Subroutines. Page 15 -10Courses may not be reproduced in whole or in part

Without the prior written permission of MCPL.

ENTRY, EXTRN, COM, AND DSECT DIRECTIVES

MAIN CSECT identifies entryEXTRN VABS point in anotherSTM 14,12,12(13) source module.. A-type constant. used when externalL 15,= A(VABS) symbol identifiedBALR 14, 15 via EXTRN...

SUB1 CSECT ENTRY defines VABSENTRY VABS to be an additional entry

VABS EQW SUB1 point;STM 14,12,12(13)...

Figure: 15-9 Illustration of ENTRY and EXTRN directives.

NOTES:

Techniques for allowing symbolic references between separately assembled modules:1) External addresses: ENTRY and EXTRN, 2) common addresses: COM, and 3)

dummy addresses.

External Addresses: ENTRY and EXTRNThe EXTRN directive essentially declares that symbol or symbols in its operand fieldrepresent external addresses. When EXTRN is used to identify an external symbol, thesymbol is referenced with an A-type constant: when EXTRN is not used, the symbol isreferenced with a V-type constant.

Page 395: Assembler Book

STUDENT NOTE BOOK

© Copyright MCPL Unit 15. External Subroutines. Page 15 -11Courses may not be reproduced in whole or in part

Without the prior written permission of MCPL.

COMMON ADDRESSES: COM

Identical statements

Figure: 15-10 Illustration of COM.

NOTES:

An area of memory common to all the programs can be defined. Parameters, data, andresults can be stored into and loaded from this area by any of the programs, as though thearea were internal each program. By using this technique, one can avoid passingparameters and using V-type or EXTRN / A-type constants.

MAIN CSECTSTM 14,12,12(13)BALR 12,0USING *, 12ST 13, SAVE+4LA 13,SAVEL 11,=A(COMMON)USING COMMON, 11.

.L 15,=V(ABS)BALR 14,15.

.SAVE DS 18F

COMCOMMON DS 0FN DS FK DS 100F

.

ABS CSECT...

USING COMMON, 11.

LOOP.

SAVE DS 18FCOM

COMMON DS 0FN DS FK DS 100F

.

.

.

Page 396: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit16. Non integer Arithmetic Introductory concepts Page 16 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

1

UNIT 16: NON INTEGER ARITHMETIC – INTRODUCTORY CONCEPTS

OBJECTIVES :

A Question of Accuracy

Conversion from one Base to another

Representation of Mixed Numbers

Overflow, Underflow and Significance Errors

Page 397: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit16. Non integer Arithmetic Introductory concepts Page 16 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

2

A QUESTION OF ACCURACY

Fractional representation of a mixed decimalnumber can be represented as a sequence of decimaldigits, dj, preceded by a decimal point.

0.d1d2d3……

Loss of Accuracy

Figure 16-1 A Question of Accuracy

NOTES :

Example : When ever we write 0.3333….we understand that we can write as manythree’s as we place in order to better approximate the rational fraction 1/3 .A fixed upperlimit on the number of digits that can be accommodated is imposed by the hardware andsoftware .If the limit is six , then our best approximation would be 0.333333.

If during the computation we were to attempt to compute the quantity (A-B)*C , where C= 30 and A – B = 1/10,000,000 the correct result of 0.000003 would be incorrectlyrepresented as 0.000000 , since to six places the value of A - B is 0.000000. If the same(A-B)*C were multiplied by another factor, D, the result would be zero no matter whatthe value of D is.

Page 398: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit16. Non integer Arithmetic Introductory concepts Page 16 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

3

CONVERSION FROM ONE BASE TO ANOTHER

Positional notation for fractions

Representation of one Base to another Base

To convert a Base P representation , 0.p1p2..pk , to a Base Q

representation , 0.q1q2…qm .the value of the number can

be expressed in

J = p1 x P –1 + p2 x P –2 +……+ pk x P –k (old system) or

J = q1 x Q –1 + q2 x Q –2 +……+ qm x Q –m (new system)

Figure 16-2 Conversion from one base to another

NOTES :

In base 10 , the value of decimal fraction represented as 0.d1d2….dm may be computedas

d1x 10 - 1 + d2 x 10- 2 + …… +dm x 10- 3

In base P , the value of the fraction consisting of the base digits Pj, 0.P1P2..Pk can becomputed as

P1 x P- 1 + P2 x P- 2 + …+Pk x P- k

To convert from the representation of a fraction in one base , P, to another base , Q, therequired calculations depend on whether they are done in the base P system(the old base)or in the base Q system.

Page 399: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit16. Non integer Arithmetic Introductory concepts Page 16 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

4

REPRESENTATION OF MIXED NUMBERS

Binary representation

XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX

Sign bit Integer Fractional portionportion Implied position of binary point

Decimal representation

Figure 16-3 Representation of mixed numbers

NOTES :

One way to represent mixed numbers in 32 bit word is to let a certain number of loworder bits be used for the fractional portion and the remaining high order bits for the signand integer portion .

The implied position of the binary point would have to be explicitly adjusted viaarithmetic shift instructions to retain the accuracy in multiplication or division .

Decimal representation is done with a method of representation known as packeddecimal format. In this format , integers and mixed numbers are represented as decimalintegers .Each decimal is represented by 4 bits is known as binary – coded decimal(BCD)A mixed number , F, is represented as the integer N = F X 10 n .

Page 400: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit16. Non integer Arithmetic Introductory concepts Page 16 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

5

FLOATING - POINT REPRESENTATION

K bits( K= p + n + 1)

p n nnnnn nnnn

Sign Exponent Fraction bitsbit bits

Figure 16-4 Floating point Representation

NOTES :

The most common method of representing mixed numbers in computers is known as thefloating-point method. In this method, numbers are represented and processed as afraction times a scale factor. The base of the scale factor is usually a power of two, say2m,rather than ten.

Generally preferred form of fraction is with its leading bit nonzero. This is known as thenormalized form of the fraction.

Exponent part can be represented in 3 ways. One way is to use the exponent bit as itssign bit and to represent the exponent in sign-magnitude form. Another way is torepresent the exponent in p-bit two’s complement form. A third way is to represent anexponent m by an unsigned binary integer, q + m. This is known as excess-q notation.

P bits n bits

Page 401: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit16. Non integer Arithmetic Introductory concepts Page 16 -Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

6

OVERFLOW, UNDERFLOW & SIGNIFICANCE ERRORS

Overflow

Underflow

Significance Errors

Figure 16-5 Overflow, Underflow and significance errors

NOTES :

As in integer arithmetic, arithmetic with mixed numbers may produce a result that cannotbe represented in the number of bits allowed. If the magnitude of the number is too largefor the range permitted, the condition is called overflow.

If the magnitude of the number is too small for the range, the condition is calledunderflow.

In Floating – point addition and subtraction, if the resulting fraction is 0 but the exponentisn’t ,all significant bits have been lost and the condition is termed a significance error .

Page 402: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 17.Packed-Decimal operations Page 17-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

UNIT 17: PACKED-DECIMAL OPERATIONS

OBJECTIVES:

Data Formats

Instruction Formats

Arithmetic Operations

Comparisons

Page 403: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 17.Packed-Decimal operations Page 17-2Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

PACKED – DECIMAL OPERATIONS

Packed – Decimal Format

Representation of Fractions :

Decimal System 0.75 = 7 * 10^-1 + 5 * 10^-2

Binary System 0.11 = 1 * 2^-1 + 1 * 2^-2

Inherent Errors

Decimal System 10 * 0.1 = 1.0

Binary System (1010) * (0.0001100110011001..)= 0.1111111..

Figure 17-1 Packed – decimal operations

NOTES:

The IBM 360 and 370 systems provide a capability for Decimal integer arithmeticbased on the representation of the numbers called ‘Packed-Decimal Format’.

Constants can be defined for this format by the DC directive and by the Literals.

Advantages of Packed-Decimal Format:To reduce the amount of memory space that would be required in EBCDICformat to store simple integers.To provide a method of processing decimal fractions without the loss ofaccuracy that could occur if they were processed as binary numbers.Avoid the Inherent errors.

Page 404: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 17.Packed-Decimal operations Page 17-3Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

DATA FORMATS

Decimal digit Packed-Decimal representation

0 00001 00012 00103 00114 01005 01016 01107 01118 10009 1001

Range: Maximum Packed-Decimal number requires 16 bytes.This gives a range (- 10 ^31) +1 to (+ 10 ^31) – 1

Sign: Sign of Packed-Decimal number always represented byRight most 4-bits.

Figure 18-2: Data formats

NOTES:

Packed-Decimal number is always represented in an integral number of bytes. TheNumber of bytes required depends on the number of digits.

Number of bytes = (N+1)/ 2 if N is odd= (N+2)/2 if N is even

Where N is number of digits.

Page 405: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 17.Packed-Decimal operations Page 17-4Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

INSTRUCTION FORMATS

SS1- type Instruction:

D1(L, B1), D2(B2)With 1 <= L <= 256

SS2-Type Instruction:

D1 (L, B1), D2(L2, B2)With 1 <= L 1 <= 16With 1 <= L2 <= 16

Length field

Figure 17-3 Instruction formats

NOTES:

SS1 type instruction has two operand fields each specifies the memory address ofthe data being operated on, and the length of each data item is specified in the firstoperand.

SS2 type instruction has two operand fields that specify the address of data items,but the length of each item is specified separately in each operand.

Length field must be specified in a DC or DS directive

Page 406: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 17.Packed-Decimal operations Page 17-5Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

ARITHMETIC OPERATIONS

Packed – Decimal Arithmetic operations :

Zero and Add Packed (ZAP)

Add Packed (AP)

Subtract Packed (SP)

Multiply Packed (MP)

Divide Packed (DP)

Figure 17-4 Arithmetic operations

NOTES:

Page 407: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 17.Packed-Decimal operations Page 17-6Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

ZERO AND ADD PACKED

ZAP D1( L1 , B1 ) , D2( L2 , B2 )

Address and length of source

Address and length of destination

Padding: A B

ZAP B(8) , A(4) Before execution : 0023456C any 8 bytesAfter execution: 0023456C 00000000

0023456C

*L1 – L2 = 4 = number of bytes of leading zeroes

Overflow: A B

ZAP B(2) , A(4) Before execution : 0023456C any 2 bytesAfter execution : 0023456C 456C

*L1 < L2 and loss of significant digits causes decimal overflow.

Figure 17-6 ZAP

NOTES:

Zero and Add Packed copy a packed decimal number from one memory locationto another, after filling the destination area with zeroes.

When L1 > L2 , the result in the destination area will contain at least L1 – L2bytes of leading zeroes.If L1 < L2 , and if there is not enough room in the destination area toaccommodate all the significant digits of the number in the source field , a decimaloverflow occurs.

Page 408: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 17.Packed-Decimal operations Page 17-7Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

ADD PACKED (AP)

AP D1( L1 , B1 ) , D2( L2 , B2 )

Address and length of source

Address and length of destination

X1 Y1

AP X1(3) , Y1(2) Before execution : 03214C 010CAfter execution: 03224C 010C

X2 Y2

AP X2(2) , Y2(3) Before execution : 099C 00001CAfter execution: 100C 00001C

Figure 17-6 AP

NOTES:

This instruction is executed; the number whose address and length are specified bythe second operand is algebraically added to the number whose address and lengthare specified by the first operand.The sum replaces the number specified by the first operand, and the conditioncode is set to 0 , 1 or 2 when the sum is 0 , negative or positive respectively.

Page 409: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 17.Packed-Decimal operations Page 17-8Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

SUBTRACT PACKED (SP)

SP D1( L1 , B1 ) , D2( L2 , B2 )

Address and length of source

Address and length of destination

X1 Y1

SP X1(3) , Y1(2) Before execution : 03214C 010CAfter execution: 03224C 010C

X2 Y2

SP X2(2) , Y2(3) Before execution : 099C 00001CAfter execution: 100C 00001C

Figure 17-7 SP

NOTES:

This instruction is executed; the number whose address and length are specified bythe second operand is algebraically subtracted from the number whose address andlength are specified by the first operand.The result replaces the number specified by the first operand, and the conditioncode is set to 0 , 1 or 2 when the result is 0 , negative or positive respectively.

Page 410: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 17.Packed-Decimal operations Page 17-9Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

MULTIPLY PACKED (MP)

MP D1( L1 , B1 ) , D2( L2 , B2 )

Multiplier

Multiplicand

V1 W1

MP V1(4) , W1(2) Before execution : 0000999C 999DAfter execution: 0998001D 999D

V2 W2

MP V2(2) , W2(3) Before execution : 00999C 999DAfter execution: 98001D 999D

Figure 17-8 MP

NOTES:

This instruction is executed; the number whose address and length are specified bythe first operand is multiplied by the number whose address and length arespecified by the second operand.

The result, its sign determined by the rules of algebra, replaces the multiplicand inmemory but the condition code is not set.

Page 411: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 17.Packed-Decimal operations Page 17-10Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

DIVIDE PACKED (DP)

DP D1( L1 , B1 ) , D2( L2 , B2 )

Divisor

DividendL1 bytes

Dividend field before division

Dividend field after division

L1 – L2 bytes L2 bytes

Figure 17-9 DP

NOTES:

This instruction is executed; the number whose address and length are specified bythe first operand is divided by the number whose address and length are specifiedby the second operand.

The result consists of two components: integer quotient, of length L1 – L2 bytesAnd the integer remainder, of length L2 bytes.

dividend

Quotient remainder

Page 412: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 17.Packed-Decimal operations Page 17-11Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

COMPARISONS

CP D1(L1 , B1 ) , D2( L2 ,B2)

Address and length of 1st operand (V1)Address and length of 2nd operand (V2)

Examples :V1 V2

CP V1(2) , V2(3) 012C 00345DRessult:V1>V2

V1 V2

CP V1(3) , V2(2) 00345C 345CRessult:V1 = V2

V1 V2

CP V1(4) , V2(1) 1234567D 0CRessult:V1 < V2

Figure: 17-10 Comparisons

NOTES:

Two Packed-Decimal numbers can be algebraically compared without changingeither number, it accomplished by means of Compare Packed (CP) instruction, aSS2 – type instruction.

The condition code sets as follows:If condition is V1 = V2, condition code = 0If condition is V1 < V2, condition code = 1If condition is V1 > V2, condition code = 2

Page 413: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 18.Floating-Point Operation Page 18-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

UNIT 18. FLOATING-POINT OPERATIONS

OBJECTIVES: Introduction

Assembly Language Representation

Floating-point Instructions

Load and Store Operation

Arithmetic Operations

Error Handler

Conversion TO and From Floating-Point

Comparing and Testing Floating-Point

Page 414: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 18.Floating-Point Operation Page 18-2Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

FLOATING-POINT OPERATIONS

The concept, format and use of numbers written in floating-point

notation are similar to that of numbers written in so-called scientific

notation.

But as will be seen floating-point operations provide an important

simplification for the problem of decimal-point alignment; alignment is

performed by the hardware during the execution of floating-point

instruction.

Figure 18-1 Floating-point operations

NOTES:

Page 415: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 18.Floating-Point Operation Page 18-3Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

ASSEMBLY LANGUAGE REPRESENTATION

Three types of floating-point constants in assembly language.

E = short format (single-precision)

D = long format (double-precision)

L = extended format (quadruple-precision)

Figure: 18-2 Assembly language representation

NOTES:

Boundary AlignmentUse of scale and exponent modifiers, Sn and En

Scale modifier Sn is used only when we want to create an normalized floating-pointnumber.

Exponent modifier En can be used to express the constant in scientific notation.

Page 416: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 18.Floating-Point Operation Page 18-4Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

FLOATING-POINT INSTRUCTIONS

All 51 instructions are either RX or RR-type instructions.

Figure: 18-3 Floating-point instructions

NOTES:

In Rx-type floating-point instructions, the first operand field must designate anappropriate floating-point register address.

In RR-type floating-point instructions, both operands must designate appropriatefloating-point register addresses.

Page 417: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 18.Floating-Point Operation Page 18-5Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

LOAD AND STORE OPERATORS

Opcode MeaningLE LOAD (short)

Copies the short-format number v2 from memoryInto the high-order 32 bits of the registerDesignated by the first operand field. The low order32 bits of that register are not changed.

LD LOAD (long)Copies the long-format number v2 from memoryInto the register designated by the first operand.

STE STORE (short)Copies the short-format number v1 from the highorder32 bits of the register designated by the firstoperand to the memory location designated by thesecond operand.

STD STORE (long)Copies the long-format number v1 from the registerdesignated by the first operand to the memorylocation designated by the second operand.

Figure: 18-4 Load and store operators

NOTES:

V1 = the floating-point number whose address is designated by the first operand field inan instruction.

V2 = the floating-point number whose address is designated by the second operand fieldin an instruction.

Page 418: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 18.Floating-Point Operation Page 18-6Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

ARITHEMATIC OPERATIONS

ADD

SUBTRACT

MULTIPLY

DIVIDE

HALVE

ROUND

Figure 18-5 Arithmetic operations

NOTES:

Page 419: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 18.Floating-Point Operation Page 18-7Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

ERROR CONDITION

Four types of error situations can be detected :

Exponent overflow

Exponent underflow

Significance exception

Divide exception

Figure 18-6 Error condition

NOTES:

1.Exponent overflow :occurs when the magnitude of a result is equal to or grater than1664

2.Exponent underflow: occurs when the magnitude of a result is equal to or grater than16-64

3.Significance Exception :Occurs when the mantissa of the intermediate sum ordifference resulting from any add or subtract is less tans Zero.

4.Divide exception :Occurs when the mantissa of a division(v2) in any floating-pointdivide instruction is zero.

Page 420: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 18.Floating-Point Operation Page 18-8Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

CONVERSION TO AND FORM FLOATING-POINT FORMAT

Two main types of conversions:

Between floating-point and fixed-point integers.

Between floating-point and ebcdic.

Figure 18-7 Conversion to and form floating-point format

NOTES:

1.In converting to and from text format, only seven significant digits are used since aneight-digit decimal number cannot in general be accurately represented in six availablehex digits.

2. In converting from floating-point to integer format, the value of the integer cannotexceed 231-1 or less than -231

Page 421: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 18.Floating-Point Operation Page 18-9Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

COMPARING AND TESTING OF FLOATING-POINT

Example1.CE 0 , X V1 V2

Floating-point register 0 memory location X

450000C4 41C40000

Result: V1=V2, i.e., 12.25=12.25

Example2.CDR 2 , 4 V1 V2

Floating-point register 2 Floating-point register 4

AF0000006FAB5760 C96FAB5760000000

Result: V1>V2, i.e., +2.9976 X 10 10 > -2.9976 X 1010

Figure :18-8 Comparing and testing of floating-point

NOTES:

There are no extended-precision instructions for comparing, testing or performing signoperation on extended-precision numbers.

None of these instructions can cause an exponent overflow.

Page 422: Assembler Book

STUDENT NOTEBOOK

Copyright MCPL Unit19 Cosmetic Directives PAGE 19-Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

1

UNIT 19: COSMETIC DIRECTIVES

OBJECTIVES: EJECT

TITLE

SPACE

PRINT

OPSYN

ISEQ

ICTL

Page 423: Assembler Book

STUDENT NOTEBOOK

Copyright MCPL Unit19 Cosmetic Directives PAGE 19-Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

2

DEFINATION OF DIRECTIVES

COSMETIC DIRECTIVES

USES OF COSMETIC DIRECTIVES

Figure 19 -1 definitions of directives

NOTES:

Directives that provide control over the appearance of source language statements on thelisting and over certain aspects of the validity of source language statements will bereferred to as cosmetic directives.

Cosmetic directives can be used for the following purposes:1. To begin a new page at any point on the listing (EJECT)2. To put a title on each page of the listing (TITLE)3. To create line spacing that visually separates adjacent bodies of

statements on the listing (SPACE)4. To suppress the printing of selected portions of the listing (PRINT)5. To define additional mnemonic opcodes in terms of existing ones and to

declare specific mnemonic opcodes to be invalid (OPSYN)6. To require sequence checking of source language statements (ISEQ)7. To define a nonstandard statement format (ICTL)

Page 424: Assembler Book

STUDENT NOTEBOOK

Copyright MCPL Unit19 Cosmetic Directives PAGE 19-Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

3

EJECT, TITLLE AND SPACE

EJECT: BEGIN A NEW PAGEOpcode operand

EJECT BLANK TITLE: DEFINE A TITLE LINE FOR EACH PAGE

Opcode operand

TITLE a text string of up to 100 characters,enclosed in apostrophes

SPACE: INSERT BLANK LINESOpcode operand

TITLE a self-defining decimal term or blank

Figure 19 -2 EJECT, TITLE AND SPACE

NOTES:

An EJECT directive may appear anywhere in the source program and may be used anyno.of times. It is not printed on the listing. Its purpose is to separate different portions ofthe listing from one another, there by enhancing the readability of the listing.

A TITLE directive may appear anywhere and any no.of times in the source code, but it isnot printed on the listing.

The TITLE and EJECT directives should not be used in consecutive statements, sinceeach one causes a skip to a new page. And two consecutive apostrophes or ampersandsmust be used to represent a single apostrophe or ampersand in a TITLE operand.

A SPACE directive may appear anywhere and any no.of times in the source code, but it isnot printed on the listing. The no.of blank line to be inserted is specified in the operandfield either as a self-defining decimal term or as a blank.

Page 425: Assembler Book

STUDENT NOTEBOOK

Copyright MCPL Unit19 Cosmetic Directives PAGE 19-Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

4

PRINT

PRINTOpcode operand

PRINT one or more key words, separated byCommas

PRINT OPTIONSKeywords meanings

ON or OFF whether or not any lines following thePRINT directive are printed on the listing

GEN or whether or not the statements generatedNOGEN in a macro expansion are Printed.DATA or whether the object code of a constant isNODATA printed in its entirely, or whether only

only the first 8-bytes of each constantsObject codes are printed.

Figure 19 -3 PRINT

NOTES:

Assembly Language has two other directives, PUSH and POP.To suspend the most recently established key words of a Print directive, the format of thePUSH directive is simply

Opcode operand

PUSH PRINTTo restore the key words of the most recently suspend PRINT directive, the format of thePOP directive is

POP PRINT

Page 426: Assembler Book

STUDENT NOTEBOOK

Copyright MCPL Unit19 Cosmetic Directives PAGE 19-Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

5

OPSYN, ISEQ OPSYN: DEFINE A NEW MNEMONIC OPCODE

Name field Opcode operand

A new opcode OPSYN an existing opcodean existing opcode OPSYN blank

ISEQ: SOURCE-STATEMENT SEQUENCE CHECKINGThe format for initiating sequence checking is

Opcode operand

ISEQ P,QThe format for terminating sequence checking is

Opcode operand

ISEQ blank

Figure 19 –4 OPSYN, ISEQ

NOTES:

OPSYN: The first format defines the opcode given in the name field to have all theproperties of the code given in the operand field. The second format removes the opcodegiven in the name field from the set of allowable opcodes.

ISEQ directive is used to cause the assembler to verify that the statements in a sourcemodule are in the sequence in which they were intended to be .The verification dependsupon sequence numbers that the programmer has placed in the identification field of eachsource statement.

The ISEQ directive is used in pairs; the first ISEQ of the pair initiates sequence checking,the one terminates it.

Page 427: Assembler Book

STUDENT NOTEBOOK

Copyright MCPL Unit19 Cosmetic Directives PAGE 19-Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

6

ICTL

ICTL: DEFINE NONSTANDARD STATEMENT FORMAT

The format for ICTL directive is

Opcode operand

ICTL bICTL b, eICTL b, e, c

Figure: 19 –5 ICTL

NOTES:

There are two essentially different statement formats allowable in the IBM 360 and 370Assembly language: standard format and non-standard format. If you wish to use a nonstandard format, the first statement of s source module must be an ICTL directive.

In standard format, these three positions are defined asb = beginning position = position 1e = ending position = position 71c = continuing position = position 16

The letters b, e and c represent decimal integers whose values obey the followingconstraints:

1 < = b <= 40, 2 <= c < = 40, 41< = e <= 80 and b < c < e, b + 5 < = e.

Page 428: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit20.Pseudo-Ops. Pages20-1

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL

UNIT 20: PSEUDO – OPS

OBJECTIVES:

Control Sections CSECT START ORG LTORG END DSECT COM

Page 429: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit20.Pseudo-Ops. Pages20-2

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL

CONTROL SECTIONS

Executable control sections

Reference control sections

MLC

Figure 20-1 Control Sections

NOTES:An Assembly language source module consists of one or more relocatable subdivisionsknown as Control Sections: Executable and Reference Control sections.

Executable control section can contain instructions, constants and data areas that initiatedby CSECT or START directives.

Reference control section contains neither instructions nor constants; it merely describesor reserves memory areas for use by executable control sections at run time that initiatedby DSECT or COM directives.

The Assembler maintains a separate memory location counter (MLC) for each controlsection in a source module. I.e. the address assigned to symbols defined in one controlsection are independent of the addresses assigned to symbols defined in any other controlsection.

Therefore separate implied base register should be established for each of the controlsections of a source module.

Page 430: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit20.Pseudo-Ops. Pages20-3

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL

CSECT

Figure 20-2 CSECT

NOTES:

The Control Section (CSECT) pseudo-op is used to specify the beginning of anexecutable control section in a source module. It must also be used to indicate the point atwhich any previously initiated executable control section is to be resumed.

The symbol appearing in the name field is the name of the control section. This is alwaysconsidered to be a control section entry point.

If the name field is blank, the control section is said to be unnamed or private. Unnamedsections cannot be referenced by other control sections.

Name Field Opcode Operand

Any symbol CSECT BlankOr

Blank

Page 431: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit20.Pseudo-Ops. Pages20-4

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL

START

Figure 20-3 START

NOTES:

The START pseudo-op is used to denote the beginning of the 1st executable controlsection in a source module. It is not as flexible as CSECT but it provides a clear-cutindication of where the 1st executable section begins.

The symbol in the name field is the symbolic name of the control section. Being initiatedthis is always considered to be a control section entry point.

If the name field is blank, the control section is said to be unnamed or private. Unnamedsections cannot be referenced by other control sectionsThe value of self-defining term in the operand designates the initial value for the memorylocation counter of the control section, by default is zero.

START cannot be used to resume an executable control section.

Name Field Opcode Operand

Any symbol STARTS A self definingOr term or

Blank blank

Page 432: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit20.Pseudo-Ops. Pages20-5

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL

ORG

Figure 20-4 ORG

NOTES:

The Origin (ORG) pseudo-op instructs the assembler to change the value of the memorylocation counter of the control section in which the ORG occurs.

If the operand field contains relocatable expression, the memory location counter set tothe value of that expression.If the operand field is blank, the counter is said to be smallest address that has not beenpreviously assigned to any constants, data area or instruction in the control section.

The value of relocatable expression can be equal to , greater than or less than the locationcounter value that it replaces. If it is equal to that value there is essentially no effect otherthan to assign the value to the name field symbol.

The main use of ORG is to set the location counter back to a previous value in order toredefine an area of the memory.

Name Field Opcode Operand

Any symbol ORG A relocatableOr expression or

Blank blank

Page 433: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit20.Pseudo-Ops. Pages20-6

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL

LTORG

Figure 20-5 LTORG

NOTES:

The LTORG pseudo-op causes the assembler to assemble all the literal constants it hasaccumulated. I.e. assigned a memory location in the control section for the literal constantwhich is in the literal pool and then it removed from the pool.

The first literal assembled each time a LTORG is processed is assembled on a doubleword boundary.

If there are more than one executable control sections in a source module, there should bea LTORG directive at the end of each of the sections.

If the statements from different control sections are intermingled in the source module.

Name Field Opcode Operand

Any symbol LTORG BlankOr

Blank

Page 434: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit20.Pseudo-Ops. Pages20-7

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL

END

Figure 20-6 END

NOTES:

The END directive indicates to the assembler that there are no more statements to beprocessed in the source module.

The operand is used to designate the first instruction that is to be executed at run time.If the operand is blank, the assembler assumes that the first instruction to be executed isthe first one of the first executable control section in the module. if the operands containsa relocatable expression , the value of that expression is the address of the first instructionto be executed.

When the END directive is processed by the assembler, all control sections except thefirst executable section in the source module are terminated.

Any literals remaining in the literal pool are then assembled into the first executablesection, and that section is terminated.

Name Field Opcode Operand

Any symbol END A relocatableOr expression or

Blank blank

Page 435: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit20.Pseudo-Ops. Pages20-8

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL

DSECT

Figure 20-7 DSECT

NOTES:

Name Field Opcode Operand

Any symbol DSECT BlankOr

Blank

Page 436: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit20.Pseudo-Ops. Pages20-9

Course Materials may not be reproduced in whole or in partWithout the prior written permission of MCPL

COM

Figure 20-8 COM

NOTES:

Name Field Opcode

Any symbol COMOr

Blank

Page 437: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 21.Constants and Data Areas Page 21-1Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

UNIT: 21. CONDITIONAL ASSEMBLIES

OBJECTIVES:

Sequence symbols

Assembly variables and their scope GBLx, LCLx, SETx

Conditional assemblies: AIF , AGO , ANOP

System variable symbols

Arithmetic Boolean and character expressions

Additional capabilities

Page 438: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 21.Constants and Data Areas Page 21-2Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

CONDITIONAL ASSEMBLIES

Directives:

Enable the assembler to skip over specific statement.

Create or modify the variables.

AGO, AIF and ANOP are the directives

Figure: 21 - 1. Directives.

NOTES:

Assembler normally processes the statements of a source module in the order in whichthey exists; this normal processing sequence can be altered by the use of certaindirectives.

Control directives to denote the directives used to affect the outcome of conditionalassemblies.

Page 439: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 21.Constants and Data Areas Page 21-3Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

SEQUENCE SYMBOLS

Identifies the source module statement

Indicates the position of the statement

First character must be a period (.)

Figure: 21 - 2. Sequence symbols

NOTES:

Sequence symbol is not assigned an address when processed by the assembler.

Indicates only the position of the statements in the source module.EX:

. A , . B1 , . SEQ3 , . XY31AB

A sequence symbol can appear in the name field of any statement except the following.

GBLx AND LCLx directives.

ISEQ, ICTL and OPSYN directives

EQU, ACTR, COPY , DSECT , MACRO directives

Any other statement in which an ordinary symbols or variable symbol already appears inthe name field.

Page 440: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 21.Constants and Data Areas Page 21-4Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

ASSEMBLY VARIABLES AND THEIR SCOPE

Determine how to process statement in source module.

Start with (&) symbol

Three types

Arithmetic variables

Boolean variables

Character variables

Figure: 21 - 3. Assembly variables.

NOTES:

Assembly variables also called as SET SYMBOLS

Length is 2 to 8 character.

EX:& A , & B1 , & XY31AB

An assembly variable’s type is always specified in the opcode of the directives GBLx,LCLx and SETx.

GBLA, LCLA, SETA for the arithmetic assembly variables.

GBLB, LCLB, SETB for the Boolean assembly variables.

GBLC, LCLC, SETC for the character assembly variables.

Page 441: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 21.Constants and Data Areas Page 21-5Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

GLOBAL AND LOCAL SCOPE OF ASSEMBLY VARIABLES

1

5

2

4

3

1Global scope of &r includes all statements following the first GBLx declaration for&r.2 = local scope of &x,&y and &s depends on whether they are declared inside or outsidea macro.3 = continuation of open code local scope of &x,&y and &s4=statements within open code include all except those within macro.5=statements within macro definition delimited by macro and mend.Figure: 21 - 4. Global and local scope of assembly variables

SOURCE CSECT

GBLA & RLCLA & SLCLA & X, & Y

..

.

.

.

.END .END.

MACRO..

GBLA & RLCLA & SLCLC & X

.

.MEND

MACRO..

GBLA & RLCLA & SLCLC & X

.

.MEND

Page 442: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 21.Constants and Data Areas Page 21-6Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

CONDITIONAL ASSEMBLIES: AIF, AGO, ANOP

General format of AIF, AGO, ANOP:

Name Field Opcode Operand

Sequence symbol AIF (Logical expression)or blank sequence symbol

Name Field Opcode Operand

Sequence symbol AGO Sequence symbolor blank

Name Field Opcode Operand

Sequence symbol ANOP Blanksequence symbol

Figure: 21 - 5.Conditional Assemblies.

NOTES:

AIF directive is used to cause the assembler to alter its normal statement-by-statementprocessing sequence, provided that the condition being tested is TRUE.

AGO directive causes the assembler to alter its normal processing sequence by directingit to branch to another statement without testing any condition.

ANOP directive provides a means of identifying a statement without causing any actionto be taken by the assembler.

Page 443: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 21.Constants and Data Areas Page 21-7Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

SYSTEM VARIABLE SYMBOLS

Assigned by the assembler

Value can’t changed by the SET x DIRECTIVE.

Three types of system global variables

& SYSDATE

& SYSTIME

& SYSPARM

Three types of system local variables.

& SYSECT

& SYSLIST

& SYSNDX

Figure: 21 - 6.System variable Symbols

NOTES:

&SYSDATE represented by 8 characters in the form of mm/dd/yy

&SYSTIME represented by 5 characters in the form of hh.mm

&SYSPARM is a character string established by the parm parameter of the EXECcommand in the JCL.

&SYSECT is the name of the control section in which &SYSECT is used.

&SYSLIST is the value of a positional parameter in a macroinstruction.

&SYSNDX is a 4-digit character string, 0001 to 9999

Page 444: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 21.Constants and Data Areas Page 21-8Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

ARITHMETIC BOOLEAN AND CHARACTER EXPRESSIONS

Arithmetic expressions:

ADDITION ( + ) , SUBSTRACTION ( - ) , MULTIPLICATION( * ) DIVISION ( / )

Boolean expressions

TRUE ( 1 ) , FALSE ( 0 )

Character expressions

CONCATENATION ( . )

Figure: 21- 7.Expressions

NOTES:

Variable symbols declared by the GBLA or LCLA directives

A Boolean expression can be used to assign a value of 0 or 1 to a Boolean assemblyvariable.

A character expression can have one of two forms. It can be either a string enclosed inapostrophes or it can be the concatenation of two or more strings.

Ex: (&x + & y) ( arithmetic expression )

(&x ne 100 ) (Boolean expression)

(‘ &a . & b ‘ ) (Character expression)

Page 445: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 21.Constants and Data Areas Page 21-9Course Materials may not be reproduced in whole or in part

Without the prior written permission of MCPL.

ADDITIONAL CAPABILITIES

Subscripted assembly variables

Substring notation for character variables

Figure: 21- 8.Additional Capabilities

NOTES:

Assembly variables can be subscripted with appropriate dimension.Dimension must be declared in the GBLx or LCLx directive. All components ofsubscripted assembly variables are of the same type and are assigned the initial valuesappropriate to that type.

EX:GBLA &x ( 10 ) , LCLA B &Y(5) , GBLC &Z(3)

Using sub string notation can refer one or more consecutive characters within a string.This notation can be used only in the operand of AIF , SETB and SETC directives

EX :

‘ THIS ’ ( 3 , 2 ) designates the sub string IS

Page 446: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 22. I/O Hardware Concepts Page 22-1Course Materials may not be reproduced in wholeor in part without the prior written permission of MCPL

UNIT: 22 I/O HARDWARE CONCEPTS

Objectives:

Magnetic tapes

Magnetic disks

Tape and disk comparison

Page 447: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 22. I/O Hardware Concepts Page 22-2Course Materials may not be reproduced in wholeor in part without the prior written permission of MCPL

MAGNETIC TAPE CONCEPT

Tape characteristic Tape capacity Tape blocksize

Data block inter data blockAbout to be record justProcessed gap processed

at rest here

read/writehead

Direction of tape motion

Figure: 22-1 Magnetic tape concepts

NOTES:

In a tape device, data can be recorded and sensed only while a magnetized tape surfacepass under a stationary read/write head. The acceleration time is known as start time, is oforder 10 milliseconds. The data-transfer time is of the order 100,00 to 500,000 bytes persecond. The ratio of total gap space to the length of a tape provides a useful measure ofthe efficiency with which a tape is used to store data. Each gap is one-half inch long.The more blocks there are, the more gaps there are.

Tape capacity = L B

G + B/ DWhere L= Tape length in inches

B= Blocksize in bytesD= Tape density in bytes per inchG= Gap space in inches

Page 448: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 22. I/O Hardware Concepts Page 22-3Course Materials may not be reproduced in wholeor in part without the prior written permission of MCPL

MAGNETIC TAPE CONCEPTS (contd.)

Effect of blocksize on tape capacity (for 3600-foot reel with gapsize ½ inch)

Capacity (no.of bytes)

Blocksize 800 BPI 1600 BPI

80 5.76x106 6.28x106

800 23.0x106 34.6x106

1600 27.6x106 46.1x106

3200 30.7x106 55.3x106

6400 32.5x106 61.4x106

Figure: 22-2 Effect of block size on tape capacity

NOTES:

Capacity (in bytes)

LxB/ (G+B/D)

Where L=3600x12 inch

G=1/2 inch

D=density

B=blocksize

Page 449: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 22. I/O Hardware Concepts Page 22-4Course Materials may not be reproduced in wholeor in part without the prior written permission of MCPL

EFFECT OF BLOCKSIZE ON TAPE TRANSFER TIME

Transfer time overhead

Blocksize T=2x103 ms/byte T=10x103 ms/byte Overhead % given by

S x 10080 98.4% 92.6% S+BxT800 86.2% 55.5%1600 75.6% 38.5% where S=10 ms start time3200 60.1% 23.8% T=transfer rate6400 43.9% 13.5% B=blocksize

Figure: 22-3 Effect of block size on tape transfer time

NOTES:

Transfer time = start time + (blocksize) (transfer rate)

The larger the blocksize, less the effect of start time on transfer time.

Page 450: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 22. I/O Hardware Concepts Page 22-5Course Materials may not be reproduced in wholeor in part without the prior written permission of MCPL

MAGNETIC DISKS

Disk characteristics

Disks

Offline

Online

Seeking

Seek time

Rotational-delay time

Figure: 22-4 IBM disk pack concepts

NOTES:

In disk packs such as those used in the IBM 3330 disk system, there are a number ofcontinuously rotating coaxial plates called disks.

As with tape reels, each disk pack can be easily removed from the unit that houses it andbe replaced by another pack. when removed pack (like a tape reel) is said to be offline.When placed in the unit and connected to the computer system, it is said to be online.In this type of pack, data are stored in concentric circular tracks on the surface of thedisks.

The positioning motion is called seeking.The time required for the seeking is called seek time.The time required for this rotation is called rotational-delay time.

Page 451: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 22. I/O Hardware Concepts Page 22-6Course Materials may not be reproduced in wholeor in part without the prior written permission of MCPL

COUNT DATA FORMAT: TRACK UTILIZATION FOR IBM 3330 DISK SYSTEM

N=number of B=maximum possible Maximum number PercentageData blocks Blocksize for the of bytes per track of maximumPer track indicated number of capacity

Data blocks

1 13030 13030 100 %2 6447 12894 98.963 4253 12759 97.924 3156 12624 96.885 2498 12490 95.866 2059 12354 94.817 1745 12215 93.748 1510 12080 92.719 1327 11943 91.6610 1181 11810 90.6415 742 11130 85.4220 523 10460 80.2825 391 9775 75.0230 303 9090 69.7635 241 8435 64.7440 194 7760 59.5545 157 7065 54.2250 128 6400 49.1155 104 5720 43.9060 84 5040 38.68

Figure: 22 - 5 Count-data format

NOTES:

Block size v/s tape capacity is given by N=13,165/(135+B)

Block size of less than about 1000bytes make inefficient use of the available space.

A Block size exactly equal to or slightly smaller than one of the Blocksize shown in thetable (22-5) should be chosen.

Page 452: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 22. I/O Hardware Concepts Page 22-7Course Materials may not be reproduced in wholeor in part without the prior written permission of MCPL

EFFECT OF BLOCKSIZE AND GAP SIZE ON ATTAINABLE TRACK CAPACITY IN IBM 3330

Gap

Figure: 22-6 Effect of block size and gap size

NOTES:

The average seeks time in cited for IBM publications is 30 ms.

The total time required positioning a data block under a read/write head is known as theaccess time; this is equal to sum of the rotational delay time and seek time.

Area used for first6447-byte data block

Area used for second6447-byte data block

Area used for first6450-byte data block

Not enough room forsecond 6450-byteblock

Page 453: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 22. I/O Hardware Concepts Page 22-8Course Materials may not be reproduced in wholeor in part without the prior written permission of MCPL

DATA TRANSFER OVERHEAD FOR IBM 3330 DISK SYSTEM

Data transfer overhead

Blocksize Seek time Seek time Seek time Seek time(Number of bytes) 0 10 ms 30 ms 55 ms

(1 cyl) (Pack avg) (worst case)

13030 34.2 % 52.3 % 70.4 % 79.7 %6447 51.2 69.7 82.8 88.84253 61.4 77.7 87.9 92.33156 68.2 82.5 90.7 94.22498 73.1 85.6 92.5 95.31181 85.1 92.6 96.3 97.7742 90.1 95.2 97.7 98.6523 92.8 96.6 98.3 99.0391 94.5 97.4 98.7 99.2303 95.7 98.0 99.0 99.4241 96.6 98.4 99.2 99.5

Figure: 22-7 Data-transfer overhead

NOTES:(Access time)

Overhead = x100(Access time) + (Transfer time)

Where access time is 8.4 plus seek time (in milli seconds),and data transfer time is

(Blocksize) (1.24 x10-3 ms per byte)

Page 454: Assembler Book

STUDENT NOTEBOOK

© Copyright MCPL. Unit 22. I/O Hardware Concepts Page 22-9Course Materials may not be reproduced in wholeor in part without the prior written permission of MCPL

DATA RECORD

Count data format Count key data format Tape and disk comparison

Data record(Count data format)

count block gap data block

Data record(Count key data format)

count block gap key block gap data block

Figure: 22-8 Data records

NOTES:

In count data format, each data block is preceded by a short (12-byte) count block, usedby hardware in operating system to specify the data block size and certain otherinformation.The data block and its count block are separated by a small gap; together known as datarecord. In count-key–data format, each data block is preceded by two blocks countblock and a key block. The key block contains an alphanumeric character string, calledthe key that identifies data block.

In IBM 3330 disk system, there are 19 tracks per cylinder.

The maximum capacity of a cylinder is a quarter of a million bytes: 247,570 bytes if alltracks are formatted in count-data format and 246,506 bytes if count-key-data format areused.