You are on page 1of 454

ASSEMBLY LANGUAGE

PROGRAMMING
PART - 1 STUDENT NOTE BOOK

MAINTEC COMPUTERS PRIVATE LIMITED

ASSEMBLY LANGUAGE
PROGRAMMING
PART - 2 STUDENT NOTE BOOK

MAINTEC COMPUTERS PRIVATE LIMITED

STUDENT NOTEBOOK

Contents
Course Description Agenda ..

Units Unit 1. Computer System Concepts.1-1 1.1 Computer System Concepts 1-1 Objectives. 1-1 Computer System Concepts. .1-2 Assembly Language Programming1-4 Organization1-5 Assembling your Assembler Language Program & Link-Editing. 1-6 Language Compatibility..1-7 Relati onship of assembler to Operating System.1-8 Operating System1-9 Relationship of Assembler and Loader 1-10 Typical Output Process1-11 Processing Modes1-12 Relationship of Program Components.1-13 BITS and BYTES 1-15 Memory Location and Address.. 1-16 Contents of BYTES.1-17 Machine Language Instruction format1-18 Program Location Counter..1-19 Registers .1-20 Representation of data in Memory..1-21 Character Codes..1-22 Binary and Hexadecimal Integers1-23 Number System ..1-24
Copyright MCPL. Course Materials may not be reproduced in whole, or in part without the prior written permission of MCPL

STUDENT NOTEBOOK

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

Unit 2. Fundamentals of Assembly Language.2-1 2.1 Fundamentals of Assembly Language....2-1 Objectives2-1 Statement Format2-2 Formats for Instructions and Directive2-4 Valid Symbols.2-5 Invalid Symbols..2-6 Statement Format Variations...2-7 Source Module Requirement-1....2-9 Source Module Requirement-2...2-10 Source Module Requirement-32-11 Executable vs. Non-Executable Statements.2-12 Object Module..2-13 Input and Output Operations2-14 OS I/O Macros.2-15 Sample Program Using Files2-16 DOS I/O Macros 2-18 Sample Program for DOS.. 2-20 ANSI Carriage-Control Characters... 2-21
Copyright MCPL. Course Materials may not be reproduced in whole, or in part without the prior written permission of MCPL

STUDENT NOTEBOOK

Assembly Listings.2-22 Unit 3. Instructions and Address.3-1 3.1 Instructions and Address...3-1 Objectives......3-1 Addresses...3-2 Schematic Representation of Memory...3-3 Schematic Diagram of the 16 General Register.....3-4 Registers..3-5 Base Displacement Address...3-6 Instructions......3-7 Memory Location Counter (MLC)..3-8 Machine Language Instruction Format...3-9 Assembly Language Operand Formats.....3-10 Examples for each Formats...3-11 RS Format3-12 SS1 Format3-13 Implicit Length.3-14 The BALR Using Sequence..3-15 Mnemonic Opcodes ...3-16 Unit 4. Basic Operations: Looping and Arrays.4-1 4.1 Basic Operations: Looping and Arrays.4-1 Objectives4-1 Basic Operations, Looping and Arrays..4-2 Types of Constants for DC Directive.4-3 The DS Directive4-4 Subdivisions4-5 Equivalence Constants (EQU)4-6 Relocatable and Absolute Constants..4-7 Control Sections.4-8 Source Module4-9 Sample Program to Print the sum of two Binary integers.4-10 Program to print the sum of two unsigned Decimal Integer.4-12 The LA Instructions..4-15
Copyright MCPL. Course Materials may not be reproduced in whole, or in part without the prior written permission of MCPL

STUDENT NOTEBOOK

The BXH and BXLE Instructions.4-16 Printing Nonnegative Integers..4-17 Allocating Memory Areas.4-18 Conversion from Binary to Character representation ..4-19 Reading Nonnegative Integer Input Data.4-20 Allocating memory Areas.4-21 Conversion from Character form to Binary..4-22 Unit 5. Integer Arithmetic5-1 5-1 Integer Arithmetic 5-1 Twos Compliment Arithmetic ..5-2 Arithmetic Instruction ..5-3 Subtraction . 5-4 Multiplication ... .5-5 Division. .5-6 Branching Instructions...5-7 Comparison .5-8 Complement Instructions ...5-9 Byte Operations....5-19 Moving Bytes5-21 Comparison of Bytes...5-22 Shifting Bits..5-26 Logical Shifts ...5-28 Altering Bits..5-29 Boolean Instructions on IBM 360 and 370-Systems 5-31 File Status Informations . ..5-32 Testing Bits ..5-33 The BC Instruction .. 5-35 Changing Sign and Generating Absolute Values .5-38 Unit 6. Constants and Data Areas...6-1 6.1 Constants and Data Areas..6-1 Objectives6-1 Constants.6-2 Relocatable and Absolute Constants...6-3
Copyright MCPL. Course Materials may not be reproduced in whole, or in part without the prior written permission of MCPL

STUDENT NOTEBOOK

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

Unit 7. Byte and String Manipulations 7.1 Byte and String Manipulations7.1 Character Constants .7-3 Copying Bytes ..7-5 Copying Bytes to and from Registers .7-6 Copying Bytes from one area of Memory to another .7-8 Comparing Bytes .7-9 Comparing Bytes when one of the Strings is in a register7-10 Comparing Bytes when both Strings are in Memory locations.. 711

Copyright MCPL. Course Materials may not be reproduced in whole, or in part without the prior written permission of MCPL

STUDENT NOTEBOOK

Determining the result of a String comparison7-12 String processing examples ..7-13 Destructive Overlap ..7-15 Non Destructive Overlap ..7-17 Substring Operations 7-22 String-Editing Delete Procedure ..7-24 The Execute Instruction 7-26 CLCL and MVCL Instructions .7-27 CLCL Instruction .. ..7-28 CLCL Loop ..7-30 MVCL ..7-31 TR and TRT Instructions .7-33 General Descriptions 7-34 Unit 8. Bit Manipulations.8-1 8.1 Bit manipulations... . 8-1 Objectives. 8-1 Bit Manipulations. 8-2 Shifting Bits. 8-3 Arithmetic Shift Instruction. 8-4 Arithmetic Shifts. .8-5 Logical Shifts. ..8-7 Altering Bits .8-9 Use of Bits as Indicators.. 8-10 Bit Variations8-11 Boolean Operations..8-12 Boolean OR Operation 8-13 Boolean AND Operation..8-14 The Boolean Exclusive OR Operation..8-15 Testing Bits..8-16 Test Under Mask..8-17 Test and Set..8-18 Condition Code.8-19 Condition Code Value..8-20 BC and BCR Mask Field..8-21
Copyright MCPL. Course Materials may not be reproduced in whole, or in part without the prior written permission of MCPL

STUDENT NOTEBOOK

Condition Code settings for Non privileged Instructions.8-22 Integer Operations.8-23 Byte Operations.....8-24 Bit Operations8-25 Decimal...8-26 Floating Point..8-27 Miscellaneous..8-28 Non Privileged Instructions that do not set Condition Code.8-29 Bit Manipulation Examples...8-30 Status Byte.8-31 Definitions for a file Status Byte8-32 Use of a Status World8-33 Testing or Resetting Bit N.8-34 Setting or Inverting Bit N..8-35 Conversion of HEX digits to EBCDIC.8-36 Translate from Decimal to Binary.8-37 Convert HEX digits to EBCDIC Codes8-38 Translating a Non-Negative Integer from EBCDIC to Binary8-39 Unit 9. Macros9-1 9.1 Macros9-1 Objectives9-1 Macro Definition.9-2 Macro Prototype Statement..9-3 Macro - Header Statement .9-4 A Sample Macro..9-5 A Macros Definition..9-6 Example 19-7 Use of Control directives.9-8 Return Macro Definitions9-9 MEXIT Directive..9-10 VSAM Processing Assembler9-11 Creating ACBs and RPLs ..9-12 ACB MACRF Parameter..9-13 RPL OPTCD Parameter ..9-14
Copyright MCPL. Course Materials may not be reproduced in whole, or in part without the prior written permission of MCPL

STUDENT NOTEBOOK

Assembler Error Handling9-15 Unit 10. Sequential Organization10-1 10.1 Sequential Organization10-1 Objectives.10-1 Sequential Organization ..10-2 The System Input and Output data set.10-3 SYSIPT and SYSLST in DOS System10-4 Processing fields in a Logical record...10-5 Processing variable Length Records.10-7 Move Mode..10-8 Locate Mode10-9 Printer Output..10-10 Title.10-11 Date and Time Macros10-12 Dormitory Room Master File..10-13 Transaction record Format..10-14

Copyright MCPL. Course Materials may not be reproduced in whole, or in part without the prior written permission of MCPL

STUDENT NOTEBOOK

Unit 11. Indexed Sequential Organization


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

11-1

Copyright MCPL.

Course Material may not be reproduced in whole or in part without the prior written permission of MCPL

STUDENT NOTEBOOK

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


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

Copyright MCPL.

Course Material may not be reproduced in whole or in part without the prior written permission of MCPL

STUDENT NOTEBOOK

Unit 13. Assembler Concepts....


Assembler concepts..... 13-1 Objectives 13-1 Assembler Input and Output 13-2 Two Pass Assembler. 13-3 Assembler tables and File usage.. 13-4 Fundamentals of the Assembly Process.. 13-5 Assembler Processing Requirements... 13-6 Opcode table. 13-7 Directive table.. 13-9 Symbol table. 13-10 Literal Table.. 13-11 Base register table.. 13-12 Intermediate File.... 13-13 Assembler processing Logic Pass1. Assembler processing Logic Pass 2 The Object module. .. Table Searching.. .. Linear Searching. . Binary Search.. . Linear vs. Binary Search Time .. .. Sorting Tables. .. Straight Insertion sort Other Sort Techniques Cross Reference.. .. Cross Reference List Structure 13-14 13-15 13-16 13-17 13-18 13-19 13-21 13-22 13-23 13-24 13-25 13-26

13-1

Copyright MCPL.

Course Material may not be reproduced in whole or in part without the prior written permission of MCPL

STUDENT NOTEBOOK

Unit 14. Internal subroutines.. 14-1


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

Unit 15. External Subroutines 15-1


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

Copyright MCPL.

Course Material may not be reproduced in whole or in part without the prior written permission of MCPL

STUDENT NOTEBOOK

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


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

Unit 17. Packed Decimal Operations17-1


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

Copyright MCPL.

Course Material may not be reproduced in whole or in part without the prior written permission of MCPL

STUDENT NOTEBOOK

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


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

Unit 19. Cosmetic Directives19-1


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

Copyright MCPL.

Course Material may not be reproduced in whole or in part without the prior written permission of MCPL

STUDENT NOTEBOOK

Unit 20.

Pseudo OPS

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

Unit 21. Conditional Assemblies..21-1


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

Copyright MCPL.

Course Material may not be reproduced in whole or in part without the prior written permission of MCPL

STUDENT NOTEBOOK

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


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

Copyright MCPL.

Course Material may not be reproduced in whole or in part without the prior written permission of MCPL

STUDENT NOTEBOOK

UNIT 1. COMPUTER SYSTEM CONCEPTS


OBJECTIVES : Assembly language programming. Operating syst ems. Hardware. Representation of data in memory. Binary and hexadecimal int egers.

Copyright MCPL.

Unit 1.Computer System Concepts 1-1

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

STUDENT NOTEBOOK

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 systems electronic, electromagnetic, electromechanical components: in short, its physical equipment. and

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

Copyright MCPL.

Unit 1.Computer System Concepts 1-2

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

STUDENT NOTEBOOK

Program or computer program means a sequence of actions and conditions written in such a way That they may either be processed directly by hardware or be translated into a form that may be processed directly by the hardware. A program that can be processed directly by the hardware is known as a machine language program. A program that can be translated into machine language is said to be written in a computer programming language. An assembly language program consists of the statement that processed by a program known as assembler. The statements are collectively called the source code, or source module. A significant position of an assembly language program consists of statements that represent the detailed operations- known as instructions- that the hardware is capable of executing. An instruction is a symbolic representation of a single machine language operation that will be executed by the hardware at run time. A directive is a request to assembler to perform a function other than translating instructions into machine language.

Copyright MCPL.

Unit 1.Computer System Concepts 1-3

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

STUDENT NOTEBOOK

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 the machine language representation of the source module statements. When the assembler is processing a programmers source module, it is the assembler program that is being executed by the hardware, not the programmers. The period of time 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 is being executed, not the programmers. This is known as load time. The period of time during which the programmers program is being executed by the program is known as run time.

Copyright MCPL.

Unit 1.Computer System Concepts 1-4

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

STUDENT NOTEBOOK

ORGANIZATION
ETR CP U EXPANDE D STORAGE CP U CHANNEL SUBSYSTEM Serial channel paths
DYNAMIC SWITCH DYNAMIC SWITCH

MAIN STORAGE

Parallel channel paths

CU

CU

CU

CU

CU

CU

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 channel subsystem through control units. ETR is an external time reference. The maximum number of sub-channels is 65536.

Copyright MCPL.

Unit 1.Computer System Concepts 1-5

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

STUDENT NOTEBOOK

Assembling your Assembler Language Program and Link-editing

SOURCE MODULE

HIGH LEVEL ASSEMBLER

OBJECT MODULE

MESSAGE S& LISTINGS Figure 1-4 Assembler language program and link-editing NOTES:

LINKAG E EDITOR

LOAD MODUL E

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

Copyright MCPL.

Unit 1.Computer System Concepts 1-6

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

STUDENT NOTEBOOK

LANGAUGE COMPATIBILITY

ASSEMBLER H VERSION 2 HIGH LEVEL ASSEMBLER

DOS/VSE ASSEMBLER

X Figure 1-5 language compatibility NOTES:

MACRO SET SYMBOLS Variable SYMBOLS

Migration from Assembler H V2 or DOS/VSE Assembler to High Level Assembler will require an analysis of existing assembler language programs to ensure that they do not contain Macro instructions with names that conflict with High Level Assembler symbolic operation codes, SET symbols and variable symbols that conflict High Level Assembler system variable symbols. HLA supports assembly of programs using Extended Architecture Instructions and ESA instructions. A generated object program using 370-XA/ESA/370 instructions can only be run on a 370-XA/ESA/370 mode processor.

Copyright MCPL.

Unit 1.Computer System Concepts 1-7

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

STUDENT NOTEBOOK

RELATIONSHIP OF ASSEMBLER TO OPERATING SYSTEM.

MVS/ESA

MVS/XA VSE/ESA

HIGH LEVEL ASSEMBLER MVS/ESA VM/XA

Figure: 1-6 Relationship of assembler to operating system NOTES: The operating systems provide the Assembler with services for assembling a source module and running the assembled object module as a program.

Copyright MCPL.

Unit 1.Computer System Concepts 1-8

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

STUDENT NOTEBOOK

OPERATING SYSTEM

OS Vs DOS In many IBM 360 and 370 computers, the operating system is 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.

Copyright MCPL.

Unit 1.Computer System Concepts 1-9

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

STUDENT NOTEBOOK

Relationship of assembler and loader.


Assembly time Assemble r Program executing Load time Loader Program executing Run time Users Program executing

Source Module

Object module

listing

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 for execution by the hardware.

Copyright MCPL.

Unit 1.Computer System Concepts 1-10

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

STUDENT NOTEBOOK

TYPICAL OUTPUT PROCESS


User program executing DCB for output Data area for output 1 22 1 1 2 SECONDARY MEMORY Output data Description Of data Jcl statements MAIN MEMORY

System data area

System control area

Operating system 1. process that occur when a file is opened 2. 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 control language (jcl) statements and (2) by means of instructions. The principal functions of jcl statements are to identify the user and the users accounting parameters, to initiate and terminate jobs, to describe files and request certain activities related to files. Job is a unit of work such as assembling , loading, and running a program that is to be performed 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.

Copyright MCPL.

Unit 1.Computer System Concepts 1-11

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

STUDENT NOTEBOOK

PROCESSING MODES PROBLEM MODE SUPERVISOR MODE

Figure 1-10 Processing mode. NOTES : When a users program is being run, the hardware, or more precisely , the central processing unit is in what is known as problem mode; this means that only those instructions 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 in supervisor 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 system integrity , they can be executed in supervisor mode and are therefore known as privileged instructions.

Copyright MCPL.

Unit 1.Computer System Concepts 1-12

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

STUDENT NOTEBOOK

RELATIONSHIP OF PROGRAM COMPONENTS


Central processing unit (CPU)

Main memory

I/o Devices

I/o Processor

I/o Processor

Secondary Memory

Figure 1-11. Relationship of program component. NOTES : Main memory contains the operating system and any other program that is being executed by the hardware. It contains data and control information required by the operating system and the programs that are being executed. The central processing unit (CPU) contains electronics required to interpret and execute machine language instructions, to control the transfer of data and programs into and out of main memory, and to detect the various errors as they arise.

Copyright MCPL.

Unit 1.Computer System Concepts 1-13

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

STUDENT NOTEBOOK

The i/o (input/output) processors, called data channels in IBM systems , contain the electronics 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 when they 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 memory from sources external the computer system. Output devices receive signals transmitted from main memory for use outside the computer system.

Copyright MCPL.

Unit 1.Computer System Concepts 1-14

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

STUDENT NOTEBOOK

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 numbered from 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 , which may 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 consecutive bits.

Copyright MCPL.

Unit 1.Computer System Concepts 1-15

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

STUDENT NOTEBOOK

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, in memory, and each location is identified by a numeric name called its address.

Copyright MCPL.

Unit 1.Computer System Concepts 1-16

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

STUDENT NOTEBOOK

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 the instruction 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 and data are represented in machine language. Machine language is numeric language. In many instructions, two items of data is represented in operand field, and some instructions three are represented. These are known as two operand or three operand instructions respectively.

Copyright MCPL.

Unit 1.Computer System Concepts 1-17

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

STUDENT NOTEBOOK

PROGRAM LOCATION COUNTER


CPUs execute only one instruction at a time. At any instant, the address of the next instruction to be executed is contained in a program element known as program location counter (PC) .

The PC is part of the program status word (PSW) , which records various information 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 first instruction in a program, but once program execution is under way, the CPU controls the address in the PC. When an instruction is obtained from memory, the CPU anticipates that the next instruction will be obtained from the next sequential location in memory.

Copyright MCPL.

Unit 1.Computer System Concepts 1-18

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

STUDENT NOTEBOOK

REGISTERS

Registers are special memory elements designed to provide faster access to data than is possible through main memory. Registers contribute substantially to the speed with which a program can be executed.

Figure 1-16 Registers NOTES : In addition to fetching instructions and data directly from main memory, the CPU and main memory often are interfaced to one- another through registers. Registers are specifically designed to be used by the CPU for various arithmetic and logical operations. Registers are more expensive than the main memory elements, there are far fewer registers than main memory locations in a computer system.

Copyright MCPL.

Unit 1.Computer System Concepts 1-19

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

STUDENT NOTEBOOK

REPRESENTATION OF DATA IN MEMORY

Data are represented as one or more sequences of bits. The bit sequences that are used generally 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 processes than is used for numbers that participate in non-arithmetic processes. An example of a number used in an arithmetic process is the mathematical constant pi = 3.14159 An example of a number used in non-arithmetic process is a telephone number, such as 5551346. All data that are transmitted between computers main memory and external input or output devices are almost invariably transmitted in a form known as character data.

Copyright MCPL.

Unit 1.Computer System Concepts 1-20

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

STUDENT NOTEBOOK

CHARACTER CODES ASCII American National Standard Code for Information Interchange EBCDIC Extended Binary-coded Decimal Interchange Code

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.

Copyright MCPL.

Unit 1.Computer System Concepts 1-21

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

STUDENT NOTEBOOK

BINARY AND HEXADECIMAL INTEGERS

In the binary number system, only two digits are used in the representation of numbers: 0 and 1. In the hexadecimal system, there are sixteen digits, represented by the symbols 0,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 as hexadecimal digits.

Figure 1-19. Binary and hexadecimal integers. NOTES : Calculations involving address are of critical importance in assembly language programming, and almost such calculations are based on binary systems. The range of integers that can be represented in computer systems is not infinite and attempts to generate an integer whose value is outside the allowable range usually produce erroneous Results.

Copyright MCPL.

Unit 1.Computer System Concepts 1-22

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

STUDENT NOTEBOOK

NUMBER SYSTEM

Programming in assembler language requires a working knowledge of three different number systems: BINARY HEXADECIMAL DECIMAL

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

Figure: 1-20 Numbering system NOTES:

Copyright MCPL.

Unit 1.Computer System Concepts 1-23

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

STUDENT NOTEBOOK

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 a number. The digits are 0,1,2,3,4,5,6,7,8, and 9. Every number in the decimal system is comprised of one or more of these digits. The value that each digit contributes to the number depends on its position in that number. In this positional notation a particular digit has a value equal to that digit multiplied by the base of that number system raised to a power that reflects its relative position in the number. (Power of a number are the result of 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 1 always results in the number itself. Copyright MCPL. Unit 1.Computer System Concepts 1-24

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

STUDENT NOTEBOOK

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 a number is shown as the sum of the values contributed by each of its digits. The decimal number 743 in its expanded form would be : One last process to consider while was we are still working in the familiar decimal number system is the simple process of counting. In counting we advance through the range of symbols or digits in the system until the range is exhausted. We then carry 1 to the next, more significant, position and start through the range again. In the Copyright MCPL. Unit 1.Computer System Concepts 1-25

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

STUDENT NOTEBOOK

decimal system, we count from 0-9; once 9 is reached, we carry 1 to the tens positions and begin over with 0 in the units position. This process is the same regardless of the number 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 should acquire a working knowledge and understanding of the binary number system. As in the decimal system, the value of a particular digit in a binary number is a reflection the position of that digit in the number. Binary means base 2.

Copyright MCPL.

Unit 1.Computer System Concepts 1-26

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

STUDENT NOTEBOOK

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 (represents the same value as) the decimal number 45. Whatever we have done is to use the expanded 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 equivalent of a number in any base can be obtained by multiplying each digit by its positional value and summing the results. Try converting the following to their decimal representation.

Copyright MCPL.

Unit 1.Computer System Concepts 1-27

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

STUDENT NOTEBOOK

DECIMAL NUMBERING
Subscripts indicate the base of a number, with no subscript indicating a decimal number.

Respectively, your answers should be:

Figure: 1-25 Decimal numbering NOTES:

Copyright MCPL.

Unit 1.Computer System Concepts 1-28

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

STUDENT NOTEBOOK

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 first way is the multiple-division method. The number to be converted is divided repeatedly by 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. The remainder from the first division operation is used as the digit in the rightmost (leastsignificant) position in the resultant binary number; the remainder from the second Copyright MCPL. Unit 1.Computer System Concepts 1-29

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

STUDENT NOTEBOOK

division operation becomes the next digit, and so on, until the evaluation is complete. For example, converting the decimal number 45 to binary takes the following series of division 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:

Copyright MCPL.

Unit 1.Computer System Concepts 1-30

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

STUDENT NOTEBOOK

SECOND METHOD FOR CONVERTING DECIMAL NUMBERS TO BINARY

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

Figure 1-28 Second method of conversition NOTES: Copyright MCPL. Unit 1.Computer System Concepts 1-31

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

STUDENT NOTEBOOK

NUMBER REPRESENTATION

Binary integers Signed binary integers Unsigned binary integers Decimal integers Floating point numbers Conversion examples
Figure:1-29 Number representation NOTES:

Copyright MCPL.

Unit 1.Computer System Concepts 1-32

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

STUDENT NOTEBOOK

BINARY INTEGERS

+ 26 Invert Add 1 - 26

0000 1111

0000 1111

0001 1110

1010 0101 0001

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 twos compliment form.

Copyright MCPL.

Unit 1.Computer System Concepts 1-33

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

STUDENT NOTEBOOK

32-Bit Signed Binary Integers


2147483647 65536 1 0 -1 -65536 -2147483647 = -2147483648 = = = = = = = 0111 0000 0000 0000 1111 1111 1000 1000 1111 0000 0000 0000 1111 1111 0000 0000 1111 0000 0000 0000 1111 1111 0000 0000 1111 0001 0000 0000 1111 1111 0000 0000 1111 0000 0000 0000 1111 0000 0000 0000 1111 0000 0000 0000 1111 0000 0000 0000 1111 0000 0000 0000 1111 0000 0000 0000 1111 0000 0001 0000 1111 0000 0001 0000

Figure 1-31. 32-bit signed binary integers NOTES : The signed binary integer is a weighted code, negative numbers are represented in twos complimented form.

Copyright MCPL.

Unit 1.Computer System Concepts 1-34

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

STUDENT NOTEBOOK

Signed Binary Integer Arithmetic Overflow and carries part 1


Ex 1: +57 +35 ----92 ----= = = 0011 0010 -----0101 -----1001 0011 ------1100 -----Ex 2: +57 = 0011 1001 -35 = 1101 1101 --------- ----+22 = 0001 0110 --------- -----No overflow + 57 = 0011 1001 + 92 = 0101 1100 ---------- -----+149 = *1001 0101 ----------- -------

Ex : 3 + 35 = -57 = -----22 = ----Ex : 5 -57 -35 -----92 ----= = = 1100 1101 -----1010 ------

0010 0011 1100 0111 ------- ------1110 1010 ------- -------

Ex :4

Ex : 6 0111 1101 -----0100 ------57 -92 -----149 ----= = = 1100 1010 -----* 0110 -----1011 0100 -----1011 ------

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

Copyright MCPL.

Unit 1.Computer System Concepts 1-35

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

STUDENT NOTEBOOK

Signed Binary Integer Arithmetic Overflow and carries part 2

Ex 1&3 2 &5 4 6

Overflow No No Yes Yes

Carry into leftmost position No Yes Yes No

Carry out No Yes No Yes

Figure 1-33 Signed Binary Integer Arithmetic Overflow and carries NOTES :

Copyright MCPL.

Unit 1.Computer System Concepts 1-36

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

STUDENT NOTEBOOK

Unsigned Binary Integer Arithmetic


Ex 1: 57 35 ---92 - --= = = 0011 0010 -----0101 -----1001 0011 -----1100 -------

Ex 2: 57 = 0011 221 = 1101 1101 ---------278 = *0001 - --------

1001 -----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 on the application.

Copyright MCPL.

Unit 1.Computer System Concepts 1-37

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

STUDENT NOTEBOOK

Decimal Integers Packed format Zoned format

Decimal Value + 123 -4321 -7

Packed form 12 3C or 123 F 04 32 1D 7D

Zoned Form F1 F2 C3 or F1 F2 F3 F4 F3 F2 D1 D7

Figure 1-35 Decimal Integers NOTES : The decimal digits are in BCD with the values 0-9 encoded as 0000-1001. The sign is represented as 1100 (C Hex) for plus and 1101 (D Hex) for minus. Copyright MCPL. Unit 1.Computer System Concepts 1-38

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

STUDENT NOTEBOOK

Floating Point Numbers


Short floating point Number S Characteristic 6- Digit Fraction 0 1 8 Long floating point Number S 0 Characteristic 1 14-digit Fraction 8 63

31

Extended Floating-Point Number S 0 S 64 High-order Part High-order Leftmost 14 digits of characteristic 28-digit Fraction 1 8 63 Lower-order Part Low-order characteristic Rightmost 14 digits of 28-digit Fraction 72 127

Figure:1-36 Floating point number N0TES: Copyright MCPL. Unit 1.Computer System Concepts 1-39

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

STUDENT NOTEBOOK

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 each format (0 for plus, 1 for minus). The exponent sign is obtained by expressing the exponent 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 its representation in another depends on each number system the competitions are performed in . Conversion from base 10 to base 2 18 = 10010 Conversion from base 16 to base 10 12 = 18 Conversion from base 10 to base 16 18 = 12

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

Copyright MCPL.

Unit 1.Computer System Concepts 1-40

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

STUDENT NOTEBOOK

Copyright MCPL.

Unit 1.Computer System Concepts 1-41

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

STUDENT NOTEBOOK

UNIT 2: FUNDAMENTALS OF ASSEMBLY LANGUAGE

OBJECTIVES: STATEMENT FORMATS STATEMENT FORMAT VARIATIONS SOURCE MODULE REQUIREMENTS INPUT AND OUTPUT OPERATIONS ASSEMBLY LISTINGS

Copyright MCPL. Unit2.Fundamentals of Assembly Language Page 2 - 1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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 column input line.

Copyright MCPL. Unit2.Fundamentals of Assembly Language Page 2 - 2 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

STATEMENT FORMATS
Comment statement format 1 Comment filed Comment Indicator

71 72 73

Identification

80

Continuation

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

Figure 2-2 Statement format NOTES: The first column of a comment statement begins with an asterisk (*); continuation column 72 contains any nonblank character for continuation onto next line. Each continuation line begins in position 16. Name field. When the first character in main field is not blank, the name field must consist of from one to eight characters followed by a blank. Opcode field. The opcode field must contain availed assembly language code of from one to five alphabetic characters that identifies one of the instructions of directives that exist in the language. Operand field. The format of the operand field depends on whether the opcode field designates an instruction or a directive, and it also depends on which instructions or directive is specified.

Copyright MCPL. Unit2.Fundamentals of Assembly Language Page 2 - 3 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

FORMAT FOR INSTRUCTIONS AND DIRECTIVE


Format for instructions and directives

name

opcode

15

operand

39

comment

72

identification

80

Continuation

Figure 2-3. Formats for instructions and directives NOTES: Continuation field. The statement may be extended over two or more lines by means of the continuation field. If the continuation field contains any none blank character, then following line will be assumed to be a continuation of the line whose continuation field is non 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 which the statement appears and (2) to record the sequential position of the statement within the source module.

Copyright MCPL. Unit2.Fundamentals of Assembly Language Page 2 - 4 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

VALID SYMBOLS
Example of valid symbols

Q A101 LOOP FOUND REP 12 #1 CONTINUE @ HERE $###2

Figure 2-4. Valid symbols NOTES :

Copyright MCPL. Unit2.Fundamentals of Assembly Language Page 2 - 5 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

INVALID SYMBOLS
Example of invalid symbols:

3 101A F(1) LOOP 1 LOOP.1 LOOP-1 ENCOUNTER

first character not a letter parentheses not among the allowable characters blank period to many characters : maxmum 8

Figure 2-5. Invalid symbols. NOTES :

Copyright MCPL. Unit2.Fundamentals of Assembly Language Page 2 - 6 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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 of the IBM 360 and 370 assembly language.

Other characteristics of standard fixed format include the following: Copyright MCPL. Unit2.Fundamentals of Assembly Language Page 2 - 7 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

Any field that is omitted must be blank. All none blank fields must be left justified within the field boundaries and be field with trailing blanks. Positions 9,15 and 39 must be blank. Information of the operand or / and comment fields of one line of a statement may be continued on the following line, provided that the continuation field contains a nonblank 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 indent the opcode and operand fields. In both standards fixed format or standard free format, the positions of the continuation and identification fields remain fixed in positions 72 and 73-80,respectively; and the beginning, ending, and continuing positions remain fixed in positions 1,71,and 16, respectively.

Copyright MCPL. Unit2.Fundamentals of Assembly Language Page 2 - 8 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

SOURCE MODULE REQUIREMENT - 1


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

Name field Modname This symbol Used as name Of the source module

opcode CSECT STM BALR USING ST LA

operand 14, 12, 12 (13) 12, 0 *, 12 13, SAVE +4 13, SAVE

Figure : 2-7 Source module requirements NOTES:

Copyright MCPL. Unit2.Fundamentals of Assembly Language Page 2 - 9 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

SOURCE MODULE REQUIREMENT - 2

The last executable statement of source module should be NAME FIELD Exit name Any valid symbol OPCODE L LM BR OPERAND 13, SAVE+4 14, 12, 12 (13) 14

Figure 2-8. Source module requirements NOTES :

Copyright MCPL. Unit2.Fundamentals of Assembly Language Page 2 -10 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

SOURCE MODULE REQUIREMENT- 3

The last executable statement of source module should be NAME FIELD Save This symbol must be SAVE OPCODE DS END OPERAND 18F

Figure 2-9 Source module requirements NOTES:

Copyright MCPL. Unit2.Fundamentals of Assembly Language Page 2 -11 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

EXECUTABLE VS. NON-EXECUTABLE STATEMENTS


Instructions are known as executable statements. Some directives are also executable statements. 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 run time by the hardware.

Copyright MCPL. Unit2.Fundamentals of Assembly Language Page 2 -12 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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 and data areas, are assembled into object module that can be loaded into main memory and executed at run time.

Copyright MCPL. Unit2.Fundamentals of Assembly Language Page 2 -13 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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 to generate the instructions needed to request that the corresponding operations to be performed by the operating system. The areas of memory to be used for the input and output data must be reserved by the defined storage (DS) and define constants (dc) directives. There must be DCB macro associated with each file that is used in a program, the DCB macro informs the operating systems how you intend to use the file.

Copyright MCPL. Unit2.Fundamentals of Assembly Language Page 2 -14 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

OS I/O MACROS
Input file Symbol 1 DCB DSORG =-----, MACRF = (---), DDNAME = SYSIN, EODAD = Symbol2, RECFM =-----, LRECL = ---, BLKSIZE = --X X

Printer file Symbol 1 DCB DSORG = ---, MACRF = (---), DDNAME = SYSPRINT, RECFM=---, LRECL = ---, BLKSIZE = -----X X

Figure: 2-13 OS I/O macros NOTES: The input file parameters DSORG = PS for a sequential file, MACRF = (GM) for a GET macro. DDNAME = SYSIN for the standard system input file. The parameter EODAD names the symbol of the statement to which control is to be transferred when the end-offile condition is reached. The RECFM parameter describes the type of records, which is either FB or VB. LRECL is for logical record length and BLKSIZE parameter stands for block size for storing records. The printer file parameter has MACRF = (PM) for put macro. RECFM = FBA which says that records are of fixed length and ANSI carriage control character will be used for printer line spacing.

Copyright MCPL. Unit2.Fundamentals of Assembly Language Page 2 -15 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

SAMPLE PROGRAM USING FILES


Sample assembly language program for OS.
DEMO CSECT STM BALR USING ST LA OPEN OPEN MVC GET MVI MVC PUT B CLOSE CLOSE L LM BR DCB DCB DS DS DC DC DS END 14, 12, 12(13) STANDARD ENTRY TO PROGRAM 12, 0 *, 12 13, SAVE +4 13, SAVE (INDCB, (INPUT)) OPEN INPUT DATA STREAM FILE (OUTDCB, (OUTPUT)) OPEN PRINTER OUTPUT FILE INAREA,=80C BLANK OUT INAREA' INDCB, INAREA READ DATA INTO 'INAREA' OUTCARR, C' ' SET SINGLE-PACE CONTROL CHAR OUTLINE (80), INAREA COPY DATA TO OUTPUT LINE AREA OUTDCB,OUTAREA WRITE DATA FROM 'OUTAREA' IOLOOP CONTINUE UNTIL END-OF-FILE (INDCB) CLOSE INPUT FILE (OUTDCB) CLOSE OUTPUT FILE 13, SAVE+4 STANDARD EXIT FROM PROGRAM 14, 12, 12(13) 14 DSORG=PS, MACRF=(PM), DDNAME=SYSIN, EODAD=FINISH X RECFM=FB, LRECL=80,BLKSIZE=4080 DSORG=PS, MACRF=(GM), DDNAME=SYSPRINT, X RECFM=FBA, LRECL=133,BLKSIZE=3990 CL80 80 BYTES FOR AN INPUT RECORD OCL133 133 BYTES FOR A PRINTER LINE CL1 ' ' 1 BYTE FOR CARRIAGE CONTROL CHAR CL132 ' ' 132 BYTES FOR DATA TO BE PRINTED 18F

10LOOP

FINISH EXIT INDCB OUTDCB INAREA OUTAREA OUTCARR OUTLINE SAVE

Copyright MCPL. Unit2.Fundamentals of Assembly Language Page 2 -16 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

DOS I/O MACROS


Input file Symbol 1 Printer file Symbol 1 DTFCD DEVADDR = _______, IOAREA1=_________, WORKA=____, EOFADDR=_____, BLKSIZE= _____ DTFPR DEVADDR=______, IOAREA1=________, WORKA=______, CTLCHR=______, BLKSIZE==______ X

X X

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 from the standard system input device. The IOAREA1= symbol parameter identifies the area into which each input record will be read. WORKA=YES indicates that after the input data has been read, it will be available to your program in the work area whose name is specified in the GET macro. The EOFADDR = parameter names the symbol of the statement to which control is to be passed on reaching the end-of-file condition. For printer 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 is specified in the PUT macro. CTICHR=ASA means than an ANSI carriage-control character will be used for printer line-spacing. The first byte of every record is a ANSI control character and the remaining 132 bytes contain the character to be printed.

Copyright MCPL. Unit2.Fundamentals of Assembly Language Page 2 -17 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

The ANSI ANSI C C 0 C __ C | C +

Carriage control character and their functions are function single spacing double spacing Triple spacing skip to new page suppress spacing

Copyright MCPL. Unit2.Fundamentals of Assembly Language Page 2 -18 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

SAMPLE PROGRAM FOR DOS


DEMO CSECT BALR 12, 0 STANDARD ENTRY TO PROGRAM USING *, 12 LA 13, SAVE OPEN INDTF OPEN INPUT DATA STREAM FILE OPEN OUTDTF OPEN PRINTER OUTPUT FILE MVC INAREA, =80C ' ' BLANK OUT 'INAREA' GET INDTF, INAREA READ DATA INTO 'INAREA' MVI OUTCARR, C ' ' SET SINGLE-SPACE CONTROL CHAR MVC OUTLINE, INAREA COPY DATA TO OUTPUT LINE AREA PUT OUTDTF, OUTAREA WRITE DATA FROM 'OUTAREA' B IOLOOP CONTINUE UNTIL END-OF-FILE CLOSE INDTF CLOSE INPUT FILE CLOSE OUTDTF CLOSE OUTPUT FILE EOJ STANDARD EXIT FROM PROGRAM DTFCD DEVADDR=SYSIPT, IOAREA1=INBUF, WORKA=YES, X EOFADDR=FINISH, BLKSIZE=80 DTFPR DEVADDR=SYSLST,IOAREA1=OUTBUF,WORKA=YES, X CTLCHR=ASA, BLKSIZE=133 DS CL80 80 BYTES FOR INPUT 'WORKA' DS CL80 80 BYTES FOR INPUT "IOAREA" DS OCL133 133 BYTES FOR PRINTER 'WORKS' DC CL1 ' ' 1 BYTE FOR CARRIAGE CONTROL CHAR DC CL132 ' ' 132 BYTES FOR DATA TO BE PRINTED DS CL133 133 BYTES FOR PRINTER " IOAREA1" DS 9D END

IOLOOP

FINISH EXIT INDTF OUTDTF INAREA INBUF OUTAREA OUTCARR OUTLINE OUTBUF SAVE

Copyright MCPL. Unit2.Fundamentals of Assembly Language Page 2 -19 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

ANSI CARRIAGE-CONTROL CHARACTERS


The ANSI carriage-control characters and their functions are these: ANSI C C0 C- C1 C+ character (blank) (zero) (minus) (one) (plus) function single spacing: double spacing: triple spacing: skip to new page: suppress spacing: action print on the next available line leaves one blank line before printing leave two blank lines before printing print on first line of next page 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 in the first position of the print line they are not printed; instead they cause the printer to adjust the paper position before printing the line.

Copyright MCPL. Unit2.Fundamentals of Assembly Language Page 2 -20 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

ASSEMBLY LISTINGS
The appearance of the assembly listing can be enhanced by using the following simple 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 language together with your source language statements and indicates what (if any) errors have been detected during the assembly process. The listing also includes an index of the name field symbols defined in the source module. The index is known as the cross-reference list (XREF). It is very useful when debugging and modifying programs. It identifies the statement in which each symbol is defined and the statement in which each is used. The cross-reference list also gives the value of each symbol and the length of the instruction or data field that the symbol is associated with.

Copyright MCPL. Unit2.Fundamentals of Assembly Language Page 2 -21 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

UNIT 3: INSTRUCTIONS AND ADDRESSES


OBJECTIVES : ADDRESSES INSTRUCTIONS MACHINE LANGUAGE FORMATS ASSEMBLY LANGUAGE FORMATS THE BALR-USING SEQUENCE MNEOMONIC OPCODES

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.

STUDENT NOTEBOOK

ADDRESSES

First byte of memory

last byte of memory

0 1 2 3 4 5 6 7 8 9 A B C Byte address byte address FFFFFF 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 the total number of bytes available in memory, , i.e. , the memorys capacity. Memory addresses are written in hexadecimal notation.

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.

STUDENT NOTEBOOK

SCHEMATIC REPRESENTATION OF MEMORY

Addresses of full , double & Half words

0 4 8 C last byte

1st double word

FFFFFC

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 a number 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 double word, respectively.

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.

STUDENT NOTEBOOK

SCEMATIC DIAGRAM OF THE 16 GENERAL REGISTER


REGISTER ADDRESS DECIMAL 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 HEXA DECIMAL 0 1 2 3 4 5 6 7 8 9 A B C D E 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 is referred to by an address that is an unsigned integer in the range from 0 to 15. Each register contains 32 bit. The left most bit are the most significant, or high order, bits of a register: the right most bits are the least significant, or low-order, bits. The 32-bit quantity in a register is often called the contents of that register. BIT # 31 IS THE LEAST SIGNIFICANT,or LOW-ORDER, bIT IN EACH REGISTER

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.

STUDENT NOTEBOOK

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 bit address.

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.

STUDENT NOTEBOOK

BASE DISPLACEMENT ADDRESS

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 bits long 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 the displacement. This 16-bit representation of a memory address is known as the base-displacement form of that address. At run time, base displacement form of an address is translated by the central processing unit (CPU) into a 24-bit memory address. M is known as the effective address generated from the base-displacement address.

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.

STUDENT NOTEBOOK

INSTRUCTIONS
Each machine language instruction consists of a certain number of bytes. The number of bytes comprising an instruction is known as the instructions length. In many computers, 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 instruction set 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 of a fixed-length set, has one significant advantage, . The number of bytes required for any instruction is just sufficient to provide only the information required in that instruction. This results in an overall saving of memory space in a program. In fixed-length sets, the length used for all instructions is the length needed by the instructions that contain the most information. This can result in unusable memory space. Figure: 3-6 Instructions NOTES:

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.

STUDENT NOTEBOOK

MEMORY LOCATION COUNTER (MLC)


The assembler maintains a counter, called the memory location counter whose initial value is 0. Memory Location Counter address assigned to an instruction = address assigned to preceding instruction = length of preceding instruction

Address assigned To a symbol

memory location counter

address assigned to 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 the assemblers symbol table.

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.

STUDENT NOTEBOOK

MACHINE LANGUAGE INSTRUCTION FORMAT


Instruction Type RR Machine Language Instruction Format OPCODE 0 RX 8 R1 12 B2 16 R2 12 I2 8 OPCODE 0 SS1 0 OPCODE D2 16 L 8 B1 16 20 16 B1 20 D1 B2 32 36 B2 32 36 6 48 20 B3 16 B1 20 D1 4 32 20 D1 4 32 D3 4 32 D2 4 32 R2 Instruction length No .of bytes no. of bits 2 16

OPCODE R1 X2 0 8 12

RS 0 SI

OPCODE R1 8 OPCODE 0

SS2

OPCODE L1 L2 B1 D1 D2 0 8 12 16 20

48

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 seven different instruction formats namely RR, RX, RS, SI, S, SS and SS2. The S format is available on IBM 370 machines only.

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.

STUDENT NOTEBOOK

ASSEMBLY LANGUAGE OPERAND FORMATS


Instruction Type RR RX Operand Explicit Explicit Format R1, R2 R1, D2(X2, B2) R1, D2 (,B2) R1, D2(X2) R1, D2 R1, S2 (X2) R1, S2 R1, R2, D3(B3) R1, R2, S3 D1 (B1), I2 S1, I2 D1 (B1) S1 D1(L, B1), D2(B2) S1, S2 D1( L, B1), S2 S1 (L), D2 (B2) S1 (L), S2 S1, D2 (B2) D1 (L1,B1), D2(L2,B2) S1, S2 D1 (L1, B1), S2(L2) D1 (L1, B1), S2 S1 (L1),S2 (L2) S1 (L1), S2 S1, S2 (L2) S1(L1), D2(L2,B2) S1, D2 (L2, B2)

Implicit RS SI S SS1 Explicit Implicit Explicit Implicit Explicit Implicit Explicit Implicit Mixed

SS2

Explicit Implicit Mixed

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.

Copyright MCPL. Unit3.Instructions and Address Page 3 - 10 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

EXAMPLES FOR EACH FORMAT


Eg 1: RR Format Machine language OP 1A 6 R1 5 R2 Assembly Language OP AR R1, R2 5, 6

Eg 2: RX Format Machine Language OP D2 5A 004 R1 X2 B2

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 denotes the absence of X2.

Copyright MCPL. Unit3.Instructions and Address Page 3 - 11 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

RS FORMAT
OP R1 D3 R2 B3 OP R1, R2, D3 (B3)

8A 004

10

SRA

7, 4 (10)

Eg 4:

SI Format OP I2 B1 D1 OP D1 (B1), I 2

95 020

30

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 in assembly language and not used in machine language. In the above Eg 3 R1 denotes register to be shifted and D3 (B3) specifies number of positions to be shifted.

Copyright MCPL. Unit3.Instructions and Address Page 3 - 12 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

SS1

FORMAT
Machine Language OP D2 L B1 D1 B2 Assembly Language OP D1 (L, B1), D2 (B2)

D5 0C8

04

040

CLC 64 (5, 12) 200(12)

Eg : 6 SS2 Format OP D2 0 8 F8 8 F8 0C8 L1 12 4 L2 B1 D1 32 040 B2 36 C ZAP B(8), A(4) OP D1(L1, B1), D2 (L2,B2)

16 20 C

Figure: 3-12 SS1 format NOTES: SS1 type instruction is used to compare bytes at one memory location with those at another. SS2 type instruction is used to compare L1 number of bytes starting from memory address designated by B1, D1 with L2 number of bytes starting at B2, D2.

Copyright MCPL. Unit3.Instructions and Address Page 3 - 13 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

IMPLICIT LENGTH
A 3, Z ? D2 + operand A, R = memory address of Z base address implied displacement

5A 3 0 ? OP R1 X2 B2 Memory address Represented by Z Opcode USING Implied Displacement = base address

Figure: 3-13 Implicit Length NOTES: The USING directive is used at assembly time and must occur before any statement in the source module that contains an operand for which an implied displacement must be calculated. If memory address of Z = 80 A & Base address is 6, then implied displacement = 80A 6 = 804.

Copyright MCPL. Unit3.Instructions and Address Page 3 - 14 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

THE BALR USING SEQUENCE


BALR BALR USING Eg: SAMP1 CSECT STM BALR USING ST LA = R1, R2 12, 0 *, 12 14, 12, 12 (13) 12, 0 *, 12 13, SAVE + 4 13, SAVE Memory address represented symbolically by SAVE + 4 Base address

Implied Displacement

for the instruction

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

Figure: 3-14 Blar sequence NOTES:

Copyright MCPL. Unit3.Instructions and Address Page 3 - 15 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

MNEMONIC OPCODES
The letters used in the opcodes are designed to help you remember each opcode and its purpose. For this reason the opcode are said to be mnemonic, from Greek words meaning mindful and remember

Figure: 3-15 Mnemonic Opcode. NOTES:

Copyright MCPL. Unit3.Instructions and Address Page 3 - 16 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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

Copyright MCPL. Unit 4.Basic Operations: Looping and Arrays Page 4 - 1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

BASIC OPERATIONS, LOOPING AND ARRAYS


Defining Constants Defining Storage

Define constant (DC) directive Name field Any symbol Or blank DC operand sub-field components Optional Duplicator Constant Required Figure: 4 1 Basic operations NOTES: The DC directive is used to denote constants in various forms. The duplicator denotes the number of consecutive representations of the constant. The modifier can be a length scale or exponent modifier. DC FL1 50 This generates a 1-byte binary integer representation of 50. Type Modifier Opcode DC Operand One or more sub-fields, separated by comma

Eg:

DC

FS10 8
10

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

= 3072

Copyright MCPL. Unit 4.Basic Operations: Looping and Arrays Page 4 - 2 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

TYPES OF CONSTANTS FOR DC DIRECTIVE


Type code F H C E D L X P Z B A V meaning (full word) Binary Integer Binary Integer (Half word) Text or characters Floating Point (Short form) Floating point (Long form) Floating Point (Extended form) Hexadecimal Decimal Numbers (Packed form) Decimal Numbers (Zoned form) Bit sequence Address (internal) Address (External) Example F8 H 8 CHello E 8.3 D 8.3 L8.3 XABC P8.5 Z8.5 B1001 A (Symbol) V (Symbol)

Figure: 4-2 DC directives NOTES: Each character is converted to its 8-bit EBCDIC representation. The characters are stored 75 in consecutive bytes. For D format the maximum approx. is 7.2 x 10 with about 1675 digit accuracy. For E format the maximum approx. is 7.2 x 10 with about 7-digit 75 accuracy. For L format the max approx. is 7.2 x 10 with about 32-digit accuracy. For P 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.

Copyright MCPL. Unit 4.Basic Operations: Looping and Arrays Page 4 - 3 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

THE DS DIRECTIVE
Name Opcode Operand

a symbol, or blank Required Duplicator Constant Type

DS

one or more sub-fields, separated by commas

Modifier

Optional

Eg 1

DATE

DS

2 CL 8
Modifier Type Duplicator

Eg 2:

MVC MVC

DATE(10),=C09/10/1998 DATE,=C09/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 field is omitted when specifying a symbolic address in an SS 1 or SS2 instruction, the assembler uses the length attribute of that symbol.

Copyright MCPL. Unit 4.Basic Operations: Looping and Arrays Page 4 - 4 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

SUB DIVISIONS
DATE MONTH DAY YEAR DS DS DS DS DS DS 0CL10 CL2 C CL2 C CL4

MONTH YEAR 2 1 10 COBOL EQUIVALENT 2

DAY 1 4

01

02 02 02 02 02

MONTH DAY YEAR

DATE.

PIC PIC PIC PIC PIC

XX. X. XX. X. XXXX.

Figure: 4 4 Sub divisions NOTES: Subdivisions are convenient for defining areas within an area. In the above example DATE and MONTH both will have the same address.

Copyright MCPL. Unit 4.Basic Operations: Looping and Arrays Page 4 - 5 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

EQUIVALENCE CONSTANTS (EQU)


Eg 1 Eg 2 Eg 3 MLC MSG1 RESULT T1 T2 ST ON OFF CLI BE Invalid use of EQU EQU DC EQU DC DC DC EQU DS EQU EQU . . ST, ON PUTON * C MAINTEC COMPUTERS * - MSG1 F1 F2 F3 * - T1 CL1 XFF X00 CLI BE ST, XFF PUTON

Eg 4

EX1
EX2

EQU
DC

* - EX2

CHELLO

Figure: 4 5 Equivalence constants NOTES: EQU directive is to define a value for a symbol. This value cannot be changed in the program. The EQU does not cause any bytes to be generated on the object module. The assembler at assembly time uses the constant defined by the EQU directive.

Copyright MCPL. Unit 4.Basic Operations: Looping and Arrays Page 4 - 6 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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 an absolute term. The value of an absolute term remains unchanged during run time and assembly time whereas the value of a re-locatable term may change from assembly time to run time.

Copyright MCPL. Unit 4.Basic Operations: Looping and Arrays Page 4 - 7 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

CONTROL SECTIONS
SOURCE MODULE OBJECT MODULE

Executable Control section Reference Control section

A CSECT B DSECT END C COM

Executable section A Dummy reference Section B Common reference section C

Input

output

Figure: 4-7 Control sections NOTES: There are 2 types of control sections namely executable control section and reference control section. An executable control section consists of instructions, constants and data areas whereas a reference control section consists of directives only. The assembler keeps a separate memory location counter for each control section in the source module.

Copyright MCPL. Unit 4.Basic Operations: Looping and Arrays Page 4 - 8 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

SOURCE MODULE
7FC 328 800 0 A 0 B A CSECT . .. DSECT CSECT END Opcode CSECT Operand blank

CSECT Name field Any symbol Or blank START Name field Any symbol

Opcode START

Operand blank or

Or 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; it can be referred as an external symbol from another source module. START specifies the beginning of the first executable control section in a source module. The START pseudo-op cannot be used to resume an executable control section. The value of the selfdefining term in the operand (if present) designates the initial value for the memory location counter of the control section. If the operand is blank, the initial value is zero.

Copyright MCPL. Unit 4.Basic Operations: Looping and Arrays Page 4 - 9 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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 BALR ST LA OPEN 14, 12, 12 (13) 12,0 13,SAVE+4 13,SAVE (PRINTER, (OUTPUT)) 3,X 3, Y 3, Z 5, Z 5,BCD SUM, BCD SUM+9, X F0 STANDARD ENTRY

USING

*, 12

FILE * ADD L INTEGERS A Y, AND ST ADDRESS * CONVERT L REGISTERS CVD UNPK OI LOW-ORDER

OPEN THE PRINTER OUTPUT COMPUTE THE SUM OF THE AT SYMBOLIC ADDRESSES X & STORE THE SUM AT SYMBOLIC COPY THE SUM INTO CONVERT IT TO BCD FORM CONVERT THAT TO EBCDIC ELIMINATE SIGN CODE IN

Copyright MCPL. Unit 4.Basic Operations: Looping and Arrays Page 4 - 10 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

* PRINT PUT PRINTER, LINE WRITE THE SUM, TOGETHER WITH TEXT, ONTO THE PRINTER. * EXIT CLOSE (PRINTER) L 13, SAVE+4 STANDARD EXIT LM 14,12,12(13) BR 14 * INTEGER CONSTANTS, AND AREA RESERVED FOR THEIR SUM X DC F437 BINARY REPRESENTATION OF DECIMAL +437 Y DC F562 BINARY REPRESENTATION OF DECIMAL +562 Z DS F BINARY SUM, TO BE CONVERTED TO EBCDIC BCD DS D 8 BYTES RESERVED ON DOUBLEWORD * AREA RESERVED FOR 132-BYTE PRINT LINE LINE DS 0CL132 BEGINNING AND LENGTH OF LINE DC CL7 COLS 1 7 BLANK DC CTHE SUM IS SUM DS CL10 DC CL104 * * DATA CONTROL BLOCK FOR OUTPUT TO PRINTER PRINTER 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 a 10-byte character form for printing.

Copyright MCPL. Unit 4.Basic Operations: Looping and Arrays Page 4 - 11 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

PROGRAM TO PRINT THE SUM OF TWO UNSIGNED DECIMAL INTEGER RDPRT CSECT

* THIS PROGRAM READS TWO NON-NEGATIVE INTEGERS FROM A DATA CARD THAT IS IN * THE INPUT DATA STREAM, COMPUTERS THEIR SUM, AND PRINTS THE RESULT IN A * SINGLE LINE ON THE PRINTER.THE INPUT DATA IS ASSUMED TO BE REPRESENTED AS * 10-BYTE UNSIGNED DECIMAL INTEGERS, WITH EITHER LEADING ZEROES OR LEADING * BLANKS. * THE SUM IS PRINTED AS A 10-BYTE UNSIGNED DECIMAL INTEGER, WITH LEADING * ZEROES PRINTED AS ZEROES. STM 14, 12, 12(13) BALR 12, 0 USING *, 12 ST 13, SAVE+14 LA 13, SAVE * OPEN STANDARD ENTRY

INPUT AND OUTPUT FILES OPEN (TRANS,(INPUT) CARDS FROM INPUT DATA STREAM OPEN (PRINTER,(OUTPUT) PRINTER IS SYSOUT GET ONE DATA CARD TRANS, CARD INPUT AREA IS CARD

* READ

CONVERT EACH NUMBER TO 32-BIT BINARY PACK BCD,INT1 FIRST INTEGER IS AT INT1 CVB 5, BCD ITS 32-BIT BINARY INTEGER FORM IS STORED AT X. PACK BCD,INT2 SECOND INTEGER IS AT INT2. CVB 5,BCD ITS 32-BIT BINARY INTEGER FORM IS ST 5, Y STORED AT Y.

Copyright MCPL. Unit 4.Basic Operations: Looping and Arrays Page 4 - 12 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

COMPUTE THE SUM, AND STORE BINARY INTEGER RESULT AT Z . L 3, X INTEGERS GIVEN A 3, Y AND ST 3, Z ADDRESS Z. COMPUTE THE SUM OF THE AT SYMBOLIC ADDRESSES X & Y, STORE THE SUM AT SYMBOLIC

CONVERT THE SUM TO UNSIGNED 10-BYTE CHAR, FORM WITH LEADING ZEROES. L S, Z PUT THE SUM IN A REGISTER CVD 5, BCD CONVERT IT TO BINARYCODED DEC. UNPK SUM,BCD CONVERT THAT TO CHAR (EBCDIC) OI SUM+9, X FO ELIMINATE SIGN CODE * PRINT THE RESULT PUT PRINTER, LINE EOJ CLOSE (PRINTER) CLOSE (TRANS) L 13, SAVE+14 LM 14,12,12(13) BR 14

CLOSE ALL FILES STANDARD EXIT

* AREAS RESERVED FOR TWO BINARY INTEGERS AND THEIR SUM X DS F BINARY REPRESENTATION OF INTEGER AT INT1 Z DS F SUM OF X AND Y INTEGERS * AREA RESERVED FOR INTERMEDIATE BINARY-CODED DECIMAL REPRESENTATION BCD DS D SAME AREA USED FOR ALL CONVERSIONS * AREA RESERVED FOR 80-BYTE INPUT CARD CARD DS OCL 80 BEGINNING AND LENGTH OF AREA DS CL5 COLS 1 5 UNUSED INT1 DS CL10 6 15 FIRST 10-BYTE DECIMAL INTEGER DS CL5 16 20 UNUSED INT2 DS CL10 21 - 30 SECOND 10-BYTE DECIMAL INTEGER DS CL50 31 80 UNUSED

Copyright MCPL. Unit 4.Basic Operations: Looping and Arrays Page 4 - 13 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

* AREA RESERVED FOR 132-BYTE PRINT LINE LINE DS OCL132 BEGINNING AND LENGTH OF LINE DC CL7 COLS 1- 7 BLANK DC CTHE SUM IS 8 18 EXPLANATORY TEXT SUM DS CL10 19 28 10 BYTE SUM DC CL104 29 132 BLANK TRANS DCB DSORG-PS, MACRF-(GM), DDNAME-SYSIN,EODADEOJ, X RECFM=FB, LRECL-80,BLKSIZE=4080 PRINTER DCB DSORG=PS,MACRF=(PM),DDNAME=SYSPRINT, X RECFM=FB,LRECL=132,BLKSIZE=4092 REQUIRED STATEMENTS SAVE DS 18F END

NOTES: The program uses instructions such as PACK to convert from Zoned to BCD form and CVB convert form BCD form to Binary integer form. The resulting sum is printed as a 10 byte unsigned decimal integer.

Copyright MCPL. Unit 4.Basic Operations: Looping and Arrays Page 4 - 14 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

THE LA INSTRUCTION
General form 1. 2. 3. 4. LA LA LA LA R1, S2 R1, D2 R1, D2 (X2) R1, D2(X2, B2)

Eg 1: Eg 2: Eg 3 : Eg 4 :

LA LA LA LA

5,W 5,4 5,4 (5) 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.

Copyright MCPL. Unit 4.Basic Operations: Looping and Arrays Page 4 - 15 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

THE BXH AND BXLE INSTRUCTION


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

Implicit form :

Eg : L L L Loop L A ST BXLE 9, LIMIT 8, INCR 7,=F0 3,X(7) 3,Y(7) 3,Z(7) 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 index that is in register 7 and compare the sum to the limit that is in register 9. If the sum is less than or equal to the limit then branch to symbol called LOOP otherwise do not branch.

Copyright MCPL. Unit 4.Basic Operations: Looping and Arrays Page 4 - 16 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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 number system, where as all data transmitted between memory and most input and output devices are in character format. In the IBM 360 and 370 systems, EBCDIC character format is used. To print an integer that is represented in binary form in memory, it must first be converted to its character form. The sequence of instructions must be used to converts a binary integer to its representation as a decimal integer in character form. The instructions (DS and DC directives) are also used to allocating memory areas for the characters that are to be printed.

Copyright MCPL. Unit 4.Basic Operations: Looping and Arrays Page 4 - 17 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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 one position for the sign : Symbol DS CLn n is an unsigned decimal integer and symbol 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 other than an apostrophe () or an ampersand (&) .

To assign m blanks to unused print positions : DC CLm m , an unsigned decimal integer, and is the number 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 of memory must be reserved for the entire line, some of these bytes must be allocated for the integers . that are to printed, others for any text that is also to be printed, and the remainder for blanks that fill out the line.each such allocation will designate the print position that are to be used.

Copyright MCPL. Unit 4.Basic Operations: Looping and Arrays Page 4 - 18 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

CONVERSION FROM BINARY TO CHARACTER REPRESENTATION

Four Conversion Instructions :


L CVD UNPK OI 5,Z 5 , BCD SUM ,BCD SUM+9,XF0
COPY THE BINARY INTEGER INTO A REGISTER CONVERT IT TO BCD FORM CONVERT THAT TO CHARACTER FORM 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 the Load(L) instruction. The address of the ten-byte memory area that is allocated for the character representation of the number must be specified in the first operand of the UNPK instruction. The address of the low-order byte of the ten-byte character area must be specified in the first operand of the OI instruction. The address of the area reserved for the intermediate binary coded decimal representation must be specified in the second operand of both the CVD and the UNPK instructions.

Copyright MCPL. Unit 4.Basic Operations: Looping and Arrays Page 4 - 19 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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 for printing. The character form of the decimal integer occupies exactly ten positions ,right justified with either leading zeroes or leading blanks. Its sign is omitted; it is assumed to be nonnegative.

Copyright MCPL. Unit 4.Basic Operations: Looping and Arrays Page 4 - 20 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

ALLOCATING MEMORY AREAS

The Directives required to allocate memory area for the data : CARD DS DS INT DS DS 0CL80 CL5 CL10 CL65
DEFINE BEGINNING AND LENGTH OF CARD RESERVE 5 BYTES FOR UNUSED POSITIONS 10 BYTES FOR CHARACTER FORM OF INTEGER 65 BYTE POSITION FOR REMAINDER OF CARD

Figure: 4 - 15 Memory allocating area NOTES :

Copyright MCPL. Unit 4.Basic Operations: Looping and Arrays Page 4 - 21 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

CONVERSION FROM CHARACTER FORM TO32-BIT BINARY INTEGER FORM THREE INSTRUCTIONS ARE REQUIRED FOR CONVERSION : PACK BCD , INT CONVERT FROM CHAR. TO BCD CVB 5 , BCD CONVERT THAT TO 32-BIT BINARY IN REGISTER 5 ST 5,X STORE THE BINARY FORM AT SYMBOLIC ADDRESS X THE 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 character representation of the number must be specified in the second operand of the PACK instruction. The address of the area reserved for intermediate BCD representation of the number must be specified in the first operand of the PACK instruction and in the second operand of the CVB instruction. The address of the area reserved for the binary integer must be specified in the second operand of the ST instruction.

Copyright MCPL. Unit 4.Basic Operations: Looping and Arrays Page 4 - 22 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

UNIT 5 :INTEGER ARITHMETIC


OBJECTIVES: Twos complement arithmetic Addition, subtraction, multiplication, division Conditional branches Comparing integers Two dimensional arrays Changing sign and generating absolute values

Copyright MCPL. Unit 5. Integer Arithmetic 5 - 1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

TWOS 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 +0 +1 +2 +3 +4 +5 +6 +7 binary 0000 0001 0010 0011 0100 0101 0110 0111 decimal -0 -1 -2 -3 -4 -5 -6 -7 binary 1000 1001 1010 1011 1100 1101 1110 1111

Figure: 5 1 Twos 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 fullword and half-word binary numbers: copying data into and out of a register; addition, subtraction, multiplication and division of two binary integers; changing sign, and generating the absolute value of a binary integer; testing for positive, negative, or zero numeric result; and comparing two binary integers algebraically.

Copyright MCPL. Unit 5. Integer Arithmetic 5 - 2 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

ARITHMETIC INSTRUCTION
Addition Instruction A, AR, AH Al, ALR Condition codes 0 1 result was zero Result = -ve result was zero Result was not zero With no carry With no carry out Out of sign bit Of sign position Position 2 Result = +ve Result was zero With a carry out of sign bit position 3 Overflow Result was Zero with a carry out of sign bit position.

Eg 1: A Eg 2: AR Eg 3: AH 8, =H5 8, 9 5,=F15

Reg 5 Before : 0000 0030 After : 0000 003F Reg 8 Before: 0000 0001 After : 0000 0011 Reg 8 Before : 0000 0040 After : 0000 0045

= F15 0000 000F 0000 000F Reg 9 0000 0010 0000 0010 = H5 0005 0005

Figure: 5-2 Arithmetic Instructions NOTES: Condition code stores the status of each add instruction after execution.

Copyright MCPL. Unit 5. Integer Arithmetic 5 - 3 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

SUBTRACTION
Instruction Instruction S, SR, SH Sl, SLR 0 Result = 0 Condition Codes 1 Result = -ve Result was not zero with no carry out of sign bit position 2 Result = +ve Result was zero with a carry out of sign bit position 3 Overflow result was not zero with a carry out of the sign bit position.

Eg 1: S 5, = F10

Reg 5 Before: 0000 0030 After: 0000 0026 Reg 8

=F10 0000 000A 0000 000A Reg 9 0000 1000 0000 1001 =H80 0050 0050

Eg 2:

SR

8, 9

Before : FFFF FFFF After : FFFF FFFF Reg 8

Eg 3:

SH

8, =H80

Before : 0000 0008 After : FFFF FFB8

Figure 5-3 Subtractions NOTES: If the result after subtraction is negative then the result is in twos complement form.

Copyright MCPL. Unit 5. Integer Arithmetic 5 - 4 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

MULTIPLICATION
even register Before After Eg 1 : : SR 4,4 L 5,=F3 M 4,=F2 odd register

Some Number Multiplicand 64 bit product even-odd pair Reg 4 Reg 5 Before : 0000 0000 0000 0003 After : 0000 0000 0000 0006

Eg 2

SR 6,6 L 7,=F65536 MR 6, 7

Before : After :

Reg 6 0000 0000 0000 0001 Reg 9 0000 0003 0000 000F

Reg 7 0001 0000 0000 0000

Eg 3

L 9,=F3 MH 9,=H5

Before : After :

Figure: 5 4 Multiplication NOTES: While using M and MR instructions, Multiplicand must always be in an odd-numbered register. The product is 64-bit signed integer that occupies two consecutive registers (called even-odd pair).

Copyright MCPL. Unit 5. Integer Arithmetic 5 - 5 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

DIVISION
even-odd register pair even numbered Register odd numbered register

Before

64 bit dividend

After Eg 1 L L D L L L DR

32-bit remainder 7, = F9 6, = F0 6, = F2 9, = F150 8, = F0 10,=F-40 8, 10

32-bit quotient Reg 6 0000 0000 0000 0001 Reg 8 Before : 0000 0000 After : 0000 001E Reg 7 0000 0009 0000 0004 Reg 9 0000 0096 FFFF FFFD FFFF FFFF FFD4 Reg

Before : After :

Eg 2 10 FFD4

Figure 5 5 Division NOTES: While using the D & DR instructions the dividend is a 64-bit integer. Divisor could be stored in any register. The remainder is stored in the even-numbered register and the quotient is stored in the odd-numbered register.

Copyright MCPL. Unit 5. Integer Arithmetic 5 - 6 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

BRANCHING INSTRUCTIONS
BZ BNZ BM BNM BP BNP

LTR Eg 1: L M LTR BM BZ B 5, M1 4, M2 5,5 NEGT ZERO POS

R1,R2

Figure 5 6 Branching Instructions NOTES: The conditional branch instructions do not set the condition code. They only test it. The LTR instruction sets the condition code according to whether register R1 is zero, negative or positive. Before testing, the LTR instruction first copies the contents of R2 to R1.

Copyright MCPL. Unit 5. Integer Arithmetic 5 - 7 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

COMPARISON
INSTRUCTION 3 C, CR, CH -----Opcode BE BNE BL BNL BH BNH L C BE BH 5, Z 5,=F6 EQ HIGH L CH BNE 3, Z 3,=H Z NEQ 0 N1 = N2 CONDITION CODE 1 N1 < N2 2 N1 > N2

RELATED BRANCH INSTRUCTIONS Meaning N1 = N2 N1 N2 N1 < N2 N1 N2 N1 > N2 N1 N2

Eg 1

Eg 3

Eg 2: L L CR BNH B

3, Z 4,=F6 3, 4 LORE GT

Figure 5 7 Comparison NOTES: One of the two numbers to be compared must be in a register and the other number can be in a register or memory location. None of the numbers are affected by the compare instruction.

Copyright MCPL. Unit 5. Integer Arithmetic 5 - 8 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

COMPLEMENT INSTRUCTIONS
Instruction LCR LPR LNR 0 result = 0 result = 0 result = 0 CONDITION CODE 1 2 result = -ve ------result = -ve result= +ve result=+ve ------Reg 5 Eg 1 LCR 5,5 before After Eg 2: LCR 5, 6 Before After Eg 3: LPR 5, 4 : : 0000 FFFF 0002 FFFE Reg 6 8000 0000 8000 0000 Reg 5 3 overflow overflow -----------

Reg 5 : 1234 5678 : 8000 0000 Reg 4

Before :FFFF FFFA 0000 00AB After Eg 4: LPR 4, 5 : FFFF FFFA 0000 0006 Reg 4 Before : FFFF FFFA After : 000 00AB Reg 5 0000 00AB 0000 00AB

Copyright MCPL. Unit 5. Integer Arithmetic 5 - 9 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

Eg 5:

LNR

4,5

Reg 4 Before : FFFF FFFA After : FFFF FF55

Reg 5 0000 00AB 0000 00AB Reg 5 0000 00AB FFFF FFFA

Eg 6:

LNR

5, 4

Reg 4 Before : FFFF FFFA After : FFFF FFFA

Figure: 5-8 complement instruction NOTES: The LCR instruction loads the twos complement of a register. The LNR instruction is used to load the negative absolute value of a number. The LPR instruction is used to load the positive absolute value of a number.

Copyright MCPL. Unit 5. Integer Arithmetic 5 -10 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

Sample programs using arrays.


* THIS PROGRAM ADDS INTEGERS STORED IN AN ARRAY

* REQUIRED STATEMENTS * START CSECT STM 14,12,12(13) BALR 12,0 USING *,12 ST 13,SAVE+4 * WTO 'FIRST STEP' LA 13,SAVE OPEN (FILE,(OUTPUT)) * * ADDITION OF THE TWO INTEGERS * S LA 8,ARRAY L 9,N SR 10,10 ADD A 10,0(8) LA 8,4(8) BCT 9,ADD ST 10,Z * * CONVERSION OF BINARY O/P TO EBCDIC * CONVERT L 5,Z CVD 5,BCD UNPK SUM,BCD OI SUM+9,X'F0' PUT FILE,OUTREC CLOSE FILE * L 13,SAVE+4 LM 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 * Copyright MCPL. Unit 5. Integer Arithmetic 5 -11 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

*** DEFINING THE CONSTANTS USED IN THE PROGRAM Z DS F N 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 0D SAVE DS 18F

Copyright MCPL. Unit 5. Integer Arithmetic 5 -12 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

* * *

THIS PROGRAM ADDS FINDS AVERAGE OF AN ARRAY REQUIRED STATEMENTS CSECT STM BALR USING ST WTO LA OPEN 14,12,12(13) 12,0 *,12 13,SAVE+4 'FIRST STEP' 13,SAVE (FILE,(OUTPUT)) INTEGERS

START

* * S ADD

AVERAGE LA L SR A LA BCT ST M D ST ST

OF THE

* * CONVERSION * CONVERT L CVD UNPK OI PUT L CVD UNPK OI PUT L

8,ARRAY 9,N 11,11 11,0(8) 8,4(8) 9,ADD 11,Z 10,=F'1' 10,N 11,QUOT 10,REM OF BINARY O/P TO EBCDIC 5,Z 5,BCD SUM,BCD SUM+9,X'F0' FILE,OUTREC1 6,QUOT 6,BCD Q,BCD Q+9,X'F0' FILE,OUTREC2 7,REM

Copyright MCPL. Unit 5. Integer Arithmetic 5 -13 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

CVD UNPK OI

7,BCD R,BCD R+9,X'F0'

PUT FILE,OUTREC3 CLOSE FILE L LM BR 13,SAVE+4 14,12,12(13) 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 PROGRAM Z DS F N DC F'3' QUOT DS F REM DS F ARRAY 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 D SAVE DS 18F

Copyright MCPL. Unit 5. Integer Arithmetic 5 -14 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

* THIS PROGRAM MULTIPLIES EACH INTEGER IN AN ARRAY BY A CONSTANT * REQUIRED STATEMENTS * START1 CSECT STM 14,12,12(13) BALR 12,0 USING *,12 ST 13,SAVE+4 * WTO 'FIRST STEP' LA 13,SAVE OPEN (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,N L 3,CONST MULT SR 10,10 L 11,0(8) MR 10,3 ST 11,Z ST 10,Y * * CONVERSION OF BINARY O/P TO EBCDIC * CONVERT L 5,Z CVD 5,BCD UNPK SUM,BCD OI SUM+9,X'F0' SNAP DCB=SNAPDCB,ID=2,PDATA=(PSW,REGS), STORAGE=(START1,SAVE) PUT L CVD UNPK FILE,OUTREC1 6,Y 6,BCD Q,BCD

OI Q+9,X'F0' Copyright MCPL. Unit 5. Integer Arithmetic 5 -15 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

PUT LA BCT CLOSE CLOSE L LM BR

FILE,OUTREC2 8,4(8) 9,MULT FILE SNAPDCB 13,SAVE+4 14,12,12(13) 14

* * DATA CONTROL BLOCK FOR WRITING THE O/P * FILE DCB DSORG=PS,MACRF=(PM),DDNAME=SYSOUT, RECFM=FB,LRECL=80,BLKSIZE=8000 * SNAPDCB DCB DSORG=PS,MACRF=(W),RECFM=VBA,BLKSIZE=1632,LRECL=125, DDNAME=SNAPSHOT *** DEFINING THE CONSTANTS USED IN THE PROGRAM Z DS F Y DS F CONST 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 D SAVE DS 18F

Copyright MCPL. Unit 5. Integer Arithmetic 5 -16 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

* THIS PROGRAM COUNTS THE NUMBER OF POSITIVE INTEGERS IN AN ARRAY * REQUIRED STATEMENTS START1 CSECT STM BALR USING ST WTO LA OPEN SNAP OPEN LA L L LTR BNP A LA BCT ST 14,12,12(13) 12,0 *,12 13,SAVE+4 'FIRST STEP' 13,SAVE (SNAPDCB,(OUTPUT)) DCB=SNAPDCB,ID=1,STORAGE=(START1,SAVE), PDATA=(PSW,REGS) (FILE,(OUTPUT)) 8,ARRAY 9,N 11,0(8) 11,11 LOOPCTL 10,=F'1' 8,4(8) 9,POSCHK 10,POSCTR OF BINARY O/P TO EBCDIC 5,POSCTR 5,BCD SUM,BCD SUM+9,X'F0' DCB=SNAPDCB,ID=2,PDATA=(PSW,REGS),

X * * S POSCHK

LOOPCTL

* * CONVERSION * CONVERT L CVD UNPK OI SNAP X

STORAGE=(START1,SAVE) PUT FILE,OUTREC1 CLOSE FILE CLOSE SNAPDCB

Copyright MCPL. Unit 5. Integer Arithmetic 5 -17 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

* * DATA CONTROL BLOCK FOR WRITING THE O/P * FILE DCB DSORG=PS,MACRF=(PM),DDNAME=SYSOUT, X RECFM=FB,LRECL=80,BLKSIZE=8000 * SNAPDCB DCB DSORG=PS,MACRF=(W),RECFM=VBA,BLKSIZE=1632,LRECL=125, DDNAME=SNAPSHOT *** DEFINING THE CONSTANTS USED IN THE PROGRAM POSCTR DS F N 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 D SAVE DS 18F

L LM BR

13,SAVE+4 14,12,12(13) 14

Copyright MCPL. Unit 5. Integer Arithmetic 5 -18 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

BYTE OPERATIONS

Opcode IC STC ICM STCM

Type RX RX RS RS

Register 0 Mask 8 16 24

Eg 1: IC 8, A

Reg 8 Before : 01 02 03 04 After : 01 02 03 A1 Reg 4

mem locn 500 A1 A2 A3 A4 A1 A2 A3 A4 mem loc 400 A1 A2 A3 A4 04 A2 A3 A4

Eg 2:

STC

4, Z

Before After

: 01 02 03 04 : 01 02 03 04

Copyright MCPL. Unit 5. Integer Arithmetic 5 -19 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

Eg 3:

ICM

6, XA, A Before After

Reg 6 : 01 02 03 04 : A1 02 A2 04 1 0 0 1

mem loc. 500 A1 A2 A3 A4 A1 A2 A3 A4

Eg 4:

STCM 4, 0011, Z

Reg 4

mem loc. Z A1 A2 A3 A4 03 04 A3 A4

Before : 01 02 03 04 After : 01 02 03 04

Figure 5-9 Byte NOTES: Set of bytes can be copied from memory to register and vice-versa. The ICM and STCM instructions are available on the IBM 370 only and not on the IBM 360. The number of bytes that are inserted or stored is equal to the number of 1s in the 4-bit mask. The relative position of the bytes in the register is dependent on the position of bit 1s in the mask. A one-to-one correspondence from left to right is used.

Copyright MCPL. Unit 5. Integer Arithmetic 5 -20 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

MOVING BYTES
Opcode MV1 MVC MVC IN MVCL Type SI SS1 SS1 RR

Eg 1: MVI

Z+3, C !

Location Z in hexadecimal in characters Before : D4 E3 C5 C3 M T E C After : D4 E3 C5 5A M T E ! mem locn 800 F A R M F A R M

Eg 2: MVC

Z(4), Y

mem loc 500 (Z) Before : S T U D After : F A R M : : : :

Eg 3: MVC Eg 4: MVCIN

Z+1(3), Z Before After Z+3(4), Y Before After

mem locn 500 G O O D G G G G mem locn 500 (Z) T H A T P O S H

mem locn (Y) 1000 S H O P S H O P

Figure 5-10Moving Bytes NOTES: The MVCL and MVCIN instructions are available on the IBM 370 only and not on the IBM 360. The MVC instruction has a length field which specifies the number of bytes that are to be copied. In Eg 3 the sending field 500-502 overlaps receiving field 501503. In the MVCIN instruction memory location Y is the sending field and memory location Y is the sending field and memory location Z is the receiver.

Copyright MCPL. Unit 5. Integer Arithmetic 5 -21 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

COMPARISON OF BYTES
OPCODE Opcode CL CLR CLM CLI CLC CLCL

Type RX RR RS SI SSI RR

Condition Code Instruction CL, CLC, CLR CLCL, CLI, CLM 0 S1 = S2 1 S1<S2 2 S1>S2 3 ----

Relative Conditional Branch instructions are BE BNE BL BNL BH BNH

Figure 5-11 Comparison Of Bytes NOTES: CLCL instruction is available only on IBM 370 and not on IBM 360. SI is the first string and S2 is the second string.

Copyright MCPL. Unit 5. Integer Arithmetic 5 -22 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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

CMP NXT

TXT LEN

LA LA CLI BNE MVI LA BCT . . . DC EQU

4, TEXT 5, LEN 0(4), C ? NXT 0(4), C. 4, 1(4) 5, CMP

C How? WHEN? WHY? * - TEXT

Figure 5-12 Sample programs NOTES: The program uses register 4 to store the address of TEXT and register 5 to store the length of the TEXT. The string TEXT is searched for the question mark and replaced with period.

Copyright MCPL. Unit 5. Integer Arithmetic 5 -23 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

Sample program segment to find the first comma or blank and compute the length of the string preceding it. LA LA CLI BE CLI BE LA BCT LA SR STH . . DC EQU DS . . 4, text 5, LEN 0(4),C , DONE 0(4), C OVER 4, 1(4) 5, CMP 4, LEN 4, 5 4, POSIT

CMP

OVER EXIT

TEXT LEN POSIT

C FIRST COMMA, OR BLANK * - TEXT H

Figure 5-13 Sample programs NOTES: The assembler calculates the difference of two addresses ,the starting byte and the byte following last byte to compute the length of the string.

Copyright MCPL. Unit 5. Integer Arithmetic 5 -24 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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


LA LA CLC BE LA BCT SR ST . . . DC DC DC DC EQU DS . . . 4, TABLE 5, ELEMTS 0 (5,4), STR EXIT 4, 5(4) 5, REPEAT 4, 4 4, POSIT

REPEAT

EXIT

STR TABLE ELEMTS POSIT

CL5STOP CL5END CL5HERE CL5STOP (* - TABLE) / 5 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 in POSIT. If the string is found then the address of the matching string is stored.

Copyright MCPL. Unit 5. Integer Arithmetic 5 -25 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

SHIFTING BITS
ARITHMETIC LOGICAL Opcode SRA, SLA SLDA, SRDA RS RS Reg 9 Before : 0001 0001 0001 0001 0001 0001 0001 0001 After : 0000 0000 0000 0000 0000 0000 0000 0000 Eg 2: SRA 8,5 Reg 8 Before : 1111 1111 1111 1111 1111 1010 1010 1000 After Eg 3: SLA 4,4 (10) : 1111 1111 1111 1111 1111 1110 1101 0101 SHIFT SHIFT Type

Eg 1 : SRA

9, 31

Propagation of sign bits Reg 10: Displacement : 0000 0000 0000 0000 1000 0000 0000 00 1100 Reg 4

1000 0100

Before : 1111 1010 1111 1000 0000 0111 0000 0110 After : 0000 0000 0111 0000 0110 0000 0000 0000

Copyright MCPL. Unit 5. Integer Arithmetic 5 -26 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

Eg 4 :

SRDA 6, 3 Before : After :

Reg 6 1A 1B 1C 1D 03 43 63 83

Reg 7 1E 1F 10 11 A3 C3 E2 02 1E 1F 10 11 F8 80 88 00

Eg 5 : SLDA

6, 11 Before : After :

1A 1B 1C 1D 58 ED E8 F0

Figure 5-14 Shifting bits NOTES: In an arithmetic shift the sign bit of a register or register pair is treated differently from the 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 code is not set.

Copyright MCPL. Unit 5. Integer Arithmetic 5 -27 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

LOGICAL SHIFTS
Opcode SRL, SRL, SLL, SRDL, SLDL Type RS

SRL SLL

8, 5 8, 4(10)

Reg 8 Before : 1111 1111 1111 1111 1111 1111 1010 0100 After : 0000 0111 1111 1111 1111 1111 1111 1101 Reg 10 : Displacement : 0000 0000 0000 0000 1000 1000 0000 0000 0100

SRDL 6, 3 SLDL 6, 11

00 1100 Reg 8 Before : 0000 1001 0000 1000 0000 0111 0000 0110 After : 1000 0000 0111 000 0110 0000 0000 0000 Reg 6 Reg 7 Before : 1A 1B 1C 1D 1E 1F 10 11 After : 03 43 63 83 A3 C3 E2 02 Reg 6 Reg 7 Before : 1A 1B 1C 1D 1E 1F 10 11 After : 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 right most bits are lost and zeros are inserted into the X left - most positions. The sign bit is treated as any other bit. The condition code is not set.

Copyright MCPL. Unit 5. Integer Arithmetic 5 -28 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

ALTERING BITS
0 1 2 3

OPEN BIT OPEN I/O TYPE EOF 0

I/O

TYPE

EOF COMMENT File not open File open If open, file is used for input only If open, file is used for output only. Sequential file indexed sequential file 5 File has not reached end-of-file File has reached end-of-file

VALUE 0 1 0 1 0 1 1 2 0 1 4 3

Open

I/O

Type

EOF

Copyright MCPL. Unit 5. Integer Arithmetic 5 -29 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

BIT OPEN I/O

VALUE 0 1 00 01 10 11 00 01 10 11 0 1

COMMENTS File not open File open No meaning Opened for input only Opened for output only Opened for input & output No meaning Sequential indexed sequential direct not end-of-file end-of-file

TYPE

EOF

Figure 5 Alternating system NOTES:

Copyright MCPL. Unit 5. Integer Arithmetic 5 -30 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

Boolean Instructions on IBM 360 and 370-systems

Opcode

Type

Location of mark

Locn of

O, N, X (Second operand) OR, NR, XR operand) OX, NI, XI operand) OC, NC, XC memory (First operand)

RX Memory (First operand) RR SI SS,

Register Register (First Memory (First L byte

Register (second Operand) Immediate data field (Second operand) L byte memory

(Second operand)

Figure 5-16 Boolean Instructions NOTES: The OR, AND and EXCLUSIVE OR instructions are used to alter bits. The conditional branch instructions following boolean instructions are BZ, BZR, BNZ, BNZR.

Copyright MCPL. Unit 5. Integer Arithmetic 5 -31 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

FILE STATUS INFORMATION


FILESTAT OPEN IO IOIN IOOUT IOINOUT TYPE TYPSAM TYPISAM TYPBDAM EOF USAGE 1. OI 2. OI 3. TM BO TM BO . 4. TM BO 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. DC EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU B0000 0000 B1000 0000 B0110 0000 B0010 0000 B0100 0000 B0110 0000 B0001 1000 B0000 1000 B0001 0000 B0001 1000 B0000 0100

FILESTAT, OPEN FILESTAT, TYPISAM FILESTAT, IOOUT OUTPUT FILESTAT, IOIN INPUT FILESTAT, IOINOUT BOTH

Copyright MCPL. Unit 5. Integer Arithmetic 5 -32 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

TESTING BITS
Assembly language format Opcode operand TM D1 (B1), I2 TM S1, I 2 Machine Language format 91 D1 91 I2 I 2 Implied Displacement Base Register B1

Related Conditional Branch Instructions are BM BZ BO

TEST AND SET Assembly Language format TS TS D1 (B1) S1 Machine Language format 93 D1 93 0 8 16 B1

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. TS instruction tests only 1 bit, the sign bit and then sets all bits in the tested byte to 1. TS instruction is use in a program that controls the use of non sharable resources.

Copyright MCPL. Unit 5. Integer Arithmetic 5 -33 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

Eg 1 TM CHQ, X FO

Mask Byte = 1111 0000 Assumed target byte = 1010 1111 BM will branch whereas BO & BZ will not branch Eg 2 TM CHQ, XOF

Mask Byte = 0000 1111 Assumed 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 1111 BZ will branch whereas BM and BO will not branch Eg 4 TS CHQ CHQ Before : 0111 1000 After : 1111 1111 BZ will branch whereas BNZ will not Eg 5 TS CHQ CHQ Before : 1000 0000 After : 1111 1111 BNZ will branch BZ will not NOTES: BM means branch on mixed zeroes and ones BZ means branch on zeros BO means branch on ones.

Copyright MCPL. Unit 5. Integer Arithmetic 5 -34 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

THE BC INSTRUCTION
RX format for BC OP D2 M1 X2 B2 RR format for BCR OP R2 M1

Mask field of BC & BCR

CC = 0 CC = 1 Mask field 1000 1100 0000 USAGE BC

CC = 3

CC = 2 Comment If condition code = 0, BC & BCR will branch If condition is 0 or 1, BC & BCR will branch Whatever the condition BC & BCR will not will not branch (no-op instruction) 8, FOUND = BE FOUND

Assembly language format BC BC BE M1, D2 (X2, B2) 8, FOUND FOUND

Machine Language format 47 D2 47 M1 8 8 Mask 12 0 X2 16 B2 20

Figure 5-19 BC instruction

Copyright MCPL. Unit 5. Integer Arithmetic 5 -35 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

NOTES: The condition code settings are 2 bit, therefore condition codes can have a value of 0, 1, 2 or 3. ASM1 CSECT STM 14,12,12(13) BALR 12,0 USING *,12 ST 13,SAVE+4 LA 13,SAVE OPEN (OUTFILE,(OUTPUT)) MVC DATE1+2(2),D1 MVC DATE2+2(2),D2 MVC COMP+2(2),=C'60' CLC DATE1,COMP BH HIGH1 BL LOW1 HIGH1 MVC DATE1(2),=C'19' L 2,DATE1 B SUB1 LOW1 MVC DATE1(2),=C'20' L 2,DATE1 SUB1 CLC DATE2,COMP BH HIGH2 BL LOW2 HIGH2 MVC DATE2(2),=C'19' L 3,DATE2 B FIRST LOW2 MVC DATE2(2),=C'20' L 3,DATE2 FIRST MVC OUT1,DATE1 PUT OUTFILE,OUTLINE1 MVC OUT3,DATE2 PUT OUTFILE,OUTLINE2 C 2,DATE2 BH HIGH BL LOW HIGH MVC OUT5,=C'DATE1' PUT OUTFILE,OUTLINE3 B EXIT LOW MVC OUT5,=C'DATE2' PUT OUTFILE,OUTLINE3

Copyright MCPL. Unit 5. Integer Arithmetic 5 -36 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

EXIT

CLOSE OUTFILE L 13,SAVE+4 LM 14,12,12(13) BR 14 OUTFILE DCB DSORG=PS,MACRF=(PM),DDNAME=SYSOUT,RECFM=FB,LRECL=80, X BLKSIZE=8000 D1 DC CL2'00' D2 DC CL2'98' DATE1 DS CL4 DATE2 DS CL4 COMP DS CL4 OUTLINE1 DS 0CL80 DC CL20'FIRST DATE IS ' OUT1 DS CL4 OUT2 DC CL56' ' OUTLINE2 DS 0CL80 DC CL20'SECOND DATE IS ' OUT3 DS CL4 OUT4 DC CL56' ' OUTLINE3 DS 0CL80 DC CL20'LARGEST DATE IS ' OUT5 DS CL5 OUT6 DC CL56' ' SAVE DS 18F

Copyright MCPL. Unit 5. Integer Arithmetic 5 -37 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

CHANGING SIGN AND GENERATING ABSOLUTE VALUES

Opcode LCR

Meaning LOAD COMPLEMENT FROM REGISTER Copies the negative of V2 i,e its twos complement into the register occupied by V1;the result replaces V1. LOAD POSITIVE ABSOLUTE VALUES FROM REGISTER Copies the positive absolute value of V2 into the register occupied by V1;the result replaces V1. LOAD NEGATIVE ABSOLUTE VALUE FROM REGISTER Copies the negative absolute value of V2 into the register occupied by V1; the result replaces V1.

Type RR

LPR

RR

LNR

RR

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 instructions like BZ, BNZ, BM, BNM , BP and BNP.

Copyright MCPL. Unit 5. Integer Arithmetic 5 -38 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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

Copyright MCPL. Unit 5. Integer Arithmetic 5 -39 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

UNIT 6: CONSTANTS AND DATA AREAS OBJECTIVES: Relocatable and absolute constants Runtime constants Assembly time constants Data areas Boundary alignments

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.

STUDENT NOTEBOOK

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; Constants used 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 are classified as being either relocatable or absolute. Data Areas are memory locations that are defined by DS directives for specific type of data. The beginning address of the each runtime constants and data area is known as address boundary.

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.

STUDENT NOTEBOOK

RELOCATABLE AND ABSOLUTE CONSTANTS


ABSOLUTE Constants are independent of the program memory location

RELOCATABLE Constants are dependent on the program memory location. RELOCATABLE Constants are MAIN MEMORY Addresses. CONSTANT consists of an Algebraic expression containing one or more terms. EXAMPLES: Let R, S, T are non-negative Relocatable constants. A, B, C are 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)
Figure: 6-2 Relocatable and absolute constants NOTES: Any algebraic combination of two absolute terms or the difference between two allocatable terms is an absolute constant. If an absolute term is added to or subtracted from relocatable term is a relocatable constant.

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.

STUDENT NOTEBOOK

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-defining terms RUN-TIME Constants occupy memory location when program being 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 0000 The character representation of the 3 is ; 1111 0011

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.

STUDENT NOTEBOOK

TYPES OF CONSTANTS
ASSEMBLY LANGUAGE TEXT Binary Integers Floating -point Single precision Double precision Decimal Hexadecimal Binary Digits Address FORTRAN COBOL Enclosed in quotes USAGE IS DISPLAY INTEGER(full word interger) USAGE IS COMP REAL DOUBLE PRECISION ---------Program names Variable names USAGE IS COMP-1 USAGE IS COMP-2 USAGE IS COMP-3 ----------Program names elementary, groups Record names Paragraph, sections

Statement labels Figure: 6-4 Types of constants NOTES:

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

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.

STUDENT NOTEBOOK

DEFINED CONSTANTS (DC)

By using Define Constant (DC) directive we can generate the machine language constants. DC Directive format:
Name field Any symbol Or Blank Opcode DC Operand One or more sub fields, separated by commas

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 field opcode and the operand. But those are optional. Each specification of the constant must be preceded by the type code identifying the form in which the constant is being specified.

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.

STUDENT NOTEBOOK

DC OPERAND SUBFIELD FORMAT


DC OPERAND SUBFIELD COMPONANT:

Required

Duplicator

Type

Modifier

Constant

Optional Figure 6-6. Dc operand sub field format NOTES:

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.

STUDENT NOTEBOOK

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 operand without having to define that constant else where in the program.

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.

STUDENT NOTEBOOK

LITERALS

Required = Duplicator Type Modifier Constant optiona l Statement1 Statement2 Statement3 FCON DC L L F 1 5,FCON 5, =F 1

Figure: 6-8 Literals NOTES: A literal is a symbolic representation of a constant to which the assembler assigns address. When single constant is needed in the operand of certain instructions, the programmer can use a literal to designate that constant without having to define the constant with a DC directive. The literal cant be used to designate a register address in any instruction, to specify the immediate 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 SI instructions.

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.

STUDENT NOTEBOOK

SELF-DEFINING TERMS
SELF-DEFINING TERMS : Type of Term Decimal Integer Binary Integer Method of representation Comments Maximum, OS: 2 31-1 Maximum, OS: 32 bits Maximum, OS:8 hex digit DOS: 6 hex digit Maximum, OS: 5 char DOS:3 char Examples 3 12 B0001 B11 B 1011 X5A X6D X5100 CZ CCAT CA=B

Unsigned decimal integer B binary digits DOS :25 bits Hexa X Decimal hexadecimal Integer digits Sequence C Of text text Characters character Figure : 6-9 Self-defining terms NOTES:

A self defining term is an absolute constant that can be written 5 ways. Those are decimal integer, Binary integer and hexadecimal integer, sequence of text characters. The assembler substitutes its 5-bit binary representation.

Copyright MCPL. Unit 6.Constants and Data Areas Page 6 - 10 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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 the assembly language itself and those represented by user defined symbols.

Copyright MCPL. Unit 6.Constants and Data Areas Page 6 - 11 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

MEMORY LOCATION SYMBOL (*)


Memory address determination Address associated with a statement generated or Preceding statement

Address associated with the preceding statement

Number of bytes Reserved by the statement

Figure : 6-11 Memory location symbol ( * ) NOTES: The value of the memory location symbol depends on the statement in which it is used.

Copyright MCPL. Unit 6.Constants and Data Areas Page 6 - 12 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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 time constant. 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 is not known in advance by the programmer. HERE is the relocatable constant it represents the memory location.

Copyright MCPL. Unit 6.Constants and Data Areas Page 6 - 13 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

VALUE TOO TEDIOUS TO COMPUTE BY HAND

MSG1 TLNG1

DC EQU

C SAMPLE USE OF THE 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 the symbol MSG1. If the text value changed by the programmer the value TLNG1 is automatically changed when the program is reassembled. The TLNG1 is an absolute constant , since it equals the difference of two relocatable constants.

Copyright MCPL. Unit 6.Constants and Data Areas Page 6 - 14 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

VALUE CAN CHANGE IF PROGRAM IS CHANGED


TABLE2 DC DC DC DC DC EQU DC DC DC DC DC DC EQU F 1 F 2 F 3 F 4 F 5 *-TABLE2 (value of TLNG2 is 20) F 1 F 2 F 3 F 4 F 5 F 6 (new statement added) *-TABLE2 (value of TLNG2 is 24)

TLNG2 TABLE2

TLNG2

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 of integers ( 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 TLNG2 will be recomputed by the assembler.

Copyright MCPL. Unit 6.Constants and Data Areas Page 6 - 15 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

VALUE USED SYMBOLICALLY


STATUS OFF ON CLI BE CLI BE DS CL1 EQU X00 EQU XFF device status byte device is off device is on.

STATUS , ON POWERON THIS IS EQUIVALENT TO WRITING STATUS, XFF POWERON DS EQU EQU EQU CL 1 X00 XOF XFF device status byte device is off device is on but not in use device is on but being used.

STATUS OFF ON INUSE CLI BE CLI BE

STATUS, ON POWERON CAN BE WRITTEN AS STATUS,XOF POWERON

Figure : 6-15. Value used symbolically NOTES: The use of ON has two advantages, each use of on will be recorded in the crossreference listing by the assembler and the change can be made to the value of ON without having 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.

Copyright MCPL. Unit 6.Constants and Data Areas Page 6 - 16 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

SYMBOLIC REGISTER ADDRESSES AND SYMBOLIC DISPLACEMENTS

OFFSET

EQU 12

STM AND STM

14,12,12(13)

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 gained from symbolically defining the address of general registers and the value of the displacement constant.

Copyright MCPL. Unit 6.Constants and Data Areas Page 6 - 17 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

SYMBOLIC REGISTER ADDRESSES


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

Figure : 6-17. Symbolic register addresses NOTES:

Copyright MCPL. Unit 6.Constants and Data Areas Page 6 - 18 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

INVALID USE OF EQU

SPLNG SPCHAR

EQU DC

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

SPCHAR SPLNG

DC EQU

C@#$%c&&*()+-=;;?/,. * - 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 number of characters in the SPCHAR constant. The reason the first is invalid and the second is valid is that all the symbols appearing in the operand of EQU directive must have been defined prior to their appearance in the operand.

Copyright MCPL. Unit 6.Constants and Data Areas Page 6 - 19 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

RELOCATABLE
L LA LA LA L 4,Y 5,Y 6,W 7,Z 8,Z

VS

ABSOLUTE CONSTANT

IMPLICIT: USES IMPLIED BASE REGISTER IMPLICIT: USES IMPLIED BASE REGISTER IMPLICIT: USES IMPLIED BASE REGISTER EXPLICIT: SAME AS LA 7 , 4(0,0) EXPLICIT: SAME AS L 8 , 4(0,0)

Y DC F4 Y IS A RELOCATABLE CONSTANT (A SYMBOLIC ADDRESS) Z EQU 4 Z IS AN ABSOLUTE CONSTANT W EQU Y W IS A RELOCATABLE CONSTANT (EQUAL TO AN ADDRESS)

Figure : 6-19 Relocatable NOTES:

vs.

Absolute constant

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,Z instruction loads.

Copyright MCPL. Unit 6.Constants and Data Areas Page 6 - 20 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

DATA AREAS
Define Storage (DC) Directive General format is : Name Symbol or blank Opcode DC Operand One or more sub fields separated by comma Required

DS Operand sub field component:

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 a designated amount of memory space to be reserved in the program but dont place any data into the reserved area. EX for sub field component: Date DS 2 C LB Type Duplicator Modifier

Copyright MCPL. Unit 6.Constants and Data Areas Page 6 - 21 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

BOUNDARY ALIGNMENTS AND LENGTH OF AN AREA


Length modifier Type code Constant Boundary Length Alignment

Length Any valid Either no constant Byte boundary Determine via modifier Type code or any valid Length modifier is used constant in the operand B,C,P,X,Z Any valid constant Byte boundary Determine by No constants Byte boundary Constants 1 H OR Y Either no constants half word boundary 2 OR Any valid constants

Length modifier

Is not used in operand

E,F,A,Q ,S Either no constant full word boundary 4 D OR L 8 OR Any valid constants Either no constant double word boundary OR Any valid constants

Figure : 6-21. Boundary alignments and length of an area NOTES:

Copyright MCPL. Unit 6.Constants and Data Areas Page 6 - 22 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

BOUNDARY ALIGNMENT
DS 0H DS 0F DS 0D Half word boundary Full word boundary Double word boundary

Figure : 6-22. Boundary alignment NOTES: The most straight forward way to force alignment to the desired boundary for any constant or data area is to immediately precede the DC or DS directive that defines it with one of these three statements. DS DS DS EX: DC DS DC X80000000 0F X 80000000 0H 0F 0D

Copyright MCPL. Unit 6.Constants and Data Areas Page 6 - 23 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

DS

0D

FORCED AND NATURAL ALIGNMENT


LOCTN OBJECT CODE SOURCE STATEMENT

001000 001000 80 001004 00000001 001008 0010028 0010028 F1F2F3 00102C 0002 001030 001078 C5D5C4 00107B FF

DS DC DC DS DC DS DC

0F X80 F1 DS 0D DC H2 18F DC XFF

FORCE ALIGNMENT TO FULL WORD 1-BYTE CONSTANT 4-BYTE CONSTANT, ON FULL-WD BDY CL25 25-BYTE RESERVED FORCED ALIGNMENT TO DBL-WD BDY FF1F2F3 3-BYTE CONSTANT 2-BYTE CONSTANT,ON HALF WORD BDY 18 FULL WORD RESERVED C END 3-BYTE CONSTANT,ON BYTE BDY 1-BYTE CONSTANT,ON BYTE BDY

Figure : 6-23. Forced and natural alignment NOTES:

Copyright MCPL. Unit 6.Constants and Data Areas Page 6 - 24 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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

Copyright MCPL. Unit 7. Byte and String Manipulation 7-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

BYTE AND STRING MANIPULAITON


The word byte refers to any addressable 8-bit quantity. A sequence of bytes is called a string. The number of bytes in string called string length. Copying bytes, comparing two sequence of bytes, and searching a sequence of bytes

Figure 7-1 NOTES:

Byte and String Manipulations

Byte-manipulation instructions have three general characteristics. 1 All byte-manipulation instructions operate on two strings. One of the strings in memory; the other may be in memory or in a register, depending on the instruction itself. 2 All byte-manipulation instructions require that the number of bytes being operate 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 8bit nonalgebraic quantities: the high-order bit is not considered to be a sign bit but is treated in the same way as the other bits.

Copyright MCPL. Unit 7. Byte and String Manipulation 7-2 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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. This code may be used in DC directive in literals and in self-defining terms. One byte is always allotted for each specified character. The maximum number of characters that can be specified for a single DC or literal constant is 256. When the length modifier Ln specifies fewer bytes than are needed to contain the binary representation of the data constant given in a C-type DC directive, the assembler 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 the binary representation of the data constant given in a C-type DC directive, the assembler adds blank characters on the right to fill the length that was specified. This is called padding with blanks.

Copyright MCPL. Unit 7. Byte and String Manipulation 7-3 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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 memory 2 copy bytes from one area of memory to another area .The former are called INSERT and STORE instructions, respectively, the latter are called MOVE instructions.

Copyright MCPL. Unit 7. Byte and String Manipulation 7-4 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

COPYING BYTES TO AND FROM REGISTERS


Opcode IC Meaning INSERT CHARACTER Type RX

Copies 1 byte from memory into the 8 right-most bits of a register, without altering the other bits in that register.

STC

STORE CHARACTER Copies 1 byte the 8 right-most bits of a register---- into Memory. INSERT CHARACTERS UNDER MASK Copies N bytes, n<4, from memory into a register. The Number of bytes copied and their relative positions in the Register are specified in the second operand of the instruction.

RX

ICM

RS

STCM

STORE CHARACTERS UNDER MASK RS Copies N bytes, n<4, from register into memory. The Number of bytes copied and their relative positions in the Register are specified 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 the IBM 360. The letter M in these instructions refers the fact that the second operand of the ICM and STCM constitutes a mask rather than a register address or a length.

Copyright MCPL. Unit 7. Byte and String Manipulation 7-5 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

COPYING BYTES TO AND FROM REGISTERS (contd..)

4-bit register

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 inserted or stored is equal to the number of 1s in 4-bit mask. And second, the relative position of the bytes in the register is determined by the relative position of the 1s in the mask , the corresponding being from left to right,one for one.

Copyright MCPL. Unit 7. Byte and String Manipulation 7-6 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

COPYING BYTES FROM ONE AREA OF MEMORY TO ANOTHER


Opcode MVI Meaning MOVE IMMEDIATE Copies 1 byte from 12 field of MVI Instruction to memory Location designated by first operand. MOVE CHARACTERS MOVE INVERSE Copies L bytes, L<=256, from memory location designated By second operand to memory location designated by first operand.(L = value of length field in first operand..) MVCL MOVE CHARACTERS LONG Copies L bytes, L<=224, from memory location designated by Bits 8-31 of the general register specified in the second operand Operand to memory location designated by bits 8-31of the General register specified in the first operand. (L = value of Length field associated with the first operand.) RR Type S1

MVC MVCIN

SS1 SS1

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 on the IBM 360. The MVCIN instruction is available as a special feature rather than as a standard instruction on most IBM 370 systems. MVCIN can copy from 1 to 256 bytes from one location to another. The sending locations address is specified in the second operand field, and the receiving locations address and length are specified in the first operand field. Copyright MCPL. Unit 7. Byte and String Manipulation 7-7 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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-bit numbers. An unsigned quantity such as a byte contents is called logical quantity, whereas signed quantities such as integers are arithmetic quantities.

Copyright MCPL. Unit 7. Byte and String Manipulation 7-8 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

COMPARING BYTES WHEN ONE OF THE STRINGS IS IN A REGISTER


Opcode CL Meaning COMPARE LOGICAL Compares two 4-byte strings: first string is in the register Designated by the first operand. Second string is in the Memory location designated by the second operand. COMPARE LOGICAL REGISTER Compares two 4-byte strings: first string is in the register Designated by the first Operand. Second string is in the Register Designated by the operand. COMPARE LOGICAL UNDER MASK RS Compares two N-byte strings, n >= 4; first string is in the Register designated by the first operand. Second string is in The memory location designated by the second operand. Type RX

CLR

RR

CLM

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 the letter 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 operand is a mask.The CLM mask functions in a manner similar to that in the ICM and STCM instructions .

Copyright MCPL. Unit 7. Byte and String Manipulation 7-9 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

COMPARING BYTES WHEN BOTH STRINGS ARE IN MEMORY LOCATIONS


Opcode CLI Meaning COMPARE LOGICAL IMMEDIATE Compares two 1-byte strings: first string is in the memory Location designated by the first operand. Second string is in the Immediate data field of the instruction itself. COMPARE LOGICAL CHARACTERS Compares two N-byte strings, N<=256: first string is in the register Designated by the first operand. Second string is in the Register designated by the operand. COMPARE LOGICAL CHARACTERS LONG Compares two possibly unequal-length strings, Maximum Length = 224 1; first string and second string is in the memory Location designated by 8-31 bits of the general registers. Type SI

CLC

SS1

CLCL

RR

Figure : 7-9 Comparing Bytes both strings are in Memory locations. NOTES: The CLCL instructions are available on the IBM 370 but not the IBM360.

Copyright MCPL. Unit 7. Byte and String Manipulation 7-10 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

DETERMINING THE RESULT OF A STRING COMPARISON

Opcode BE BNE BL BNL BH BNH

Meaning Branch if v1 equals v2 Branch if v1 is not equal to v2 Branch if v1 is less than v2 Branch if v1 is not less than v2 Branch if v1 is higher than v2 Branch if v1 is not higher than v2

Type v1 = v2 v1 = v2 v1 < v2 v1 >= v2 v1 > 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 determined by means of a condition branch instruction. The same conditional branch instructions used in determining the result of algebraic comparison are used in determining the result of 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 the condition being tested is true.If the condition is not true, then no branch is made,instead,execution of the program continues with the instruction that immediately follows the conditional branch instruction. Copyright MCPL. Unit 7. Byte and String Manipulation 7-11 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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 preceded the first blank or comma that was found. Compare an arbitrary 5-byte string with the END to see if it is equal to it or not. Compare an arbitrary 5-byte string with an each of three 5-byte strings 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 a program is written.

Copyright MCPL. Unit 7. Byte and String Manipulation 7-12 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

EXAMPLE 1. FILL AN AREA WITH BLANKS

1 MVI Temp, C PUT A BLANK INTO FIRST BYTE 2 * OF AREA NAMED TEMP 3 MVC TEMP+1(79), TEMP PROPAGATE BLANK INTO REMAINDER 4 * 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 the area named TEMP: MVC MVC TEMP(80),BLANKS TEMP, BLANKS EXPLICIT LENGTH FIELD LENGTH FIELD IMPLIED

To fill an area of memory with blanks, two things must be known: (1) the address of the area and (2) the number of bytes in the area, i.e., the areas length. The address can be written either symbolically or in base-displacement form. The areas length, an unsigned integer, can be written symbolically or numerically, or can be omitted and implied by the length attribute of the area.

Copyright MCPL. Unit 7. Byte and String Manipulation 7-13 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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 two conditions exist simultaneously: (1) the sending area designated by the second operand overlaps the receiving area designated by the first operand, and (2) the first byte of the receiving area is with in the sending area.

Copyright MCPL. Unit 7. Byte and String Manipulation 7-14 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

DESTRUCTIVE OVERLAP (CONT.)

Temp area Arbitrary data Arbitrary data Arbitrary data . All blanks All blanks

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 the sending area bytes, one at a time, before they are copied into the receiving area.

Copyright MCPL. Unit 7. Byte and String Manipulation 7-15 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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 the programmer is unaware of the destructive overlap potential of the sending and receiving fields. If the first byte of the receiving area is not within the sending area, destructive overlap cannot occur. If in this situation, the areas partially overlap, they are said to overlap nondestructively.

Copyright MCPL. Unit 7. Byte and String Manipulation 7-16 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

EXAMPLE 2. REPLACE EXCLAMATION POINTS WITH PERIODS


1 * INITALIZATION 2 START LA 4, STRING R4=ADDR OF FIRST BYTE OF STRING 3 LA 5, LENGTH R5=LENGTH OF STRING 4 * SEARCH FOR ALL EXCLAMATIION POINTS 5 COMPARE CLI 0(4), C, COMPARE CURRENT BYTE TO ! 6 BNE NEXTIF NOT EQUAL, ATTEMPT NEXT BYTE 7 MVI O(4), C IF EQUAL, ATTEMPT NEXT BYTE 8 * LOOP CONTROL 9 NEXT LA 4,1(4) R4 = ADDR OF NEXT BYTE OF STRING 10 BCT 5, COMPARE DECR STR LNG BY 1,REPEAT LOOP 11 * END OF PROCEDURE . . . 12 STRING DC CTEST! 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 the reduction is non zero , the BCT branches to the statement named COMPARE to continue the search .If the counter reaches 0 no branch will make.

Copyright MCPL. Unit 7. Byte and String Manipulation 7-17 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

EXAMPLE 3. FIND FIRST COMMA OR BLANK IN A STRING AND COMPUTE LENGTH


1 * INITIALIZATION 2 START LA 4, STRING R4=ADDR OF FIRST BYTE OF STRING 3 LA 5, LENGTH R5=LENGTH OF STRING 4 * SEARCH FOR FIRST BLANK OR COMMA 5 COMPARE CLI 0(4), C , COMPARE CURRENT BYTE TO COMMA 6 BE DONE IF COMMA, TERMINATE SEARCH 7 CLI 0(4),C IF NOT, COMPARE TO BLANK 8 BE DONE IF BLANK, TERMINATE SEARCH 9 * LOOP CONTROL 10 LA 4,1(4) R4=ADDR OF NEXT BYTE OF STRING 11 BCT 5,COMPARE DECR STR LNG BY 1,REPEAT LOOP 12 * COMPUTE NUMBER OF BYTES PRECEDING THE BLANK OR COMMA 13 DONE LA 4.LENGTH ORIGINAL LENGTH MINUS REMAINING 14 SR 4,5 LENGTH IS RESULT DESIRED 15 * END OF PROCEDURE 16 EXIT STH 4,POSIT R4=LENGTH UP TO COMMA OR BLANK 17 STRING DC CFIND COMMA, OR BLANK 18 LENGTH EQU *-STRINGASSBLRCOMPUTES #BYTES IN STRING 19 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 is terminated either when a comma or blank is found or when there are no more bytes to be examined, and (2) when the search is terminated, the number of bytes that precede the first comma or blank is calculated and stored in the location named POSIT. It always requires at least two types of statements to examine a string: the first is a comparison, the second is a conditional branch determining the results of the comparison.

Copyright MCPL. Unit 7. Byte and String Manipulation 7-18 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

EXAMPLE 4. COMPARE 5-BYTE STRING TO CEND

1 CLC COMMAND(5),STRING 2 BE FOUND 3 STRING DS

COMPARE 5-BYTE STRINGS BRANCH IF EQUAL

. . CL5 5-BYTE AREA RESERVED FOR STRING

4 COMMAND DC CL5END 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 is used. 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.

Copyright MCPL. Unit 7. Byte and String Manipulation 7-19 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

COMPARE 5-BYTE STRING WITH STRINGS IN A TABLE


1 * INITIALIZTION 2 START LA 4,TABLE R4=ADDR OF FIRST ENTRY IN TABLE 3 LA 5,TABLE R5=NUMBER OF ENTRIES 4 * COMPARE STRING TO EACH ENTRY (STRING LENGTH IS 5) 5 LOOK CLC 0(5,4),STRING COMPARE CURRENT ENTRY TO STRING 6 BE EXIT TERMINATE PROCEDURE WHEN FOUND 7 * LOOP CONTROL 8 LA 4,5(4) IF NOT FOUND, ADV TO NEXT ENTRY 9 BCT 5,LOOK DECR #ENTRIES BY 1,REPEAT LOOP 10 * END OF PROCEDURE WHEN SEARCH IS COMPLETE, EITHER 11 SR 4,4 R4=0 IF NOT FOUND IN TABLE, OR 12 EXIT ST 4,POSIT R4=ADDR OF ENTRY THAT WAS FOUND . 13 STRING DS CL5 S-BYTE AREA RESERVED FOR STRING 14 TABLE DC CL5END TABLE WITH 3 5-BYTE ENTRIES 15 DC CL5FINIS 16 DC CL5STOP 17 ENTRIES EQU (*-TABLE)/5 ASSBLR COMPUTES NO.ENTRIES 18 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 memory An item in a table is almost always called a Table entry The number of entries in a table depends on length of each entry and amount of space available for the table. There are three entries given in the statement 14 through 16. But, instead of using the number three in the program, Statement 17 lets the assembler calculate the number and assign it to the symbol ENTRIES. Statements 5,8, and 12 require comment. Statement 5 compares the 5-byte string located at the current table-entry address given in Register 4 with the 5-byte string located at the symbolic address STRING. Statement 8 increments the table-entry address in Register4 by five (the length of each table entry) so that the second iteration of the loop will examine the second entry, and the third iteration will examine the third entry. Copyright MCPL. Unit 7. Byte and String Manipulation 7-20 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

SUBSTRING OPERATIONS
EXAMPLE:

T: S: S1: S2:

A NOT SO TYPICAL STRING NAMED T NOT SO VERY 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 each occurrence of S from T; replacing S by another string S1; or of inserting a string S2, immediately following S in T. Three operations illustrated for above example as follows 1. 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 Copyright MCPL. Unit 7. Byte and String Manipulation 7-21 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

SUBSTRING OPERATIONS (CONT.)


Pseudocode for string-editing procedures DELETE, REPLACE and INSERT.
STRING-EDIT: REPEAT UNTIL number of remaining comparisons <= 0 IF current sub string in t = s THEN IF operation = replace Copy s1 to current position in TNEW; Increase length of TNEW by length of S1; Adjust current position in TNEW by length of S!; ELSE IF operation = insert THEN 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 T To 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 Copyright MCPL. Unit 7. Byte and String Manipulation 7-22 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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.

* INITIALIZTIONS LA 1,S LA 2,T LA 9,TNEW LH 10, =H0 LH 3, N SH AH BNP 3, M 3, =H 1 MOVE

R1 = ADDR OF S R2 = ADDR OF CURRENT POSITION IN T R9 = ADDR OF CUR. POSITION IN TNEW R10=COMPUTED LNG OF TNEW (INITIALLY 0) R3 = NUMBER OF COMPARISONS REMAINING TO BE MADE. INITIALLY, EQUAL TO N ( M 1) IF N < M THEN MAKE NO COMPARISONS

LH 4, M R4 = LENGTH OF S, MINUS 1 SH 4,=H1 +1 IS SUBTRACTED FOR EX INSTR * COMPARES TO SUBSTRING OF SAME LENGTH IN T LOOP EX 4,COMPARE COMPARISON OF M BYTES BE EQUAL BRANCH IF SUBSTRING S IS FOUND NOTEQUAL MVC 0(1,9),0(2) COPY ONE CHAR FROM T TO TNEW AH 10, =H1 INCR LNG OF TNEW BY +1 LA 9,1(9) ADJ CUR POSIT IN TNEW BY +1 LA 2,1(2) ADJ CUR POSIT IN T BY +1 BCT 3,LOOP REDUCE #REMAINING COMPARISONS BY +1 B MOVE IF NO MORE COMPAISONS, GO COPY REST OF T Figure : 7-22 Byte and String Manipulations

Copyright MCPL. Unit 7. Byte and String Manipulation 7-23 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

STRING-EDITING DELETE PROCEDURE (CONT)


*DELETE OPERATION AVOIDS MOVING S FROM T TO TNEW EQUAL AH 2,M SH 3,M BP LOOP ADJ CUR POSITION IN T BY LENGTH OF S REDUCE # REMAINING COMPARISONS BY LNG OF S if more comparisons remain, do them

* COPY REMAINING CHARACTER (IF ANY) FROM T TO TNEW MOVE LA AH SR BNP AR SH EX 5,T COMPUTE # CHARACTERS REMAINING IN T, BY 5,N SUBTRACTING CUR. POSIT. IN T FROM ADDR 5,2 OF FIRST BYTE BEYOND T NOMORE NO MORE CHARS IF S OCCUPIED LAST M 10,S BYTES OF T. OTHERWISE, INCR LNG OF 5, =H1 TNEW, AND PREPARE TO MOVE REMAINING 5,MOVEX CHARS TO TNEW VIA EX INSTR 5TH DS DS DS DS DS DS 10,NN CL256 CL256 CL256 H H H STORE COMPUTED LENGTH OF TNEW SPACE FOR MAX LENGTH T STRING SPACE FOR MAX LENGTH S STRING SPACE FOR MAX LENGTH TNEW STRING SPACE FOR LENGTH OF T ( 0<LNG<256) SPACE FOR LENGTH OF S (0<LNG < = 256) SPACE FOR LENGTH OF TNEW

NOMORE T S TNEW N M NN

FOLLOWING ARE TARGET INSTRS FOR EX INSTRUCTIONS IN ABOVE PROCEDURE COMPARE 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 = POSIT IN T Figure: 7-23 String Editing-Delete Procedure NOTES:

Copyright MCPL. Unit 7. Byte and String Manipulation 7-24 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

THE EXECUTE INSTRUCTION


Opcode EX operand R1, D2 (X2, B2) Address of target instruction Designated 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 EX instruction. One of the main uses of the EX instruction depends on its capability for effectively but not 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 SS2 instructions and to vary the mask-field contents RS and SI instructions.

Copyright MCPL. Unit 7. Byte and String Manipulation 7-25 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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 of bytes operated on is not restricted to be less than or equal to 256,as is the case of CLC and MVC. In CLCL and MVCL the number of bytes can be from 0 to 2 24 - 1 The CLCL and MVCL are designed as RR type instructions.

Copyright MCPL. Unit 7. Byte and String Manipulation 7-26 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

CLCL INSTRUCTION
OPCODE OPERAND CLCL R1, R2 Reg R1 1100 Address 0 8 Reg R2 31 0 8 Reg R1 + 1 Reg length 31

1-byte padding character 0 8 Reg R2 first string 31 0 8 Reg R2 + 1 31

Address

length

Second string

31 0

31

1-byte padding character


Figure: 7-26 CLCL NOTES: 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 CLCL instruction one register pair contains address and length of one of the strings to be compared, 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 the registers 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 second operand string field.

Copyright MCPL. Unit 7. Byte and String Manipulation 7-27 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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 the instruction. If the result of the comparison is that the two strings are not equal , the length and address fields of each register pair identify the bytes that caused the unequal result. One consequence of the register alterations just described is that if the CLCL is to be used in a loop, the length fields must be reloaded before each execution of the CLCL, and, depending on the locations of the strings being compared, the address fields may also have to be reloaded into the registers

Copyright MCPL. Unit 7. Byte and String Manipulation 7-28 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

MVCL
Opcode operand MVCL R1,R2 Reg1 Address Reg1+1 length

8 Receiving field Reg2

310

31

Reg 2 +1

Address Figure : 7-31 MVCL

length

310 Specification for sending field

31

1-byte padding character

Figure: 7-28 MVCL NOTES: The MVCL Instruction, like the CLCL instruction, utilizes two even-odd pairs of registers during its execution. The MVCL and the meaning of the contents of the register pairs are similar to CLCL. The number of bytes specified by the length field in Register R1+1 is copied into the Receiving field, beginning at the address designated in Register R1. The bytes are copied from the sending field, starting from the address designated in Register R2.if the sending field length is less than the receiving field length, the remaining bytes of the receiving field are filled with the padding character.If the receiving field length is specified as zero,no bytes are copied. Copyright MCPL. Unit 7. Byte and String Manipulation 7-29 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

TR AND TRT INSTRUCTIONS

The TR and TRT instructions are used to help reduce the size and running time of programs that perform the following types of recurring string operations: Replacing some, but not necessarily all, bytes in a string with other predetermined bytes and Searching a string from left to right for the first occurrence of any one 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 certain bytes in a string with other byes. The TRT instruction can be used in any situation where we want to find one of a number of different characters in a string.

Copyright MCPL. Unit 7. Byte and String Manipulation 7-30 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

GENERAL DESCRIPTION

Argument String Function String Length of Argument String Length of Function String Opcode TR TRT Operand D1(L,B1), D2(B2) D1(L,B1), D2(B2) Argument Function String string
Figure : 7-30 General Description NOTES: Both the TR and TRT instructions operate on two strings. One string is called the argument string and the other is called the function string. The bytes in the argument string are generally not known to the programmer, for it is the bytes in the argument string 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 be achieved by the TR or TRT instructions. In the TR and TRT instructions, the argument string and its length are designated by the first operand and the function string is designated by the second operand. The length of the function string, which is usually 256 bytes, is not specified in either instruction.

Copyright MCPL. Unit 7. Byte and String Manipulation 7-31 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

UNIT 8 : BIT MANIPULATIONS


OBJECTIVES :

Shifting Bits Altering Bits Testing Bits The Condition Code Bit Manipulation Examples

Copyright MCPL. Unit 8. Bit Manipulations 8-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

BIT MANIPULATIONS
Bit Manipulations includes several types of instructions that operate on one or more 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 Bit String. The Bit String is usually used to refer to a sequence of bits.

Copyright MCPL. Unit 8. Bit Manipulations 8-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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 from other 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 the condition code is not set.

Copyright MCPL. Unit 8. Bit Manipulations 8-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

ARITHMETIC SHIFT INSTRUCTIONS


The four Arithmetic shift instructions are Opcode SRA SLA SRDA SLDA meaning Shift Right Single Arithmetic Shift Left Single Arithmetic Shift Right Double Arithmetic Shift Left Double Arithmetic Type RS RS RS RS

Figure 8-3. Arithmetic Shift Instructions. NOTES: The 32-bit quantity in the register designated by the first operand is arithmetically shifted right(or left) N bit positions. The 64-bit quantity in the even-odd register pair designated by the first operand is arithmetically 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 rightmost bits are lost, and the sign bit (bit 0) that existed before the shift began is inserted into each of the N left-most vacated positions, i.e., into bit positions 1 through N. The sign bit itself remains unchanged. When the contents of a register or register pair are shifted N bits to the left, zeroes are inserted into the N right-most vacated positions, the N left-most bits (not including the sign bit) are lost, and condition code 3 the overview indicator is set if a bit value different from that of the sign bit was among those that were lost. The sign bit itself remains unchanged. Copyright MCPL. Unit 8. Bit Manipulations 8-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

ARITHMETIC SHIFTS
Eg 1 : SRA 9, 31 Reg 9 Before : 0001 0001 0001 0001 0001 0001 0001 0001 After : 0000 0000 0000 0000 0000 0000 0000 0000 Eg 2: SRA 8,5 Reg 8 Before : 1111 1111 1111 1111 1111 1010 1010 1000 After Eg 3: SLA 4,4 (10) : 1111 1111 1111 1111 1111 1110 1101 0101

Propagation of sign bits Reg 10: Displacement : 0000 0000 0000 0000 1000 0000 0000 00 1100 Reg 4

1000 0100

Before : After Eg 4 : SRDA 6, 3 Before : After : Eg 5 : SLDA 6, 11 Before :

1111 1010 1111 1000 0000 0111 0000 0110

: 0000 0000 0111 0000 0110 0000 0000 0000 Reg 6 1A 1B 1C 1D 03 43 63 83 Reg 7 1E 1F 10 11 A3 C3 E2 02 1E 1F 10 11 F8 80 88 00

1A 1B 1C 1D 58 ED E8 F0

After : Figure 8-4. Arithmetic Shifts NOTES:

In an arithmetic shift the sign bit of a register or register pair is treated differently from the other, bits and the condition code has a value which denotes the status of the result. Copyright MCPL. Unit 8. Bit Manipulations 8-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

In a logical shift the sign bit is treated as similar to any other bit and the condition code is not set.

Copyright MCPL. Unit 8. Bit Manipulations 8-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

LOGICAL SHIFTS
Logical Shifts are used in conjunction with other bit and byte-manipulation to separate or join sequences of bits. Opcode SRL SLL SRDL SLDL Meaning Shift Right Single Logical Shift Left Single Logical Shift Right Double Logical Shift Left Double Logical Type RS RS RS 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 rightmost 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 left most 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 is not set.

Copyright MCPL. Unit 8. Bit Manipulations 8-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

LOGICAL SHIFTS
Opcode SRL, SRL, SLL, SRDL, SLDL SRL SLL 8, 5 8, 4(10) Type RS

Reg 8 Before : 1111 1111 1111 1111 1111 1111 1010 0100 After : 0000 0111 1111 1111 1111 1111 1111 1101 Reg 10 : Displacement : 0000 0000 0000 0000 1000 1000 0000 0000 0100

00 1100 Reg 8 Before : 0000 1001 0000 1000 0000 0111 0000 0110 After : 1000 0000 0111 000 0110 0000 0000 0000 SRDL 6, 3 Reg 6 Before : 1A 1B 1C 1D After : 03 43 63 83 Reg 6 Before : 1A 1B 1C 1D After : D8 E0 E8 F0 Reg 7 1E 1F 10 11 A3 C3 E2 02 Reg 7 1E 1F 10 11 F8 80 88 00

SLDL 6, 11

Figure 8-6. Logical Shifts. NOTES: When the contents of a register or register pair are shifted X bits to the right then X right most bits are lost and zeros are inserted into the X left - most positions. The sign bit is treated as any other bit. The condition code is not set.

Copyright MCPL. Unit 8. Bit Manipulations 8-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

ALTERING BITS
The Assembly Language Programs use the individual bits in a bit string to represent status information. This type of information can be used to control the flow of a program and 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:

Copyright MCPL. Unit 8. Bit Manipulations 8-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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 a file as follows. Bit OPEN bit I/O bit 0 Value 0 1 1 0 1 0 1 Meaning = file not opened = file opened = if opened, file is used for input only = if opened, file is used for output only = sequential file = indexed sequential file = file has not reached end-of-file = file has reached end-of-file

TYPE bit EOF bit

Figure 8-8. Use of bits as indicators. NOTES:

Copyright MCPL. Unit 8. Bit Manipulations 8-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

BIT VARIATIONS
Bit position: 0 OPEN 1 2 3 4 5

I/O TYPE EOF The bits could have following meaning: BIT Meaning OPEN BIT I/O BITS 0 1 00 01 10 11 00 01 10 11 0 1

Value

TYPE BITS

EOF BIT

= file not opened = file opened = no meaning = opened for input only = opened for output only = opened for input and output = none of the standard types = sequential = indexed sequential = direct = not yet end-of- file = 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.

Copyright MCPL. Unit 8. Bit Manipulations 8-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

BOOLEAN OPERATIONS AND OR EXCLUSE-OR

Figure 8-10. Boolean Operators. NOTES: The Boolean operations OR, AND, EXCLUSIVE-OR have three characteristics in common: 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, selects the individual bits that are to be altered in the target bit string. Each bit in the mask that is a 1 selects the correspondingly positioned bit in the target, regardless of whether that target 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 the mask operates on the corresponding bit in the target. The sign bit is not given any special treatment.

Copyright MCPL. Unit 8. Bit Manipulations 8-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

THE BOOLEAN OR OPERATION.

Mask Bit 0

Target Bit 0

Resulting Bit 0 mask bit = 0 target bit unchanged

0 1 1 -----------------------------------------------------------------------------------------------1 1 0 1 1 1 mask bit = 1 target bit is set to 1

Figure 8-11. The Boolean OR Operation. NOTES: The Boolean OR operation sets the selected target bits to1, regardless of what the previous values of those bits were.

Copyright MCPL. Unit 8. Bit Manipulations 8-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

THE BOOLEAN AND OPERAION


Mask Bit 0 0 Target Bit 0 1 Resulting Bit 0 1 mask bit = 0 target bit reset to 0

----------------------------------------------------------------------------------------------1 1 0 1 0 1 mask bit = 1 target bit unchanged

Figure 8-12. The Boolean AND Operator. NOTES: The Boolean AND operation preserves the value of the selected target bits and resets the remaining bits to zero, regardless of what the previous values of those bits were.

Copyright MCPL. Unit 8. Bit Manipulations 8-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

THE BOOLEAN EXCLUSIVE-OR OPERATION


Mask Bit 0 0 Target Bit 0 1 Resulting Bit 0 1 mask bit = 0 target bit unchanged

1 1

0 1

1 0

mask bit = 1 target bit reversed

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.

Copyright MCPL. Unit 8. Bit Manipulations 8-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

TESTING BITS
Two instructions test individual bits to determine whether their values are 0 or 1. Both of these 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 altering the bits that are tested. TS tests only one bit- The higher order or sign bit of a byte and then sets all the bits in the tested byte to 1.

Copyright MCPL. Unit 8. Bit Manipulations 8-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

TEST UNDER MASK


The TM is an SI- type instruction: Assembly language format Opcode TM operand D1(B1), 12 0 TM S1, 12 91 machine language format opcode operand 91 8 12 implied displacement 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 the target byte(addressed by the first operand field). Each 1-bit in the mask causes the corresponding bit in the target byte to be selected for testing. Each 0-bit in the mask causes 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 branch instructions: BZ Branch if Zeroes Branches if all tested bits are 0s, or if all mask bits are 0s BO Branch if Ones Branches if all tested bits are 1s BM Branch if Mixed Zeroes and Ones Branches if some tested bits are 0s and the other tested bits are 1s. 12 B1 16 20 D1

Copyright MCPL. Unit 8. Bit Manipulations 8-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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 TS D1 (B1) machine language format Opcode 93 operand B1 D1

TS

S1

93 0 8 space reserved but unused in the TS

implied displacement implied base register

16

Figure 8-16. Test and Set NOTES: The result of the test made by the TS instruction can be determined by means of conditional branch instructions: BZ Branch if Zero Branches if the tested bit had a value of 0 BNZ Branch if Not Zero Branches if the tested bit had a value of 1

Copyright MCPL. Unit 8. Bit Manipulations 8-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

CONDITION CODE
The condition code is a hardware indicator that records the nature of results of certain instructions. The indicator consists of only two bits, only four possible conditions can be 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 two instructions designed for this purpose . 1.Branch on Condition (BC) 2.Branch on Condition via Register (BCR)

Copyright MCPL. Unit 8. Bit Manipulations 8-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

CONDITION CODE VALUE


The condition code value when either of these instructions is executed determines whether or not the branch is made. The BC or BCR instruction determine with setting or settings of the Condition code will cause a branch. RX format for BC instruction OP M1 X2 B2 D2 RR format for BCR OP M1 R2

Mask field of BC & BCR

Right-most bit denotes condition code 3 third bit denotes condition code 2 second bit denotes condition code 1 left-most bit denotes condition code 0 Figure 8-19. Condition code value. NOTES:

Copyright MCPL. Unit 8. Bit Manipulations 8-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

BC AND BCR MASK FIELD


Mask field 1000 1100 1010 0011 1111 0000 Meaning if the condition code is 0, the BC & BCR will branch if the condition code is 0 or 1, the BC & BCR will branch if the condition code is either 0 or 2, the BC & BCR will branch if the condition code is either 2 or 3, the BC & BCR will branch whatever the condition code setting is, the BC & BCR will branch (thereby constituting an unconditional branch). Whatever the condition code setting is, the BC & BCR will not branch(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 Extended Mnemonics . Extended mnemonics are used so that we need not remember the appropriate mask field. For example, the instruction BE FOUND Is identical to the instruction BC 8, FOUND

Copyright MCPL. Unit 8. Bit Manipulations 8-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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:

Copyright MCPL. Unit 8. Bit Manipulations 8-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

INTEGER OPERATIONS
Instruction Add A,AR,AH Subtract S,SR,SH Add AL,ALR Subtract SL,SLR condition code 0 result is 0 result is 0, With no carry (AL,ALR)only condition code 1 condition code2 condition code 3 result is negative result is positive operation generated an overflow result is not 0, result is 0, with no carry with carry result is not 0, with carry

Compare C,CR,CH both operands first operand less first operand Are equal than second greater than --Second Load LCR result is 0 result is negative result is positive overflow generated LNR result is 0 result is negative -- --LPR result is 0 --result is positive overflow generated LTR result is 0 result is negative result is positive - - Shift SLA,SLDA, result is 0 Generated SRA,SRDA result is 0 result is negative result is positive overflow result is negative result is positive ---

Figure 8-21. Integer Operations. NOTES :

Copyright MCPL. Unit 8. Bit Manipulations 8-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

BYTE OPERATIONS
Instruction Insert ICM condition code 0 condition code 1 condition code2 condition code 3 ---

all inserted bits 0, 1 st inserted bit is 1 1st inserted bit is Or all mask bits 0 0 but not all are 0 1st operand greater than second

Compare CL, both operands are 1st operand less CLR,CLC,CLI equal than second

---

CLCL operands are 1st operand less 1st operand greater equal, or have than second than second --zero lines CLM bytes selected are 1st operand field 1st operand field equal or mask bits less than second greater than second - - are all zero Copy MVCL first operand 1st operand length 1st operand length destructive length equals less than second greater than second overlap(no second operands bytes copied) Translate TRT all argument bytes one or more argu- such stopped on tested all function ment bytes not last argument byte --bytes 0 tested Figure 8-22. Byte Operations. NOTES:

Copyright MCPL. Unit 8. Bit Manipulations 8-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

BIT OPERATIONS
Instruction condition code 0 condition code 1 condition code2 result is not 0 result is not 0 result is not 0 ------condition code 3 ------all selected bits are ones

AND N,NC,NI, result is 0 NR OR O,OC,OL, result is 0 OR

EXCL-OR X, result is 0 XC,XI,XR TEST TM

all selected bits 0 some set bits are or all mask bits 0 0 and some bits are 1 left most bit of tested byte is 0 left most bit of tested byte is 1

---

TS

---

---

Figure 8-23. Bit Operations NOTES:

Copyright MCPL. Unit 8. Bit Manipulations 8-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

DECIMAL
Instruction condition code 0 condition code 1 condition code2 result is negative condition code 3

Add AP,ZAP result is 0 Subtract SP Compare CP

result is positive operation geneted an overflolw

both operands first operand less first operand great ------------Are equal than second er than second result is zero result is negative result is positive overflow generated

Shift

SRP

Figure 8-25. Bit Operations NOTES:

Copyright MCPL. Unit 8. Bit Manipulations 8-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

FLOATING POINT
Instruction condition code 0 condition code 1 condition code2 result is negative result is positive condition code 3 --------

Add AE,AER, mantissa of AD,ADR,AU, result is 0 AUR,AW,AWR AXR Subtract SE,SER mantissa of SD,SDR,SU, result is 0 SUR,SWR,SXR

result is negative

result is positive

Load LCER,LCDR result mantissa result is negative is 0. LNER,LNDR result mantissa result is negative is 0. LNPR,LPDR result mantissa I-------------is 0. LTER,LTDR result mantissa result is negative Is0. Compare CE, both operands first operand less CER,CD,CDR are equal than second Figure 8-25. Bit Operations NOTES:

result is positive -------result is positive result is positive first operand greater than second

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

-------

Copyright MCPL. Unit 8. Bit Manipulations 8-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

MISCELLANEOUS
Instruction condition code 0 condition code 1 condition code2 condition code 3 ----------

Compare CS, compared oper- compared operands And swap CDS ands equl,second not equal,first is one is replaced replaced Set pgm Mask Store clock SPM

---------

(the condition code is set to the value of bits 2 and 3 of the designated register) clock in error state last edited field is positive clock in stopped state or not-operational ---------------

STCK clock in set state clock in not-set state

Editing ED, last edited field last edited field is EDMK is 0. negative

Figure 8-26. Bit Operations NOTES:

Copyright MCPL. Unit 8. Bit Manipulations 8-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

NONPRIVILEGED INSTRUCTIONS THAT DO NOT SET CONDITION CODE. Branches Branch and link Branch on Condition Branch on Count Branch on Index Multiply Divide Load Store Copy Translate Shift Logical BAL BALR BC BCR BCT BCTR BXH BXLE M D L ST IC TR SRL SLL MR DR LM STM STC SRDL SLDL BAS BASR

Integer Operations

MH LH STH STCM MVC MVI MVCIN

Byte operations Bit operations

Decimal Multiply Operations Divide Copy Floating-point Multiply Operations Divide Halve Round Load Store

MP DP MVN MVO ME DE HER LRER LE STE MER

MVZ MD MDR DDR LDR MXD MXDR MXR

DDR DD HDR LRDR LER LD STD

Miscellaneous Decimal-binary Operations Conv. CVB CVD Decimal-EBCDIC Conv. PACK UNPK Execute EX Load Address LA Monitor Call MC Supervisor Call SVC Figure 8-27. Nonprivileged instructions that do not set the condition code. NOTES: Copyright MCPL. Unit 8. Bit Manipulations 8-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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 powers Of 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 or 1,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 which decisions could not be made by programs.

Copyright MCPL. Unit 8. Bit Manipulations 8-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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 OPEN IO 0 1,2 Value of bits 0 1 00 01 10 11 00 01 10 11 0 1 1 OPEN IO 3 5 TYPE EOF meaning = file is closed = file is opened = = = = no meaning opened for input only opened for output only opened for input and output

TYPE

3,4

= none of the standard types = sequential = Index sequential = direct = not yet end-of-file = end-of-file 6

EOF

bit position 0 bit meaning

Figure 8-29. Status Byte. NOTES: The whole byte is used for the status information, even though there are two unused bits in 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 whole byte.

Copyright MCPL. Unit 8. Bit Manipulations 8-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

DEFINITIONS FOR A FILE STATUS BYTE


1 * File status information DC EQU EQU EQU EQU B00000000 B10000000 B01100000 B00100000 B01000000 B01100000 B00011000 B00001000 B00010000 B00011000 B00000100 BIT 5 FILE STATUS INITIALLY 0S BIT 0 BIT 1,2 0=CLOSED, 1=OPEN FOR I/O STATE: 01= INPUT ONLY 10= OUTPUT ONLY 11= INPUT & OUTPUT BIT 3,4 FOR FILE TYPE 01=SEQTL (SAM) 10=INDEXED (ISAM) 11=DIRECT (BDAM) 0=NOT EOF, 1=EOF 2 FILESTAT 3 OPEN 4 IO 5 IO IN 6 IO OUT

7 IO INOUT EQU 8 TYPE 9 TYPSAM EQU EQU

10 TYPISAM EQU 11 TYPBDAM EQU 12 EOF EQU

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 BO OUTPUT TM FILESTAT, IOIN BO INPUT ................ OUTPUT EQU * . INPUT EQU * SEE IF OUTPUT BIT IS 1 BRANCH IF IT IS 1 SEE IF INPUT BIT IS 1 BRANCH IF IS 1 file is opened for output file is opened for input

Copyright MCPL. Unit 8. Bit Manipulations 8-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

USE OF A STATUS WORD several bytes in the manner described as a full word or several full words. 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 we use 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 right 0,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; if the bit N is a 1, then terminal N is being used.

Copyright MCPL. Unit 8. Bit Manipulations 8-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

TESTING OR RESETTING BIT N


To test or reset the Nth bit in the status word, that word can be placed into a register and the Nth bit isolated from the other bits. The isolation is achieved by SHIFT and AND instructions LH L SLL N 2, BITN 3, STATUS 3, 0(2) 3, PATTERN R2= VALUE OF N R3= STATUS WORD MOVE BIT N TO POSITION 0 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 is the location of the status word, and that pattern is a location that contains a one bit and position 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.

Copyright MCPL. Unit 8. Bit Manipulations 8-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

SETTING OR INVERTING BIT N


To set bit N to 1, these statements are suffice: LH L SRL O ST 2, BITN 3, PATTERN 3, 0 ( 2 ) 3, STATUS 3, STATUS R2=VALUE OF N R3= 1 IN POSITION # 0 MOVE 1 TO POSITION # N OR THE STATUS BITS INTO R3, PUT RESULT BACK INTO STATUS WORD

To invert bit N, from 0 to 1 or vice versa these statements are suffice: LH L SRL X ST 2, BITN 3, PATTERN 3, 0 ( 2 ) 3, STATUS 3, STATUS R2= VALUE OF N R3= 1 IN POSITION # 0 MOVE 1 TO POSITION # N REVERSE BIT # N, PRESERVE OTEHRS 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

Copyright MCPL. Unit 8. Bit Manipulations 8-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

CONVERT HEX DIGITS TO EBCDIC CODES


To convert hex digit or line printer ,the digit must be represented in the EBCDIC character scheme. 1 * THE SET OF STATEMENTS GENERATES EIGHT CONSECUTIVE BYTES IN 2 * EBCDIC CODE FORMAT CORRESPONDING TO EIGHT CONSECUTIVE 3 * HEX DIGITS 4 * THE HEX DIGITS ARE ASSUMED TO BE IN THE FULL WORD NAMED 5 * DIGITS 6 * THE EBCDIC BYTES ARE PLACED IN THE AREA NEAMED RESULT 7 LA 1, EBCDIC R1= ADDR OF EBCDIC CODE TABLE 8 LA 2, RESULT R2= ADDR OF FIRST RESULT BYTE 9 L 3, =F 8 R3= LOOP-CONTROL COUNTER 10 L 7, DIGITS R7= HEX DIGITS 11 * GENERATE AN EBCDIC BYTE 12 NEXT LH 6, = H 0 R6 IS CLEARED, THEN NEXT HEX 13 SLDL 6, 4 DIGIT IS SHIFTED INTO IT, AND 14 LA 8, 0 ( 6, 1 ) IS USED TO COMPUTE ADDR OF 15 MVC 0 (1,2), 0(8) CORRESPONDING EBCDIC CODE 16 * LOOP - CONTROL 17 LA 2, 1(2) ADJUST ADDR TO NEXT RESULT BYTE 18 BCT 3, NEXT REPEAT TILL EIGHT DIGITS DONE . 19 DIGITS DS F HEX DIGITS(FULLWORD) TO BE CONV 20 RESULT DS CLB AREA FOR RESULT BYTES 21 EBCDIC DC C0123456789ABCDEF EBCDIC CODES FOR HEX DIGITS . . Figure 8-34. Convert hex digits to EBCDIC codes NOTES:

Copyright MCPL. Unit 8. Bit Manipulations 8-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

CONVERSION OF HEX DIGITS TO EBCDIC


HEX DIGITS: 0 1 32 BITS 2 3 4 5 6 7

EBCDIC

F0

F1

F2

F3

F4

F5

F6

F7

64 BITS HEX DIGITS: 8 9 A B C D E F

EBCDIC

F8

F9

C1

C2

C3 C4

C5

C6

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 their EBCDIC 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 its eventual isolation 2. The use of the LA instruction in Statement 14 to compute the address of the correct EBCDIC byte, based on the numeric value of the hex digit.

Copyright MCPL. Unit 8. Bit Manipulations 8-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

TRANSLATE FROM DECIMAL TO BINARY


Whenever a data enter a computers memory from an I/O device such asa terminal or a card reader, they are stored in which the device transmitted. This type of format is the EBCDIC code scheme. In EBCDIC format, the number 1358 is represented as a 4-byte quantity whose hex representation is F1 F3 F5 F8

1 3 5 and whose binary representation is 1111 0001 1111 0011

8 1111 0101 1111 1000

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.

Copyright MCPL. Unit 8. Bit Manipulations 8-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

TRANSLATING A NON-NEGATIVE INTEGER FROM EBCDIC TO BINARY 1 * THIS SET OF STATEMENTS TRANSLATES F NONNEGATIVE INTEGER 2 * FROM ITS EBCDIC REPRESENTATION TO ITS FULL-WORD BINARY 3 * REPRESENTATION 4 * 5 * THE EBCDIC REPRESENTATION IS ASSUMED TO BE EIGHT BYTES LONG, 6 * RIGHT JUSTIFIED, BEGINNING AT SYMBOLIC ADDRESS INT10. IT MAY 7 * HAVE LEADING ZEROES OR LEADING BLANKS 8 * 9 * THE RESULTING BINARY REPRESENTATION WILL BE STORED AT INT2 10* 11* INITIALIZATION 12 LA 2,INT10X R2 = ADDR OF LOW-ORDER BYTE 13 LA 3,P10 R3 = ADDR OF TABLE OF 10 * * N 14 LH 4, =H 8 R4 = MAX # DIGHTS TO BE TRANSLATED 15 LH 5, =H 0 R5 =ACCUMULATED RESULT (INITIALLY ZERO) 16 * 17 NEXT CLI 0(2), XF0 IF CURRENT BYTE VALUE NOT BETWEEN 18 BL DONE 0 AND 9 ( IN EBCDIC) THEN A LEADING 19 CLI 0(2), XF9 BLANK HAS BEEN REACHED 20 BH DONE 21 * MULTIPLY CURRENT DIGIT BY 10 * * N : 22 IC 7, 0 (2) PUT EBCDIC DIGIT INTO ODD-NUMBERED 23 N 7,PATTERN REGISTER, AND REMOVE ITS ZONE BITS. 24 M 6, 0 (3) THEN MPY BY CURRENT POWER OF 10, AND 25 AR 5, 7 ADD PRODUCT TO RESULT IN REG 5. 26 * 27 SH 2, =H+1 FOR LOOP CONTROL, ADJUST BYTE ADDRESS 28 AH 3, =H+4 TO NEXT DIGIT, AND TABLE ADDR TO NEXT 29 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- JUSTIFIED 34 INT10X EQU * - 1 ADDR OF LEAST. SIGNIFICANT EBCDIC DIGIT 35 PATTERN DC X0000000F MASK PRESERVES RIGHT-MOST FOUR BITS 36 * 37 P10 DC F1,10,100,1000 TABLE OF POWERS OF 10, I.E. Copyright MCPL. Unit 8. Bit Manipulations 8-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

38

DC

F1E4,1E5,1E6,1E7

10 * * N FOR N = 0, 1, 2, . . . . , 7

Figure 8-37. Translating a nonnegative integer from EBCDIC to binary NOTES:

Copyright MCPL. Unit 8. Bit Manipulations 8-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

Copyright MCPL. Unit 8. Bit Manipulations 8-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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

Copyright MCPL. Unit 9. Macros Page 9- 1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

Macro Definition
The set of statements that a macro represents must be defined before the macro can be used in a source module.some macros,such as GET and PUT I/O macros,are defined by system programmers and may be used by any assembly language programmers. A Macro is an opcode that represents a set of one or more assembly language instructions, directives, or other macros. It is a kind of high-level extension of assembly language.

Figure : 9-1 Macro Definition NOTES:

Copyright MCPL. Unit 9. Macros Page 9- 2 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

MACRO - PROTOTYPE STATEMENT

MACRO - PROTOTYPE STATEMENT

Name Field Variable Symbol or Blank

Opcode Macro's name

Operand List of positional and/or keyword parameters

Figure : 9-2 Macro-prototype statement NOTES: The second statement of the definition must describe the name, opcode and operand 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 keyword parameter is represented by a variable symbol followed immediately by an equal sign.

Copyright MCPL. Unit 9. Macros Page 9- 3 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

MACRO - HEADER STATEMENT

MACRO - HEADER STATEMENT

Name Field

Opcode

Operand

Blank

MACRO

Blank

Figure : 9-3 Macro - header statement NOTES: The first statement of the macro definition must be a MACRO directive, termed as Header-Statement. The definition of a macro can be included in the source module in which it is invoked, or placed in a separate file that's accessible to the assembler while it is assembling that source module.

Copyright MCPL. Unit 9. Macros Page 9- 4 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

A SAMPLE MACRO
Example: A macro named ADD with the following property opcode operand ADD X,Y

Whenever the statement is written in a source module,the effect is equivalent to these three statements: L 5,X A 5,Y ST 5,X We can also write it as ADD ALPHA , BETA

the effect is equivalent to these three statements: L 5 , ALPHA A 5 , BETA ST 5 , ALPHA


Figure : 9-4 A sample Macro

NOTES :
The add macro such that we write any two valid symbols in place of ALPHA and BETA. It always causes Register 5 to be used,so that the previous number in that register is replaced by the result of the ADD macro. There must be exactly two symbols in the operand and,they must designate full-word integers. The number whose address is represented by the second symbol is added to the number whose address is represented by the first symbol;the sum is stored at the address represented by the first symbol.

Copyright MCPL. Unit 9. Macros Page 9- 5 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

A MACRO'S DEFINITION

A MACRO'S DEFINITION

MACRO A B C

Header Prototype

Body

M E N D

Trailer

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.

Copyright MCPL. Unit 9. Macros Page 9- 6 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

EXAMPLE 1

EXAMPLE 1

MACRO &L &L ADD L A ST MEND &A, &B 5, &A 5, &B 5, &A

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.

Copyright MCPL. Unit 9. Macros Page 9- 7 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

USE OF CONTROL DIRECTIVES The statements in the body of a macros definition can include any of the control directives. GBLx , SETx , AIF , AGO , ANOP RETURN Macro: The meaning of the RETURN macro is Return to the calling program after restoring all registers except the registers (if any) designated in the operand. The exceptions can only be Register 0,Register 15,or both Register 0 and Register 15.Thus there are four essential different ways to invoke the RETURN macro: RETRN RETRN 0 , 15 RETRN 15 RETRN 0 restores all registers restores all but R15 and R0 restores all but R15 restores all but R0

Figure : 9-7 Return Macro

NOTES: Each of the invoking statements will cause the assembler to generate the corresponding
expansion for the return sequence.

Copyright MCPL. Unit 9. Macros Page 9- 8 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

RETURN MACRO DEFINITIONS


1.The prototype statement (line2) identifies the name of the RETRN macro and the variable 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 time the RETRN macro is invoked. It is during this assembly time processing of the definition that the assembler generates the expansion. The expansion is not executed until run time. Statement no Statement 3 AIF (&R1 EQ ).R1 Explanation

This determines whether the first operand field is present.If not, assembler skips to statement identified by the sequence symbol. AIF ((&r1 NE 0) AND (&R1 NE 15)).RERR When the first operand field is present, this determines whether its value is acceptable. AIF (&R2 EQ ).R3 When the first operand is present and its value is either 0 or 15,this determines whether the second operand is present. If it is not,the assembler skips to statement identified by the sequence symbol

AIF ((&R2 NE 0) AND (&R2 NE 15)).RERR


This determines whether the Value in the second operand is is acceptable. When both operands are present and valid, the assembler skips to statement identified by the sequence symbol.

AGO

.R2

Figure : 9-8 Return macro definitions NOTES:

Copyright MCPL. Unit 9. Macros Page 9- 9 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

MEXIT Directive The MEXIT directive instructs the assembler to stop its assemblytime processing of the RETRN macro. This directive is equivalent to an unconditional skip(AGO) to the MEND directive. Syntax: Name field Sequence symbol or Blank MNOTE Directive The MNOTE directive specifies a message that is printed on the listing and a severity code. Syntax: Name field Sequence symbol or Blank Opcode MNOTE Operand n, Opcode MEXIT Operand Blank

Severity code

Character string, to be printed on the listing

Figure : 9-9 Directives NOTES:

Copyright MCPL. Unit 9. Macros Page 9- 10 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

VSAM PROCESSING - ASSEMBLER VSAM PROCESSING - ASSEMBLER


OPEN macro ACB MACRO Access method Control Block RPL MACRO Request Parameter List

Data Set

CLOSE macro

REQUEST MACROS GET PUT POINT ERASE

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 the request 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.

Copyright MCPL. Unit 9. Macros Page 9- 11 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

CREATING ACBs AND RPLs

CREATING ACBs AND RPLs

MACROS PROCESSED AT ASSEMBLY TIME

MACROS PROCESSED AT EXECUTION TIME

ACB RPL

GENCB ACB GENCB RPL

Figure 9-11 Creating acbs and rpls NOTES: GENCB generates a control block when the program is executed rather than when the program is assembled. The use of GENCB means that programs would not require reassembly with a new 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 or RPL macro.

Copyright MCPL. Unit 9. Macros Page 9- 12 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

ACB MACRF PARAMETER ACB MACRF PARAMETER

FILEA

ACB .MACRF = (processing option list). ADR I CNV I KEY DIR I SEQ I SKP IN I OUT NIS I SIS Record or CI access Access mode Input or Output Insert strategy

MACRF PROCESSING OPTIONS

Figure 9-12 ACB MACRF parameter NOTES: NIS / SIS NIS (Normal insert strategy) is the default insert strategy. Splits occur in the middle of control intervals. SIS (Sequential insert strategy) is helpful for mass sequential insertions. Splits occur at the point of record insertion.

Copyright MCPL. Unit 9. Macros Page 9- 13 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

RPL OPTCD PARAMETER

RPL OPTCD PARAMETER

RPLA RPL . OPTCD = (request option list)..

ADR I RPL DIR I REQUEST FWD I OPTIONS LOC I NSP I

CNV I KEY SEQ I SKP BWD MVE NUP I UPD

Record or CI access Access mode Forward or Backward LOCATE or MOVE mode Retrieval for UPDATE NOUPDATE

Figure: 9- 13 RPL OPTCD parameter NOTES:

ASSEMBLER ERROR HANDLING


Copyright MCPL. Unit 9. Macros Page 9- 14 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

ASSEMBLER ERROR HANDLING

KEYED - SEQUENTIAL RETRIEVAL (FORWARD) INPUT RETRVE RPL ACB MACRF=(KEY, SEQ, IN) ACB=INPUT AREA=IN, AREALEN=100, OPTCD =(KEY, SEQ, SYN,NUP,MVE )

LOOP GET RPL=RETRVE

LTR BNZ ERROR IN B DS

15, 15 ERROR

LOOP CL100

Figure 9-14 Assembler Error Handling NOTES: When an OPEN / CLOSE or request macro completes, VSAM always places a return code 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 error handling routine might interrogate.

Copyright MCPL. Unit 9. Macros Page 9- 15 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDEN

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

Copyright MCPL. Unit 10. Sequential Organization 10- 1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDEN

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. Main processing phase: each record is processed according to whatever criteria are appropriate to the problem. End-ofdata phase: the last output record remaining in main memory has to written and the data sets must be closed.

Copyright MCPL. Unit 10. Sequential Organization 10- 2 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDEN

THE SYSTEM INPUT AND OUTPUT DATA SETS


SYSIN AND SYSOUT IN OS SYSTEMS
The DD statements for SYSIN and SYSOUT are For SYSIN: / / SYSIN For SYSOUT: / /SYSPRINT DD 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 special Form 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 operating System. It is identified on a DD statement by the parameter SYSOUT =. Neither SPACE = nor DISP = can be specified for SYSOUT. To designate the block size for SYSIN and SYSOUT, choosing a value consistent with the device characteristics. Some computer installations use default values of block sizes for both these data sets. You should determine what block sizes should be specified at your computer installation. Unless stated otherwise, the above values will be coded.

Copyright MCPL. Unit 10. Sequential Organization 10- 3 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDEN

SYSIPT AND SYSLST IN DOS SYSTEM


The SYSIPT data set needs no job control statements unless it is assigned to a device other then the system card reader. For card reader, the data records described by the DTFCD Macro simply follow the // EXEC command for the program that records those data. 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 card reader, with a single I / O buffer named INBUF, and that the name of the users end-offile routine is EOJ. Move mode is used due to the WORKA = YES parameter.

Copyright MCPL. Unit 10. Sequential Organization 10- 4 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDEN

PROCESSING FIELDS IN A LOGICAL RECORD


MOVE MODE Example for move mode CARD DS CL80 RESERVE 80 POSITIONS FOR INPUT RECORD ORG CARD SET MEMORY LOCATION COUNTER TO CARD DS CL4 COLUMNS 1 - 4 UNUSED NAME DS CL40 COLUMNS 5 - 44 FOR STUDENT NAME DS CL1 COLUMN 45 UNUSED COURSE DS CL 10 COLUMNS 4655 FOR COURSE TAKEN DS CL 1 COLUMN 56 UNUSED GPA DS CL4 COLUMNS 57 60 FOR GPA (AS X.XX) ORG SET MEM LOC CTR TO FIRST BYTE BEYOND CARD
Figure 10-4. Processing fields in a logical record

NOTES :

Copyright MCPL. Unit 10. Sequential Organization 10- 5 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDEN

PROCESSING FIELDS IN A LOGICAL RECORD (contd)


LOCATE MODE : Example for locate mode CARD NAME COURSE GPA EG2 DSECT DS DS DS DS DS DS CSECT CL4 CL40 CL1 CL10 CL1 CL4 BEGIN DUMMY SECTION NAMED CARD SAME AS IN ABOVE MOVE MODE DEFINITIONS

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 logical record fields must be established at assembly time. A dummy base register that points to the beginning of the DSECT area must also be established by means of a USING directive at assembly time, and the logical record address received from the GET Macro should be loaded in to the dummy base register at run time.

Copyright MCPL. Unit 10. Sequential Organization 10- 6 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDEN

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 it is processed at run time. The record length can be obtained at run time from the record descriptor word. Once the record length is obtained, the record can be moved with an Execute instruction. The logical record area must be defined to include the record descriptor word (RDW). At the least, the area should begin on a half-word boundary, to make the count field in the RDDW accessible to LH and STH instructions. The Ds directive that defines the area with a DS OH directive: DS CARD DS OH CL84

Copyright MCPL. Unit 10. Sequential Organization 10- 7 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDEN

MOVE MODE
To process variable-length records in move mode can be code like this: COPYLOOP GET TRANSIN, CARD OBTAIN A LOGICAL RECORD LH 10,CARD LOAD RECORD LENGTH FROM RDW SH 10, =H 1 SUBT +1 FOR EXECUTE INSTR EX 10, VMVC MOVE RECORD FROM INPUT TO OUTPUT PUT TRANSOU, LINE AREAS, AND PUT IT INTO OUTPUT B COPYLOOP BUFFER. THEN GETNEXT RECORD. MVC LINE ( 0 ), CARD MVC FOR VAR-LNG MOVE. . . DCB . . . , RECFM=VB, LRECL=84, BLKSIZE =4096 DCB . . . ,RECFM=VB, LRECL= 136, BLKSIZE=4084 DFTCD . . ., RECFORM= VARUNB, BLKSIZE =84 DFTPR . . . , RECFORM=VARUNB, BLKSIZE = 136 DS CL94 DS CL136 DS 0H DS CL84 DS 0H DC CL136

VMVC TRANSIN TRANSOU *TRANSIN *TRANSOU *INBUF * CARD LINE

Figure 10-5. Move Mode NOTES:

Copyright MCPL. Unit 10. Sequential Organization 10- 8 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDEN

LOCATE MODE
COPYLOOP GET TRANSIN OBTAIN ADDRESS OF LOGICAL RECORD LR 9, GREG USE REG 9 TO SAVE INPUT RECDD ADDR MVC VRECL,0(9) GET LENGTH FROM RDW IN I /O BUFFER LH 10, VRECL LOAD RECD LNG FROM HALF-WORD AREA SH 10, =H 1 SUBT + 1 FRO EXECUTE INSTR EX 10, VMVC MOVE RECORD FROM INPUT TO OUTPUT PUT TRANSOU AREAS, AND OBTAIN ADDRESS OF NEXT LR 8, PREG OUTPUT RECORD. SAVE THIS IN REG 8 B 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 RECORD LENGTH

Figure 10-6. Locate mode NOTES: In locate mode, the process of obtaining the record length should be modified. The Record length must be obtained from the record descriptor word (RDW) of the logical Record, i.e., from the first 2 bytes of the logical record area. The general case of blocked records (RECFM =VB or RECFORM = VAR BLK ) even though The DOS SYSIPT and SYSLST files do not permit blocked records. The same method 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 is aligned on a half-word boundary, so that the LH (Load Half Word) instruction can be used whether we have An IBM 360 or IBM 370.

Copyright MCPL. Unit 10. Sequential Organization 10- 9 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDEN

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 be used to control printer line-spacing. The most common space-control functions are to single space, double space, triple space, suppress spacing and skip to new page. Control character is simply one of the 256 EBCDIC characters. There are two different sets of control characters, ANSI and IBM machine code characters. In OS , the choice of control character set is designated in the RECFM=parameter of the DCB macro. The ANSI set is designated by letter A, the IBM set by letter M: RECFM=FBA or VBA, or RECFM=FBM or VBM.

Copyright MCPL. Unit 10. Sequential Organization 10-10 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDEN

TITLE
The logical record area for the title could be defined as TITLE DS CL133 SPACE FOR TITLE LINE ORG TITLE BEGIN REDEFINITION FOR FIELDS DC XF1 ANSI CTL CHAR FOR TOP OF NEW PAGE DC CL14 BLANKS TO CENTER THE TITLE *FOLLOWING IS SOME APPROPRIATE TITLE,WITH TRIALING BLANKS 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 READABILITY DC CPAGE 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 limit established for number of lines per page. A logical record area must be defined to include the 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 time a new page is to be started.

Copyright MCPL. Unit 10. Sequential Organization 10-11 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDEN

DATE AND TIME MACROS


The TIME Macro Date and Time in OS Opcode TIME Operand blanks

The COMRG and GETIME Macros Date and Time in DOS Opcode GETIME COMRG Operand

Figure 10-9. Date and Time macros

NOTES:
To obtain the date and time in DOS two separate macros are needed, GETIME and COMRG 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 address is 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.

Copyright MCPL. Unit 10. Sequential Organization 10-12 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDEN

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 21-60 : stud-name

Cols 62-70:std-id

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 room number, and the names of the students who are assigned to that room. Since the data set will contain the information that we want to know and maintain about dorm room capacity is known as master file. The data set used to create or update the master file is known as transaction file. To process the master file as a sequential data set, we require that its logical records be in some useful sequence and that the logical records of the transaction file be in the same sequence. The dorm field in each record is thus referred to as the major field for sequencing and the room number field as the minor field. Each dormitory is identified by a one-to four character abbreviation, all of which be letters. Each dormitory room number consists of one to four letters or digits.

Copyright MCPL. Unit 10. Sequential Organization 10-13 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDEN

TRANSACTION RECORD FORMAT


CODE 1. 2. 3. 4. MEANING Add a record for this dorm and room number to the Master file Add the student identified in this transaction record to the master file record identified by the dorm and room number field given in the transaction. Delete the student identified in this transaction record From the master file record. Delete the master file record that is identified by the Dorm and room number in the transaction.

Figure 10-11. Transaction record format NOTES:

Copyright MCPL. Unit 10. Sequential Organization 10-14 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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

Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11- 1 Course Material may not be reproduced in whole or in part Without the prior permission of MCPL.

STUDENT NOTEBOOK

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:

Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11- 2 Course Material may not be reproduced in whole or in part Without the prior permission of MCPL.

STUDENT NOTEBOOK

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 users 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:

Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11- 3 Course Material may not be reproduced in whole or in part Without the prior permission of MCPL.

STUDENT NOTEBOOK

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 in EXTEND Mode.

Figure 11-3. Queued indexed sequential access method (QUISAM) NOTES: QISAM is access method used to create the indexed sequential data sets, update the records, insert the records and delete the Records from sequential data set. The processing steps used with QISAM are similar to QSAM but Some significant differences between them.

Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11- 4 Course Material may not be reproduced in whole or in part Without the prior permission of MCPL.

STUDENT NOTEBOOK

QISAM vs. QSAM


QISAM sequential processing can begin at any arbitrary record in the data set. The record processing begins must be identified by its 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:

Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11- 5 Course Material may not be reproduced in whole or in part Without the prior permission of MCPL.

STUDENT NOTEBOOK

DSORG AND MACRF PARAMETERS

The DSORG parameter must always be coded as DSORG = IS for QISAM. 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 creating the data set, not when updating or retrieving from it. Move mode or locate mode buffering can be used , but the other buffering options available with QSAM processing data mode, substitute mode , and exchange buffering are not permitted with QISAM When retrieving record in INPUT mode, we must specify in the MACRF Parameter whether or not the SETL macro will be used by coding MACRF=(GM,SK) or (GL,SK)

Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11- 6 Course Material may not be reproduced in whole or in part Without the prior permission of MCPL.

STUDENT NOTEBOOK

BASIC INDEXED SEQUENTIAL ACCESS METHOD

Used to update or retrieve the records but not to create an Indexed Sequential Dataset. Deleted records Synchronization Open Macro DCB Parameters

Figure 11-6. Basic indexed sequential access method NOTES:

Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11- 7 Course Material may not be reproduced in whole or in part Without the prior permission of MCPL.

STUDENT NOTEBOOK

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 = LOAD in the DTFIS macro. Follow the OPEN macro with a SETFL(Set File Load Mode) macro and precede the CLOSE macro with an ENDFL (End SETFL) macro. Record must be written in ascending key sequence. To create a file: //DLBL dtfname ,filename,date,ISC,..

Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11- 8 Course Material may not be reproduced in whole or in part Without the prior permission of MCPL.

STUDENT NOTEBOOK

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, use the procedure and parameters as when creating the file. Difference between creating and extending is indicated in a users program it specified in the //DLBL JCL statement. To create a file: To extend a file: //DLBL dtfname ,filename,date,ISC,.. //DLBL dtfname ,filename,date,ISE,..

Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11- 9 Course Material may not be reproduced in whole or in part Without the prior permission of MCPL.

STUDENT NOTEBOOK

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 updating procedures.
Updating in place is restricted to changing data field contents(but not the key field), and is specified 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. In random 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 a new file. There is no provision for deleting records in random mode

Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-10 Course Material may not be reproduced in whole or in part Without the prior permission of MCPL.

STUDENT NOTEBOOK

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 three distinct areas: the prime data area, the independent overflow area and the cylinder index area. In OS systems , the space allocation depend on the SPACE= parameter of the DD statement is coded. In DOS systems , the space allocation is done by //EXTENT statements.

Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-11 Course Material may not be reproduced in whole or in part Without the prior permission of MCPL.

STUDENT NOTEBOOK

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),.

//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 used for independent overflow. Fig2: Prime area = P cylinders with X cylinders as embedded index; partially used index cylinders are independent overflow areas.

Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-12 Course Material may not be reproduced in whole or in part Without the prior permission of MCPL.

STUDENT NOTEBOOK

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), // DCB=*.ddname,.. //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), // 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 at its end. FIG2: prime area = p cylinders with x cylinders as embedded index; Independent overflow area = w cylinders.

W p w

Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-13 Course Material may not be reproduced in whole or in part Without the prior permission of MCPL.

STUDENT NOTEBOOK

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), // 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 used Index cylinders used as independent overflow area. Fig2: prime area = p cylinders: index area = x cylinders : independent overflow area = w cylinders.

Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-14 Course Material may not be reproduced in whole or in part Without the prior permission of MCPL.

STUDENT NOTEBOOK

SPACE ALLOCATION IN DOS SYSTEMS


/ /DLBL dtfname,filename,date.isc / /EXTENT , ,4,0,a,n / /EXTENT , ,4,1,b,r / /EXTENT , ,1,2,c,s / /EXTENT , ,2,3,d,t -- Optional master index area. -- Required cylinder index area. -- Required prime data area. -- Optional independent overflow area.

extent type Extent seq#

Relative track number where space allocation begins. Number of consecutive tracks in the space allocation.

Figure 11-13. Space allocation in dos system NOTES:

Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-15 Course Material may not be reproduced in whole or in part Without the prior permission of MCPL.

STUDENT NOTEBOOK

ADDING RECORDS TO AN INDEXED SEQUENTIAL DATA SET


Track0 prime Track 260 1

480

track 2 Track-index track

Track1 Key data block 230 110

120

180

230 Prime data tracks (one block per track)

Track2 key data block 480 340 Track18

380

405

425

FF 480

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 5 records/block and record 480 flagged for deletion

Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-16 Course Material may not be reproduced in whole or in part Without the prior permission of MCPL.

STUDENT NOTEBOOK

SPACE REQUIREMENTS
For the IBM 3330 system the track capacity formula is 13165 191 + KL + DL

Number of blocks per track = 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.

Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-17 Course Material may not be reproduced in whole or in part Without the prior permission of MCPL.

STUDENT NOTEBOOK

CREATING AN INDEXED SEQUENTIAL DATA SET


Block size. Maximum possible block size for IBM 3330 is DL = (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 the data set. Some DCB parameters and DTFIS parameters are required.

Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-18 Course Material may not be reproduced in whole or in part Without the prior permission of MCPL.

STUDENT NOTEBOOK

PRICIPAL DCB PARAMETERS


Parameter BLKSIZE=n CYLOFL=c DDNAME=ddname DSORG=IS KEYLEN=k LRECL=m {(PM)} MACRF={(PL)} NTM= t OPTCD= Meaning block size of n bytes including 4 bytes for block descriptor word. c tracks in each prime data cylinder for overflow area. DD statement that describes data set. specifies that organization is indexed sequential. length of the key field in each record is k m bytes in each logical record. PM for PUT macro in move mode PL for PUT macro in locate mode. if the cylinder index requires more than t tracks then master index will be created. 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. Fixed length records Variable length records p is the relative position of the first byte in the key field.

{(FB)} RECFM={(VB)} RKP=p

Figure 11-17 Principal dcb parameters NOTES: BLKSIZE,CYLOFL,KEYLEN,LRECL,NTM,OPTCD,RECFM And RKP can only be specified when creating an indexed sequential data set. They cannot be specified when updating or retrieving from the data set.

Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-19 Course Material may not be reproduced in whole or in part Without the prior permission of MCPL.

STUDENT NOTEBOOK

PRINCIPAL DTFIS PARAMETERS


PARAMETER CYLOFKL=c DEVICE = device# MEANING c tracks in each primary data cylinder for overflow area. 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 records RECFORM={----------- } { FIXUNB}unblocked fixed length records RECSIZE=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:

Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-20 Course Material may not be reproduced in whole or in part Without the prior permission of MCPL.

STUDENT NOTEBOOK

FIXED LENGTH RECORD FORMAT

Byte 0 - 1: byte deletes flag Bytes 1 - 4: 4-byte dorm abbreviation} Bytes 5 - 8: 4 byte room number} record key field

Student name (40 bytes)

Id Student name (9) (40 bytes) Space used whether needed or not

Id (9)

Figure 11-19. Fixed length record format NOTES:

Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-21 Course Material may not be reproduced in whole or in part Without the prior permission of MCPL.

STUDENT NOTEBOOK

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 Student name (9) (40 bytes) Space not used unless needed

Id (9)

Figure 11-20. Variable length record format NOTES:

Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-22 Course Material may not be reproduced in whole or in part Without the prior permission of MCPL.

STUDENT NOTEBOOK

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 data set. 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 be inserted into an existing data set using sequential mode which requires overflow area.

Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-23 Course Material may not be reproduced in whole or in part Without the prior permission of MCPL.

STUDENT NOTEBOOK

SEQUENTIAL MODE IN OS SYSTEMS


The various modes are: EXTENDING

Open the data set in EXTEND mode. DISP=(MOD,KEEP) in DD statement. Specify the MACRF parameter in DD statement and use PUTX macro.

UPDATING

DELETING

OPTCD=L and Move XFF in to the delete-flag and rewrite the record.

Figure 11-22. Sequential mode in OS systems NOTES:

Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-24 Course Material may not be reproduced in whole or in part Without the prior permission of MCPL.

STUDENT NOTEBOOK

SEQUENTIAL MODE IN DOS SYSTEMS


The various modes are: EXTENDING To create a data set code ISC in //DLBL statement. To update or extend code ISE in //DLBL statement. SETFL and ENDFL are not used for updating. PUT macro is used to rewriting an updated record. Move XFF in to the first byte of the record there is no delete flag.

UPDATING

DELETING

Figure 11-23. Sequential mode in DOS systems NOTES:

Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-25 Course Material may not be reproduced in whole or in part Without the prior permission of MCPL.

STUDENT NOTEBOOK

OS RANDOM MODE PROCESSING


DYNAMIC BUFFERING READ And WRITE MACROS MACRF parameter I/O synchronization INVALID key conditions

Figure 11-24. NOTES:

Os random mode processing

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.

Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-26 Course Material may not be reproduced in whole or in part Without the prior permission of MCPL.

STUDENT NOTEBOOK

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.

Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-27 Course Material may not be reproduced in whole or in part Without the prior permission of MCPL.

STUDENT NOTEBOOK

UPDATING IN RANDOM MODE


INITILIZATION

The file is opened and the first transaction record is read.

MAIN PROCESSING Move the key of the current transaction record to the area that is designated by the key address parameter in an OS read or write macro and by the KEYARG=parameter in DOSDTF macro. END-OF-DATA INVALID KEY
Figure 11-26 Updating in random mode NOTES:

Copyright MCPL. Unit 11. Indexed Sequential Organization Page 11-28 Course Material may not be reproduced in whole or in part Without the prior permission of MCPL.

STUDENT NOTEBOOK

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

Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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 is intended 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 IBMs Information Management System (IMS). The Access Method Services Utility Program (AMS) provides means of creating VSAM Data Sets, and the VSAM I/O provides a variety of processing option.

Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -2 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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:

Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -3 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

ESDS: ENTRY SEQUENCED DATA SET


RECORD1 RECORD2 RECORD3 UNUSED SPACE R R C D D I F F D F R D F R D F C I D F

RECORD1

RECORD2

RECORD3

UNUSED SPACE

R D F

Figure 12-3 ESDS NOTES: ESDS records are stored in a data set in the sequence in which they are presented to the operating system. In this sense the sequencing of ESDS records is analogous to that of sequential data-set records ESDS has only a data component it contains fixed length or variable length records. New records are only added at the end of the dataset, existing records can never be deleted, but they can be updated. Access Methods: 1. Sequential Access 2. Direct Access by means of relative byte address (RBA)

Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -4 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

RRDS: RELATIVE RECORD DATA SET


CI 0 SLOT1 CI 1 SLOT1 CI 2 SLOT1 SLOT2 SLOT3 SLOT4 SLOT2 SLOT3 SLOT4 SLOT2 SLOT3 SLOT4

Figure 12-4 RRDS NOTES: RRDS consists of a number of preformatted fixed-length slots. each slot has a unique relative record number, and the slots are sequenced by ascending relative record number. 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)

Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -5 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

KSDS: KEY-SEQUENCED DATA SET


Index component IS1 IS2 IS3

Data component CA1


CI 1 CI 2 CI 3 CI 4

SS 1

SS 2

SS 3
CA3
CI 1 CI 2

SS 4
CA4
CI 1 CI 2

SS

SS 6
CA6
CI 1 CI 2

CA2
CI 1 CI 2

CA5
CI 1 CI 2

Figure 12-5 KSDS NOTES: KSDS has a data and an index component, it contains fixed length and variable length records. 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 to those of indexed sequential data set records. Access Methods: 1. Sequential Access 2. Direct Access by means of key 3. Skip sequential access

Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -6 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

VSAM BUILDING BLOCKS


Physical block All physical block can contain logical records and unused space LR Control Interval Track1 LR Track2 LR LR Control Interval LR PB LR LR Control Area LR Last physical block also contains CI info ..

LR

(M<=19) Tracks LR LR LR

Figure 12-6 VSAM building blocks NOTES: LR = Logical Record A logical record is a unit of information used to store data in a VSAM data set. CI = Control Interval VSAM uses CI s to contain records. Whenever record is retrieved from DASD, the entire CI containing the record is read into VSAM I/O buffer in virtual storage. CA = Control Area The CIS in a VSAM data set are grouped together into fixed-length contiguous areas of direct storage called CAS.A VSAM data set is composed of one or more CAs.

Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -7 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

RBAS AND CONTROL INTERVAL FORMATS


3 RD F3 Cidf

1 L1

2 L2

3 L3

n Ln UNUSED SPACE

RDFn

Rdf2 Rdf1

LOGICAL RECORDS CONTROL INTERVAL

CONTROL INFORMATION

Figure 12-7 RBA and CI s NOTES:

Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -8 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

RBAS AND CONTROL INTERVAL FORMATS (CONT..)


CIDF=CONTROL INTERVAL DEFINITION FIELD

2 L

2 U

TOTAL LENGTH OF RECORDS SPACE 1 THRU n 1 X00 RDFk = RECORD DEFINITION FIELD FOR RECORD K Figure 12-8 RBA and CIs continue.. NOTES :

LENGTH OF UNUSED 2 Lk

LENGTH OF RECORD K

Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -9 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

RBA S AND CONTROL INTERVAL FORMATS (CONT)


3 3 X04

X08

L2

L1 1

L2 2 3

L3

L2

Ln n

3 RDF RDF1 CIDF

RDFn RDF

m CONSECUTIVE RECORDS EACH OF LENGTH L2

2RDFS

Figure 12-9 RBA and CIs continue.. NOTES: VSAM always uses the RBA to determine a records location in a dataset. But except in certain advanced applications of VSAM, RBAs are not normally needed by user programs to access records.

Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -10 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

AMS COMMAND SUMMARY


General usage DEFINE Creates a catalog entry for a VSAM object

DELETE Deletes one or more VSAM objects and their catalog entries LISTCAT List information contained in a VSAM catalog PRINT Prints the contents of a VSAM data set or of a sequential or Indexed-sequential data set REPRO Copies a VSAM or sequential or indexed sequential data set Into another catalog VERIFY Verifies and corrects certain information about a data set in a catalog
Figure 12-10 AMS command summary. NOTES: AMS is the VSAM Utility program, executable under the name IDCAMS in both OS and 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 data sets. It prints the contents of VSAM catalogs and data sets

Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -11 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

AMS COMMAND SUMMARY (CONT..)


Special Usage ALTER Changes catalog information about a VSAM object that was previously defined

BLDINDEX Initially loads a newly defined alternate index CHKLIST List tape data set that were open at the time a checkpoint was taken (OS only) CNVTCAT Converts OS catalog entries into VSAM VSAM catalog entries (OS only) EXPORT Unloads a VSAM base cluster or alternate index , together with its catalog entry, onto a movable storage volume; alternatively, copies a user catalog onto a movable volume and then disconnects that catalog from the systems master catalog

Figure 12-11 AMS command summary continue. NOTES:

Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -12 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

AMS COMMAND SUMMARY (CONT..)


EXPORTRA Unloads data sets whose catalog entries are damaged, using the information about the data set that is in the catalog recovery area instead of the information in the catalog itself. IMPORT IMPORTRA LISTCRA Defines and loads a data set or catalog that had been unloaded via EXPORT Reconstructs a data set that had been unloaded via EXPORTRA, by redefining it and reloading it Lists the contents of a catalog recovery area and (optionally) compares it with the contents of the associated catalog Adjusts information in a catalog to be consistent with that which is in its associated catalog recovery area and in the VTOC

RESETCAT

Figure 12-12 AMS command summary continue NOTES:

Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -13 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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 catalog that is created by AMS for the entire system .The master catalog is usually defined by the system administrator and will not be considered here . 2. Every VSAM user data set must be described either in the master catalog or in a user catalog that is created by AMS. For various reasons (e.g. ,Increased processing efficiency and easier transportability to other computer systems), a user 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. ,one per disk pack ). Like the master catalog , user catalogs are ordinarily define by a system administrator rather than by a programmer. 4. No two VSAM data sets that are listed in the same catalog can have the same data set name indeed , no two VSAM objects that are listed in the same catalog can have the same name The names of VSAM objects must contain from 1 to 44 characters, of which the first must be a letter (A through Z, and @,#,$) and the others can be letters or 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 cannot be a period. The portion of a name consisting of period and all characters to the left that period is known as a qualifier; names containing qualifiers are known as qualified names.

Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -14 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

DATA COMPONENTS, INDEX COMPONENTS, AND CLUSTERS


KLA XYZ

CDC

EFG

KLA

USA

XYZ

C O
N T R O L I N T E R V A L

BDE

BRO

CDC

CRA DA B

AA A

AB C

BDE BRO

E F G C R A D A B
EFG

W X Y

X A B

XY Z
WX Y XA B

CDC

XY Z

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 in ascending prime key sequence. The imbedded index sequence set (the lowest level index) contains the highest key and a pointer for each control interval that contains data in the control area that the sequence set pertains to. Each higher-level index contains the highest key and the pointer for each of the immediately lower-level indexes that pertain to.

Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -15 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

VSAM MACRO SUMMARY


Nonexecutable Control Block Macros ACB EXLST RPL Generates an access-method control block at assembly time Generates a list of exit-routine addresses at assembly time Generates a request parameter list assembly time

Executable Control Block Macros GENCB MODCB SHOWCB TESTCB Generates the same information that an ACB, EXLST, or RPL macro does so at run time rather than assembly time Modifies the contents of any of the control blocks that were generated by ACB,EXLST,RPL, or GENCB Obtains the contents of one or more fields of any control block 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/O programming is accomplished via macros. Types of Macros: 1. Request Macros 2. Control Block Macros Control Block Macros are used to create, modify, obtain or test selected fields of the control blocks. The control blocks themselves are similar in purpose to the DTFxx areas in DOS and the DCP areas in OS systems. The provided information is used at run time by the operating system. The information generated by the ACB, RPL and EXLST macros in both DOS and OS systems.

Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -16 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

VSAM MACRO SUMMARY (CONT.)


Request Macros for General Use CHECK CLOSE ENDREQ ERASE GET OPEN POINT PUT Waits for completion of an asynchronous I/O request Disconnects a program from a data set Terminates an asynchronous I/O request Deletes a record from a key-sequenced or relativerecord data set Retrieves a record from a data set Connects a program to a data set Positions a data set at a designated record or class of records 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.

Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -17 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

VSAM MACRO SUMMARY (CONT..)


Request Macros For Advanced Applications BLDVRP DLVRP GETIX MRKBFR Builds a VSAM resource pool Deletes a VSAM resource pool Retrieves a specified index control interval (OS only) Marks a buffer for output, or to release it from exclusive control or shared status (OS only) Stores a specified index control interval (OS only)

PUTIX

Figure 12-16 VSAM Macro summary continue. NOTES:

Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -18 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

VSAM MACRO SUMMARY (CONT..)


SCHBFR SHOWCAT VERIFY WRTBFR Searches a buffer for an RBA with in specified ranges (OS only) Retrieves information from a VSAM catalog Ensures that the end-of-data information contained in the catalog for a specific data set is accurate (OS only) Writes a deferred buffer or (in OS only) writes a buffer that was marked for output via MRKBFR.

Figure 12-17 VSAM Macro summary continue. NOTES:

Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -19 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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)

GET PUT Etc

RPL = rplname

Figure 12-18 Relationship of JCL and VSAM Macro. NOTES:

Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -20 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

ACB MACRO PARAMETER


General format : acbname ACB keyword1 = value1..keywordn = valuen KEYWORDS COMMONLY USED AM =VSAM DDNAME = dname MACRF = (macrf-options) KEYWORD FOR ERROR HANDLING EXLST = existname Identifies this ACBs EXLST macro States that the access method is VSAM DDname identifies the associated JCL statement Specifies options for run-time processing

MAREA = addressnames an area to receive OPEN/C error messages MLEN = length Specifies length of the MAREA area

Figure 12-19 ACB macro parameter NOTES:

Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -21 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

ACB MACRO PARAMETER (CONT)


KEYWORD FOR BUFFERS BUFND = n1 BUFNI = n2 BUFSP = s STRNO = n3 BSTRNO = n4 Keywords for catalogs PASSWD = address n1 = # I/O buffers used for data component Cis n2 = # I/O buffer used for index components Cis s = maximum number of bytes for all data and index buffers n3 = max number of request required concurrent data-set positioning n4 = # strings accessing the base cluster of the path Names a field that contains the highest-level password required for type of access specified in MACRF Specifies whether catalog is being Opened as a catalog (YES) or as a dataset(NO); default is NO Requests system or user storage be Used when processing a catalog recovery area

CATALOG = NO | YES CRA = SCRA | UCRA

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 or DOS DLBL statement that in turn identifies the VSAM data set to be processed and their anticipated logical record accessing modes. The other options may be specified in an ACB are the buffer space requirements for reading and writing CONTROL INTERVALS and the address of the EXLST Macro that pertains to this ACB. If needed password also can be specified.

Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -22 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

ACB MACRO PARAMETER (CONT..)


MACRF-Options For Data Set Access KEY | ADR | CNV SEQ | DIR | SKP IN | OUT NRM | AIX Keyed addressed, or control-interval Access Sequential, direct or skip-sequential Access IN means retrieval only; OUT means Loading or updating NRM means process the object named by DDNAME = ; AIX means Process the alt index whose path is named by DDNAME = NRS: not a reusable data set, or else do not set high-RBA to zero; RST: reset high-RBA of reusable data set to zero

NRS | RST

Figure 12-21 ACB Macro summary continue NOTES:

Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -23 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

ACB MACRO PARAMETER (CONT)


Macrf-options for performance improvement NUB | UBF NFX | CFX NCI | ICI NIS | SIS Macrf-options for shared resources NSR | LSR |GSR NDF | DFR DDN | DSN Non shared locally shared or Globally shared resources nondeferred or deferred writing Of shared buffers Shared control blocks are based on ddnames / dsnnames Whether or not user program Manages use of I/O buffers Whether or not buffers and control blocks are swappable Whether or not to use improved Control-interval processing whether or not to split control

Figure 12-22 ACB Macro summary continue NOTES: Permission to process a VSAM data set must be requested at run time by an OPEN macro. The macro must in turn specify the address of an ACB macro by describes the anticipated processing requirement. All the accessing mode that are going to used while the data set is being processed must be specified in the ACB macro.

Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -24 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

RPL MACRO PARAMETERS


General format rpl name RPL keyword1 = value1,.keywordn = valuen Keywords commonly used AM = VSAM ACB = acbname AREA = areaname AREALEN = m ARG = fieldname States that the access method is VSAM Identifies the associated ACB Control block Identifies the work area for logical Records in move mode m is the length of work area, and should be no less than the length of the longest record to be processed Identifies the field that contains the search key or RBA used in direct and skip-sequential access, and in positioning k is the length of the generic key used when OPCTD = GEN r is the length of the record that PUT Adds or inserts Specifies options for run-time processing

KEYLEN = k RECLEN = r OPTCD = (optcd-options) Figure 12-23 Rpl macro parameters NOTES:

The RPL Macro must be referred to each time any macro other than the OPEN or CLOSE (or GENCP) is executed at run time. The basic options specified in an RPL are these: the name of the ACB that the RPL is associated with; the address and length of the I/O record work area; the record accessing mode to be used for a particular request; the address of the search argument for direct accessing and for record positioning; and whether or not the request is for updating a record.

Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -25 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

KEYWORDS FOR ADVANCED APPLICATIONS


TRANSID=i ECB=address MSGAREA=address MSGLEN= length NXTRPL=address Is a number that identifies all the modified Buffers associated with a given transaction Identifies an event control block used with asynchronous Names an area to receive physical I/O error messages from VSAM Specifies the length of the MSGAREA area; Must be >= 128 Specifies the address of the next RPL in a chain Of RPLs

Figure 12-24 Keywords for advanced applications NOTES:

Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -26 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

OPTCD-OPTIONS
KEY | ADR | CNV SEQ | DIR | SKP MVE | LOC NUP | UPD | NSP KEQ | KGE Keyed, addressed, or control-interval access Sequential, direct, or skip-sequential access Move mode or locate mode Is not for update, is for update, or note sequential position With keyed access, find the first record with a key that is either equal to, or greater than or equal to, the search key Specifies whether the search key is a full key or a generic key Record accessing is either in the forward or the backward direction; if BWD, then KEQ and FKS are assumed

FKS | GEN FWD | BWD

Figure 12-25 OPTCD - OPTIONS NOTES: Defaults for all optcd-options are specified above as the first choice each group of two are three options.

Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -27 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

OPTCD-OPTIONS (CONT)
ARD | LRD ARD: record accessing is as specified in other parameters; LRD: locate or retrieve the last record in the data set (BWD) Synchronous or asynchronous accessing Specifies whether or not to give control to the users UPAD error-exit routine to synchronize processing of shared resources

SYN | ASY NWAITX | WAITX

Figure 12-26 OPTCD OPTIONS NOTES:

Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -28 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

THE DEFINE COMMANDS


The AMS DEFINE command must be used to create a new catalog and must be used to create an entry in an existing catalog for any VSAM object. There are seven variations of this command, corresponding to the seven VSAM objects: In full DEFINE MASTERCATALOG DEFINE USERCATALOG DEFINE SPACE DEFINE CLUSTER DEFINE NONVSAM DEFINE ALTERNATEINDEX DEFINE PATH
Figure 12-27 The DEFINE Command. NOTES: The methods of space allocation that seem to the author to be appropriate for most applications 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 and alternate 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 to request space for an alternate index.

abbreviated DEF MCAT DEF UCAT DEF SPC DEF CL DEF NVSAM DEF AIX DEF PATH

Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -29 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

DEFINE CLUSTER

General Format DEFINE CLUSTER(cluster options) DATA (data options) INDEX (index options) CATALOG (catalog options)

Figure 12-28 DEFINE CLUSTER NOTES:

Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -30 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

CLUSTER OPTIONS
NAME (entry name) VOLUME (volser) CYL (p s) |TRK (p s)|REC (p s) Specifies the name of the cluster Identifies the volume where the Cluster will reside Specifies the amount of space to be Allocated; p is the primary allocation, the secondary Identifies the DD or DLBL statement linked to the cluster NONINDEXED means its an ESDS; INDEXED means its a KSDS Specifies whether or not it is a Reusable data set Specifies whether the data set shares a Suballocatable data space or is allotted (KSDS only) specifies whether or not to Imbed the index sequence Set

FILE (dname) NONINDEXED | INDEXED NOREUSE | REUSE SUBALLOCATION|UNIQUE NOIMBED|IMBED Figure 12-29 Cluster options NOTES:

Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -31 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

DEFINE CLUSTER PARAMETERS


Data options: NAME(entryname) RECSZ(avg max) CISZ(size) KEYS(length offset) FSPC(ci ca) Specifies the name of the data component Specifies the average and maximum length of data records Specifies the data component control Interval size For KSDS only, specifies the length of the primary key and its displacement from the Beginning of a record. For KSDS only, CI specifies the percent of space in each control interval and CA. The percent in each control area that Is to be left free when the cluster is loaded

Figure 12-30 DEFINE CLUSTER parameters. NOTES:

Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -32 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

DEFINE CLUSTER PARAMETERS (CONT..)


Index options(for KSDS only) NAME (entryname) CISZ( size) Catalog options Specifies the name of the index compo nent specifies the index component control Interval size

CATALOGNAME / PASSWORD Identifies the name of the catalog in which the cluster is to be defined and specifies the password (if any) required to update the catalog; the slash / between catalogname and password must be included if a password is specified

Figure 12-31 Define cluster parameters continue. NOTES:

Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -33 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

THE REPRO COMMAND


For OS system //STEP004 //STEPCAT //NEWDD //OLDDD // // //SYSPRINT //SYSIN EXEC DD DD DD DD DD PGM= IDCAMS DSN=SAMPLE.UCAT, DISP=SHR DSN=DORM.FILE,DISP=OLD VOL=SER=VOLB,UNIT=3330,DISP=(OLD,KEEP), DSN=DORM.FILE,DSORG=PS, DCB=(RECFM=FB,LRECL=106,BLKSIZE=4036) SYSPRINT=A *

/*

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 records obtained from a non-VSAM dataset. The VSAM dataset that is loaded by REPRO must have been previously defined by the DEFINE command. The sequential is the input to the REPRO command and the output is a KSDS cluster.

Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -34 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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 is to 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 its data or index component names.

Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -35 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

LOADING A VSAM DATASET


1 CREATE CSECT 2 ... STANDARD ENTER NOT SHOWN 3 * 4 * INITIALIZATIONS 5 * 6 OPEN (MASTER) OPEN VSAM MASTER FILE 7 LTR 15,15 SEE IF OPEN WAS SUCCESSFUL 8 OPEN (TRANS, (INPUT)) IF NOT, TERMINATE, 9 * DOS ******** 10 * OPEN TRANS 11 **************** 12 GET TRANS,INAREA GET FIRST TRANSACTION RECORD 13 BAL 14,CONSTRUCT BEGIN CONSTRUCTING FIRST OUTPUT RECD 14 * 15 * MAIN PROCESSING 16 * 17 READ GET TRANS,INAREA GET NEXT TRANS RECD 18 * 19 WRITE PUT RPL=LOADIT MOVE OUTPUT RECD TO OUTPUT BUFFER 20 LTR 15,15 SEE IF ANY I/O ERRS 21 BNZ EOJK IF SO, TERMINATE 22 BAL 14,CONSTRUCT BEGIN CONSTRUCTING, NEXT OUTPUT RECD Figure 12-34 Loading a VSAM dataset. NOTES:

Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -36 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

LOADING A VSAM DATASET (CONT)


23 * 24 * 25 * END-OF-DATA PROCESSING 26 * 27 EOJ PUT RPL=LOADIT MOVE LAST OUTPUT RECD TO OUTPUT BUF. 28 EOJX CLOSE (MASTER) CLOSE ALL FILES 29 CLOSE (TRANS) 30 * DOS ******** 31 * CLOSE TRANS 32 ******************* 33 STDXIT . . . STANDARD EXIT NOT SHOWN 34 * 35 * OS DCP AND DOS DTFCD FOR TRANS FILE ARE ALSO THE SAME , AS ARE THE INPUT 36 * RECORD AREAS FOR THE TRANS AND MASTER FILES. BUT OS DCP AND DOS DTCST 37 * FOR MASTER FILE ARE REPLACED BY THIS VSAM ACB / RPL PAR 38 * 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:

Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -37 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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 and accessed by key. The key is known as Alternate key, to distinguish it from the prime key of KSDS cluster

Copyright MCPL. Unit12. VSAM (Virtual Storage Access Method) 12 -38 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

Student Notebook

UNIT 13: ASSEMBLER CONCEPTS


Objectives: Fundamentals of the assembly process Assembler tables Assembler processing logic The object module Table searching Sorting tables

Cross-references

Copyright MCPL.

Unit 13. Assembly Concepts Page 13 Courses may not be reproduced in whole or in part Without the prior written permission of MCPL.

Student Notebook

ASSEMBLER INPUT AND OUTPUT

dd Source sss Module

Object module Assembler Program Listing

Figure: 13-1 Assembler input and output NOTES: The machine language representation of source module is produced by the assembler and stored in an object module. Assembler produces a listing that correlates the source and object module contents and provides certain diagnostic information.

Copyright MCPL.

Unit 13. Assembly Concepts Page 13 Courses may not be reproduced in whole or in part Without the prior written permission of MCPL.

Student Notebook

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 related information. For a two pass assembler, a symbol must be defined prior to its occurrence in an EQUs operand. The assembly processes depend on the information represented in tables. Some of 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 in later sections.

Copyright MCPL.

Unit 13. Assembly Concepts Page 13 Courses may not be reproduced in whole or in part Without the prior written permission of MCPL.

Student Notebook

ASSEMBLER TABLE AND FILE USAGE

Opcode table PASS 1 Source Module P R O C E S S I N G Directive table ESD Symbol table TXT Literal table Base register table 2 P R O C E S S I N G Listing PASS Object module

RLD

Intermediate file

Figure: 13-3 Assembler table and file usage NOTES:

Copyright MCPL.

Unit 13. Assembly Concepts Page 13 Courses may not be reproduced in whole or in part Without the prior written permission of MCPL.

Student Notebook

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 of symbols, 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 relatively easy to locate and process. the simplest form of the table is single dimensional integer array in which each integer is an entry of the table. Table entries contain more than one data item; among the items is a key that identifies the entry.

Copyright MCPL.

Unit 13. Assembly Concepts Page 13 Courses may not be reproduced in whole or in part Without the prior written permission of MCPL.

Student Notebook

ASSEMBLER PROCESSING REQUIREMENTS


Directives: CSECT, DSECT, ENTRY, EXTRN, USING, DROP, DC, DS, EQU, END Data-type codes: C- , X- , F - , A- and VProcedures: SAVE + 4 Listing

Figure 13-5 NOTES:

Assembler processing requirements

Assembler is complex program written in assembley language that requires number of statements, instruction codes, instruction formats and base registers to handle the users source module. In IBM 360 and 370, there are 150 instruction codes, 50 directives, 7 instruction formats and 15 data type codes. But frequently used are mentioned above.

Copyright MCPL.

Unit 13. Assembly Concepts Page 13 Courses may not be reproduced in whole or in part Without the prior written permission of MCPL.

Student Notebook

OPCODE TABLE

5bytes Mnemonic opcode opcode A EBCDIC AD


ADR AE AER AH AL ALR AP

1 byte Machine opcode hex 5A 6A 2A 7A 3A 4A 5A 1E FA

1 Byte Mask Instr Field Hex Type 0 1 hex 0 1 0 0


0

0 0 0 0 0

0 1 1 0 6

Instr length hex 10 10 01 10 01 10 10 01 11

1 Byte

Flags binary 000000 001000 001000 001000 001000 000000 000000 000000 010000

XR ZAP

17 F8

0 0

0 6

01 11

000000 010000

Figure: 13-6 OPCODE table format NOTES:

Copyright MCPL.

Unit 13. Assembly Concepts Page 13 Courses may not be reproduced in whole or in part Without the prior written permission of MCPL.

Student Notebook

OPTCODE TABLE FORMAT (CONT.)

Instruction type: 0 = RR 2 = RS 1 = RX 3 = SI 6 = SS2 Instruction length: 01 = 2 Bytes 10 = 4 Bytes, 11 = 6 Bytes

4=S 5 = SS1

Extended mnemonic Store clock Extended precision floating point Floating point Packed decimal Unused 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 the value of this field. Machine language opcode: 1-byte information of instructions type and length. Mask field: defines conditional branch instructions. Other information in a table represented by the 1-bit flag fields.

Copyright MCPL.

Unit 13. Assembly Concepts Page 13 Courses may not be reproduced in whole or in part Without the prior written permission of MCPL.

Student Notebook

DIRECTIVE TABLE

5 Bytes Mnemonic Directive CACTR CAGO CAIF CANOP CCNOP CCOM CCOPY CCSECT 1100 CTITLE CUSING CWXTRN CDC

3 Bytes Address of processing routine AL3(DIRACTR) AL3(DIRAGO) AL3(DIRAIF) AL3(DIRANOP) AL3(DIRCNOP) AL3(DIRCOM) AL3(DIRCOPY) AL3(DIRCSECT) AL3(DIRCXD) C AL3(DIRTITLE) ) AL3(DIRDC AL3(DIRUSING) C AL3(DIRWXTRN) X D

Figure: 13-8 Directive table format NOTES: Directive table is used to process the directives and to determine the given character string 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.

Copyright MCPL.

Unit 13. Assembly Concepts Page 13 Courses may not be reproduced in whole or in part Without the prior written permission of MCPL.

Student Notebook

SYMBOL TABLE

8 bytes Symbol

Value

4 bytes

| 2 bytes

| 2 bytes

| 1 byte | 1byte

Length attribute Statement number Control section number Relocatable / absolute indicator

Figure: 13-9 Symbol table NOTES:

Copyright MCPL.

Unit 13. Assembly Concepts Page 13 - 10 Courses may not be reproduced in whole or in part Without the prior written permission of MCPL.

Student Notebook

LITERAL TABLE

2 String length

variable length Source statment

Assembled length Address

Figure: 13-10 Literal table format NOTES: A Literal is entered in to the Literal table, when it is obtained from an instructions operand field in PASS1. Addresses are assigned to any literals in the table when an END or LSTORG directive is processed. In IBM 360 and 370 systems, the first address assigned to a literal is always on a Doubleword boundary.

Copyright MCPL.

Unit 13. Assembly Concepts Page 13 - 11 Courses may not be reproduced in whole or in part Without the prior written permission of MCPL.

Student Notebook

BASE REGISTER TABLE

1 Byte

3 Byte Base address

| 1 Byte

Base register Control section number

USING DROP

Base-address , base-register-1, base-register-2,.. 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. To allow for the designation of symbolic base registers and symbolic base addresses and entries are not made in this table until PASS2. USING directive causes an entry to be made in the table for each base register designated in its operand. DROP directive causes entries to be deleted. To compute a base displacement address corresponding to a relocatable symbolic address, the assembler chooses the base register whose base address is in the same control section as the symbolic address.

Copyright MCPL.

Unit 13. Assembly Concepts Page 13 - 12 Courses may not be reproduced in whole or in part Without the prior written permission of MCPL.

Student Notebook

INTERMEDIATE FILE

1 3 T y pe MLC

3 Op/dir entry address

| Source statement

variable length

Control section member

Statement type indicator d = directive

C = comment statement I = instruction

m = macro e = opcode error

Figure: 13-12 Intermediate table format NOTES: Each entry in the intermediate file is created in PASS1, PASS2. The sequence of the entries is the same as that of the statements in the source module. Each entry contains a copy of a source module statement plus some additional information determined in PASS1. It includes the MLC at the time the statement was processed.

Copyright MCPL.

Unit 13. Assembly Concepts Page 13 - 13 Courses may not be reproduced in whole or in part Without the prior written permission of MCPL.

Student Notebook

ASSEMBLER PROCESSING LOGIC PASS 1


The principal ideas in Pass 1 are: Comment statements are processed by simply putting an appropriate entry on the intermediate. Instructions must be aligned on a half-word boundary, literals and 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:

Copyright MCPL.

Unit 13. Assembly Concepts Page 13 - 14 Courses may not be reproduced in whole or in part Without the prior written permission of MCPL.

Student Notebook

ASSEMBLER PROCESSING LOGIC PASS 2


The principal ideas in Pass 2 are: The opcode and directive tables need not be searched because intermediate file consists information to describe the statement type. After creation of object code it is not directly written to the object module instead it is placed in TXT table. Out of ten directives only four is used they are END, DC, USING and DROP. The listing is created in pass 2 one line at a time as each statement is processed. Address constants created by DC directives and literals are accumulated in the RLD table to be written on the object module at the end of pass2.
Figure 13-14. Assembler processing logic pass 2 NOTES:

Copyright MCPL.

Unit 13. Assembly Concepts Page 13 - 15 Courses may not be reproduced in whole or in part Without the prior written permission of MCPL.

Student Notebook

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:

Copyright MCPL.

Unit 13. Assembly Concepts Page 13 - 16 Courses may not be reproduced in whole or in part Without the prior written permission of MCPL.

Student Notebook

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 two types linear search and binary search.

Copyright MCPL.

Unit 13. Assembly Concepts Page 13 - 17 Courses may not be reproduced in whole or in part Without the prior written permission of MCPL.

Student Notebook

LINEAR SEARCH
LINEAR_SEARCH: J := 1; REPEAT WHILE J <= Number of entries in table IF search-key = key of Jth entry of table THEN {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. Linear search is simple to implement but it is time-consuming when there are large number of entries in the table. Linear search requires half the time of the entries that is if there are N entries then average time is A(N/2).

Copyright MCPL.

Unit 13. Assembly Concepts Page 13 - 18 Courses may not be reproduced in whole or in part Without the prior written permission of MCPL.

Student Notebook

BINARY SEARCH
BINARY_SEARCH: {set initial group to entire table} LOWPT := 1; {first entry} HIPT := M; {number of entries in table} REPEAT WHILE LOWPT < HIPT MIDPT := integer portion of (LOWPT + HIPT)/2; {index of current middle} IF search_key = key of entry of table at position MIDPT THEN {key found in MIDPT entry} EXIT BINARY_SEARCH: ELSE IF search_key < key of entry of table at position MIDPT THEN 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 = HIPT THEN {one entry remains to be checked} IF search_key = key of remaining entry of table THEN {key found in MIDPT =/- entry} EXIT BINARY_SEARCH; END IF; END IF; {key not found} EXIT BINARY_SEARCH. Figure 13-18. Binary search NOTES:

Copyright MCPL.

Unit 13. Assembly Concepts Page 13 - 19 Courses may not be reproduced in whole or in part Without the prior written permission of MCPL.

Student Notebook

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.

Copyright MCPL.

Unit 13. Assembly Concepts Page 13 - 20 Courses may not be reproduced in whole or in part Without the prior written permission of MCPL.

Student Notebook

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 of instructions used in each iteration of the search procedure. The average search time using the Binary search technique B (log2/N)

Copyright MCPL.

Unit 13. Assembly Concepts Page 13 - 21 Courses may not be reproduced in whole or in part Without the prior written permission of MCPL.

Student Notebook

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 or more 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 of memory space. This is depending on the system, on the instructions used in the algorithm, how many entries are to be sorted and how badly out of sequence.
Copyright MCPL. Unit 13. Assembly Concepts Page 13 - 22 Courses may not be reproduced in whole or in part Without the prior written permission of MCPL.

Student Notebook

STRAIGHT INSERTION SORT

INSERTION_SORT REPEAT FOR j = 2 to n k = key from record j r = copy of record j i=j1 { 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+1 Subtract 1 from i END WHILE Move r to record i + 1 END FOR EXIT-INSERTION_SORT

Figure 13-21 Straight insertion sort. NOTES:

Copyright MCPL.

Unit 13. Assembly Concepts Page 13 - 23 Courses may not be reproduced in whole or in part Without the prior written permission of MCPL.

Student Notebook

OTHER SORT TECHNIQUES


EXCHANGE TECHNIQUES: Which interchange pairs of entries that are 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 so on. DISTRIBUTION TECHNIQUES

Figure 13-21 Other sort techniques NOTES: Merge technique, which combine two or more already sequenced subset of entries to produce a new sequenced subset and continue in this way until all the sequenced subsets have been merged into one, which is the final sorted table. Distribution technique, in which a portion of each is examined and the entries separated into subsets, one for each different value of key portion being examined. A different portion of key is then used and the process repeated, maintain the order of the entries that was established by the previous distribution. Continue this process until the final portion of the key has been examined. The final subset produced consists of all the entries in sequence.

Copyright MCPL.

Unit 13. Assembly Concepts Page 13 - 24 Courses may not be reproduced in whole or in part Without the prior written permission of MCPL.

Student Notebook

CROSS REFERENCES
SPACE CONSIDARATIONS: How many tables are there and how 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 all statements in which the symbol appears in an operand field, in order that they can be printed 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 dont know how many symbols there 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 in a table. Each list entry contains at least one field that is used in locating another entry of the list. The content of that field is called Pointer. POINTER can be an address or any other number that can be used in calculating an address.
Copyright MCPL. Unit 13. Assembly Concepts Page 13 - 25 Courses may not be reproduced in whole or in part Without the prior written permission of MCPL.

Student Notebook

CROSS REFERENCE LIST STRUCTURE


Statement number in which symbol is referenced 2 bytes Pointer to next entry for this symbol 2 bytes

# 1 5 2 6 3 8 4 11 5 12 6 15

2 5 6 0 4 0

save mainline array1 arrayfld a1 subr

Figure: 13-23 Cross-reference tables. NOTES: The entries would be place in cross reference table in pass2 of the assembler when the corresponding 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 reference for the same symbol.

Copyright MCPL.

Unit 13. Assembly Concepts Page 13 - 26 Courses may not be reproduced in whole or in part Without the prior written permission of MCPL.

Student Notebook

CROSS REFERENCE LIST STRUCTURE (CONT)


Suppose the assembler has determined the address of the symbol table entry for a symbol that 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 be used: 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 the first and last entry pointer fields, the reference counter is set to 1, and an entry made in the 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 the list. 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 are updated accordingly. The structure described for the cross reference data is known as a one way list or FIFO (first in, first - out).

Copyright MCPL.

Unit 13. Assembly Concepts Page 13 - 27 Courses may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTE BOOK

UNIT-14 INTERNAL SUBROUTINES


OBJECTIVES: Terminology Linkage Address Constants Parameters and Registers Modularization Multiple base Registers

Copyright MCPL. Unit 14. Internal Subroutines Page 14-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTE BOOK

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 computer program to perform some task of that request of that program. An internal subroutine is one whose statements are contained within the requesting program at assembly time. An external subroutine is one whose statements are assembled separately from the requesting program. Alternative names for the concept of a subroutine are subprogram and procedure.

Copyright MCPL. Unit 14. Internal Subroutines Page 14-2 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTE BOOK

TERMINOLOGY
Calling and called programs. Program P. Instructions and Data of Program P Called Program P calls Q Q returns to Ps re-entry point Program Q. Instructions and Data of Program Q. Calling Program

Sequence of Called Programs: P P calls Q Q Q calls R R returns to Q R

Q returns to P to P

Figure 14.2 Terminology NOTES: When a program requests that a subroutine perform its task, it is said to call that subroutine. The program making the request is known as the caller. The subroutine requested to perform the task known as the called program. The address of the first instruction executed by a subroutine when it is called is the subroutines entry point. The address of the instruction to which a subroutine branches is called is the subroutines entry point. A closed subroutine is one written in such a way that a single copy of it is all that is required, no matter how many places it is used in a program.

Copyright MCPL. Unit 14. Internal Subroutines Page 14-3 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTE BOOK

LINKAGE Calling a Subroutine Returning from a Subroutine RR type Branches BALs 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. In IBM 360 and 370 systems, there are two instructions that do this: an RR-type Branch and Link via register(BALR), and an RX-type Branch and Link (BAL) instruction. The RRtype BALR instruction will be needed when calling external subroutines. To use BAL, the subroutines central point is specified symbolically in second operand: BAL R1, Symbol BR 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 had been loaded into that register by the caller. Symbolically given below. BR R1 The subroutine can return to the re-entry point via a BR or other RR-type branch instruction provided both the BAL and the RR-type branch use the same register for the re-entry point address.1

Copyright MCPL. Unit 14. Internal Subroutines Page 14-4 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTE BOOK

ADDRESS CONSTANTS
Address is Basic to the use of Subroutines

1. If Z is defined in the name field of an instruction then LZ= 2,4 or 6. (2, 4, or 6 bytes) 2. If Z is defined in the name field of a DC or DS directive containing a Length modifier Ln, then LZ= n. 3. If Z is defined in the name field of a DC or DS directive not containing a length modifier then LZ is the length of the constant: LZ = 2 for H-type constants LZ = 4 for F-type constants etc.,

Figure 14.4 Address Constants NOTES: An A-type constant whose value is the value of LZ is specified simply as A (LZ).Address contains can contain more than one field separated by commas: for example A (X, Y, Z) is a same as three consecutive full word address constants, the first being 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 can contain one or more name-field symbols. In address constants, you use a left and right parenthesis rather than apostrophes to enclose the expression. A (X) instead of A X The length attribute of a symbol is the number of bytes that the assembler assign to the memory area associated with the symbol. Such as an instruction or a DC or DS directive.

Copyright MCPL. Unit 14. Internal Subroutines Page 14-5 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTE BOOK

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 a subroutine. The formal parameters are the ones that are referred to from within the subroutine so that 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 it is called. Two methods are given below. 1. The subroutine can specify symbolic address for its input data as well as for its output results. 2. The caller can specify either the address or the value of the parameters when it calls the subroutine, so that the subroutine doesnt need to specify symbolic address.

Copyright MCPL. Unit 14. Internal Subroutines Page 14-6 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTE BOOK

EXAMPLES OF INTERNAL SUBROUTINE PARAMETERS


INTERNAL SUBROUTINE with ASSEMBLYTIME Parameters INTERNAL SUBROUTINE with RUN TIME Parameters INTERNAL SUBROUTINE with ASSEMBLY TIME and RUN-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 3, STRING 0(3), C 14 3, 1(3) SKIPL R3 = ADDR OF STRING LOOK FOR BLANKS RETURN WHEN NON-BLANK FOUND ELSEE, ADVANCE TO NEXT CHAR

SKIP LA SKIPL CLI BNER LA B

Copyright MCPL. Unit 14. Internal Subroutines Page 14-7 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTE BOOK

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 routines To carry out the details. LEVEL 1: The initialization task in this problem need only consists of opening two Files: 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 in EBCDIC format, the task is accomplished in two steps: 1.Convert EBCDIC hex to internal binary format 2.Convert internal binary to EBCDIC decimal format. LEVEL 3 Our CVX and CVE subroutines are at LEVEL3 & the subroutines called by & ThemSKPBLK, HEXCHK, HEXCONare at LEVEL 4 LEVEL 4 LEVEL 5: We can put the I / O data areas, DCBs (or DTFs), and constants at LEVEL 5 Which are the lowest levels in our organization.

Copyright MCPL. Unit 14. Internal Subroutines Page 14-8 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTE BOOK

MULTIPLE BASE REGISTERS


Example of the using directive
MAIN CSECT STM 14,12,12(13) BALR 12,0 USING * , 12, 11, 10 BASE O L 11, BASE 1 L 10 , BASE2 B BEGIN BASE1 DC A(BASE0 + 4096) BASE1 DC A(BASE0 + 8192) BASE1 ST 13, SAVE + 4 LA 13 , SAVE . . .

Exactly 4096 Bytes

range of Reg 12

. .
18F

Exactly 4096 Bytes Up to 4096 Bytes

Range of Reg 11 range of Reg 10

SAVE

. DS END

Figure 14.8 Multiple Base Registers

NOTES:
The Using directive, Opcode USING operand B0, R0, R1, R2. Rn

Where B0 = symbol whose value is assumed by the assembler to be the base address in Register. Rx = address of any one of the general register.

Copyright MCPL. Unit 14. Internal Subroutines Page 14-9 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTE BOOK

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

Copyright MCPL

Unit 15. External Subroutines. Page 15 -1 Courses may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTE BOOK

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 that Subroutine. The program making the request is known as the calling program, whereas the subroutine requested 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 as the subroutines entry point. Correspondingly, the address of the instruction to which a subroutine branches when it returns to a calling program is known as the calling programs reentry point. The Linkage requirements are:1) Passing the values of the parameters, 2) Passing the address of the reentry point and 3) Branching to the entry point. The mechanism by which these requirements are met is known as the calling sequence.

Copyright MCPL

Unit 15. External Subroutines. Page 15 -2 Courses may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTE BOOK

ADDRESSING AND ADDRESS CONSTANTS

Assembly-Time versus Run-Time Address Internal versus External Addresses Program Ps Instructions And data 0 4 8 C

0 8 C

10 14 18 20

10 14

program Qs instructions and data

1C

Np

Nq

Addresses assigned by the assembler to program P

Addresses assigned by the assembler 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 will be no conflict when they are run because their respective addresses can be mapped into different real memory address. The addresses assigned to a program at assembly time are internal to that program. The addresses that are internal to one program are external to all other programs.

Copyright MCPL

Unit 15. External Subroutines. Page 15 -3 Courses may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTE BOOK

ADDRESSING AND ADDRESS CONSTANTS (contd.)


0 4 8 C 10 14 Np Np+4 Np+8 Resolving Address Conflicts Specifying external Addresses

Program

Program Q

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. It produces what is known as a load module. An External address Constant symbolically specifies an address that is in some other program than the one in which it is specified. Register 13 and Save area: The contents of Register 13 must be saved and since they will be needed when restoring the other register contents, they had better be saved in an area from which they can be recovered prior to returning to the calling program.

Copyright MCPL

Unit 15. External Subroutines. Page 15 -4 Courses may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTE BOOK

LINKAGE CONVENTIONS
P CSECT STM 14,12,12(13) BALR 12,0 USING *, 12 ST 13,SAVE+4 LA 13,SAVE . . . LA 1,=A(X,Y,) L 15, = V(Q) BALR 14,15 . PEXIT L 13,SAVE+4 LM 14,12,12(13)

CSECT STM 14,12,12(13) BALR 12,0 USING *, 12 ST 13,SAVE+4 LA 13,SAVE . . . LA 1, =A(X,Y,) L 15, = V (Q) . .

QEXIT L 13,SAVE+4 BR 14,

Figure: 15-4 Standard linkage convention. NOTES: Every Program, be it a called or calling program, begins and ends its execution in the same manner. The value of the parameters and the address of the result areas are passed indirectly through register one.

Copyright MCPL

Unit 15. External Subroutines. Page 15 -5 Courses may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTE BOOK

PASSING PARAMETER ADDRESS THROUGH REGISTER 1.


LA 1,=A(X,Y,Z,)

Addresses assigned to X R1 OF PARAMETER


ADDRESSES ADDRESS OF TABLE

Area allocated for Z Area allocated for X Area allocated for Y

Addresses assigned to Y Addresses assigned to Z

Figure: 15-5 Passing parameter addresses through Register 1. NOTES:

Copyright MCPL

Unit 15. External Subroutines. Page 15 -6 Courses may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTE BOOK

PASSING VALUES OF PARAMETERS.


Parameter address table Accessing the Parameter Address Table

Figue: 15-6 Passing values of parameters. NOTES: The Linkage conventions method of passing parameters to an external subroutine is different from that of internal subroutines. What is passed to an external subroutine is the address of the table., not the values of the parameters, not the addresses of the parameters, 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 register contents and the callers SAVE area address is one that will obtain one or more parameter addresses from the table. For example, to copy the first parameter address into Register 2, this instruction is sufficient: L 2,0(1) To copy the first two parameter addresses into register 2 and 3, respectively, these two instructions can be used: L 2,0(1) L 3,4(1) Or this single instruction can be used: LM 2,3,0(1)

Copyright MCPL

Unit 15. External Subroutines. Page 15 -7 Courses may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTE BOOK

RESTORING REGISTERS WHEN RETURNING FROM A SUBROUTINE. To restore all registers: L 13, SAVE + 4 LM 14, 12, 12(13) BR 14 to restore all but register 15: L 13, SAVE + 4 L 14,12(13) LM 0, 12, 20(30) BR 14

To restore all but register 0: L 13, SAVE + 4 LM 14, 15,12(13) LM 1,12,24(13) BR 14

to restore all but 0 and 15: L 13,SAVE + 4 L 14,12(13) LM 1,12,24(13) BR 14

Figure.15-7 Restoring registers when returning from a subroutine. NOTES: The act of restoring the calling programs Register 0 and/or Register 15 contents would void 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).

Copyright MCPL

Unit 15. External Subroutines. Page 15 -8 Courses may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTE BOOK

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 someone else. If the subroutines method of return is clear to both persons, neither has to investigate the details of the others program. 2) The passing of parameters is done in a single consistent manner, whether the data and results are integers, characters, or of any other type or length. 3) If all compilers generate the same standard code for the equivalent of the subroutine call and return operations, then programs written in Fortran, Cobol, and other high level languages 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 program from one computer installation to another, if the same conventional methods are used at both sites.

Copyright MCPL

Unit 15. External Subroutines. Page 15 -9 Courses may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTE BOOK

ENTRY, EXTRN, COM, AND DSECT DIRECTIVES


MAIN CSECT EXTRN VABS STM 14,12,12(13) . . . L 15,= A(VABS) BALR 14, 15 . . . CSECT ENTRY VABS EQW SUB1 STM 14,12,12(13) . . . identifies entry point in another source module A-type constant used when external symbol identified via EXTRN

SUB1 VABS

ENTRY defines VABS to be an additional entry point;

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 EXTRN The EXTRN directive essentially declares that symbol or symbols in its operand field represent external addresses. When EXTRN is used to identify an external symbol, the symbol is referenced with an A-type constant: when EXTRN is not used, the symbol is referenced with a V-type constant.

Copyright MCPL

Unit 15. External Subroutines. Page 15 -10 Courses may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTE BOOK

COMMON ADDRESSES: COM


MAIN CSECT STM 14,12,12(13) BALR 12,0 USING *, 12 ST 13, SAVE+4 LA 13,SAVE L 11,=A(COMMON) USING COMMON, 11 . . L 15,=V(ABS) BALR 14,15 . . SAVE DS 18F COM COMMON DS 0F N DS F K DS 100F . ABS CSECT . . . USING COMMON, 11 . . DS COM DS DS DS 18F 0F F 100F

LOOP SAVE COMMON N K . . .

Identical statements Figure: 15-10 Illustration of COM. NOTES: An area of memory common to all the programs can be defined. Parameters, data, and results can be stored into and loaded from this area by any of the programs, as though the area were internal each program. By using this technique, one can avoid passing parameters and using V-type or EXTRN / A-type constants.

Copyright MCPL

Unit 15. External Subroutines. Page 15 -11 Courses may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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

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.

STUDENT NOTEBOOK

A QUESTION OF ACCURACY Fractional representation of a mixed decimal number can be represented as a sequence of decimal digits, 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 many
threes as we place in order to better approximate the rational fraction 1/3 .A fixed upper limit on the number of digits that can be accommodated is imposed by the hardware and software .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 incorrectly represented 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 what the value of D is.

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.

STUDENT NOTEBOOK

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.q1q2qm .the value of the number can be expressed in J = p1 x P 1 + p2 x P 2 ++ pk x P k J = q1 x Q 1 + q2 x Q 2 ++ qm x Q m (old system) (new system) or

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 computed as 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 be computed 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, the required calculations depend on whether they are done in the base P system(the old base) or in the base Q system.

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.

STUDENT NOTEBOOK

REPRESENTATION OF MIXED NUMBERS


Binary representation
XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX Sign bit Integer portion Fractional portion 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 low order bits be used for the fractional portion and the remaining high order bits for the sign and integer portion . The implied position of the binary point would have to be explicitly adjusted arithmetic shift instructions to retain the accuracy in multiplication or division . via

Decimal representation is done with a method of representation known as packed decimal format. In this format , integers and mixed numbers are represented as decimal integers .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 .

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.

STUDENT NOTEBOOK

FLOATING - POINT REPRESENTATION

K bits ( K= p + n + 1) p P bits Sign bit Exponent bits n nnnnn n bits Fraction bits nnnn

Figure 16-4 Floating point Representation

NOTES :
The most common method of representing mixed numbers in computers is known as the floating-point method. In this method, numbers are represented and processed as a fraction times a scale factor. The base of the scale factor is usually a power of two, say 2m,rather than ten. Generally preferred form of fraction is with its leading bit nonzero. This is known as the normalized form of the fraction. Exponent part can be represented in 3 ways. One way is to use the exponent bit as its sign bit and to represent the exponent in sign-magnitude form. Another way is to represent the exponent in p-bit twos complement form. A third way is to represent an exponent m by an unsigned binary integer, q + m. This is known as excess-q notation.

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.

STUDENT NOTEBOOK

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 cannot be represented in the number of bits allowed. If the magnitude of the number is too large for the range permitted, the condition is called overflow. If the magnitude of the number is too small for the range, the condition is called underflow. In Floating point addition and subtraction, if the resulting fraction is 0 but the exponent isnt ,all significant bits have been lost and the condition is termed a significance error .

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.

STUDENT NOTEBOOK

UNIT 17: PACKED-DECIMAL OPERATIONS


OBJECTIVES: Data Formats Instruction Formats Arithmetic Operations Comparisons

Copyright MCPL. Unit 17.Packed-Decimal operations Page 17-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

PACKED DECIMAL OPERATIONS


Packed Decimal Format Representation of Fractions : Decimal System Binary System Inherent Errors Decimal System Binary System 10 * 0.1 = 1.0 (1010) * (0.0001100110011001..) = 0.1111111.. 0.75 = 7 * 10^-1 + 5 * 10^-2 0.11 = 1 * 2^-1 + 1 * 2^-2

Figure 17-1 Packed decimal operations NOTES: The IBM 360 and 370 systems provide a capability for Decimal integer arithmetic based 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 EBCDIC format to store simple integers. To provide a method of processing decimal fractions without the loss of accuracy that could occur if they were processed as binary numbers. Avoid the Inherent errors.

Copyright MCPL. Unit 17.Packed-Decimal operations Page 17-2 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

DATA FORMATS
Decimal digit 0 1 2 3 4 5 6 7 8 9 Packed-Decimal representation 0000 0001 0010 0011 0100 0101 0110 0111 1000 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 by Right most 4-bits. Figure 18-2: Data formats NOTES: Packed-Decimal number is always represented in an integral number of bytes. The Number 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.

Copyright MCPL. Unit 17.Packed-Decimal operations Page 17-3 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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 <= 16 With 1 <= L2 <= 16 Length field

Figure 17-3 Instruction formats NOTES: SS1 type instruction has two operand fields each specifies the memory address of the data being operated on, and the length of each data item is specified in the first operand. 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

Copyright MCPL. Unit 17.Packed-Decimal operations Page 17-4 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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:

Copyright MCPL. Unit 17.Packed-Decimal operations Page 17-5 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

ZERO AND ADD PACKED


ZAP D1( L1 , B1 ) , D2( L2 , B2 ) Address and length of source Address and length of destination Padding: ZAP 0023456C B(8) , A(4) A B

Before execution : 0023456C any 8 bytes After execution: 0023456C 00000000

*L1 L2 = 4 = number of bytes of leading zeroes Overflow: ZAP B(2) , A(4) A Before execution : 0023456C After execution : 0023456C B any 2 bytes 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 location to another, after filling the destination area with zeroes. When L1 > L2 , the result in the destination area will contain at least L1 L2 bytes of leading zeroes. If L1 < L2 , and if there is not enough room in the destination area to accommodate all the significant digits of the number in the source field , a decimal overflow occurs.

Copyright MCPL. Unit 17.Packed-Decimal operations Page 17-6 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

ADD PACKED (AP)


AP D1( L1 , B1 ) , D2( L2 , B2 ) Address and length of source Address and length of destination X1 AP X1(3) , Y1(2) Before execution : 03214C After execution: 03224C Y1 010C 010C

X2 AP X2(2) , Y2(3) Before execution : After execution: 099C 100C

Y2 00001C 00001C

Figure 17-6 AP NOTES: This instruction is executed; the number whose address and length are specified by the second operand is algebraically added to the number whose address and length are specified by the first operand. The sum replaces the number specified by the first operand, and the condition code is set to 0 , 1 or 2 when the sum is 0 , negative or positive respectively.

Copyright MCPL. Unit 17.Packed-Decimal operations Page 17-7 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

SUBTRACT PACKED (SP)


SP D1( L1 , B1 ) , D2( L2 , B2 ) Address and length of source Address and length of destination X1 SP X1(3) , Y1(2) Before execution : 03214C After execution: 03224C Y1 010C 010C

X2 SP X2(2) , Y2(3) Before execution : After execution: 099C 100C

Y2 00001C 00001C

Figure 17-7 SP NOTES: This instruction is executed; the number whose address and length are specified by the second operand is algebraically subtracted from the number whose address and length are specified by the first operand. The result replaces the number specified by the first operand, and the condition code is set to 0 , 1 or 2 when the result is 0 , negative or positive respectively.

Copyright MCPL. Unit 17.Packed-Decimal operations Page 17-8 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

MULTIPLY PACKED (MP)


MP D1( L1 , B1 ) , D2( L2 , B2 ) Multiplier Multiplicand V1 MP V1(4) , W1(2) Before execution : 0000999C After execution: 0998001D W1 999D 999D

V2 MP V2(2) , W2(3) Before execution : After execution: 00999C 98001D

W2 999D 999D

Figure 17-8 MP NOTES: This instruction is executed; the number whose address and length are specified by the first operand is multiplied by the number whose address and length are specified by the second operand. The result, its sign determined by the rules of algebra, replaces the multiplicand in memory but the condition code is not set.

Copyright MCPL. Unit 17.Packed-Decimal operations Page 17-9 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

DIVIDE PACKED (DP)


DP D1( L1 , B1 ) , D2( L2 , B2 ) Divisor Dividend L1 bytes Dividend field before division Dividend field after division Quotient L1 L2 bytes dividend remainder L2 bytes

Figure 17-9 DP NOTES: This instruction is executed; the number whose address and length are specified by the first operand is divided by the number whose address and length are specified by the second operand. The result consists of two components: integer quotient, of length L1 L2 bytes And the integer remainder, of length L2 bytes.

Copyright MCPL. Unit 17.Packed-Decimal operations Page 17-10 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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) Ressult:V1>V2 012C V1 CP V1(3) , V2(2) Ressult:V1 = V2 00345C V1 CP V1(4) , V2(1) Ressult:V1 < V2 1234567D 00345D V2 345C V2 0C

Figure: 17-10 Comparisons NOTES: Two Packed-Decimal numbers can be algebraically compared without changing either number, it accomplished by means of Compare Packed (CP) instruction, a SS2 type instruction. The condition code sets as follows: If condition is V1 = V2, condition code = 0 If condition is V1 < V2, condition code = 1 If condition is V1 > V2, condition code = 2

Copyright MCPL. Unit 17.Packed-Decimal operations Page 17-11 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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

Copyright MCPL. Unit 18.Floating-Point Operation Page 18-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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:

Copyright MCPL. Unit 18.Floating-Point Operation Page 18-2 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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 Alignment Use of scale and exponent modifiers, Sn and En Scale modifier Sn is used only when we want to create an normalized floating-point number. Exponent modifier En can be used to express the constant in scientific notation.

Copyright MCPL. Unit 18.Floating-Point Operation Page 18-3 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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 an appropriate floating-point register address. In RR-type floating-point instructions, both operands must designate appropriate floating-point register addresses.

Copyright MCPL. Unit 18.Floating-Point Operation Page 18-4 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

LOAD AND STORE OPERATORS


Opcode LE Meaning LOAD (short) Copies the short-format number v2 from memory Into the high-order 32 bits of the register Designated by the first operand field. The low order 32 bits of that register are not changed. LOAD (long) Copies the long-format number v2 from memory Into the register designated by the first operand. STORE (short) Copies the short-format number v1 from the high order32 bits of the register designated by the first operand to the memory location designated by the second operand. STORE (long) Copies the long-format number v1 from the register designated by the first operand to the memory location designated by the second operand.

LD

STE

STD

Figure: 18-4 Load and store operators NOTES:


V1 = the floating-point number whose address is designated by the first operand field in an instruction. V2 = the floating-point number whose address is designated by the second operand field in an instruction.

Copyright MCPL. Unit 18.Floating-Point Operation Page 18-5 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

ARITHEMATIC OPERATIONS
ADD SUBTRACT MULTIPLY DIVIDE HALVE ROUND

Figure 18-5 Arithmetic operations NOTES:

Copyright MCPL. Unit 18.Floating-Point Operation Page 18-6 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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 than 1664 2.Exponent underflow: occurs when the magnitude of a result is equal to or grater than 16-64 3.Significance Exception :Occurs when the mantissa of the intermediate sum or difference resulting from any add or subtract is less tans Zero. 4.Divide exception :Occurs when the mantissa of a division(v2) in any floating-point divide instruction is zero.

Copyright MCPL. Unit 18.Floating-Point Operation Page 18-7 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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 an eight-digit decimal number cannot in general be accurately represented in six available hex digits. 2. In converting from floating-point to integer format, the value of the integer cannot exceed 231-1 or less than -231

Copyright MCPL. Unit 18.Floating-Point Operation Page 18-8 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

COMPARING AND TESTING OF FLOATING-POINT


Example1. CE 0 , X V1 V2 Floating-point register 0 memory location X 450000C4 Result: V1=V2, i.e., 12.25=12.25 41C40000

Example2.

CDR 2 , 4

V1 V2 Floating-point register 2 Floating-point register 4 C96FAB5760000000

AF0000006FAB5760

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 sign operation on extended-precision numbers. None of these instructions can cause an exponent overflow.

Copyright MCPL. Unit 18.Floating-Point Operation Page 18-9 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

UNIT 19: COSMETIC DIRECTIVES


OBJECTIVES: EJECT TITLE SPACE PRINT OPSYN ISEQ ICTL

Copyright MCPL Unit19 Cosmetic Directives PAGE 19Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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 the listing and over certain aspects of the validity of source language statements will be referred 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)
Copyright MCPL Unit19 Cosmetic Directives PAGE 19Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL. 2

STUDENT NOTEBOOK

EJECT, TITLLE AND SPACE


EJECT: BEGIN A NEW PAGE Opcode operand EJECT BLANK TITLE: DEFINE A TITLE LINE FOR EACH PAGE Opcode operand a text string of up to 100 characters, enclosed in apostrophes SPACE: INSERT BLANK LINES Opcode operand TITLE a self-defining decimal term or blank TITLE

Figure 19 -2 EJECT, TITLE AND SPACE

NOTES:
An EJECT directive may appear anywhere in the source program and may be used any no.of times. It is not printed on the listing. Its purpose is to separate different portions of the 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 is not printed on the listing. The TITLE and EJECT directives should not be used in consecutive statements, since each one causes a skip to a new page. And two consecutive apostrophes or ampersands must 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 is not printed on the listing. The no.of blank line to be inserted is specified in the operand field either as a self-defining decimal term or as a blank. Copyright MCPL Unit19 Cosmetic Directives PAGE 19Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL. 3

STUDENT NOTEBOOK

PRINT
PRINT Opcode PRINT PRINT OPTIONS Keywords ON or OFF GEN or NOGEN operand one or more key words, separated by Commas meanings whether or not any lines following the PRINT directive are printed on the listing whether or not the statements generated in a macro expansion are Printed. whether the object code of a constant is printed in its entirely, or whether only only the first 8-bytes of each constants Object codes are printed.

DATA or NODATA

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 the PUSH directive is simply Opcode operand

To restore the key words of the most recently suspend PRINT directive, the format of the POP directive is

PUSH

PRINT

POP

PRINT
4

Copyright MCPL Unit19 Cosmetic Directives PAGE 19Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

OPSYN, ISEQ

OPSYN: DEFINE A NEW MNEMONIC OPCODE Name field Opcode operand an existing opcode blank

A new opcode OPSYN an existing opcode OPSYN

ISEQ: SOURCE-STATEMENT SEQUENCE CHECKING The format for initiating sequence checking is Opcode operand ISEQ P,Q The 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 the
properties of the code given in the operand field. The second format removes the opcode given 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 source module are in the sequence in which they were intended to be .The verification depends upon sequence numbers that the programmer has placed in the identification field of each source statement. The ISEQ directive is used in pairs; the first ISEQ of the pair initiates sequence checking, the one terminates it.

Copyright MCPL Unit19 Cosmetic Directives PAGE 19Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

ICTL ICTL: DEFINE NONSTANDARD STATEMENT FORMAT


The format for ICTL directive is Opcode ICTL ICTL ICTL operand b b, e b, e, c

Figure: 19 5 ICTL

NOTES:
There are two essentially different statement formats allowable in the IBM 360 and 370 Assembly language: standard format and non-standard format. If you wish to use a non standard format, the first statement of s source module must be an ICTL directive. In standard format, these three positions are defined as b = beginning position = position 1 e = ending position = position 71 c = continuing position = position 16 The letters b, e and c represent decimal integers whose values obey the following constraints: 1 < = b <= 40, 2 <= c < = 40, 41< = e <= 80 and b < c < e, b + 5 < = e.

Copyright MCPL Unit19 Cosmetic Directives PAGE 19Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

UNIT 20: PSEUDO OPS


OBJECTIVES: Control Sections CSECT START ORG LTORG END DSECT COM

Copyright MCPL.

Unit20.Pseudo-Ops. Pages20-1

Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL

STUDENT NOTEBOOK

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 subdivisions known as Control Sections: Executable and Reference Control sections. Executable control section can contain instructions, constants and data areas that initiated by CSECT or START directives. Reference control section contains neither instructions nor constants; it merely describes or reserves memory areas for use by executable control sections at run time that initiated by DSECT or COM directives. The Assembler maintains a separate memory location counter (MLC) for each control section in a source module. I.e. the address assigned to symbols defined in one control section are independent of the addresses assigned to symbols defined in any other control section. Therefore separate implied base register should be established for each of the control sections of a source module. Copyright MCPL. Unit20.Pseudo-Ops. Pages20-2

Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL

STUDENT NOTEBOOK

CSECT

Name Field Any symbol Or Blank

Opcode CSECT

Operand Blank

Figure 20-2 CSECT NOTES: The Control Section (CSECT) pseudo-op is used to specify the beginning of an executable control section in a source module. It must also be used to indicate the point at which 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 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. Unnamed sections cannot be referenced by other control sections.

Copyright MCPL.

Unit20.Pseudo-Ops. Pages20-3

Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL

STUDENT NOTEBOOK

START

Name Field

Opcode

Operand

Any symbol Or Blank

STARTS

A self defining term or blank

Figure 20-3 START NOTES: The START pseudo-op is used to denote the beginning of the 1 st executable control section in a source module. It is not as flexible as CSECT but it provides a clear-cut indication of where the 1 st executable section begins. The symbol in the name field is the symbolic name of the control section. Being initiated this 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. Unnamed sections cannot be referenced by other control sections The value of self-defining term in the operand designates the initial value for the memory location counter of the control section, by default is zero. START cannot be used to resume an executable control section.

Copyright MCPL.

Unit20.Pseudo-Ops. Pages20-4

Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL

STUDENT NOTEBOOK

ORG

Name Field Any symbol Or Blank

Opcode ORG

Operand A relocatable expression or blank

Figure 20-4 ORG NOTES: The Origin (ORG) pseudo-op instructs the assembler to change the value of the memory location counter of the control section in which the ORG occurs. If the operand field contains relocatable expression, the memory location counter set to the value of that expression. If the operand field is blank, the counter is said to be smallest address that has not been previously 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 location counter value that it replaces. If it is equal to that value there is essentially no effect other than 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 to redefine an area of the memory.

Copyright MCPL.

Unit20.Pseudo-Ops. Pages20-5

Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL

STUDENT NOTEBOOK

LTORG

Name Field Any symbol Or Blank

Opcode LTORG

Operand Blank

Figure 20-5 LTORG NOTES: The LTORG pseudo-op causes the assembler to assemble all the literal constants it has accumulated. I.e. assigned a memory location in the control section for the literal constant which 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 double word boundary. If there are more than one executable control sections in a source module, there should be a LTORG directive at the end of each of the sections. If the statements from different control sections are intermingled in the source module.

Copyright MCPL.

Unit20.Pseudo-Ops. Pages20-6

Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL

STUDENT NOTEBOOK

END

Name Field Any symbol Or Blank

Opcode END

Operand A relocatable expression or blank

Figure 20-6 END NOTES: The END directive indicates to the assembler that there are no more statements to be processed 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 is the first one of the first executable control section in the module. if the operands contains a relocatable expression , the value of that expression is the address of the first instruction to be executed. When the END directive is processed by the assembler, all control sections except the first executable section in the source module are terminated. Any literals remaining in the literal pool are then assembled into the first executable section, and that section is terminated.

Copyright MCPL.

Unit20.Pseudo-Ops. Pages20-7

Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL

STUDENT NOTEBOOK

DSECT

Name Field Any symbol Or Blank

Opcode DSECT

Operand Blank

Figure 20-7 DSECT NOTES:

Copyright MCPL.

Unit20.Pseudo-Ops. Pages20-8

Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL

STUDENT NOTEBOOK

COM

Name Field Any symbol Or Blank

Opcode COM

Figure 20-8 COM NOTES:

Copyright MCPL.

Unit20.Pseudo-Ops. Pages20-9

Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL

STUDENT NOTEBOOK

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

Copyright MCPL. Unit 21.Constants and Data Areas Page 21-1 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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 which they exists; this normal processing sequence can be altered by the use of certain directives. Control directives to denote the directives used to affect the outcome of conditional assemblies.

Copyright MCPL. Unit 21.Constants and Data Areas Page 21-2 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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 in the name field.

Copyright MCPL. Unit 21.Constants and Data Areas Page 21-3 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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 variables 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.

Copyright MCPL. Unit 21.Constants and Data Areas Page 21-4 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

GLOBAL AND LOCAL SCOPE OF ASSEMBLY VARIABLES


SOURCE CSECT GBLA &R LCLA &S LCLA & X, & Y .. MACRO . . GBLA &R LCLA &S LCLC &X . . MEND MACRO . . GBLA LCLA LCLC . . MEND 1

&R &S &X

3 . . . . END . END. 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 outside a macro. 3 = continuation of open code local scope of &x,&y and &s 4=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 Copyright MCPL. Unit 21.Constants and Data Areas Page 21-5 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

CONDITIONAL ASSEMBLIES: AIF, AGO, ANOP


General format of AIF, AGO, ANOP: Name Field Sequence symbol or blank sequence symbol Name Field Sequence symbol or blank Name Field Sequence symbol sequence symbol Opcode AIF Operand (Logical expression)

Opcode AGO

Operand Sequence symbol

Opcode ANOP

Operand Blank

Figure: 21 - 5.Conditional Assemblies. NOTES: AIF directive is used to cause the assembler to alter its normal statement-by-statement processing sequence, provided that the condition being tested is TRUE. AGO directive causes the assembler to alter its normal processing sequence by directing it to branch to another statement without testing any condition. ANOP directive provides a means of identifying a statement without causing any action to be taken by the assembler.

Copyright MCPL. Unit 21.Constants and Data Areas Page 21-6 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

SYSTEM VARIABLE SYMBOLS


Assigned by the assembler Value cant 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 EXEC command 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

Copyright MCPL. Unit 21.Constants and Data Areas Page 21-7 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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 assembly variable. A character expression can have one of two forms. It can be either a string enclosed in apostrophes 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)

Copyright MCPL. Unit 21.Constants and Data Areas Page 21-8 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

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 of subscripted assembly variables are of the same type and are assigned the initial values appropriate 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

Copyright MCPL. Unit 21.Constants and Data Areas Page 21-9 Course Materials may not be reproduced in whole or in part Without the prior written permission of MCPL.

STUDENT NOTEBOOK

UNIT: 22 I/O HARDWARE CONCEPTS Objectives: Magnetic tapes Magnetic disks Tape and disk comparison

Copyright MCPL. Unit 22. I/O Hardware Concepts Page 22-1 Course Materials may not be reproduced in whole or in part without the prior written permission of MCPL

STUDENT NOTEBOOK

MAGNETIC TAPE CONCEPT


Tape characteristic Tape capacity Tape blocksize
Data block Processed

About to be

inter data block record just gap processed

at rest here read/write head

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 surface pass under a stationary read/write head. The acceleration time is known as start time, is of order 10 milliseconds. The data-transfer time is of the order 100,00 to 500,000 bytes per second. The ratio of total gap space to the length of a tape provides a useful measure of the 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/ D Where L= Tape length in inches B= Blocksize in bytes D= Tape density in bytes per inch G= Gap space in inches Copyright MCPL. Unit 22. I/O Hardware Concepts Page 22-2 Course Materials may not be reproduced in whole or in part without the prior written permission of MCPL

STUDENT NOTEBOOK

MAGNETIC TAPE CONCEPTS (contd.)


Effect of blocksize on tape capacity (for 3600-foot reel with gap size inch) Capacity (no.of bytes) Blocksize 80 800 1600 3200 6400 800 BPI 5.76x106 23.0x106 27.6x106 30.7x106 32.5x106 1600 BPI 6.28x106 34.6x106 46.1x106 55.3x106 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

Copyright MCPL. Unit 22. I/O Hardware Concepts Page 22-3 Course Materials may not be reproduced in whole or in part without the prior written permission of MCPL

STUDENT NOTEBOOK

EFFECT OF BLOCKSIZE ON TAPE TRANSFER TIME


Transfer time overhead Blocksize
80 800 1600 3200 6400

T=2x103 ms/byte T=10x103 ms/byte


98.4% 86.2% 75.6% 60.1% 43.9% 92.6% 55.5% 38.5% 23.8% 13.5%

Overhead % given by S S+BxT x 100

where S=10 ms start time T=transfer rate 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.

Copyright MCPL. Unit 22. I/O Hardware Concepts Page 22-4 Course Materials may not be reproduced in whole or in part without the prior written permission of MCPL

STUDENT NOTEBOOK

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 of continuously rotating coaxial plates called disks. As with tape reels, each disk pack can be easily removed from the unit that houses it and be 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 the disks. 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.

Copyright MCPL. Unit 22. I/O Hardware Concepts Page 22-5 Course Materials may not be reproduced in whole or in part without the prior written permission of MCPL

STUDENT NOTEBOOK

COUNT DATA FORMAT: TRACK UTILIZATION FOR IBM 3330 DISK SYSTEM
N=number of Data blocks Per track 1 2 3 4 5 6 7 8 9 10 15 20 25 30 35 40 45 50 55 60 B=maximum possible Blocksize for the indicated number of Data blocks 13030 6447 4253 3156 2498 2059 1745 1510 1327 1181 742 523 391 303 241 194 157 128 104 84 Maximum number of bytes per track Percentage of maximum capacity 100 % 98.96 97.92 96.88 95.86 94.81 93.74 92.71 91.66 90.64 85.42 80.28 75.02 69.76 64.74 59.55 54.22 49.11 43.90 38.68

13030 12894 12759 12624 12490 12354 12215 12080 11943 11810 11130 10460 9775 9090 8435 7760 7065 6400 5720 5040

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 the table (22-5) should be chosen.

Copyright MCPL. Unit 22. I/O Hardware Concepts Page 22-6 Course Materials may not be reproduced in whole or in part without the prior written permission of MCPL

STUDENT NOTEBOOK

EFFECT OF BLOCKSIZE AND GAP SIZE ON ATTAINABLE TRACK CAPACITY IN IBM 3330

Area used for first 6447-byte data block

Area used for first 6450-byte data block

Area used for second 6447-byte data block

Gap
Not enough room for second 6450-byte block

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 the access time; this is equal to sum of the rotational delay time and seek time.

Copyright MCPL. Unit 22. I/O Hardware Concepts Page 22-7 Course Materials may not be reproduced in whole or in part without the prior written permission of MCPL

STUDENT NOTEBOOK

DATA TRANSFER OVERHEAD FOR IBM 3330 DISK SYSTEM Data transfer overhead Blocksize (Number of bytes) 13030 6447 4253 3156 2498 1181 742 523 391 303 241 Seek time 0 34.2 % 51.2 61.4 68.2 73.1 85.1 90.1 92.8 94.5 95.7 96.6 Seek time 10 ms (1 cyl) 52.3 % 69.7 77.7 82.5 85.6 92.6 95.2 96.6 97.4 98.0 98.4 Seek time Seek time 30 ms 55 ms (Pack avg) (worst case) 70.4 % 82.8 87.9 90.7 92.5 96.3 97.7 98.3 98.7 99.0 99.2 79.7 % 88.8 92.3 94.2 95.3 97.7 98.6 99.0 99.2 99.4 99.5

Figure: 22-7 Data-transfer overhead

NOTES:

Overhead =

(Access time) (Access time) + (Transfer time)

x100

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)

Copyright MCPL. Unit 22. I/O Hardware Concepts Page 22-8 Course Materials may not be reproduced in whole or in part without the prior written permission of MCPL

STUDENT NOTEBOOK

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, used by hardware in operating system to specify the data block size and certain other information. The data block and its count block are separated by a small gap; together known as data record. In count-keydata format, each data block is preceded by two blocks count block and a key block. The key block contains an alphanumeric character string, called the 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 all tracks are formatted in count-data format and 246,506 bytes if count-key-data format are used. Copyright MCPL. Unit 22. I/O Hardware Concepts Page 22-9 Course Materials may not be reproduced in whole or in part without the prior written permission of MCPL

You might also like