OS/390 Assembler Programming Introduction

© Copyright IBM Corp., 2000, 2004. All rights reserved.

OS/390 Assembler Programming Introduction
Unit: Assembler Language Overview Topic: Language Hierarchy
Assemblers
What are Assemblers? In the very early days programmers wrote in Machine Language. It was a slow, tedious and error prone process, only feasible for short and simple programs. To simplify the task of Programming and allow larger programs to be created, programs called Assemblers were created.
11010010 00001111 01000000 00001000 00011000 00011000

ASSEMBLER LANGUAGE

MVC PLACE 1, PLACE 2

Continued…
Concepts
© Copyright IBM Corp., 2000, 2004. All rights reserved.

Page 2 of 58

OS/390 Assembler Programming Introduction
Unit: Assembler Language Overview Topic: Language Hierarchy
Assemblers (cont’d)
Assembler allowed programmers to write in Assembler Language. Although an Assembler Language program had the same number of instructions as the equivalent machine program, writing Assembler program is much simpler. In Assembler Language, operations are represented by mnemonic codes (such as MVC for MOVE) and the data is represented by symbolic codes (such as PLACE1) rather than addresses.

11010010 00001111 01000000 00001000 00011000 00011000

SYMBOLIC NAMES

MENEMONIC CODE

ASSEMBLER LANGUAGE

MVC PLACE 1, PLACE 2

Continued…
Concepts
© Copyright IBM Corp., 2000, 2004. All rights reserved.

Page 3 of 58

OS/390 Assembler Programming Introduction
Unit: Assembler Language Overview Topic: Language Hierarchy
High Level Languages
What is a High Level Language? High Level Languages (HLL) go one step further than Assembler languages in simplifying the programming task. In a HLL, the program is expressed at a higher level of abstraction. An Assembler language program might contain five or ten times as many instructions as the same program written in a HLL.

COBOL
HLL (COBOL) ADD A TO B

PACKX,A PACKY,B AP X,Y UNPKB,X

(11110010.........) (11110010.........) (11111010......…) (11110011.........)

Continued…
Concepts
© Copyright IBM Corp., 2000, 2004. All rights reserved.

Page 4 of 58

OS/390 Assembler Programming Introduction
Unit: Assembler Language Overview Topic: Language Hierarchy
High Level Languages (cont’d)
Listed below are some examples of HLL: Fortran – first HLL language in general use, developed for scientific and general computing • COBOL – another early HLL, designed to facilitate the programming of business and commercial programs C – most popular in use today for a wide range of programming tasks C++ and Smalltalk – object oriented languages that are becoming increasingly popular

COBOL

ADD A TO B GIVING C

FORTRAN

C=A+B

C

C:=A+B; /*ADD A TO B*/

C**

- C:=A+B; //ADD A TO B

Continued…
Concepts
© Copyright IBM Corp., 2000, 2004. All rights reserved.

Page 5 of 58

OS/390 Assembler Programming Introduction
Unit: Assembler Language Overview Topic: Language Hierarchy
Advantages of HLL and Assembler Language
What are the advantages of HLL over Assembler Language? HLL is advantageous over Assembler Language because of the following reasons: • • Ease of development Portability
S/390 Assembler S/390 Processor S/400 Assembler AS/400 Processor

What is the advantage of Assembler Language? Assembler Language contains statements that correspond instruction by instruction to the Machine Language of the computer.

INTEL Assembler INTEL Processor

RS/6000 Assembler RS/6000 Processor

Concepts

© Copyright IBM Corp., 2000, 2004. All rights reserved.

Page 6 of 58

OS/390 Assembler Programming Introduction
Unit: Assembler Language Overview Topic: Language Hierarchy
Advantages of Assembler Language
Why program in Assembler Language? Assembler Language is chosen for programming because of the following reasons: • It provides extensive control of the hardware environment Assembler Language instructions correspond one-for-one with machine instructions making it possible to do anything the hardware allows
ASSEMBLER ADVANTAGES Control of environment

HLLs on the other hand, do not provide the programmer with extensive control of the hardware. The efficiency of a HLL program is subject to the way the compiler translates the HLL program.

Continued…
Concepts
© Copyright IBM Corp., 2000, 2004. All rights reserved.

Page 7 of 58

and in some cases may not translate it to produce the most efficient Machine Language.OS/390 Assembler Programming Introduction Unit: Assembler Language Overview Topic: Language Hierarchy Advantages of Assembler Language (cont’d) Assembler may also be considered when efficiency is a major concern. 2004. A compiler must be designed to translate all possible valid combination of HLL code. Page 8 of 58 . 2000. and a good Assembler programmer can achieve the maximum efficiency of Machine Language code. Assembler instructions are translated one-for-one into Machine Language. ASSEMBLER ADVANTAGES Control of environment Maximum efficiency Continued… Concepts © Copyright IBM Corp.. All rights reserved.

2004. Concepts © Copyright IBM Corp. Coding only those parts of a program which are executed frequently may achieve significant efficiency gains. Assembler coding is not done for a whole system or even a whole program. All rights reserved. but only for selected modules.OS/390 Assembler Programming Introduction Unit: Assembler Language Overview Topic: Language Hierarchy Advantages of Assembler Language (cont’d) It may not be necessary to code a whole program in Assembler Language to achieve the benefits of increased efficiency. Page 9 of 58 .. 2000. In many cases.

Page 10 of 58 . All rights reserved. The image is a program which is loaded into the memory in order to execute in the Assembler program space. it must be loaded into the memory or main storage area of the computer.. What does the program space consist of? A program space consists of: • Executable Machine Language instructions • Areas to store the program’s variable data • The program’s constant data • File definitions for use in Input/Output operations Machine Language Instructions Variable Data Constant Data File Definitions 10110010 8 BITS 1 BYTE Continued… Concepts © Copyright IBM Corp. 2000. 2004.OS/390 Assembler Programming Introduction Unit: Assembler Language Overview Topic: Assembler Program Components Program Execution What is an Image? ADDRESS SPACE In order for a program to execute.

Page 11 of 58 . and also for performing binary arithmetic. and can be used by any Assembler program when executing. counting for loops and many other purposes.OS/390 Assembler Programming Introduction Unit: Assembler Language Overview Topic: Assembler Program Components General Purpose Registers What are General Purpose Registers? The architecture of S/390 computers provides 16 General Purpose Registers (GPRs). GPRs are part of the hardware of the computer. 2000. 2004. All rights reserved. passing control and data from one module to another. What are the functions of GPRs? GPRs are very important to the Assembler programmer. They are used in addressing both instruction and data. GPRs are also used in conventional ways. ADDRESS SPACE Executable Instructions Constants General Storage Areas File Definitions I/O Areas Other General Purpose Registers 0 1 2 15 Continued… Concepts © Copyright IBM Corp..

.OS/390 Assembler Programming Introduction Unit: Assembler Language Overview Topic: Assembler Program Components General Purpose Registers (cont’d) Essentials of GPRs Effective management of GPRs is a basic skill required of the Assembler programmer. 2004. Page 12 of 58 . 0 1 2 3 15 Binary Arithmetic Address Values Concepts © Copyright IBM Corp. 2000. All rights reserved. It is important to know which registers are available and for what purposes specific GPRs must be reserved.

• • • Name used to refer to the data The format and size of the records and blocks within the dataset Types of instructions used to access the dataset and the current status of the dataset I/O Areas Concepts © Copyright IBM Corp. The DCB is created using a system macro instruction. The DCB is a special kind of data area. …. OUTFILE ….OS/390 Assembler Programming Introduction Unit: Assembler Language Overview Topic: Assembler Program Components Data Control Block Definition What is a DCB ? A file definition. All rights reserved.DCB INFILE ….. …. 2004. Page 13 of 58 . which maintains information about an external file. called a Data Control Block (DCB) must be created for each file the Assembler programmer wishes to access in a program. The DCB contains the following: File Definitions ADDRESS SPACE Executable Instructions Constants General Storage Areas File Definitions . 2000.

2004. the Assembler provides macro instructions. Continued… Concepts © Copyright IBM Corp. Page 14 of 58 . All rights reserved.. To help the programmer cope with such complex situations. 2000. A macro instruction is an instruction that is processed by the assembler to generate a group of Assembler instructions. However there are some situations where it is not feasible for the Assembler Language programmer to code at this detailed level.OS/390 Assembler Programming Introduction Unit: Assembler Language Overview Topic: Assembler Program Components Macro Instructions What are macro instructions? Assembler Language instructions generally correspond one-for-one with Machine Language instructions.

Page 15 of 58 . All rights reserved. The DCB macro instruction generates the various data areas and constants necessary to maintain information about an external file.OS/390 Assembler Programming Introduction Unit: Assembler Language Overview Topic: Assembler Program Components Macro Instructions Definition (cont’d) What are macro instructions? The I/O macro instructions like OPEN. PUT and ENTRÉE create multiple Assembler instructions to perform the specific I/O operation required. 2004. GET. Program Source Code Program Source Code BEGIN NEXT ENTREE MVC SR AR etc +BEGIN +BEGIN + + + + + + NEXT ENTREE STM BALR USING ST LA ST LR MVC SR AR etc Concepts © Copyright IBM Corp. CLOSE. The Assembler program only has to know how to handle I/O at a high level. 2000. The expansion of the macro instruction into multiple low level instructions generates the detailed level code..

Access Registers Vector Registers – Used for advanced math calculations Vector Registers Concepts © Copyright IBM Corp.. There are several registers in S/390 architecture. 2004. Page 16 of 58 . Floating .OS/390 Assembler Programming Introduction Unit: S/390 Memory Usage Topic: Hardware Components Registers What are registers? Registers are another location where operands reside in an Assembler Language program. Control Registers Control Registers and Access Registers – Used by the Operating System. All rights reserved. Types of registers in S/390 architecture are: • • • • • General Purpose Registers (GPRs) Floating Point Registers (FPRs) Control Registers Access Registers Vector Registers General Purpose Registers (GPRs) GPR – Used by the Programmer for Storage Address. Accumulator and Work Area.Point Registers (FPRs) FPR – Performs Floating Point Arithmetic. 2000.

483. numbered from 0-15.OS/390 Assembler Programming Introduction Unit: S/390 Memory Usage Topic: Hardware Components General Purpose Registers What are General Purpose Registers (GPRs)? General Purpose Registers GPRs are of the most interest to programmers. 0 R0 R1 R15 BITS 31 GPRs are used as: • Part of the address for all storage operands • As accumulators and work areas in performing fixed-point arithmetic 1 byte 1 byte 1 byte 1 byte Concepts © Copyright IBM Corp. The GPRs are 32 bits in length and can hold fixed-point values between -2. 147. R1. There are 16 general purpose registers (GPRs). 647. They are referred to with a prefix of R (R0. 2000. 147. Page 17 of 58 . 648. 483. R15). R2….. and +2. 2004. All rights reserved.

OS/390 Assembler Programming Introduction
Unit: S/390 Memory Usage Topic: Hardware Components
Program Status Word
What is a Program Status Word (PSW)? The Program Status Word is a hardware location where the current status of the Central Processing Unit (CPU) is represented. It is a register that is of particular interest to the Assembler Language programmer. Amongst other fields, the PSW contains: • • • The address of the next instruction to be executed The current value of the condition code (CC) Other flags, such as the one to indicate whether the CPU is in problem state or supervisor state
0000 0000 Instruction Address

C

P

CC

Program Mask

0000 0000

0

8

12

18

20

24

31

32

40

63

Program Status Word (EC Mode)

Concepts

© Copyright IBM Corp., 2000, 2004. All rights reserved.

Page 18 of 58

OS/390 Assembler Programming Introduction
Unit: S/390 Memory Usage Topic: Data Representation
Arithmetic Instructions
Although EBCDIC represents numbers in character form, it cannot be used for arithmetic operations. What are the kinds of arithmetic instructions? Fixed-Point (Binary) arithmetic and Decimal arithmetic are integer based, handling only whole numbers . Floating-Point arithmetic handles real numbers, numbers with fractional portions.
Fixed Point (Binary) 0111111111111111

Decimal: Zoned Decimal Packed Decimal

F3F2F7F6C7 32767C

Floating Point:

278.31924

Briefly look at each of the types and how it is used to represent numeric values.
Concepts
© Copyright IBM Corp., 2000, 2004. All rights reserved.

Page 19 of 58

OS/390 Assembler Programming Introduction
Unit: S/390 Memory Usage Topic: Data Representation
Fixed-Point Arithmetic
What is Fixed-Point arithmetic?
0 2 HALF HALFWORD = 2 bytes

Fixed-Point arithmetic uses three data types: • Full words – sometimes called a word, is four bytes (32 bits) in length • Half words – 2 bytes (16 bits) in length • Double words – 8 bytes (64 bits) in length What do fixed-point numbers consist of? Fixed-point numbers consist of two parts, a sign and a magnitude. The sign is in the leftmost, or high-order bit, and the magnitude occupies the rest of the field. A zero bit represents a positive sign, a one bit a negative sign.

2 bytes x 8 Bits = 16 Bits
0 FULL

4 FULLFWORD = 4 bytes

4 bytes x 8 Bits = 32 Bits 0 DOUBLE 8 bytes x 8 Bits = 64 Bits DOUBLEWORD = 8 bytes 0 1 0 0 1 Magnitude Sign 8

0

0

0

Continued…
Concepts
© Copyright IBM Corp., 2000, 2004. All rights reserved.

Page 20 of 58

OS/390 Assembler Programming Introduction
Unit: S/390 Memory Usage Topic: Data Representation
Fixed-Point Arithmetic (cont’d)
For positive numbers, the magnitude is represented in true binary. A half word value of +25 would be represented as: 0000 0000 0001 1001
Halfword Value of + 25

For negative numbers the magnitude is expressed in twos-complement form. To convert a binary value to twos-complement, flip all the bits, change 1s to 0 and 0s to 1, and then add one. A halfword value of -25 would be represented as: 1111 1111 1110 0111

0000 1111

0000 1111

0001 1110

1001 0110 1 0111 = +25 REVERSE BITS ADD + 1 = -25

TWOS-COMPLEMENT 1111 1111 1110

Halfword Value of - 25

Concepts

© Copyright IBM Corp., 2000, 2004. All rights reserved.

Page 21 of 58

OS/390 Assembler Programming Introduction
Unit: S/390 Memory Usage Topic: Data Representation
Leading Zeros and Twos-complement
Leading zeroes
Positive Numbers:

Note that in positive numbers, leading zeroes (0s) are insignificant, and in negative numbers, leading one (1s) are insignificant. In general, bits equal to the sign bit are insignificant. Twos-complement

0000

1000 Leading Zeros

0001

Negative Numbers:

Twos-complement notation used to represent negative fixed-point numbers makes doing arithmetic easy for the computer.

1111

0111

1111

Leading Ones

Concepts

© Copyright IBM Corp., 2000, 2004. All rights reserved.

Page 22 of 58

OS/390 Assembler Programming Introduction
Unit: S/390 Memory Usage Topic: Data Representation
Types of Decimal Numbers
Decimal numbers are of the following two types: • • Zoned Decimal Packed Decimal
1

Zoned Decimal

What is packed decimal? Packed decimal requires less storage than EBCDIC, since each number is represented by half a byte (4 bits). Arithmetic is only done on packed decimal numbers. What is zoned decimal? Zoned decimal is an intermediate format, used in converting numbers from characters to packed decimal. Packed numbers can be from 1 to 31 digits in length, while zoned can be from 1 to 16 digits.
to DIGITS 16

Packed Decimal

1

to DIGITS

31

Concepts

© Copyright IBM Corp., 2000, 2004. All rights reserved.

Page 23 of 58

OS/390 Assembler Programming Introduction
Unit: S/390 Memory Usage Topic: Data Representation
Zoned Decimal Number
What is a zone nibble? Each byte in a zoned decimal number consists of a zone nibble and a numeric nibble. The zone nibble is the first half of each byte, and the numeric nibble is the second half. Each numeric nibble contains the decimal digit value for that position. All zone nibbles except the rightmost contain the hex value F (one one binary). The rightmost nibble contains the sign. The hex character C represents a positive sign and D represents a negative sign.
Zoned Decimal Number: Numeric nibble

F

0

F

4

F

5

F

2

C

1

Sign Zone nibble

A nibble is half a byte.
Concepts
© Copyright IBM Corp., 2000, 2004. All rights reserved.

Page 24 of 58

OS/390 Assembler Programming Introduction
Unit: S/390 Memory Usage Topic: Data Representation
Packed Decimal Number
Packed decimal notation adds one decimal digit into each nibble, except for the rightmost nibble, which contains the sign. The sign is coded the same way as for zoned decimal. A three byte packed decimal number containing the value 4521 would be represented (in hex) as: 04521C

Packed Decimal Number: -2 digits/byte

Byte 1 04

Byte 2 52

Byte 3 1C

Zoned Decimal Number: -1 digit/byte F0 F4 F5 F2 C1 Byte 5

Byte 1 Byte 2

Byte 3 Byte 4

Concepts

© Copyright IBM Corp., 2000, 2004. All rights reserved.

Page 25 of 58

OS/390 Assembler Programming Introduction
Unit: S/390 Memory Usage Topic: Data Representation
Using Floating Point Numbers
Fixed point and decimal numbers are integers. Real numbers, numbers with a fractional part, are represented with floating point numbers. Floating point numbers allow you to represent a large range of numbers.
1.74642 X 1017

= 174642000000000000

Concepts

© Copyright IBM Corp., 2000, 2004. All rights reserved.

Page 26 of 58

OS/390 Assembler Programming Introduction
Unit: S/390 Memory Usage Topic: Data Representation
Floating-Point Numbers
Following are the 3 data types used for floatingpoint numbers? • • • Short numbers – 4 bytes in length Long - 8 bytes in length Extended – 16 bytes in length
Floating Point Numbers:

4 bytes

SHORT Mantissa (3 bytes)

8 bytes

LONG Mantissa 7 bytes

A floating-point number consists of the following parts:
16 bytes

EXTENDED Mantissa 7 bytes Low Order 1 byte ( Unused) Exponent ( 7 bits) 0 1010001

• • •

A Sign A Mantissa An Exponent

Mantissa 7 bytes High Order Sign (1st bit) 0 – Positive 1 - Negative 1 byte

Concepts

© Copyright IBM Corp., 2000, 2004. All rights reserved.

Page 27 of 58

OS/390 Assembler Programming Introduction
Unit: S/390 Memory Usage Topic: Data Representation
Floating-Point Formats
The three floating-point formats all provide for essentially identical ranges of magnitude, since the exponent is the same size in each. Going from short to long or from long to extended simply increases the length of the mantissa, and thus provides more precision.

Floating-Point Formats

0.32641 X 1070

0.32641347961 X 1070

0.3264134796128439 X 1070

Concepts

© Copyright IBM Corp., 2000, 2004. All rights reserved.

Page 28 of 58

OS/390 Assembler Programming Introduction
Unit: S/390 Addressing and Instructions Topic: Addressing
Modes of Operation
ADDRESS LENGTH BC MODE 111111111111111111111111 16Mb System (16,777,216 bytes) EC MODE 2 Gb System (2,147,483,647 bytes (0- 16,777,215) Address Range 24 BITS

0111111111111111111111111111111 (0 – 2,147,483,647 bytes) Address Range

31 BITS

What are the two modes of operation in System /390 architecture? One of the most distinctive features of a computer’s architecture is the way it addresses main storage. The S/390 architecture provides two modes of operation: • Basic Control Mode (BC) • Extended Control Mode (EC)

Concepts

© Copyright IBM Corp., 2000, 2004. All rights reserved.

Page 29 of 58

2000.192) 8K 4096 Bytes BASE REGISTER BASE ADDRESS (12. with no segmentation of memory from the programmer’s point of view.. Page 30 of 58 .OS/390 Assembler Programming Introduction Unit: S/390 Addressing and Instructions Topic: Addressing Address Space Flat address space means that the memory is continuously addressable. However the most common concern of a programmer is addresses within instructions. 0K 4K (8. All rights reserved.288) 12K 16K 20K 24K Concepts © Copyright IBM Corp. In a few cases the programmer must deal with absolute addresses. 2004.

either instructions would vary in length depending on the mode. • Using absolute addresses in instructions affects program relocatability. • If absolute addresses were used in instructions.ADD. specifying the data upon which the operation is to be performed. 2004. All rights reserved. or there would be wasted space when BC mode was used. etc. MOVE. 2000. and a number of operands. Specifying 31 bits for each address in an instruction will produce very long instructions. (DATA 1) MULTIPLY.OS/390 Assembler Programming Introduction Unit: S/390 Addressing and Instructions Topic: Addressing Machine Instruction Machine instructions consist of operations (add. The operands may specify registers or memory locations. Machine Instruction: OPCODE R1 X2 B2 D2 OPERATION OPERAND 1 (EG. multiply and so on). Page 31 of 58 ..) OPERAND 2 (DATA 2) BC Code 24 Bits EC Code 31 Bits Concepts © Copyright IBM Corp. Architecture with instructions specifying absolute addresses is generally not designed because: • The length of absolute addresses depends on the mode BC or EC.

In this form the address is specified as a displacement from the address contained in a GPR. When the processor is decoding an instruction.OS/390 Assembler Programming Introduction Unit: S/390 Addressing and Instructions Topic: Addressing Base Displacement Address What is Base Displacement Addressing? The form of address used in instructions is called base displacement addressing.. and when a GPR is used in this way it is called a base register. Page 32 of 58 . it converts each base-displacement address to an absolute address by adding the specified displacement DDD to the contents of the specified base register B.4095) Continued… Concepts © Copyright IBM Corp. 2000. so any register can be represented by one hex digit (one nibble). The displacement DDD is a 3 nibble or a 12 bit quantity. B stands for base. This is represented as a BDDD. All rights reserved. and so contains values from 0 – 4095. 2004. B DDD Base Register Displacement B2 D2 1 NIBBLE (4 Bits) 3 NIBBLES (12 Bits) (0. There are 16 GPRs. numbered 0 – 15.

OS/390 Assembler Programming Introduction Unit: S/390 Addressing and Instructions Topic: Addressing Base Displacement Address (cont’d) There is an exception to this rule of address formation. 2000. that there is one instruction type which extends this address formation process. That is. it means that no base register is to be used in the address calculation. but to specify that you wish to use displacement only in the address calculation. a base register B and an index register X . if R0 is specified as base and/or index register. B DDD Base Register Displacement RO GPR – RO = no Base Register D2 Displacement Only = Continued… Page 33 of 58 . RX instructions use two registers. What are RX instructions? It will be seen in the next section unit 2 -1. you cannot use R0 as a base register in the normal way. it is ignored in the address calculation. 2004. along with a displacement in address generation. If the base register B specifies register 0.. With RX instructions. Concepts © Copyright IBM Corp. All rights reserved.

Concepts © Copyright IBM Corp. 2000. All rights reserved. Page 34 of 58 . and 12 to specify the displacement. or 8 high order bits to get a 24 bit BC address. adds the displacement and drops either 1 high order bit to get a 31 bit EC address. 2004. When it decodes the instruction. prior to execution. while still specifying full address indirectly.. 4 to specify the base register. the processor takes the contents of the base register (32 bits).OS/390 Assembler Programming Introduction Unit: S/390 Addressing and Instructions Topic: Addressing Base Displacement Address (cont’d) Base Register (B2) Displacement (D2) OPCODE 0 7 8 R1 11 12 (X2) 15 16 1100 19 20 4 Bits 0100000000000 31 12 Bits 16 Bits Base Displacement Address A base displacement address uses 16 bits. The instructions are kept short.

they would always have to be loaded in the same storage location in order to run properly.OS/390 Assembler Programming Introduction Unit: S/390 Addressing and Instructions Topic: Addressing Advantages of Base Displacement Advantages of base displacement are: • • Base displacement addresses keep instruction length short It allows for common instruction format with no wasted space. from an operating system point of view. 2004. 2000. regardless of processor mode Provides easy relocatability of programs 0K 64K 128K 192K PROG1 • PROG2 PROGA PROG3 Why is relocatability important? 256K It is highly desirable. All rights reserved. If instructions used absolute addresses. 384K Concepts © Copyright IBM Corp. Page 35 of 58 . that programs be allowed to run on any location in main storage..

This is a relatively simple task.240 14. 2000.. 2004.048 6. Page 36 of 58 . These addresses do have to be adjusted when the program is loaded into main storage for execution to reflect the program’s actual load point.336 18.144 10. All rights reserved.OS/390 Assembler Programming Introduction Unit: S/390 Addressing and Instructions Topic: Addressing Absolute Addresses FIRST EXECUTION BASE ADDRESS = 6144 DISPLACEMENT = 1122 (FIELD A) ------ADDRESS = 7266 PROG1 • FIELD A MAIN STORAGE ADDRESS 2. since the number of absolute addresses is usually very small.432 PROG1 • FIELD A SECOND EXECUTION BASE ADDRESS = 10240 DISPLACEMENT = (FIELD A) ADDRESS = 1122 -------11362 Many programs do contain some absolute addresses. Concepts © Copyright IBM Corp.

which is an address evenly divisible by 2. which is 1 byte in length (there are two instructions with 2 byte opcodes.OS/390 Assembler Programming Introduction Unit: S/390 Addressing and Instructions Topic: Machine Instruction Formats Assembler Language Instructions Assembler Language Instructions: 1 Halfword 2 Bytes 4 Bytes 6 Bytes OPCODE OPCODE OPCODE 2 Halfwords 3 Halfwords Halfword Boundary Assembler Language instructions are 1. divide. Page 37 of 58 . but they are not commonly used in application programming). All rights reserved. Concepts © Copyright IBM Corp. What are opcodes? The first field in every instruction is the operation code (opcode). and are always aligned on a halfword boundary. such as add..2 or 3 halfwords in length. The operation code specifies what the instruction does. move or compare. 2004. 2000.

Page 38 of 58 . The different types of operands are: • • • Registers. specified by a register number Main storage location. but some have 0. Register R1 Base Displacement Address (BDDD) B2 D2 Indexed base Displacement Address (XBDDD) X2 B2 D2 • Immediate Data (I) I1 Continued… Concepts © Copyright IBM Corp.OS/390 Assembler Programming Introduction Unit: S/390 Addressing and Instructions Topic: Machine Instruction Formats Types of Operands What are the different types of operands? Most instructions have 2 operands. contained within the instruction itself (I). specified with an indexed base displacement address (XBDDD) A single byte of immediate data. 2000. 2004.. specified by a base displacement address (BDDD) Main storage locations. All rights reserved. 2 or 3. 1.

2004. Continued… Concepts © Copyright IBM Corp. In other cases.OS/390 Assembler Programming Introduction Unit: S/390 Addressing and Instructions Topic: Machine Instruction Formats Types of Operands (cont’d) 1 Halfword OPCODE X B D B D ADD HALFWORD (AH) INSTRUCTION STORAGE OPERAND In some cases. the length of a storage operand is implied by the instruction.. 2000. the length of a storage operand is explicitly specified as part of the instruction (L). All rights reserved. Page 39 of 58 . The storage operand for an Add Halfword (AH) instruction is a halfword in length.

OPCODE R1 R2 Operand 1 Operation (Add) Operand 1 Addition SUM R2 + R1 = SUM Concepts © Copyright IBM Corp. In most instructions. Add has two operands. 2000. For example. The Add instruction (A) fetches both operands. the result of the operations replaces the first operand..OS/390 Assembler Programming Introduction Unit: S/390 Addressing and Instructions Topic: Machine Instruction Formats Types of Operands (cont’d) Most instructions have two operands. adds them together and replaces the first operand with the sum. All rights reserved. 2004. Page 40 of 58 .

They are: • • • 1 halfword instructions have no storage operands 2 halfword instructions have one storage operand 3 halfword instructions have 2 storage operands Concepts © Copyright IBM Corp. Page 41 of 58 .OS/390 Assembler Programming Introduction Unit: S/390 Addressing and Instructions Topic: Machine Instruction Formats Instruction Lengths OPCODE 1 Halfword – no Storage Operands OPCODE 1 Storage Operand OPCODE 2 Halfwords 3 Halfwords 2 Storage Operands What are the different instruction lengths? There are 3 possible instruction lengths.. 2 or 3 halfwords. All rights reserved. 2000. 1. 2004.

The first byte contains the opcode.OS/390 Assembler Programming Introduction Unit: S/390 Addressing and Instructions Topic: Machine Instruction Formats RR Instruction Format The instruction is 16 bits or one halfword in length. All rights reserved. Continued… Page 42 of 58 .. and the second byte contains the two operands. 2000. 2004. Concepts © Copyright IBM Corp. start from zero. RR Instruction: Operation Operand 1 Operand 2 OPCODE 0 7 8 R1 R2 Bits 11 12 15 In numbering the bits in the instruction format. not one. both of which are registers.

2004. When this instruction is executed. Page 43 of 58 . 2000. The first operand is R3. the contents of R4 would be added to the contents of R3 and the sum would be placed in R3. replacing the first operand. Operation (Add) Operand 1 1A 3 4 SOURCE CODE OPCODE R3 R4 SUM R4 + R3 = SUM Concepts © Copyright IBM Corp.OS/390 Assembler Programming Introduction Unit: S/390 Addressing and Instructions Topic: Machine Instruction Formats RR Instruction (cont’d) An example of RR Instruction is: 1A34 Operand 1 1A is the operation code for the Add Register instruction.. The second operand is R4. All rights reserved.

All rights reserved. 2004.OS/390 Assembler Programming Introduction Unit: S/390 Addressing and Instructions Topic: Machine Instruction Formats RX Instruction RX Instruction: OPCODE 0 7 8 1 HALFWORD R1 11 12 X2 15 16 B2 19 20 DISPLACEMENT 1 HALFWORD D2 31 Bits 1st INDEX BASE OPERAND REGISTER REGISTER 2nd OPERAND Format This instruction is 32 bits (or 2 halfwords) in length. the base register specification • D2. the index register specification • B2. The following nibble contains the first operand. They are: • X2. Page 44 of 58 . the 12 bit displacement of the second operand Continued… Concepts © Copyright IBM Corp. which is a register. The remaining fields in the instruction contain the three components that specify the second operand. The first byte contains the opcode. 2000..

The second operand is the fullword at the storage location whose absolute address is formed by adding together the contents of R8. the contents of R12.. 12E.OS/390 Assembler Programming Introduction Unit: S/390 Addressing and Instructions Topic: Machine Instruction Formats RX Instruction (cont’d) 5B 5 R5 8 R8 C R12 12E D2 OPCODE R1 X2 B2 D2 DIFF R5 – FULLWORD = DIFF (R8 + R12 + D2) Absolute Address 2nd OPERAND Address Storage FULLWORD An example of RX instruction is: 5B58C12E 5B is the operation code for the Subtract instruction. Page 45 of 58 . 2000. and the value of the displacement. The first operand is R5. Concepts © Copyright IBM Corp. the fullword from storage will be subtracted from the value in R5 and the difference placed in R5. All rights reserved. 2004. When this instruction is executed.

2000. specified in base displacement form. Note that this instruction has three operands not just two. Page 46 of 58 . Continued… Concepts © Copyright IBM Corp. The first byte of the instruction is the opcode. the storage operand. Finally the second operand. 2004.OS/390 Assembler Programming Introduction Unit: S/390 Addressing and Instructions Topic: Machine Instruction Formats RS Instruction RS Instruction: OPCODE 0 7 8 1 HALFWORD R1 11 12 R3 15 16 B2 19 20 DISPLACEMENT 2nd OPERAND BASE DISPLACEMENT 1 HALFWORD D2 31 Bits 1st 3rd BASE OPERAND OPERAND REGISTER Format The instruction is 32 bits or 2 halfwords in length. both registers.. This is followed by the first and third operands. All rights reserved.

When this instruction is executed. 2004. 2000.R7 .R4 .R6 .OS/390 Assembler Programming Introduction Unit: S/390 Addressing and Instructions Topic: Machine Instruction Formats RS Instruction (cont’d) 98 4 R4 9 R9 C R12 124 D2 SOURCE CODE OPCODE 1ST FULLWORD LOADED NEXT FULLWORD LOADED NEXT FULLWORD LOADED NEXT FULLWORD LOADED NEXT FULLWORD LOADED NEXT FULLWORD LOADED . The third operand is R9. the next into R6..R9 DIFF R1 R3 B2 D2 2nd OPERAND (R12 + 124) Absolute Address Format 9849C124 98 is the opcode for the Load Multiple instruction. Concepts © Copyright IBM Corp. the next into R7. The first operand is R4. The second operand is the 6 consecutive full words starting at the storage location. All rights reserved. the base register. the next into R5. the first fullword at the storage location would be loaded into R4. whose absolute address is formed by adding the displacement 124 to the contents of R12.R5 .R8 . the next into R8 and the next into R9. Page 47 of 58 .

The first byte of the instruction is the opcode. All rights reserved.. Continued… Concepts © Copyright IBM Corp. 2004. 2000.OS/390 Assembler Programming Introduction Unit: S/390 Addressing and Instructions Topic: Machine Instruction Formats SI Instruction SI Instruction: OPCODE 0 7 8 IMMEDIATE DATA 2nd OPERAND 1 HALFWORD I2 15 16 B2 19 20 DISPLACEMENT 1st OPERAND BASE DISPLACEMENT 1 HALFWORD D2 31 Bits BASE REGISTER Format The instruction is 32 bits or two halfwords in length. The operand is exactly one byte long. Page 48 of 58 . not an address. This byte contains the actual operand. an immediate storage operand. The rest of the instruction is the base and displacement specifying the first operand. The next byte is the second operand.

the base register. Page 49 of 58 . 2004.OS/390 Assembler Programming Introduction Unit: S/390 Addressing and Instructions Topic: Machine Instruction Formats SI Instruction (cont’d) 92 40 EBCDIC (SPACE) C R12 33A D2 SOURCE CODE OPCODE I2 B1 D1 BLANK MOVED TO ADDRESS SPECIFIED BY B1D1 1ST OPERAND Base Displacement (R12 + D2) Storage Address Address Storage BLANK An example of SI instruction is: 9240C33A 92 is the opcode for the Move Immediate instruction. 2000. All rights reserved. the EBCDIC code for space. is the second operand. The first operand is the byte at the absolute storage address formed by adding the displacement 33A to the contents of R12. Concepts © Copyright IBM Corp. 40.. When this instruction is executed a blank would be moved to the address specified by the first operand.

. which applies to both of its operands. Continued… Concepts © Copyright IBM Corp. 2000. The second has a separate length specified for each operand. Page 50 of 58 . 2004. All rights reserved.OS/390 Assembler Programming Introduction Unit: S/390 Addressing and Instructions Topic: Machine Instruction Formats SS Instruction SS Instruction: OPCODE 0 7 8 1 HALFWORD ONE LENGTH L 15 16 B1 19 20 1 HALFWORD D1 31 32 B2 35 36 1 HALFWORD D2 47 Bits L1 L2 BASE DISPLACEMENT BASE REGISTER REGISTER 1st OPERAND BASE DISPLACEMENT DISPLACEMENT 8 15 Bits TWO LENGTH 2nd OPERAND BASE DISPLACEMENT What are the two formats of SS instructions? The first format has single length specification.

2000. when there is a single length specification it is a byte in length. each is specified as a nibble. both specified in base displacement format. represents a real length of 1. The two SS formats are shown above.. a machine length specification of 0. and so on. 2004. Page 51 of 58 . and so in order to provide maximum facility. All lengths in machine instructions are coded as 1 less than the actual length. All rights reserved. The instructions are 48 bits or 3 halfwords in length. The next byte is the length or lengths.OS/390 Assembler Programming Introduction Unit: S/390 Addressing and Instructions Topic: Machine Instruction Formats SS Instruction (cont’d) SS Instruction: OPCODE 0 7 8 1 HALFWORD ONE LENGTH L 15 16 B1 19 20 1 HALFWORD D1 31 32 B2 35 36 1 HALFWORD D2 47 Bits L1 L2 BASE DISPLACEMENT BASE REGISTER REGISTER 1st OPERAND BASE DISPLACEMENT DISPLACEMENT 8 15 Bits TWO LENGTH 2nd OPERAND BASE DISPLACEMENT When there are two lengths. Continued… Concepts © Copyright IBM Corp. This is followed by operand one and operand two. This is because a zero length dosen’t make sense for an operation. and can contain values from 0 – 255. and can contain values from 0 – 15. 1 represents 2. The first byte is the opcode.

equivalent to an actual length of 100 bytes. destroying the original value of the first operand. 2004. When this instruction is executed. The first operand is the 100 character string whose absolute address is formed by adding the displacement of 124 to the contents of R12. 63 is the machine coded length. Page 52 of 58 . would be copied to the first operand. Concepts © Copyright IBM Corp.. 2000. the 100 bytes of the second operand. All rights reserved.OS/390 Assembler Programming Introduction Unit: S/390 Addressing and Instructions Topic: Machine Instruction Formats SS Instruction (cont’d) D2 63 LENGTH C R12 124 D1 C R12 388 D2 OPCODE L B1 D1 B2 D2 (100 BYTES) MOVE CHARACTERS 1ST OPERAND Base Displacement 100 BYTES (R12 + 124) (R12 + 388) (COPY 100 BYTES OF 2ND OPERAND OVERWRITING 1ST OPERAND) An example of one length SS instruction is: D263C124C388 D2 is the opcode for the Move Characters instruction. The second operand is the 100 character string whose absolute address is formed by adding the displacement of 388 to the contents of R12.

Continued… Concepts © Copyright IBM Corp. Page 53 of 58 . 2004. equivalent to an actual length of 5. 0 is the machine coded length of the second operand.. All rights reserved. equivalent to an actual length of one.OS/390 Assembler Programming Introduction Unit: S/390 Addressing and Instructions Topic: Machine Instruction Formats SS Instruction – An Example 5B Two Length SS Instruction 4 L1 0 L2 C R12 1AA D1 C R12 249 D2 Source Code OPCODE SUBTRACT DECIMAL L1 L1 B1 D1 B2 D2 CODED LENGTH 1st OPERAND (5) 1st OPERAND Absolute Address (L1)(5 Byte Packed Decimal Number CODED LENGTH 2nd OPERAND (1) 2nd OPERAND Absolute Address (L1)(1 Byte Packed Decimal Number An example of two length SS instruction is: 5B40C1AAC249 5B is the opcode for the Subtract Decimal instruction. 4 is the machine coded length of the first operand. 2000.

2000. The second operand is the 1 byte packed decimal number whose absolute address is formed by adding the displacement of 249 to the contents of R12. Page 54 of 58 . When this instruction is executed the value of the second operand will be subtracted from the value of the first.. All rights reserved.OS/390 Assembler Programming Introduction Unit: S/390 Addressing and Instructions Topic: Machine Instruction Formats SS Instruction – An Example (cont’d) An example of two length SS instruction (cont’d) The first operand is the 5 byte packed decimal number whose absolute address is formed by adding the displacement of 1AA to the contents of R12. 2004. Concepts © Copyright IBM Corp. and the difference would replace the first operand.

operand 1 and operand 2.OS/390 Assembler Programming Introduction Unit: S/390 Addressing and Instructions Topic: Assembler Language Formats Difference in RR Format In the RR format. Page 55 of 58 . operation.R2 R3.. RR Format Example Code: 1A34 Machine Language OPCODE 1A R1 3 R2 4 Instruction Assembler Language Op AR R1. All rights reserved. 2004. the components for both Machine language and Assembler language follow in the same order.R4 Instruction Concepts © Copyright IBM Corp. 2000.

2000. 2004. All rights reserved. Page 56 of 58 . R12).. followed by operand1. the syntax is quite different.302(R8. Operand2 is specified with the displacement first. Continued… Concepts © Copyright IBM Corp.R12) Instruction With RX format where we have storage operands. Notice displacement is decimal in the Assembler language and hexadecimal in machine language. and in parentheses (example: R8. Start with operation.OS/390 Assembler Programming Introduction Unit: S/390 Addressing and Instructions Topic: Assembler Language Formats Difference in RX Format RX Format Example Code: 5B58C12E Machine Language OPCODE 5B R1 5 X2 8 B2 C D2 12E Instruction Assembler Language Op S R1. separated by a comma. This is followed by the index register and the base register.D2(X2.B2) R5.

Page 57 of 58 . All rights reserved. 2004.292(R12) Instruction With RS format.R9.. 2000.OS/390 Assembler Programming Introduction Unit: S/390 Addressing and Instructions Topic: Assembler Language Formats Difference in RX Format (cont’d) Example Code: 9849C124 Machine Language OPCODE 98 R1 4 R3 9 B2 C D2 124 Instruction Assembler Language Op LM R1. Concepts © Copyright IBM Corp. The storage operand is specified as displacement (decimal).R3D2.(B2) R4. and is followed by the base register in parentheses. again notice the opcode and register operands in Assembler Language parallel the machine language format.

precedes the storage operand.. Concepts © Copyright IBM Corp. 2000.OS/390 Assembler Programming Introduction Unit: S/390 Addressing and Instructions Topic: Assembler Language Formats Difference in SI Format SI Format. the order of the operands is different in the two formats. Example Code: 9240C33A Machine Language OPCODE 98 I2 4 B1 9 D1 33A Instruction Assembler Language Op MVI D1. Page 58 of 58 . 2004. In Assembler Language.X’40’ Instruction In SI format. the immediate operand I2. In Machine Language. All rights reserved.I2 826(R12). The immediate operand is specified as a hex value of 40 in the notation shown.(B1). the storage operand comes first.

Note in the example that the length is 100 decimal.R12). it is placed with the first operand. for example (100.OS/390 Assembler Programming Introduction Unit: S/390 Addressing and Instructions Topic: Assembler Language Formats Difference in SS1 Format Example Code: D263C124C388 Machine Language OPCODE D2 L 63 B1 C D1 124 B2 C D2 388 Instruction Assembler Language Op MVC D1. within parentheses. not the second. 2004. The machine length is one less than the actual length. All rights reserved. If there is only one length.B1).(L.. 2000. it is specified as the actual length.D2(B2) 292(100. 10010 = 6416. Page 59 of 58 . so the machine length is 63. Concepts © Copyright IBM Corp.904(R12) Instruction When a length is specified with a storage operand.R12). followed by a comma. and precedes the base register.

R12).OS/390 Assembler Programming Introduction Unit: S/390 Addressing and Instructions Topic: Assembler Language Formats Difference in SS2 Format SS2 Format Example Code: 5B40C1AAC249 Machine Language OPCODE 5B L1 4 L2 0 B1 C D1 1AA B2 C D2 249 Instruction Assembler Language Op SP D1. In this case there are two lengths.585(1. within parentheses. Lengths are coded before the base register.D2(L2. Concepts © Copyright IBM Corp.(L1. Page 60 of 58 . All rights reserved.B1)..R12) Instruction This example follows the same pattern as the previous one.B2) 426(5. one for each operand. 2000. 2004.

Continued… Concepts © Copyright IBM Corp.OS/390 Assembler Programming Introduction Unit: S/390 Addressing and Instructions Topic: Assembler Language Formats Assembler Program What is an Assembler Program? Looking at all the instruction formats for both Assembler and Machine Languages may be somewhat intimidating. However the job of the Assembler programmer is not as complex as you might expect. 2004. Page 61 of 58 . All rights reserved. 2000. The Assembler program converts your Assembler statements to Machine Language for you..

DISCOUNT Concepts © Copyright IBM Corp. All rights reserved. 585(1.R12) SP NETPRICE. 2004. 2000..OS/390 Assembler Programming Introduction Unit: S/390 Addressing and Instructions Topic: Assembler Language Formats Assembler Program (cont’d) Thus.R12) You would probably write something like this: 426(5.585(1. DISCOUNT SP NETPRICE. Page 62 of 58 .R12). instead of writing an instruction like this: SP 426(5.R12).

Page 63 of 58 .OS/390 Assembler Programming Introduction Unit: The Program Development Process Topic: Assembler Language Syntax Assembler Language Statements What are Statements? Assembler Language programs are made up of statements.*()‘/& blank Continued… Concepts © Copyright IBM Corp. All rights reserved. 2004. 2000.=. $. except when used in quoted strings.. Lower case alphabetic characters are considered equivalent uppercase characters by the Assembler. Statements are composed of characters. Characters: Alphabetic characters a –z and A.Z National characters @. and # Underscore _ Digits 0–9 Special characters +-.

OS/390 Assembler Programming Introduction
Unit: The Program Development Process Topic: Assembler Language Syntax
Assembler Language Statements (cont’d)
What constitutes Assembler Language Statements? Assembler Language Statements are coded in 80 character records or lines. By default, each 80 character line consists of 3 fields; positions 1-71 constitute the statement field, 72 is the continuation indicator field, and 73-80 is the identifier/sequence field. Assembler Language statements and comments must be written in the statement field. It consists of: • Begin Column - The first position of the statement field • Continue Column - second and subsequent statements of a continued statement begin • Continuation Indicator Field - The position following the end column
STATEMENT Identifier/ Sequence Field Statement Field

1

71 72 73 ……….80
Continuation Indicator Field

Begin Column (Position 1)

End Column (Position 71)

Concepts

© Copyright IBM Corp., 2000, 2004. All rights reserved.

Page 64 of 58

OS/390 Assembler Programming Introduction
Unit: The Program Development Process Topic: Assembler Language Syntax
Assembler Language Instruction Statements
Assembler Language Instruction Statement consists of up to 4 fields, specified in the following order: 1. 2. 3. 4. Name Operation Operand Comments
Begin Column (Position 1)

BE NOTEQ

EQUALRTN

BRANCH ON EQUAL SET THERE FIELD COMPARE TO”A”

MVC THERE,HERE CLI C’A’,TESTFLD

STORERTN STM

2,12,SAVEAREA SAVE REGISTERS

Comment Field Operand Field Operation Field Continued…
Concepts
© Copyright IBM Corp., 2000, 2004. All rights reserved.

Name Field

Page 65 of 58

OS/390 Assembler Programming Introduction
Unit: The Program Development Process Topic: Assembler Language Syntax
Assembler Language Instruction Statements (cont’d)
Assembler Language instructions are free format, with one or more blanks delimiting fields. The name field and operation field is separated by one or more blanks, as are the operation and the operand, and the operand and the comment. Embedded blanks are not allowed in the operand field, unless they are part of a quoted string. Otherwise they would indicate the end of the operand field. The name field, if present, must begin in the begin column. If the name field is omitted, the operation field must start after the begin column.
Begin Column (Position 1)

BE

EQUALRTN

BRANCH ON EQUAL

NOTEQ

MVC

THERE,HERE

SET THERE FIELD

One or more BLANKS denoting Change of Field

Continued…
Concepts
© Copyright IBM Corp., 2000, 2004. All rights reserved.

Page 66 of 58

OS/390 Assembler Programming Introduction
Unit: The Program Development Process Topic: Assembler Language Syntax
Assembler Language Instruction Statements (cont’d)
Although the Assembler allows free format statements, most programmers align their fields (operation, operand and comments) in specific positions for readability. If you wish to code a comment field on a statement with no operand field, you must indicate to the Assembler, that the operand field is missing. You do this by coding a comma, preceded and followed by a blank, between the operation and the comment. An example of this is shown on the right.
Coding a Comment Field with no Operand Field:

Comma

Statement

End

,

The end of the program

BLANK

Concepts

© Copyright IBM Corp., 2000, 2004. All rights reserved.

Page 67 of 58

OS/390 Assembler Programming Introduction
Unit: The Program Development Process Topic: Assembler Language Syntax
Use of Comments
How can you use comments effectively? As noted previously comments can be included as the fourth field on any Assembler Language instruction statement. It is also possible to have statements in your program consisting entirely of comments. An Assembler Language comment statement has an asterisk in the statement in the begin column. The rest of the statement, up to and including the end column, is interpreted as a comment.

* * * *

THE FOLLOWING ROUTINE IS USED TO INITIALIZE THE OUTPUT AREA

Begin Column (Position 1)

End Column (Position 71)

Concepts

© Copyright IBM Corp., 2000, 2004. All rights reserved.

Page 68 of 58

OS/390 Assembler Programming Introduction
Unit: The Program Development Process Topic: Assembler Language Syntax
Use of Comments (cont’d)
How can you use comments effectively? It is good programming practice to include plenty of comments. It is desirable to clearly document what your code is doing when using a low level language like Assembler Language. A block of comment statements should describe the purpose of each module and of each major section of code. Comments should be coded on instruction statements to indicate the purpose of each individual statement.

NOTEQ

MVC THERE,HERE CLI C’A’,TESTFLD

SET THERE FIELD COMPARE TO”A”

STORERTN STM

2,12,SAVEAREA SAVE REGISTERS

Comment Field Typical Comments

Concepts

© Copyright IBM Corp., 2000, 2004. All rights reserved.

Page 69 of 58

OS/390 Assembler Programming Introduction
Unit: The Program Development Process Topic: Assembler Language Syntax
Formatting Assembler Language Statements

Position 1 Position 16 INDCB DCB DDNAME=INFILE,DSORG=PS,MACRF=GM,RECFM=FB, LRECL=80,EODAD=ENDRTN Position 72 X

Most Assembler Language statements will easily fit in one line. Sometimes, particularly with complex macro instructions, a statement will not fit on a single line, between the start and end columns.

The example above shows a statement continued on the next line.
Concepts
© Copyright IBM Corp., 2000, 2004. All rights reserved.

Page 70 of 58

put a non-blank character in the continuation indicator column and resume coding with the start of the next operand in the continuation column of the next line Concepts © Copyright IBM Corp. 2000. Code the statement up to the end column. Page 71 of 58 . All rights reserved. put a non-blank character in the continuation indicator column and resume coding in the continuation column of the next line 2..’ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMN OPQRSTUVWXYZ0123456789’ X Following are the two ways of breaking a statement for continuation: 1.OS/390 Assembler Programming Introduction Unit: The Program Development Process Topic: Assembler Language Syntax Breaking Statements Position 1 Position 16 BE EQUALRTN BRANCH ON EQUAL Position 72 X THE COMMENT FOR THIS STATEMENT CONTINUES ON LINE 2 MVC TO FIELD. 2004. Code the statement to the end of a complete operand and its following comma.

2000.. Page 72 of 58 . All rights reserved. written in Assembler Language and convert it to an object module in Machine Language. This conversion includes: • Converting Assembler Language mnemonic opcodes into Machine Language numeric opcodes • Converting the Assembler Language instruction formats into Machine Language forms • Converting the numeric notation used in the source program (decimal by default) to hexadecimal form used in the Machine Language • Determining the address of all the instructions and data areas used in the program • Converting reference symbols into base displacement addresses ASSEMBLER (Converts Assembler Language to Machine Language) OBJECT MODULE Concepts © Copyright IBM Corp.OS/390 Assembler Programming Introduction Unit: The Program Development Process Topic: The Assembly Process Assembler Functions What are the functions of an Assembler? The major purpose of the Assembler is to take a source program. 2004.

OS/390 Assembler Programming Introduction Unit: The Program Development Process Topic: The Assembly Process Converting Addresses to Base-Displacement Format What is USING Instruction? In order for the Assembler to convert addresses to base-displacement format. and what value the register will contain at execution time. You must also include machine instructions in your program. A standard way of accomplishing these two actions is with the following instructions. Page 73 of 58 . R12 BALR R12. to load the proper value into the base register at execution time. This information is provided with the USING instruction. you must tell the Assembler what register to use as a base register.R12 Established address ability Continued… Concepts © Copyright IBM Corp. All rights reserved. 2000.. included as part of the program initiation: BALR R12.R0 and USING*.0 Load the base register USING *. 2004.

2004. The * symbol is used to represent the current value of the location counter in an Assembler program. places the absolute address of the next instruction after BALR into register 12. All rights reserved. To established Program Address ability: BALR R12. The USING instruction tells the Assembler that R12 is to be used as the base register. and that R12 will contain the address of the current instruction.R12 Current Value Established R12 as the Base Register Concepts © Copyright IBM Corp.OS/390 Assembler Programming Introduction Unit: The Program Development Process Topic: The Assembly Process Converting Addresses to Base-Displacement Format (cont’d) The first of these instructions. Page 74 of 58 . a Machine instruction..0 Loads next Instruction intro R12 ABSOLUTE ADDRESS USING *. 2000. Since BALR has in fact loaded R12 with the address of the instruction following BALR (which is now the current instruction) this correctly establishes addressability in the program.

After the Assembler produces an object module it can be linked and executed.OS/390 Assembler Programming Introduction Unit: The Program Development Process Topic: The Assembly Process SS Instruction Example As previously discussed.B) Full Operand D (B) D (X. 1=length Attribute of D B=0 1=length attribute of D Concepts © Copyright IBM Corp. Page 75 of 58 . B=0 B=0 X=0 B=0 .B) From Omission D D D (X) D (.. storage operands can be represented as either symbols. or in base displacement format. D (1. base index displacement. and uses default values for the omitted parts. 2000.B) Assembler Default B=0 X=0 . All rights reserved. 2004.B) D D (1) D (. This process is indicated in the table on the right. The Assembler allows certain portions of the base displacement. or base length displacement forms to be omitted.

Concepts © Copyright IBM Corp. Topic: The Define Storage (DS) Instructions Object Module Since DS does not define an executable instruction. but rather sets up an area of storage. Continued… Page 76 of 58 . If you wish to assign a name to the storage being defined. 2004. The operation for defining storage is DS. All rights reserved.. you specify a symbol in the name field of the DS instruction.OS/390 Assembler Programming Introduction Unit: Defining Data Define Storage Instruction What is Define Storage (DS) Instruction ? The Define Storage (DS) Assembler instruction is used to define storage areas within a program. it is an Assembler instruction. 2000.

2004. 2000. which are: • • • • A duplication factor A type specifier A length modifier A nominal value Object Module Object Module Concepts © Copyright IBM Corp.. All rights reserved.OS/390 Assembler Programming Introduction Unit: Defining Data Topic: The Define Storage (DS) Instructions Define Storage Instruction (cont’d) What are the components of a DS statement? The operand field of a DS statement consists of up to 4 components. Page 77 of 58 .

not a constant. when a DC statement is intended. This is not flagged as an error by the Assembler. The nominal value field is not used. but will likely produce an execution time error. while the other three components are optional. Continued… Page 78 of 58 . All rights reserved. d – duplication factor t – type specifier LI – length attribute ‘value’ – nominal value A common mistake is coding a nominal value in a DS statement. DS dtLI’value’ The duplication factor and the length modifier has default values when not coded explicitly. 2000. 2004.OS/390 Assembler Programming Introduction Unit: Defining Data Topic: The Define Storage (DS) Instructions Components of a DS Statement The type specifier must be supplied. and is simply considered as documentation since it is defining storage. Concepts © Copyright IBM Corp. since the syntax is correct..

All rights reserved. Example: To define a fullword called FWD1. you would specify the following statement as indicated: FWD1 DS F Concepts © Copyright IBM Corp. Page 79 of 58 . 2000. 2004. and has a default length and alignment..OS/390 Assembler Programming Introduction Unit: Defining Data Topic: The Define Storage (DS) Instructions Components of a DS Statement (cont’d) Data Type Character Hexadecimal Binary Zoned Decimal Packed Decimal Halfword Fullword Long Floating Point Type Specifier C X B Z P H F D Default Length 1 1 1 1 1 2 4 8 Default Alignment byte byte byte byte byte halfword fullword doubleword The type specifier indicates the type of data the field should contain. Each data type is specified by a single character identifier. The most common field types are indicated above.

This consists of the letter L. To define a character field 100 bytes long. 2000. It is placed immediately following the type specifier. All rights reserved. you specify a length modifier. followed by the desired field length in bytes. Page 80 of 58 .OS/390 Assembler Programming Introduction Unit: Defining Data Length Modifier What is the function of a length modifier? Length Modifier Topic: The Define Storage (DS) Instructions Often you wish to define a field with a length different from a default length. 2004. To do this.. you would specify: STRING1 DS CL100 STRING1 DS CL100 Continued… Concepts © Copyright IBM Corp. called STRING1.

One way to force boundary alignment even if the definition does not guarantee it. and reverts to byte alignment. All rights reserved. There is no boundary alignment guarantee for FWD3. Page 81 of 58 .. 2000. There is a guarantee that FWD2 would be aligned on a fullword boundary. specifying a length modifier removes the alignment guarantee. 2004.OS/390 Assembler Programming Introduction Unit: Defining Data Length Modifier (cont’d) For fields that are aligned on other than a byte boundary. is to precede the field with another statement that forces the desired alignment. Topic: The Define Storage (DS) Instructions FWD2 DS F FWD3 DS FL3 Concepts © Copyright IBM Corp.

The Assembler maintains a location counter (LC). The skipped bytes are not initialized to any specific value. 2000. then the Assembler skips enough bytes to such an address that provides the required alignment. and is increased by the length of each assembled instruction as the assembler proceeds. except when alignment is required. 2004. Page 82 of 58 .. which starts at zero at the beginning of the Assembly. If the alignment is required. Topic: The Define Storage (DS) Instructions Concepts © Copyright IBM Corp. and the value of the location counter is not at an address that would provide the appropriate alignment. All rights reserved.OS/390 Assembler Programming Introduction Unit: Defining Data Location Counter The Assembler assigns each new field you define immediately following the previous one.

Topic: The Define Storage (DS) Instructions Concepts © Copyright IBM Corp. or the default length if no length modifier is coded. which reference the field. is the length attribute of the field. All rights reserved. and you may use it in assembling SS type Machine instructions.OS/390 Assembler Programming Introduction Unit: Defining Data Length Attribute The value specified as the length modifier. 2000.. The Assembler associates a length attribute to each field you define. 2004. Page 83 of 58 .

Page 84 of 58 . If the duplication factor is omitted. 2000. preceding the type specifier.. 2004. Concepts © Copyright IBM Corp. each represented by a 2 byte packed decimal number we would code: MARKS DS 100PL2 The amount of storage allocated by a DS instruction is the product of the duplication factor and the length. is coded as the first part of the operand. a default value of 1 is assumed. All rights reserved. The duplication factor specifies the number of occurrences of the specified type and length specified. if it is provided.OS/390 Assembler Programming Introduction Unit: Defining Data The Duplication Factor What is the duplication factor? The duplication factor. 1 – To define a program save area of 18 fullwords. we would code: SAVEAREA DS 18F Topic: The Define Storage (DS) Instructions 2 – To define an array with 24 entries to hold hourly temperature readings (represented as halfwords) for one day we would code: TEMPARR DS 24H 3 – To define an array to hold the marks of 100 students.

2000. Remember that each data item as a length attribute assigned to it. which is defined as character type. Thus the length attribute of the three declarations are as shown on the right: Topic: The Define Storage (DS) Instructions Continued… Concepts © Copyright IBM Corp. Are they identical in effect? Not quite. What is the difference between them? They all allocate 100 bytes of storage.. Page 85 of 58 . 2004. All rights reserved. The length attribute is the implicit or explicit length modifier.OS/390 Assembler Programming Introduction Unit: Defining Data The Length Attribute Why is the length attribute important? Consider the following three declarations on the right.

. In the first case. 2004. All rights reserved. Page 86 of 58 . 2000.OS/390 Assembler Programming Introduction Unit: Defining Data Topic: The Define Storage (DS) Instructions The Length Attribute (cont’d) What is the effect of the following 3 statements on the right? All three of these statements move data from the location DATA1 to the destination (first operand) field. Continued… Concepts © Copyright IBM Corp. only 1 byte is moved and in the third case 2 bytes are moved. In the second case. 100 bytes of data are moved.

. the length would need to be coded explicitly in the MVC instruction. When an explicit length is omitted in an SS instruction. Concepts © Copyright IBM Corp. Page 87 of 58 . 2004. the length attribute of the destination field is used.OS/390 Assembler Programming Introduction Unit: Defining Data Topic: The Define Storage (DS) Instructions The Length Attribute (cont’d) To move 100 bytes of data from DATA1 to X2. 2000. All rights reserved. It would look like the statement on the right.

2004. Why is this done? Remember that the amount of storage allocated is the product of the duplication factor and the length. 2000. If the duplication factor is zero. Page 88 of 58 .OS/390 Assembler Programming Introduction Unit: Defining Data Use of Duplication Factors Why are zero duplication factors used? To specify a duplication of zero is a special situation of a data declaration. Topic: The Define Storage (DS) Instructions Continued… Concepts © Copyright IBM Corp. All rights reserved. so is the product of duplication factor and length. so no storage is allocated..

Continued… Concepts © Copyright IBM Corp. Page 89 of 58 .byte character field is to be defined which is aligned on a doubleword boundary. 2000. Thus the definition looks as it does on the right. Since the doubleword is not actually used for anything. All rights reserved. it is defined with a duplication factor of zero. Its only purpose is to cause the Assembler to skip enough bytes to move to the doubleword boundary. 2004. It does not even have to be given a name. other than to force alignment. The easiest way to do this is to define a doubleword (forcing doubleword alignment) immediately followed by the character field.OS/390 Assembler Programming Introduction Unit: Defining Data Topic: The Define Storage (DS) Instructions Use of Duplication Factors (cont’d) Common reasons for using zero duplication factors: One reason is to force alignment. Suppose a 100 .. since it will not be used.

When reading the record the programmer wishes to treat it as a single 120-byte field. MULTIPLE REFERENCES TO DATA RECORD FLD1 FLD2 FLD3 DS DS DS DS 0CL120 CL40 CL40 CL40 RECORD FLD1 FLD2 FLD3 Continued… Concepts © Copyright IBM Corp. It can be accomplished using a zero duplication factor on the first definition. 2004. the programmer wants to process its fields separately. All rights reserved. The definition is shown on the right..OS/390 Assembler Programming Introduction Unit: Defining Data Topic: The Define Storage (DS) Instructions Use of Duplication Factors (cont’d) In the other situation a zero duplication factor is often used is when the same piece of storage is defined in two or more different ways. but suppose this record contains 3 fields. each 40 bytes in length. Page 90 of 58 . The record is 120 bytes in length. After it is read. Suppose an area of storage is to be set up to hold a record that will be read into our program from disk. 2000.

The fields can be broken down even further.OS/390 Assembler Programming Introduction Unit: Defining Data Topic: The Define Storage (DS) Instructions Use of Duplication Factors (cont’d) The RECORD is defined with a zero duplication factor.. The length attribute of RECORD is 120. FLD2 also has a length attribute of 40 as does FLD3. All rights reserved. the actual space assigned to it is 0 * 120 = 0. The address of FLD2 is 40 higher than the address of FLD1. Page 91 of 58 . MULTIPLE REFERENCES TO DATA RECORD FLD1 FLD1A FLD1B FLD1C FLD1D FLD2 FLD3 DS DS DS DS DS DS DS DS 0CL120 0CL40 CL5 CL15 CL8 CL12 CL40 CL40 RECORD FLD1 F L D 1 A F L D 1 B F L D 1 C F L D 1 D FLD2 FLD3 Concepts © Copyright IBM Corp. 2000. but has a length attribute of 40. FLD1 has the same location as RECORD. 2004. The space assigned by the Assembler is 1 * 40 = 40. FLD1 could consist of 4 smaller fields.

All rights reserved. Page 92 of 58 .OS/390 Assembler Programming Introduction Unit: Defining Data Topic: The Define Constant (DC) Instructions Define Constant (DC) Instruction What is Define Constant (DC) Instruction? The Define Constant (DC) instruction is used to define constants. 2000. but the nominal value field is compulsory.. In fact the term constant is somewhat misleading since there is no guarantee that the storage set up by a DC Assembler instruction will remain constant throughout program execution. In fact. The nominal value specifies the value to which the field is initialized. what DC does is to define storage and initialize it to the value you specify in the DC instruction. 2004. Concepts © Copyright IBM Corp. The operand field of DC contains the same 4 components as the DS instruction.

then the nominal value is either padded or truncated to fit the explicitly specified field length. It is truncated on the right if it is too long. If an explicit length is specified. then the length required to hold the nominal value is used. 2004. that length is the one used. All rights reserved.. If no length modifier is specified. and it does not agree with the length of the nominal value. The nominal value is specified as a series of characters. Length Modifier Specified: Topic: The Define Constant (DC) Instructions DC CL4‘THINK’ Value = ‘THIN’ Length attribute = 4 bytes No Length Modifier Specified: DC C’THINK’ Value = ‘THINK’ Length attribute = 5 bytes Concepts © Copyright IBM Corp. Page 93 of 58 . the nominal value is left justified and padded on the right with blanks if it is shorter than the field length. For character constants. 2000. The way that padding or truncation is done depends on the field type. If a length modifier is specified in the definition.OS/390 Assembler Programming Introduction Unit: Defining Data Length of a Field The length of a field defined by a DC statement can be established in one of two ways.

In the following examples. with length determined by the nominal value Definition CFLD4 Field Contents C1C2C3C1C2C3 Continued… Concepts © Copyright IBM Corp.OS/390 Assembler Programming Introduction Unit: Defining Data Character Value The Assembler converts the character value specified in the definition into EBCDIC code. 2004. With no length modifier the length is determined by the nominal value Definition CFLD1 Field Contents C1C2C3 Topic: The Define Constant (DC) Instructions DC C'ABC' Explicit length of 5. All rights reserved. the nominal value is left justified and right padded with blanks Definition CFLD2 Field Contents C1C2C34040 DC CL5'ABC' Explicit length of 2. we will represent the field contents (EBCDIC) in hex notation. DC 2C'ABC' Page 94 of 58 . 2000.. the nominal value is left justified and right truncated Definition CFLD3 Field Contents C1C2 DC CL2'ABC' Duplication factor of 2.

2000. length of 1 is determined by the nominal value Definition CFLD7 Field Contents 5C5C5C5C5C5C5C5C5C5C DC 10C'*' Concepts © Copyright IBM Corp. 2004. the nominal value is left justified and right padded with blanks Definition CFLD6 Field Contents 5C40404040404040404040 DC CL10'*' Duplication factor of 10. Duplication factor of 2 and explicit length of 3 Definition CFLD5 Field Contents C1C2C3C1C2C3 Topic: The Define Constant (DC) Instructions DC 2CL3'ABC' Explicit length of 10. Page 95 of 58 . All rights reserved..OS/390 Assembler Programming Introduction Unit: Defining Data Character Value (cont’d) The maximum length of a character constant is 256 bytes.

padded on the left with zeroes or truncated on the left if needed. Definition XFLD2 Field Contents 003C2F DC XL3'3C2F' Explicit length of 1 is shorter then the nominal value. The examples below illustrate the use of hexadecimal constant definitions. Definition XFLD4 Field Contents 0ABC Continued… Concepts © Copyright IBM Corp. The nominal value is specified as a series of hexadecimal characters. With no length modifier the length is determined by the nominal value Definition XFLD1 Field Contents 3C2F Topic: The Define Constant (DC) Instructions DC X'3C2F' Explicit length of 3 is longer the nominal value. Field is left truncated. Definition XFLD3 Field Contents 2F DC XL1'3C2F' Field must contain an even number of nibbles. All rights reserved. 2000.. are right justified in their field. DC X'ABC' Page 96 of 58 . 2004.OS/390 Assembler Programming Introduction Unit: Defining Data Hexadecimal Constants When do you use hexadecimal constants? Hexadecimal constants. like other numeric constants. Leading zero is inserted. Field is right justified and left padded with zeros.

Definition XFLD7 Field Contents AB0CDE DC X'AB.. with each length determined from the length of the nominal value. Definition XFLD5 Field Contents 0ABC0ABC DC 2X'ABC' Duplication factor of 3 and left truncated to 3 bytes. Page 97 of 58 . 2004. All rights reserved.OS/390 Assembler Programming Introduction Unit: Defining Data Topic: The Define Constant (DC) Instructions Hexadecimal Constants (cont’d) With data types other than character. Duplication factor of 2 and and padded to an even number of nibbles. multiple values can be defined in a single DC statement. by separating the values with commas. Definition XFLD6 DC 3XL3'1234567AB' Field Contents 4567AB4567AB4567AB Two values.CDE' Concepts © Copyright IBM Corp. 2000.

Definition BFLD4 Field Contents (Hex) 2D2D DC 2B'101101' Concepts © Copyright IBM Corp. left padded with zeros to form a complete byte. With no length modifier. The nominal value is specified as a string of bits (ones and zeroes).The field is padded on the left with zeros. Three leadings zero bits are added to form a complete byte. 2004.OS/390 Assembler Programming Introduction Unit: Defining Data Binary Constants When do you use binary constants? As a numeric type. Definition BFLD2 Field Contents 0017 DC BL2'10111' Length modifier of 1 determines the field length. binary constants are right justified. truncated on the left or padded on the left with zeroes. All rights reserved.. Definition BFLD3 Field Contents (Hex) BL1'10101010101' 55 DC Duplication factor of 2. Both binary and hexadecimal constants have a maximum length of 256. Definition BFLD1 Field Contents (Hex) 17 Topic: The Define Constant (DC) Instructions DC B'10111' Length modifier of 2 determines the field length. The nominal value is right justified and left truncated. Page 98 of 58 . 2000. length is determined by the nominal value.

In packed decimal format.OS/390 Assembler Programming Introduction Unit: Defining Data Zoned Decimal Format What are the two formats of decimal numbers? There are two formats of decimal numbers. Page 99 of 58 . Zoned decimal is represented one digit per byte. Topic: The Define Constant (DC) Instructions Zoned (Z) format: NUMERIC NIBBLE F 1 F 2 C 3 ZONE NIBBLE Packed (P) format: SIGN: C = + D=- 1 2 3 C F ONE BYTE ONE BYTE SIGN: C= + D= - The zone nibble is F in all nibbles except the rightmost.. which contains one numeric nibble and the sign nibble. except the rightmost. with each byte consisting of a zone nibble and a numeric nibble. 2000. each byte contains two numeric nibbles. Continued… Concepts © Copyright IBM Corp. 2004. All rights reserved. where it is a sign (usually C for + and D for -). zoned decimal and packed decimal.

Page 100 of 58 . All rights reserved. padded on the left with zeroes or truncated on the left. length is determined by the nominal value. so field is left padded with a zero. Definition ZFLD4 Field Contents (Hex) C1D2C3 DC Z'1. Some examples of zoned decimal constants are shown on the right.3' Duplication factor of 2. so field is left truncated. decimal constants are right justified. Definition ZFLD3 Field Contents (Hex) F2F3F4C5 DC ZL4'12345' Three separate constants. With no length modifier.-2. 2000.OS/390 Assembler Programming Introduction Unit: Defining Data Topic: The Define Constant (DC) Instructions Zoned Decimal Format (cont’d) As with other numeric types. Definition ZFLD5 Field Contents F1F2C5F1F2C5 DC 2ZL3'125' Concepts © Copyright IBM Corp. Definition ZFLD1 Field Contents F1F2F3F4C5 DC Z'12345' Explicit length of 6. Definition ZFLD2 Field Contents F0F1F2F3F4C5 DC ZL6'12345' Explicit length of 4. 2004..

you can specify nominal values that have an embedded decimal point.OS/390 Assembler Programming Introduction Unit: Defining Data Packed Decimal Although decimal numbers are integers.-4892' Decimal point is ignored. left padded with zeros.45' Concepts © Copyright IBM Corp. if the numbers are being used to represented a quantity with a decimal. In such cases. Definition PFLD2 Field Contents 0012345C DC PL4'12345' Explicit length of 2. Definition PFLD1 Field Contents 12345C Topic: The Define Constant (DC) Instructions DC P'12345' Explicit length of 4. With no length modifier. Page 101 of 58 . last two padded. such as dollars and cents. The hardware treats the value as an integer. Definition Field Contents (Hex) PFLD3 DC PL2'12345' 345C Three constants. 2004. so left padded with a zeros. so left truncated. Definition PFLD5 Field Contents 0003945C DC PL4'39. but the programmer can provide code to present the number with a decimal point when it is printed. Definition PFLD4 Field Contents (Hex) 1C037C04892D DC P'1. The maximum length of a decimal constant is 16 bytes. The technique can be useful for documentation purposes. 2000.. All rights reserved.37. the decimal point is ignored. length is determined by the nominal value.

The nominal value is coded in decimal. Definition HFLD3 Field Contents (Hex) 00050005 DC 2H5'5' Three constants. 2004. Definition HFLD2 Field Contents FFFB DC H'-5' Duplication factor of 2. 2000. represented in true binary Definition HFLD1 Field Contents 000A Topic: The Define Constant (DC) Instructions DC H'10' Constant is 2 bytes (1 halfword) long. DC H'50. Constant is 2 bytes (1 halfword) long. Definition HFLD4 Field Contents 0032FFF600A0 Continued… Concepts © Copyright IBM Corp.OS/390 Assembler Programming Introduction Unit: Defining Data Fixed Point Numbers Fixed-point numbers (halfwords and fullwords) are represented internally in true binary format for positive numbers and in two’s complement form for negative numbers.-10. represented in two's complement form.160' Page 102 of 58 .. All rights reserved.

2000. Constant is 4 bytes (1 fullword) long.30' Concepts © Copyright IBM Corp. Page 103 of 58 .28.31. represented in two's complement. Definition FFLD1 Field Contents 000000000000 0000000000000 DC 3F'0' Four constants. Definition FFLD1 Field Contents 000000FF DC F'255' Constant is 4 bytes (1 fullword) long. Definition FFLD4 Field Contents 0000001F000000 1C0000001F0000001E DC FL'31. All rights reserved. 2004.. represented in two's complement. Definition FFLD2 Field Contents FFFFFF9C DC F'-100' Duplication factor of 3.OS/390 Assembler Programming Introduction Unit: Defining Data Topic: The Define Constant (DC) Instructions Fixed Point Numbers (cont’d) The nominal value is coded in decimal.

2004. but only one will be discussed.. All rights reserved. An A-type address constant contains the absolute address of its operand. The nominal value of an address constant is specified within parentheses. rather than quotes. There are several types of address constants.OS/390 Assembler Programming Introduction Unit: Defining Data Address Constant What is an Address Constant? The final type of constant is called an address constant. 2000. To have the Assembler generate an address constant containing the address of FFLD1. An Atype address constant is 4 bytes long by default and is aligned on a fullword boundary. you would specify: AFLD1 DC A(FFLD1) Topic: The Define Constant (DC) Instructions Concepts © Copyright IBM Corp. Page 104 of 58 .

. . Suppose you wished to add 1 to the fixed-point value in GPR 5. ONE R5.ONE DC H’1’ Continued… Concepts © Copyright IBM Corp. . .OS/390 Assembler Programming Introduction Unit: Defining Data Literals What are Literals? Literals are used as a shortcut in Assembler Language programming. and then add that constant to the register. 2000. Page 105 of 58 . Without Literals: Topic: Literals AH . All rights reserved. An example of the code is shown on the right. 2004. One way to do this would be to be to code a constant with a value of 1.

followed by a value that would be valid in the operand field of a DC instruction. What actually happens when you code a literal is that the assembler sets up a constant. Without Literals: Topic: Literals AH R5. Page 106 of 58 . =H’1’ is the literal value. A literal is represented as an equal sign. All rights reserved. In the example. = H’1’ Literal Value Concepts © Copyright IBM Corp. at some place in storage (called the literal pool) and places the address of that constant in the operand field of the AH Instruction.OS/390 Assembler Programming Introduction Unit: Defining Data Literals (cont’d) What are the uses of literals? Using a literals allows you to eliminate the separate definition of the constant.. 2004. 2000.

OS/390 Assembler Programming Introduction Unit: Defining Data Addressability The Assembler creates an area called literal pool and places all literals into that area. Unless we tell the Assembler differently.. The assembler provides the programmer with some control over where that literal pool is created. it will create a single literal pool for all the modules in the assembly. All rights reserved. Why should we care? One reason is that some programs are composed of multiple modules. A value defined in one module may not be addressable by code in another module. each of which establishes it own addressability. 2004. Each module should be self-contained. Topic: Literals Concepts © Copyright IBM Corp. This is likely to produce addressability problems. Page 107 of 58 . 2000.

It does not have any operands. it creates a literal pool at that point. the literal pool is placed at the end of the first control section (CSECT) of your program. If you do not use any LTORG instructions in your program. if this is the first LTORG. 2000. All rights reserved. When the assembler encounters a LTORG instruction within a program. or since the beginning of the program. Continued… Concepts © Copyright IBM Corp.. containing all the literals specified since the last LTORG instruction. Page 108 of 58 . 2004.OS/390 Assembler Programming Introduction Unit: Defining Data Topic: Literals Functions of LTORG Instruction What is the function of the LTORG? The assembler instruction that directs the location of the literal pool is LTORG.

each CSECT will have its own literal pool at the end of the module. All rights reserved. 2004. MOD1 CSECT LTORG MOD2 CSECT LTORG MOD3 CSECT LTORG END Concepts © Copyright IBM Corp. Page 109 of 58 . 2000. So.. you should code a LTORG instruction as the last instruction of each control section in the program.OS/390 Assembler Programming Introduction Unit: Defining Data Topic: Literals Functions of LTORG Instruction (cont’d) To avoid addressability problems in multimodular programs.

and then print out the resulting data (output). except for the definition of I/O areas. which is done with assembler instructions. Read input data 5. Make the data set available 4.OS/390 Assembler Programming Introduction Unit: Basic MVS I/O Facilities Processing Input and Output Data The main purpose of most assembler programs is to read in data (input). 2004. I/O PROCESSING TASKS 1..DC OPEN GET PUT CLOSE Topic: Defining Data Sets Concepts © Copyright IBM Corp. All rights reserved. process it. The major steps for processing input and output data in a program are shown. Define the data set 2. Free the data set MVS MACRO DCB DS. Page 110 of 58 . 2000. Write output data 6. Define I/O areas 3. I/O macros are used to accomplish all of these tasks.

2004. Page 111 of 58 . The data is organized sequentially and processed by the DCB (Data Control Block) macro in the same manner. The block of constants is a set of data fields (or parameters) that control the look of the data set being processed. DCB RECORD1 EXE DCB PUT Continued… Concepts © Copyright IBM Corp. DATA SET GET Topic: Defining Data Sets The DCB macro instruction generates a large block of constants in order to process the data set.OS/390 Assembler Programming Introduction Unit: Basic MVS I/O Facilities Elements of Defining Data Sets Every Assembler program that processes I/O must provide information to the Assembler about the data sets to be processed. All rights reserved. 2000..

All rights reserved. 2000. .. Key Word Operand A DCB is a collection of data fields that contain information concerning the data set. . including: • The size and format of the records • The I/O macros used to process the data • The name and the current status of the data set Page 112 of 58 Concepts © Copyright IBM Corp. . . X EODAD=ENDDATA DATA FIELD DATA FIELD DATA FIELD DATA FIELD DATA FIELD DATA FIELD Keyword=SIGN Value MACRF=GM X Data Control Block Macro .RECFM=FB. . 2004.LRECL=80.OS/390 Assembler Programming Introduction Unit: Basic MVS I/O Facilities Topic: Defining Data Sets Elements of Defining Data Sets (cont’d) Name Field DCB Name Data Control Block INFILE DCB DDNAME=IN.MACRF=GM.DSORG=PS.

.. or the FILE parameter on the ALLOCATE TSO statement for interactive execution... The DDNAME parameter is used as a link to the external file this DCB represents. TSO ALLOCATE FILE(INPUT) ..etc... 2000. Concepts © Copyright IBM Corp..etc. 2004... All rights reserved. The value of the DDNAME parameter must match the DDNAME on the JCL DD statement for batch execution.etc Topic: Defining Data Sets JCL //INPUT DD ... DCB IN DCB DDNAME=INPUT. .OS/390 Assembler Programming Introduction Unit: Basic MVS I/O Facilities Parameters What are the parameters used in DCBs? A variety of keyword parameters are used with input and output DCBs. Page 113 of 58 .

In the examples in this course. and FBA (fixed length blocked records with American National Standard Institute (ANSI) printer control characters) for output. 2000.OS/390 Assembler Programming Introduction Unit: Basic MVS I/O Facilities Kinds of Parameters The DSORG parameter specifies the organization of the data set represented by this DCB. and PM (Move mode of the PUT Macro) for output. the parameter is always PS. You specify GM (Move mode of the GET macro) for input.. The MACRF parameter specifies the format of macros used to access the records in the data set. which is an acronym for Physical Sequential. You specify FB (fixed length blocked records) for input. Topic: Defining Data Sets DSORG PS GM MACRF PM INPUT OUTPUT FB RECFM FBA INPUT OUTPUT Continued… Concepts © Copyright IBM Corp. 2004. Page 114 of 58 . All rights reserved. The RECFM parameter specifies the record format of the data set being processed.

Page 115 of 58 . Omit this parameter for input data sets and use 6650 for output.RECFM=FB. 2000. 2004.RECFM=FBA. or blocks. All rights reserved.DSORG=PS.OS/390 Assembler Programming Introduction Unit: Basic MVS I/O Facilities Kinds of Parameters (cont’d) INPUT DATA SET INFILE DCB INPUT 80 Bytes from Data DDNAME=IN.. in the data set. The BLKSIZE parameter specifies the size of physical records. This parameter is only specified for input data sets.BLKSIZE=6650. EODAD=ENDDATA X Topic: Defining Data Sets SPECIFY WITH INPUT DATA SETS ONLY OUTFILE DCB DDNAME=OUT.MACRF=GM.LRECL=80.MACRF=PM OUTPUT 133 Characters to Printer X OUTPUT DATA SET The LRECL parameter specifies the length of logical records in the data set. You specify 80 for input and 133 for output. LRECL=133. DSORG=PS. Concepts Concepts © Copyright IBM Corp. The EODAD parameter (End of Data Address) specifies a label in your program where control is to be transferred when a GET is attempted and no more data exists.

2000. (OUTFILE. For output data sets. You use the OPEN macro instruction for this purpose. they must be opened. OPEN will create a new data set if the JCL or ALLOCATE statement so specifies. and prepare it for processing. Macro Input DCB Output DCB Label of the DCB statement associated with the data set Indicates the purpose for which the data set is being opened Concepts © Copyright IBM Corp.OS/390 Assembler Programming Introduction Unit: Basic MVS I/O Facilities Defining Data Set Elements Before input and output operations on data sets can be performed.. 2004. All rights reserved. confirm that it matches your specifications.(INPUT)) . OPEN (INFILE. or made available for processing. Page 116 of 58 .(OUTPUT)) Topic: Defining Data Sets What is the function of the OPEN macro? The OPEN macro generates executable instructions that invoke operating system routines to check for the presence of a data set.

These statements are discussed in more detail in the next section. prior to ending the program.. The CLOSE macro to close the two data sets is coded as follows: CLOSE (INFILE.. code data transfer macros. Page 117 of 58 .OS/390 Assembler Programming Introduction Unit: Basic MVS I/O Facilities Defining Data Sets ..OUTFILE) Close Macro: Topic: Defining Data Sets CLOSE (INFILE . 2000. 2004.The CLOSE macro is used for file housekeeping. GET for input and PUT for output. Having finished the I/O processing. All rights reserved. close the DCBs. OUTFILE) Macro (GET) (PUT) no options required Concepts © Copyright IBM Corp.Summary Once the DCB has been opened.

. for input. moves the record from the data set to a buffer in main storage and from the buffer to the work area named INAREA.(OUTPUT)) Topic: Data Transfer Macros Although data is transferred between the I/O device and buffer is main storage. The Move Mode data transfer macro. Move Mode I/O moves single logical record to/from a work area.OS/390 Assembler Programming Introduction Unit: Basic MVS I/O Facilities Move Mode What is Move Mode? The method by which data is transferred from or to an I/O device is called Move Mode. you must define a work area for each data set.INAREA PUT OUTFILE.(INPUT). one block at a time. The Move Mode data transfer macro. All rights reserved.OUTFILE) Continued… Concepts © Copyright IBM Corp..INAREA MVC OUTREC. moves the record from the work area named OUTAREA to the buffer in the main storage and from the buffer to the I/O device. 2000. OPEN (INFILE. for output. LOOP EQU * GET INFILE.OUTFILE. Page 118 of 58 . When using this mode. 2004.OUTAREA B ENDDATA EQU LOOP * CLOSE (INFILE.

2000. The output records are 133 characters in length. DATA Topic: Data Transfer Macros 80-bytes GET INAREA DS CL80 PUT MVC CL80 OUTAREA DS CL133 CL133 Concepts © Copyright IBM Corp.. Page 119 of 58 . These areas could be subdivided by using the zero duplication factor technique. All rights reserved.OS/390 Assembler Programming Introduction Unit: Basic MVS I/O Facilities Move Mode (cont’d) The work area must be the same length as the logical record. so the input work area is defined as shown. The logical records in the input data set are 80 bytes in length. 2004. so the output work area is defined as shown.

INAREA Concepts © Copyright IBM Corp. the macro would be coded as shown on the right. Topic: Data Transfer Macros Move Mode: GET dcbname . and another GET macro is issued. All rights reserved. When the end of the input data is reached. the GET macro reads the next logical record in the data set into a work area. control is transferred to the address specified as the EODAD in the DCB macro. workareaname GET INFILE . 2000. 2004.OS/390 Assembler Programming Introduction Unit: Basic MVS I/O Facilities GET Macro Once a data set is opened. The format of the GET macro in the move mode is shown on the right. Using the names used up to this point. Page 120 of 58 ..

OS/390 Assembler Programming Introduction Unit: Basic MVS I/O Facilities PUT Macro What is the function of the PUT Macro? The PUT macro is used to write the next logical record from the work area to the output data set. Using the names used up to this point.. OUTAREA Topic: Data Transfer Macros Move Mode: PUT dcbname . workareaname PUT Concepts © Copyright IBM Corp. coding would appear as shown on the right. 2000. The format of the PUT macro in move mode is shown on the right. OUTFILE . Page 121 of 58 . 2004. All rights reserved.

All rights reserved. which is used to specify spacing on the printer. The most common ANSI printer control characters and their meanings are shown on the right. Topic: Data Transfer Macros RECFM=FBA ANSI Control Character ANSI Printer Control Character Space 0 + 1 Meaning Single space Double space Triple space Suppress space (overprint last line) Skip to top of next page Concepts © Copyright IBM Corp.. 2000. Page 122 of 58 . 2004.OS/390 Assembler Programming Introduction Unit: Basic MVS I/O Facilities ANSI Control Character The record format parameter we have used for our output data set is FBA and is coded as shown: RECFM=FBA The A specifies that the first byte of each record is an ANSI control character.

OUTAREA B LOOP EQU * CLOSE (INFILE.LRECL=133. 2000.DSORG=PS. double spaced.. on the printer.LRECL=80. All rights reserved. DSORG=PS. you code a program segment to read data from an input data set.OUTFILE) CL80 DS C'0' CL80 DC DCB DCB prepare dcbs for processing get next input record move to output record write output record continue with next record handle end of data situation close dcbs INPUT GET DATA OP LO RECORD M VC RECORD OUTPUT PUT INAREA DS OUTAREA OUTASA DC OUTREC DS INFILE OUTFILE RECORD 0CL133 specify double spacing copy of input goes here make the rest spaces X X CL52 ' ' DDNAME=IN. 2004. OUTFILE.OS/390 Assembler Programming Introduction Unit: Basic MVS I/O Facilities Consolidating I/O Information Topic: Data Transfer Macros LOOP ENDDATA OPEN (INFILE.RECFM=FBA. INAREA MVC OUTREC. and then print it out. Page 123 of 58 . Concepts Concepts © Copyright IBM Corp. (OUTPUT) ) EQU * GET INFILE.MACRF=GM.RECFM=FB.BLKSIZE=6650.MACRF=P RECORD To put all of this I/O information together. EODAD=ENDDATA DDNAME=OUT. INAREA PUT OUTFILE.. (INPUT) .

A or E = (+) Positive D or B = (-) Negative If you attempt to perform decimal arithmetic with an operand that is not in valid format. 2004. F.. Topic: Basics of Decimal Arithmetic Packed Decimal Operand: 40 4C Valid Packed Decimal Number Digits 0 to 9 Sign Code C. The preferred signs for packed decimal numbers are C for positive and D for negative. a data exception will occur. All rights reserved. The remaining bytes of a packed decimal number (other than the rightmost) contain two decimal digits. Continued… Page 124 of 58 . one in each nibble.OS/390 Assembler Programming Introduction Unit: Decimal Arithmetic Packed Decimal Operands What do packed decimal operands contain? Packed decimal operands are fields in main storage from 1 to 16 bytes in length. The rightmost byte of a packed decimal field contains a decimal digit in the left nibble and a sign in the right nibble. Concepts © Copyright IBM Corp. 2000.

All rights reserved. Page 125 of 58 . A or E = (+) Positive D or B = (-) Negative Concepts © Copyright IBM Corp.1 digits. The maximum field length for a multiplier or divisor is 8 bytes. The maximum number of digits in a packed decimal number is 31.OS/390 Assembler Programming Introduction Unit: Decimal Arithmetic Topic: Basics of Decimal Arithmetic Packed Decimal Operands (cont’d) A packed field n bytes long can hold 2 * n -. 2004. since the maximum field length is 16.. F. 2000. Packed Decimal Operand: 40 4C Valid Packed Decimal Number Digits 0 to 9 Sign Code C.

decimal arithmetic allows both +0 and -0 to be represented. If overflow occurs.. If a packed decimal arithmetic operation generates a zero result without overflow. Page 126 of 58 . Unlike fixed-point representation. which only provides one zero value. the truncated number is zero. 1C + 1D 0C Zero Result Without Overflow – Result Equals (+0) Bytes truncated 5D + 5D 0D Overflow-truncation-Result Equals (-0) Concepts © Copyright IBM Corp. 2004.OS/390 Assembler Programming Introduction Unit: Decimal Arithmetic Topic: Basics of Decimal Arithmetic Decimal Arithmetic Instructions What are decimal arithmetic instructions? The decimal arithmetic operations are SS (Storage to Storage) (2 length) instructions. the sign generated is that of the non-truncated number. Decimal arithmetic is performed in main storage. 2000. Operands do not have to be of the same length. the result will be +0. All rights reserved.

. 2 bit Field CC 18 Program Mask 20 Instruction Operands: RR AR R1. and can then be tested by subsequent instructions to implement conditional execution. • SS instructions have both operands in storage. 2000. DATA1 SS MVC FLD2. Where are instruction operands located? Instruction operands are located in main storage or in registers.OS/390 Assembler Programming Introduction Unit: Decimal Arithmetic Condition Code What is a condition code? EC Mode PSW: Topic: Basics of Decimal Arithmetic The condition code is a two-bit field in the Program Status Word (PSW) that is set by some instructions. 2004. The operand's instruction type determines the location of the operands for each particular instruction: • RR instructions have two operands in registers • RX instructions have the first operand in a register and the second in storage. Page 127 of 58 . All rights reserved. R2 RX L R3.FLD1 Concepts © Copyright IBM Corp.

ZONED DECIMAL DATA Zone Nibble F Numeric Nibble Sign Nibble C – (+) D – (-) 1 F 1 F 1 Sign Nibble C – (+) D – (-) 1 2 3 C One Byte PACKED DECIMAL DATA Numeric Nibble Concepts © Copyright IBM Corp. with an 'F' sign. Packed decimal data consists of two decimal digits per byte for the rightmost.. 2004. 2000. which contains a numeric nibble followed by a sign nibble.OS/390 Assembler Programming Introduction Unit: Decimal Arithmetic Topic: Decimal Type Conversion Digits in Zoned and Packed Decimal Types How many digits do zoned decimal and packed decimal data contain? Zoned decimal data has one digit per byte. with each byte consisting of a zone nibble and a decimal numeric nibble. Numbers in character form (EDCDIC code) are zoned. The zone in the rightmost byte is the sign. All rights reserved. Page 128 of 58 .

All rights reserved.. but in order to be used in decimal arithmetic they must be packed. 2004.DATA CC setting – Condition Code is Unchanged Pack (PACK): SS Format (2 length) – Storage to Storage PACK 1st Operand NUM NUM. Page 129 of 58 . The second operand is converted from zoned to packed format. and the result stored in the first operand.OS/390 Assembler Programming Introduction Unit: Decimal Arithmetic Topic: Decimal Type Conversion Converting Zoned Decimal Numbers to Packed Decimal Numbers How do you convert zoned decimal numbers to packed decimal format? You often need to convert zoned decimal numbers to packed decimal format. For example: PACK NUM. The numbers are read in zoned form. The instruction that performs this conversion is called Pack (PACK) and is shown on the right. DATA 2nd Operand DATA 00 Target 00 I2 3C F1 F2 C3 Source PACK Conversion Result 00 00 I2 3C Left padding Supplied by PACK Continued… Concepts © Copyright IBM Corp. 2000.

OS/390 Assembler Programming Introduction Unit: Decimal Arithmetic Topic: Decimal Type Conversion Converting Zoned Decimal Numbers to Packed Decimal Numbers (cont’d) The operation of PACK is as follows: • It processes each operand right to left. Pairs of bytes are selected from the second operand and combined into a single byte by combining numeric nibbles and discarding zone nibbles. Page 130 of 58 . The combined single byte is stored in the first operand. All rights reserved. left padding with zeroes occurs. If the length of the second operand. Length of FLD2 4 5 6 Length =4 Contents of FLD2 F1F2F3F4 F1F2F3F4F5 F1F2F3F4F5F6 Resulting value of FLD1 01234F 12345F 23456F Length =5 • F1 F2 F3 F4 FLD2 F1 F2 F3 F4 F5 FLD2 01 23 4F FLD1 12 34 5F FLD1 Length = 6 • Left padding supplied by PACK F1 F2 F3 F4 F5 F6 FLD2 Ignored. is greater than 2*L1-1. The rightmost byte of the second operand has its nibbles reversed in order and the result is stored in the rightmost byte of the first operand. L2.. left truncation occurs. 2000. If L2 is less than 2*L1-1. truncated By PACK 23 45 6F FLD1 Concepts © Copyright IBM Corp. 2004.

For example: UNPK OUTFLD. Page 131 of 58 . 2000. CALCFLD Unpack (UNPK): SS Format (2 length) – Storage to Storage UNPK 1st Operand OUTFLD. from packed decimal to zoned decimal is performed by the Unpack (UNPK) instruction. The second operand is converted from packed to zoned format and the result stored in the first operand.. All rights reserved. 2004.OS/390 Assembler Programming Introduction Unit: Decimal Arithmetic Topic: Decimal Type Conversion Converting from Packed Decimal to Zoned Decimal Numbers How do you convert from packed decimal to zoned decimal numbers? The reverse conversion. CALCFLD 2nd Operand OUTFLD CALCFLD 00 Target 00 00 00 00 01 23 4C Source UNPK Conversion Result F0 CC setting – Condition Code is Unchanged F1 F2 F3 C4 Continued… Concepts © Copyright IBM Corp.

left truncation.OS/390 Assembler Programming Introduction Unit: Decimal Arithmetic Topic: Decimal Type Conversion Converting from Packed Decimal to Zoned Decimal Numbers (cont’d) The operation of UNPK is as follows: 1. 2. 3. or left padding with zero will occur. It is then stored in the first operand. For example: UNPK FLD3. If L1 is not equal to 2*L2-1. truncated by UPNK Length = 4 12 34 56 7C FLD4 Continued… Concepts © Copyright IBM Corp. All rights reserved. 2004. FLD4 F3 F4 F5 F6 C7 FLD3 Length Of FLD4 2 3 4 Contents of FLD4 123C 12345C 1234567C Resulting value Of FLD3 F0F0F1F2C3 F1F2F3F4C5 F3F4F5F6C7 Length =3 Length =2 12 3C FLD4 12 34 5C FLD4 F0 F0 F1 F2 C3 FLD3 F1 F2 F3 F4 C5 FLD3 Left padding supplied by UPNK Ignored. It proceeds from right to left through its two operands. The nibbles of the rightmost byte of the second operand are swapped and stored in the rightmost byte of the first operand. Page 132 of 58 .. Each nibble of the second operand is expanded to a byte by inserting an 'F' in the zone nibble. 2000.

Page 133 of 58 . and interpret the contents as characters. the right most character is not a digit. X ‘FO’ Prints as 123 DATA F1 F2 F3 C3 F0 F3 Result Continued… Concepts © Copyright IBM Corp. 2004. 2000. To unpack a number with one of these signs. That is because digits have 'F' in the zone position. the signs generated are C for + and D for -. All rights reserved. while an unpacked number has 'C' or 'D'.OS/390 Assembler Programming Introduction Unit: Decimal Arithmetic Topic: Decimal Type Conversion Converting from Packed Decimal to Zoned Decimal Numbers (cont’d) Notice that when you do arithmetic on packed numbers.. OR Immediate: Prints as 12C DATA F1 FL C3 OR Immediate changes the sign nibble 0I DATA + 2.

NUM5 PRTFLD UNPK PRTFLD. 2000. X ‘F0’ F7 © Copyright IBM Corp. 2004. DS PL4 DS ZL7 PRTFLD Prints As 123456c F1 F2 F3 F4 F5 F6 C7 OR immediate Changes the sign nibble C7 F0 0I PRTFLD F1 F2 F3 F4 F5 F6 F7 Prints as 1234567 Result Concepts Page 134 of 58 PRTFLD + 6. X ‘F0’ . . NUM5 OI PRTFLD + 6.OS/390 Assembler Programming Introduction Unit: Decimal Arithmetic Topic: Decimal Type Conversion Converting from Packed Decimal to Zoned Decimal Numbers (cont’d) The following code shown on the right formats the contents of a 4 byte packed field called NUM5 for printing. All rights reserved. . ..

OS/390 Assembler Programming Introduction Unit: Decimal Arithmetic Zero and Add Instruction What is the Zero and Add Instruction? The Zero and Add (ZAP) instruction is used to move packed data from one main storage location to another.. but the initial contents of the receiving field are not checked. 2000. . However. The sending field must contain a valid packed number .result is positive 3 . All rights reserved. DATA1 Zero and Add (ZAP): SS Format (2 length) – Storage to Storage ZAP 1st Operand DATA 12 34 5F RESULT. 2004.result is negative 2 . For example: ZAP RESULT. and then the spending field is added to it. overflow can occur if the receiving field is not long enough to hold all of the significant digits of the sending field.overflow Continued… Page 135 of 58 Concepts © Copyright IBM Corp. The field sizes of the sending and receiving fields do not have to be equal. The operation proceeds as if the receiving field was zeroed.DATA1 2nd Operand RESULT BA C0 F3 49 Topic: Decimal Arithmetic Operations Zero 1st Operand ZAP 00 00 00 00 Add 2nd Operand 12 34 5F CC setting: 0 – result is zero 1 .

= P ‘100’ . . 2000. PL1 Receiving 0C FLD1 . The overflow condition occurs when the magnitude of an arithmetic result is too large to fit into the result field. 2004. The abbreviation "CC setting: Arithmetic" will be in reference to these condition code settings. FLD1 ZAP DS FLD1. You would get an overflow condition if you executed the instruction on the right. 10 is truncated and CC is set to 3. Page 136 of 58 . All rights reserved.OS/390 Assembler Programming Introduction Unit: Decimal Arithmetic Topic: Decimal Arithmetic Operations Zero and Add Instruction (cont’d) The condition codes shown previously are standard for many arithmetic instructions.100 requires 2 Bytes -Overflow Indicator Truncated Continued… 10 0C CC <.3 Concepts © Copyright IBM Corp.. 100 will not fit into a 1 byte packed field.1 Byte 10 0C LITERAL 100 . .

It is important to give sufficient thought to choosing appropriate field lengths and to use greater lengths if you are unsure. 2000. . Page 137 of 58 . . PL1 For example: ZAP FLD1. 2004. = P ‘0’ . FLD1 ZAP DS FLD1.OS/390 Assembler Programming Introduction Unit: Decimal Arithmetic Topic: Decimal Arithmetic Operations Zero and Add Instruction (cont’d) In the latter case.=P'0' Receiving Sending 0C FLD1 .1 Byte 0C The fields FIT CC .1 Byte LITERAL 0 .0 Continued… Concepts © Copyright IBM Corp.. the program may seem to execute correctly but produce incorrect numeric results. All rights reserved.

2004. Page 138 of 58 . Packed Decimal ZAP Packed Decimal Concepts © Copyright IBM Corp. ZAP is used in these cases. 2000. All rights reserved. it is necessary to place an operand in a larger field for the operation to work successfully..OS/390 Assembler Programming Introduction Unit: Decimal Arithmetic Topic: Decimal Arithmetic Operations Zero and Add Instruction (cont’d) ZAP is used primarily to initialize packed decimal fields and to move packed data from one location to another. like multiplication and division. For some operations.

=P'1‘ LITERAL 1 A literal value of one is added to count.Arithmetic Receiving Sum replaces value in COUNT Continued… Concepts © Copyright IBM Corp.OS/390 Assembler Programming Introduction Unit: Decimal Arithmetic Add Decimal What is the function of Add Decimal? The Add Decimal (AP) adds a packed decimal sending field (second operand) to a packed decimal receiving field ( first operand). and sets the condition code according to the result.. For example: AP COUNT. VALUE Topic: Decimal Arithmetic Operations Add Decimal (AP): SS Format (2 length) – Storage to Storage AP 1st Operand AP COUNT COUNT. Page 139 of 58 . 2000. 2004. = P ‘1’ 2nd Operand + VALUE Sending SUM CC Setting . All rights reserved. It places the sum in their receiving field.

2004. . Topic: Decimal Arithmetic Operations ZAP AP AP AP ZAP TOTAL.. All rights reserved. X1 TOTAL. X3 TOTAL.OS/390 Assembler Programming Introduction Unit: Decimal Arithmetic Add Decimal (cont’d) To sum 4 values called X1. X2 TOTAL.Arithmetic Page 140 of 58 © Copyright IBM Corp. 2000. X3 and X4 into a field called TOTAL. X2. since no information is given about whether TOTAL was initialized to zero. Concepts TOTAL VALUE Receiving SUM SUM replaces Value in TOTAL CC Setting . X4 X1 TOTAL TOTAL is an unknown ZAP moves X1 to Zero TOTAL AP X2 + VALUE Sending Repeat for X3 and X4 The first instruction has to be a ZAP. you could use the code shown on the right.

and the difference placed in TOTAL. DISCOUNT VALUE Sending DIFF CC Setting . 2000. For example: SP TOTAL. 2004.Arithmetic Concepts Page 141 of 58 Topic: Decimal Arithmetic Operations Subtract Decimal (SP): SS Format (2 length) Storage to Storage SP 1st Operand 2nd Operand TOTAL. .. All rights reserved. places the difference in the receiving field (first operand). DISCOUNT The contents of DISCOUNT are subtracted from TOTAL.OS/390 Assembler Programming Introduction Unit: Decimal Arithmetic Subtract Decimal What is the function of the Subtract Decimal? The Subtract Decimal (SP) instruction subtracts a packed decimal in the sending field (second operand) from a packed decimal in the receiving field (first operand). and then sets the condition code according to the results. DISCOUNT SP TOTAL VALUE Receiving DIFF replaces value in TOTAL © Copyright IBM Corp.

and must be less than the length of the multiplicand. a data exception occurs.. 2000. a specification exception occurs. 2004. which also holds the product. . MP MPCND.OS/390 Assembler Programming Introduction Unit: Decimal Arithmetic Multiply Decimal What are the functions of the multiplier and multiplicand? Decimal multiplication takes into account the fact that the length of the product can be as long as the combined lengths of multiplier and multiplicand. as there are bytes in multiplier. . when the instruction is executed the multiplicand must have as many bytes of high order zeros. MPLR . The length of the multiplier may not exceed 8 bytes. All rights reserved. Page 142 of 58 . If this condition is not met. Also. DS DS Topic: Decimal Arithmetic Operations MPCND MPLR PL4 PL2 Specification Exception: 2 bytes longer Specification Exception Does not occur MPCND 00 00 12 3C 99 9C MPLR Data Exception: MPCND MPLR 2 bytes of high– order Zeros not present – Data Exception 00 12 34 5C 99 9C Concepts © Copyright IBM Corp. If these conditions are not satisfied.

OS/390 Assembler Programming Introduction Unit: Decimal Arithmetic Signs How do you determine the sign of a product? The sign of the product is determined by the rules of algebra. so a negative zero result can occur. This rule holds even when either multiplier or multiplicand is zero. Page 143 of 58 . All rights reserved. 2000. NUM2 2nd Operand Topic: Decimal Arithmetic Operations MP NUM2 * VALUE Sending VALUE Receiving PRODUCT PRODUCT replaces value in NUM1 NUM1 Concepts © Copyright IBM Corp. 2004. if the signs of the multiplier and the multiplicand are the same. NUM2 CC Setting – Condition Code is Unchanged Multiply Decimal (MP): SS Format (2 length) – Storage to Storage MP 1st Operand NUM1. the product is positive. For example: MP NUM1. otherwise the product is negative. The Multiply Decimal (MP) instruction multiplies a packed decimal multiplicand contained in the first operand storage location by a packed decimal multiplier contained in the second operand storage location. That is..

2000. you would define a field 8 bytes long to hold the product. DS PL5 DS PL3 DS PL8 Topic: Decimal Arithmetic Operations NUM1 NUM2 PRODUCT Length of NUM1 Length of NUM2 Length of Product 5 Byte + 3 Byte = 8 Byte To ensure that you have enough Low – Order Zeros. and NUM2 a 3 byte field. Concepts © Copyright IBM Corp. Page 144 of 58 . All rights reserved. ZAP PRODUCT. the Product field must be > or =to the Sum of the lengths of Multiplicand and Multiplier. The code to perform the multiplication is shown on the right. .NUM2 . . If NUM1 was a 5 byte field..OS/390 Assembler Programming Introduction Unit: Decimal Arithmetic Field Lengths How do you avoid problems with field lengths? A standard technique to avoid problems with field lengths using Multiply Decimal is to use a field which is the sum of the lengths of multiplier and the multiplicand for the product.NUM1 MP PRODUCT. 2004.

2000. All rights reserved.=P’4’ Topic: Decimal Arithmetic Operations 2nd Operand DP NUM3 CC Setting – Condition Code is Unchanged Continued… Concepts © Copyright IBM Corp.OS/390 Assembler Programming Introduction Unit: Decimal Arithmetic Divide Decimal What is the function of the Divide Decimal? The Divide Decimal (DP) instruction divides a packed decimal dividend (first operand) by a packed decimal divisor (second operand). % VALUE Divisor QUO REM VALUE Dividend Quotient and Remainder replaces value In NUM3 Divide Decimal (DP): SS Format (2 length) – Storage to Storage DP 1st Operand NUM3. For example: DP NUM3. Page 145 of 58 . and the remainder in the rightmost byte. with the quotient replacing all but the rightmost byte of NUM3.=P'4' Literal 4 NUM3 is divided by 4. 2004. The quotient and the remainder replace the dividend in the first operand..

Decimal Division: L1 Before DIV DIVIDEND S1 Topic: Decimal Arithmetic Operations DIVISOR L2 QUO L1 –L2 REMAINDER L2 S2 L1 = Length of Dividend in Bytes L2 = Length of Divisor in Bytes Rules: L1 – Maximum of 16 Bytes L2 – Maximum of 8 Bytes L1 must be greater than L2 Continued… © Copyright IBM Corp. 2004. the quotient and remainder share the first operand field that initially contained the dividend.. The length of the remainder field equals the length of the divisor field. The length of the quotient field is equal to the length of the dividend field. or the quotient is too large to fit into the quotient field. After the division. minus the length of the divisor field. All rights reserved. If the divisor is zero. A specification exception results if the dividend field is not longer than the divisor field. Concepts Page 146 of 58 .OS/390 Assembler Programming Introduction Unit: Decimal Arithmetic Divide Decimal (cont’d) Decimal division is integer division and so it produces both an integer quotient and an integer remainder. Both quotient and remainder are packed decimal fields. a decimal divide exception occurs. with the quotient preceding the remainder. or if the divisor length is greater than 8 bytes. 2000.

To divide NUM4 (6 bytes long) by NUM5 (2 bytes long).. . All rights reserved. the quotient is in QUOTIENT and the remainder in REMAINDER. 2000. prior to the division. .NUM5 . DS PL6 DS PL2 DS PL8 DS PL6 DS PL2 Topic: Decimal Arithmetic Operations NUM4 NUM5 QUOREM QUOTIENT REMAINDER Assume NUM4 = 1000 NUM5 = 7 Before Division After ZAP QUOREM After Division QUOREM 000000000001000C PL6 PL2 0 0 0 0 0 0 0 0 1 4 2 C 006C QUO REM Page 147 of 58 Concepts © Copyright IBM Corp.OS/390 Assembler Programming Introduction Unit: Decimal Arithmetic Divide Decimal (cont’d) A useful technique in performing decimal division is to move the dividend to a field as large as the sum of the dividend and the divisor field lengths. the code shown on the right could be used.NUM4 DP QUOREM. and one for the quotient and remainder (after the division). . After the DP instruction. You can use the technique of zero duplication factor to define this single field in two ways: one for the dividend (before the division). ZAP QUOREM. 2004.

OS/390 Assembler Programming Introduction Unit: Decimal Arithmetic Topic: Decimal Arithmetic Operations Shift and Round Decimal Instruction What is the function of the Shift and Round Decimal Instruction? The Shift and Round Decimal Instruction (SRP) allows you to multiply and divide packed decimal numbers by powers of ten.value – Right Shift CC Setting . 2000. and to round when right shifting (dividing). but with a difference. The SRP instruction is a two length SS format instruction.Arithmetic Continued… Concepts © Copyright IBM Corp. The first operand specifies the number to be shifted.. What would normally be the L2 field is called l3 and holds the rounding factor. Shift and Round Decimal (SRP): SS Format (2 length) – Storage to Storage FO L1 I3 B1 D1 B2 D2 Immediate Data Second Operand S XXXXX 0 . All rights reserved. 2004.31 Used to generate Shift Magnitude And Direction Signed Fixed – Point Value + value – Left Shift . Page 148 of 58 .

0 NUM9 00 00 12 34 5C Continued… Concepts © Copyright IBM Corp. 2004.3.0 NUM9 NUM9 is shifted 3 decimal positions to the left.. 2000. the condition code is set to indicate overflow. For example: SRP NUM9. 01 23 45 00 0C + ve shift left Rounding: SRP NUM9. In the case of a right shift. Page 149 of 58 . The first operand is shifted the number of positions and direction specified by the second operand. This is equivalent to multiplying NUM9 by 1000. the absolute value of the first operand is rounded by the rounding factor.OS/390 Assembler Programming Introduction Unit: Decimal Arithmetic Topic: Decimal Arithmetic Operations Shift and Round Decimal Instruction (cont’d) If a significant digit is shifted out during a left shift. All rights reserved.3.

3. the second operand. is a displacement field only.0 2nd Operand Displacement 0 B 0 D 0 D 3 D Continued… Concepts © Copyright IBM Corp. All rights reserved. NUM9 is the first operand. 2004. Rounding: 1st Operand Immediate Data SRP NUM9. 3. 0 is the immediate operand. the rounding factor..OS/390 Assembler Programming Introduction Unit: Decimal Arithmetic Topic: Decimal Arithmetic Operations Shift and Round Decimal Instruction (cont’d) It is useful to look at the syntax of the above instruction before proceeding. Page 150 of 58 . 2000.

What is needed in the displacement field is the value that corresponds to the 6 bit value -3. you might be tempted to specify -3 as the second operand. This would be incorrect.. 2000. Calculate this as 1111012.5 Rounding: 00011 = +3 11100 – Flip Bits +1 – Add 1 11101 = -3 Twos Complement =-3 SRP NUM9.61. To shift NUM9 3 positions to the right. in sign and two's complement form.OS/390 Assembler Programming Introduction Unit: Decimal Arithmetic Topic: Decimal Arithmetic Operations Shift and Round Decimal Instruction (cont’d) If you want to specify a right shift of 3.61. Displacements must be in the range of 0-4095. All rights reserved. specify this as follows. 2004. with half rounding.5 Continued… Concepts © Copyright IBM Corp. SRP NUM9. Page 151 of 58 . Negative displacements are invalid. which is 6110.

PRICE MP CALC.5 shift right 3 positions and half round ZAP CALC. SRP NUM9. 2000. PRICE CALC DS PL4 DS PL6 Concepts © Copyright IBM Corp. . Page 152 of 58 . to shift n positions to the right. You can actually code the second operand of SRP as follows. half rounded . . 2004.64-3. All rights reserved. to make the code more clear. =P’ 108’ (Price with Sales tax) SRP CALC .5 price with sales tax. specify the second operand as 64-n. 64-2 ..OS/390 Assembler Programming Introduction Unit: Decimal Arithmetic Topic: Decimal Arithmetic Operations Shift and Round Decimal Instruction (cont’d) In general.

. In this case. 2000.OS/390 Assembler Programming Introduction Unit: Decimal Arithmetic Editing Decimal Data For many programs.234.89. If you are doing currency calculations. PACKED Indicates Number according formatting to MASK Instruction Structure DE L B DDD B DDD Length 1st Operand 2nd Operand Concepts © Copyright IBM Corp. you can use commas to break the number up for readability . Editing: Topic: Editing Decimal Data ED MASK. 2004. All rights reserved. and with a period separating dollars and cents. If you are dealing with large numbers. your output might be presented as $1.789 are easier to read and interpret than 123456789. Page 153 of 58 .567. Numbers such as 123. you might want to present your results with a dollar sign. it is important to present numeric results in a format that is easy to read and interpret. The Edit instruction is provided for the purpose of formatting numeric output.456.

345.234.01 12. Page 154 of 58 .12 0. the power comes at a price. 2000. In order to use the full power of Edit. Edit is a very complex instruction. in that it allows you greater control and flexibility in presenting numeric output.45 12. All rights reserved.34 1.345..67 1.OS/390 Assembler Programming Introduction Unit: Decimal Arithmetic Edit Instruction What is an Edit Instruction? Edit is a very powerful instruction. 2004.23 0. Topic: Editing Decimal Data Value 1234567 0123456 0012345 0001234 0000123 0000012 0000001 -1234567 Formatted Value 12. you must take the time to understand the details of how it works.67- Concepts © Copyright IBM Corp.56 123. However.

and punctuations such as commas. However. 2004.67Punctuation Sign (-) Significant Digit Not a Significant Digit Continued… Concepts © Copyright IBM Corp. The formatted values contain digits. All rights reserved. to make reading the numbers easier. not all of the digits are significant in all of the examples. 2000.234. Zeroes preceding the first nonzero digit in a value are not significant. The positive sign is not shown. Topic: Editing Decimal Data Digit prior to period is also chosen Value 1234567 0123456 0000001 -1234567 Formatted Value 12..67 1.345.OS/390 Assembler Programming Introduction Unit: Decimal Arithmetic Edit The values of all consist of seven digits and a sign. Page 155 of 58 .01 12. periods and minus signs.56 0.345. Note that the values are all 7 digits and a sign.

Page 156 of 58 .56 ***123..01 Concepts © Copyright IBM Corp. The table of formatted values would then look like the table shown on the right. Topic: Editing Decimal Data Value 1234567 0123456 0012345 0001234 0000123 0000012 0000001 Formatted Value 12. 2000. All rights reserved.45 ****12.67 *1.OS/390 Assembler Programming Introduction Unit: Decimal Arithmetic Edit (cont’d) If you were printing an amount on a check.345.234.12 *****0. you might want to format the amounts in dollars and cents to make it difficult to manually change the check. One way to do this is to print asterisks rather than spaces prior to the first significant digit. 2004.34 *****1.23 *****0.

zero Turned on by Character in MASK Concepts © Copyright IBM Corp. Edit must be aware of whether the digit it is handling is significant or not.OS/390 Assembler Programming Introduction Unit: Decimal Arithmetic Significance Indicator What is the Significance Indicator? In order to handle this type of editing. Edit maintains a Significance Indicator to keep track of whether a significant digit has yet been detected. 2004. All rights reserved. Page 157 of 58 . 2000. This is known as forcing significance Forcing Significance: Topic: Editing Decimal Data SIGNIFICANCE INDICATOR Turned on by detecting a non . To be able to always print a digit before the decimal point. the programmer must be able to specify that Edit will behave as if it has found a significant digit once it reaches a certain position in the output field..

2004. an asterisk is used. is known as the fill character. Page 158 of 58 . All rights reserved. 2000. In the first table a blank is used. while in the second table.OS/390 Assembler Programming Introduction Unit: Decimal Arithmetic Fill Character What is the fill character? Significance Indicator: Topic: Editing Decimal Data The programmer must also be able to tell Edit what to place in the output field if the Significance Indicator has not been turned on. MASK * DS DS Specifies position for digit (SI ON) Or Fill Character (SI OFF) First character replaces leading zeros or punctuation before significance Indicator is Turned On Concepts © Copyright IBM Corp. The character used to fill the output field. until the Significance Indicator is turned on..

2000. Page 159 of 58 .. All rights reserved. The remaining characters of the edit mask are a combination of the characters shown in the table on the right. 2004. The first character of the edit mask is the fill character. Topic: Editing Decimal Data Character X ’20’ X ’21’ X ’22’ Anything else Meaning Digit Select Significance Start Field Separator Message Character Continued… Concepts © Copyright IBM Corp.OS/390 Assembler Programming Introduction Unit: Decimal Arithmetic Edit Mask What is an edit mask? The first operand of Edit is an edit mask that Edit replaces with the edited number. It is through the edit mask that the programmer specifies how the Edited number is to look.

2004.OS/390 Assembler Programming Introduction Unit: Decimal Arithmetic Edit Mask (cont’d) What are the components of an edit mask? A digit select character specifies a position where a source digit is to be placed if the Significance Indicator is set. ds ds - Topic: Editing Decimal Data 12.67- Continued… Concepts © Copyright IBM Corp. ds ss ds . A significance start character has the same effect as a digit select. but also forces the Significance Indicator on. Message Characters MASK Fill ds ds .345. 2000.. It causes the significance indicator to be turned off. All rights reserved. Page 160 of 58 . The field separator character is only used if the Edit operation is editing multiple numbers. after the digit or fill character is placed. or the fill character is placed otherwise.

All rights reserved. and after processing a byte in the mask containing a significance start character.. 2004.OS/390 Assembler Programming Introduction Unit: Decimal Arithmetic Edit Mask (cont’d) The Significance Indicator is initially turned off. It is turned on when a non-zero digit is encountered in the second operand. Topic: Editing Decimal Data Non – Zero Digit Significance Start Character Turned ON Significance Indicator (Initially OFF) Turned OFF + ve Sign Field Separator Concepts © Copyright IBM Corp. and when a field separator character is found in the mask. Page 161 of 58 . It is turned off when a positive sign is encountered in the second operand. 2000.

For example: ED MASK. The single length specifies the length of the mask.PD1 Edit (ED) SS Format (1 length) – Storage to Storage ED 1st Operand PD1 MASK. 2000. The second operand is edited according to the values in the mask. and the edited number replaces MASK. MASK The value in PDI is edited. according to the specifications in MASK. and the edited number replaces the mask in the first operand field. 2004. Page 162 of 58 . The two operands are processed left to right. The second operand is a field containing one or more packed decimal numbers. The first operand is an edit mask.PD! 2nd Operand PD1 MASK EDIT PD1 According to MASK Replace RESULT CC setting – 0 – the last field edited is zero or zero length.. All rights reserved.OS/390 Assembler Programming Introduction Unit: Decimal Arithmetic Topic: Editing Decimal Data Formatting Packed Decimal Data with Edit Instruction How do you format packed decimal data with Edit instruction? The Edit (ED) instruction is used to format packed decimal data. 1 – the last field edited is less than zero 2 – the last field edited is greater than zero Continued… Concepts © Copyright IBM Corp.

2000.PD! 2nd Operand PD1 MASK EDIT PD1 According to MASK Replace RESULT CC setting – 0 – the last field edited is zero or zero length. 2004. 1 – the last field edited is less than zero 2 – the last field edited is greater than zero Continued… Concepts © Copyright IBM Corp. MASK Page 163 of 58 .OS/390 Assembler Programming Introduction Unit: Decimal Arithmetic Topic: Editing Decimal Data Formatting Packed Decimal Data with Edit Instruction (cont’d) The mask field is replaced by the edited number. All rights reserved.. Edit (ED) SS Format (1 length) – Storage to Storage ED 1st Operand PD1 MASK. It is necessary to move the mask to the location where the editing is to be done before each repeated ED instruction to avoid destroying the mask.

Page 164 of 58 . If at least one digit is desired to be printed prior to the decimal point.234. That blank will be the first character of the edit mask.67- Continued… Concepts © Copyright IBM Corp.56 123.345.67 1.345.45 12.OS/390 Assembler Programming Introduction Unit: Decimal Arithmetic Topic: Editing Decimal Data Formatting Packed Decimal Data with Edit Instruction (cont’d) To devise the mask necessary to edit the 7 digit number specified in the earlier example. 2000. 2004. it seems that the last character of the mask must be a minus sign.12 0..34 1.23 0. you can see that the fill character is blank. From the last line of the table. Value 1234567 0123456 0012345 0001234 0000123 0000012 0000001 -1234567 Formatted Value 12.01 12. you must remember that you will want the edited number to represent a dollar and cents amount. All rights reserved. If you look at this table. you will need to specify a significance start character two positions before the decimal point. because the significance indicator is turned on after the byte with the significance start character is processed.

so the message character is printed.OS/390 Assembler Programming Introduction Unit: Decimal Arithmetic Topic: Editing Decimal Data Formatting Packed Decimal Data with Edit Instruction (cont’d) To edit a positive number.. The mask will need to contain the following characters in the order shown in the table in the right. the positive sign turns the Significance Indicator off. 2000. Using a minus sign does not turn the Significance Indicator off. All rights reserved. Page 165 of 58 . so the fill character of blank would replace the minus sign message character. 2004. Contents Blank X’20’ X’20’ Comma X’20’ X’21’ X’20’ Period X’20’ X’20’ Minus sign Purpose Fill character Digit select Digit select Message character Digit select Significance start Digit select Message character Digit select Digit select Message character Concepts © Copyright IBM Corp.

Concepts © Copyright IBM Corp. so the total number of digit selects and significance start character is seven.. It is always a good idea to check that your masks have the proper number of digit selects and significance starts. the code to do the editing is as shown above. . MASK mc ED PRTAMT . PK1 oc . Having too few will cause truncated values to be generated. the total length of the mask is 11 bytes. Assuming that the number to be edited was called PK1 and the field where you wanted to place the edited number was called PRTAMT.OS/390 Assembler Programming Introduction Unit: Decimal Arithmetic Topic: Editing Decimal Data Digit Selects and Significance Starts PK1 PRTAMT MASK MVC PRTAMT . Page 166 of 58 . DS PL4 DS CL11 DC X’4020206B2021204B202060 There are seven digits being edited in this example. All rights reserved. . When you add the fill character and message characters. Having too many may cause a data exception. 2004. 2000.

2000.NUM AP SUM.WKAREA GET INFILE. These are codes that you should memorize if you are going to be doing a lot of editing.INAREA PACK WKAREA. Continued… Concepts © Copyright IBM Corp.OUTAREA CLOSE (INFILE. period and minus are 40.OUTFILE.SUM PUT OUTFILE. 6B.WKAREA MVC OUTNUM.NUM ZAP SUM.NUM AP SUM.INAREA PACK WKAREA..(INPUT). 2004.MASK ED OUTNUM..(OUTPUT)) GET INFILE. 4B and 60 respectively. Page 167 of 58 .OUTFILE) prepare dcbs for processing get next input record convert number to packed move first number to sum get next input record convert number to packed add second number to sum get next input record convert number to packed add third number to sum move edit mask to output edit the sum write output record close dcbs The EBCDIC codes for blank. All rights reserved. comma.OS/390 Assembler Programming Introduction Unit: Decimal Arithmetic EBCDIC Code Topic: Editing Decimal Data OPEN (INFILE.WKAREA GET INFILE.INAREA PACK WKAREA.

add them and then print the edited sum. X EODAD=ENDDATA DDNAME=OUT. All rights reserved..MACRF=GM. X DSORG=PS.OS/390 Assembler Programming Introduction Unit: Decimal Arithmetic EBCDIC Code (cont’d) Topic: Editing Decimal Data INAREA NUM WKAREA SUM MASK OUTAREA OUTASA OUTNUM INFILE OUTFILE DS DS DS DS DS DC DS DC DC DS DC DCB DCB 0CL80 CL73 CL7 PL4 PL5 X’402020206B2020206B202120’ 0CL133 C’0’ specify double spacing CL10’The Sum is’ CL12 CL110’ ‘ make the rest spaces DDNAME=IN.DSORG=PS.LRECL=80.BLKSIZE=6650.LRECL=133.RECFM=FB. 2000.MACRF=PM A complete code segment.RECFM=FBA. Page 168 of 58 . 2004. to read 3 seven digit numbers from the first seven positions of 3 in a dataset. Concepts © Copyright IBM Corp. is shown above.

FWD1 Load (L) Instruction: RX Format – Register and Indexed Storage L 1st Operand FWD1 00 00 00 07 3C EA 00 R3. Page 169 of 58 . The data at location FWD1 is unchanged. or using data for addressing. CC setting: Condition Code is unchanged Concepts © Copyright IBM Corp. 2004. All rights reserved.. The first two instructions you will learn are Load (L) and Load Halfword (LH). The data is moved unchanged. For example: L R3. from storage to the register. The Load (L) instruction is used to move a fullword of data from main storage into a General Purpose Register (GPR). 2000.FWD1 2nd Operand R3 00 Target Full word 07 3C EA 00 L Copies FULWORD from main Storage address beginning at location FWD1 to GPR R3 Source Full word The fullword of data at location FWD1 would be loaded into R3.OS/390 Assembler Programming Introduction Unit: Data Manipulation Instructions Topic: Load and Store Instructions Load Operation A load operation moves data from main storage into a GPR. You will find this useful when performing fixed-point binary arithmetic.

HWD1 is expanded into a full word By inserting 16 o bits in front of the 16 bits of HWD1 CC setting: Condition Code is unchanged © Copyright IBM Corp. and places the resultant fullword into a GPR R4. expands it to a fullword by sign extension.HWD1 Load Half word (LH): RX Format – Register and Indexed Storage LH 1st Operand R4.OS/390 Assembler Programming Introduction Unit: Data Manipulation Instructions Topic: Load and Store Instructions Load Halfword Instruction The Load Halfword (LH) instruction takes a halfword of data from main storage HWD1. Concepts Copies HALFWORD from main storage address beginning at location HWD! To GPR r4 (low – order 16 bits). 2000. All rights reserved. For example: LH R4.HWD1 2nd Operand HWD1 00 00 00 00 01 Source Half word R4 00 Target Full word LH 00 00 00 01 Sign Extension The expansion occurs within the processor and does not alter any values in the main storage.. Page 170 of 58 . Since The sign of HWD1 is 0. 2004.

The high order bit of a fixed-point number is its sign.. All rights reserved. 2000. Page 171 of 58 . 2004.OS/390 Assembler Programming Introduction Unit: Data Manipulation Instructions Topic: Load and Store Instructions Sign Extension Sign Extension (Half word to Full word Expansion): 0 1 0 Register 4 1 0 0 Register 4 TARGET REGESTER Propagates 16 High – order bits 0000000 Propagates 16 High – order bits 1111111 11111111 o Half word 11101011 HWD1 0 HALF WORD 11101011 15 SIGN: 0 = (+) 1 = (-) 11111111 0000000 LH 0 FULL WORD CHANGES SIGN TO OR (+) o Half word 00000000 31 Copies into 16 Low – order bits 00000000 FULL WORD Changes Sign To 1 or (+) 11101011 HWD1 HALF WORD 1 11111111 11101011 31 Copies into 16 Lo –order bits LH 0 15 SIGN: 0 = (+) 1 = (-) SOURCE FIELD The example above shows how sign extension works. and the sign bit of the source field directly affects the high-order 16 bits in the target register. Concepts © Copyright IBM Corp.

FWDS+4 L R7.. All rights reserved. 2000. Page 172 of 58 . Using the LM instruction.FWDS L R6.Condition Code Unchanged Continued… Concepts © Copyright IBM Corp. a number of consecutive fullwords from main storage are loaded into a range of GPRs.R7. For example: LM R5.FWDS R5 R6 R7 Load Multiple (LM): RS Format: Register Storage L R5.FWDS = Target Fullword LM Source Fullword CC Setting . each loading a single fullword into a register one at a time.FWDS+8 FWDS FF FF FF FF FF FF FF FF FF FF FF FF 01 0B EF 42 72 FF 77 1A FF FF 80 FF LM R5. 2004. both inclusive. However the Load Multiple (LM) instruction is provided to facilitate this fairly common requirement by a single instruction. from the GPR specified as the first operand to the GPR specified as the second Operand.OS/390 Assembler Programming Introduction Unit: Data Manipulation Instructions Topic: Load and Store Instructions Load Multiple Instruction What is the Load Multiple (LM) Instruction? This operation could be performed by a number of load instructions.R7.

R7. R5 R6 R7 Load Multiple (LM): RS Format: Register Storage L R5. 2004.FWDS L R6. The effect of LM R5.FWDS is identical to the three instructions shown on the right. Page 173 of 58 . it loads a fullword from main storage at location FWDS to the GPRs beginning with R5. All rights reserved.FWDS+8 FWDS FF FF FF FF FF FF FF FF FF FF FF FF 01 0B EF 42 72 FF 77 1A FF FF 80 FF LM R5.R7.OS/390 Assembler Programming Introduction Unit: Data Manipulation Instructions Topic: Load and Store Instructions Load Multiple Instruction (cont’d) When the instruction executes.. 2000.FWDS+4 L R7. the next fullword in storage (i.Condition Code Unchanged Continued… Concepts © Copyright IBM Corp.FWDS = Target Fullword LM Source Fullwood CC Setting . at location FWDS+4) would be loaded into R6 and the next (at location FWDS+8) into R7.e.

R13.OS/390 Assembler Programming Introduction Unit: Data Manipulation Instructions Topic: Load and Store Instructions Load Multiple Instruction (cont’d) Load Multiple (LM) is a Register Storage format instruction.. Page 174 of 58 . 2000. R1. R12. RO. R13.FWDS Highest Register in Range 1st OPERAND 2nd OPERAND 3rd OPERAND • • • The first operand is the first in a group of consecutive target registers The second operand specifies the last register in the group The third operand specifies the source main storage address Lowest Register in Range Continued… Concepts © Copyright IBM Corp. R4.R7. R15.FWDS Highest Register in Range Ascending order: R5. R6. R7 LM Lowest Register in Range Ascending order: R14. R3. R14. R2. R7. 2004. R11. LM has three operands: LM R5. R9 R10. R8. All rights reserved. R6. R5.

R15. Page 175 of 58 .SAVE LM R14. R11 R12 FF FF FF FF FF FF FF FF 0C EF 72 FF 1B FF 64 FF Target Fullword Source Fullword LM Concepts © Copyright IBM Corp. Thus LM R14. this indicates a range of registers from R14 to R15 and from R0 to R12.R12. R0..SAVE R14 R15 R0 FF FF FF FF FF FF FF FF FF FF FF FF 01 0B 2B 42 72 08 77 1A 75 FF 80 FF Loads 15 registers. All rights reserved. from the 15 consecutive fullwords beginning at SAVE. R1….OS/390 Assembler Programming Introduction Unit: Data Manipulation Instructions Topic: Load and Store Instructions Load Multiple Instruction (cont’d) One interesting feature of Load Multiple (LM) is that if the second operand specifies a lower numbered register than the first operand.R12 in that order. 2000. 2004. R14.R12.

2004.Register to Register LR R7. and the second operand specifies the source register.R3 Load Multiple (LR): RR Format . 2000. The Load Register (LR) instruction copies a fullword from one GPR (2nd Operand) to another GPR (1st Operand). Page 176 of 58 . That is.. For example: LR R7. All rights reserved. The first operand specifies the target register. both of their operands specify registers.R3 1st Operand R7 00 00 00 00 R3 07 2nd Operand 3C EA 00 Target Fullword LR Source Fullword CC Setting: Condition Code is Unchanged Concepts © Copyright IBM Corp.OS/390 Assembler Programming Introduction Unit: Data Manipulation Instructions Topic: Load and Store Instructions Load Register The two instructions LR and LTR covered in this section are both RR (register to register) type.

For example: LTR R7. All rights reserved.R3 R7 00 00 00 00 Load and Test (LTR): RR Format . 2004.OS/390 Assembler Programming Introduction Unit: Data Manipulation Instructions Topic: Load and Store Instructions Load and Test Instruction The Load and Test (LTR) instruction is identical to Load Register (LR). except that it sets the condition code. setting the CC to indicate if the result is zero.Register to Register LTR R7. negative or positive. Page 177 of 58 .. 2000. The instruction copies the contents of one GPR (2nd Operand) to another GPR (1st Operand).R3 1st Operand R3 07 2nd Operand 3C EA 00 Target Fullword LTR Source Fullword CC Setting – 0-Result is Zero 1-Result is Negative 2-Result is Positive Concepts © Copyright IBM Corp.

the result of a store operation is placed in the second operand field. it is a move of data from a register to main storage. Page 178 of 58 . Concepts © Copyright IBM Corp.OS/390 Assembler Programming Introduction Unit: Data Manipulation Instructions Topic: Load and Store Instructions Store and Store Halfword Operations GPRs 0 1 15 STORE Main Storage LOAD STORE Fullword LOAD RX Format .Normal Process Loads Fullword from Main Storage to GPR 1st Operand 2nd Operand GPR Main Storage RX Format . rather than the first as is normal. All rights reserved. That is. 2004.Backward Process Stores Fullword from GPR to Main Storage 1st Operand GPR 2nd Operand Main Storage This section describes two operations: Store (ST) and Store Halfword (STH). The store instructions are the first examples of instructions you will see that work backwards.. 2000. A store operation is the opposite of a Load (L).

Page 179 of 58 .OS/390 Assembler Programming Introduction Unit: Data Manipulation Instructions Topic: Load and Store Instructions Store Instruction The Store (ST) instruction is similar to the Load (L). ST stores a fullword. 1st Operand R3 07 3C EA 00 2nd Operand FWD3 00 00 00 00 Source Fullword ST Target Fullword CC setting: Condition Code is unchanged Concepts © Copyright IBM Corp.Register and Indexed Storage The ST instruction stores a fullword from the GPR (1st Operand) R3 into a fullword in indexed storage (2nd Operand) at location FWD3. located in a GPR. 2000. unchanged into a specified main storage location. 2004.FWD3 ST R3. All rights reserved.FWD3 Store (ST): RX Format .. For example: ST R3.

All rights reserved.order 16 bits (halfword) of a GPR into a Halfword location in main storage. For example: STH R4. The high order 16 bits are truncated.OS/390 Assembler Programming Introduction Unit: Data Manipulation Instructions Topic: Load and Store Instructions Store Halfword Instruction The Store Halfword (STH) instruction stores the Low.HWD3 1st Operand 2nd Operand HWD3 00 00 Target Fullword 00 01 Source Fullword STH CC setting .HWD3 R4 00 00 00 01 Store Halfword (STH): RX Format .Condition Code is unchanged Concepts © Copyright IBM Corp.. 2000. with no indication if significant digits are truncated or the sign is changed.Register and Indexed Storage STH R4. Page 180 of 58 . 2004.

RO. R8. R13 • The second operand specifies the last register in the group The third operand specifies the target main storage address Lowest Register in Range • Continued… Concepts © Copyright IBM Corp. R7. R2. R9. The STM instruction performs the opposite operation of the LM instruction. R15. R4.FWDS Highest Register in Range Ascending order: R5.R7. R3. R10.FWDS Highest Register in Range Ascending order: R14.R12. R7 R14. R5. 2004. R6..R13. Page 181 of 58 . R11. R1. STM has three operands: • The first operand specifies the starting register number STM 1st OPERAND 2nd OPERAND 3rd OPERAND STM Lowest Register in Range R5. All rights reserved.OS/390 Assembler Programming Introduction Unit: Data Manipulation Instructions Topic: Load and Store Instructions Store Multiple Register Store Multiple (STM) is a RS format (register to Storage) instruction. 2000.

OS/390 Assembler Programming Introduction Unit: Data Manipulation Instructions Topic: Load and Store Instructions Elements of the Topic What is the function of the Store Multiple Instruction? STM R14. An example is shown on the right.12(R13) R13 R14 01 R15 0B R0 2B 42 72 08 77 1A 75 FF 80 FF FF FF FF FF FF FF Save Area Address FF FF FF FF FF FF R11 0C R12 EF 72 FF 1B FF 64 FF FF FF FF FF FF FF FF FF Source Fullword STM Target Fullword Concepts © Copyright IBM Corp. 2004. the first instruction frequently used is a STM to perform this operation.R12. so they can later be restored before returning control to the caller. This is performed to save the register contents of a program's caller. For example: STM R14. In fact. Page 182 of 58 . 2000.R12. All rights reserved..12(R13) The Store Multiple (STM) instruction is used as part of the standard housekeeping done at the beginning of a program.

Page 183 of 58 .BYTE1 2nd Operand BYTE1 C4 Source Byte Target Fullword Concepts © Copyright IBM Corp. What is the function of the IC Instruction? The Insert Character (IC) instruction transfers a single byte of data from main storage to the low order 8 bit positions of the register specified. For example: IC R5. 2000. All rights reserved..OS/390 Assembler Programming Introduction Unit: Data Manipulation Instructions Topic: Load and Store Instructions Insert Character Instruction The load and store instructions presented in this course all work with either fullwords or halfwords. There are also instructions that transfer bytes of data between main storage and GPRs. The high order 24 bits of the register are unchanged. 2004.Condition Code is Unchanged Insert Character (IC): RX Format Register Index Storage IC R5.BYTE1 1st Operand R5 07 3C EA 00 C4 IC CC Setting .

BYTE2 R3 07 3C EA C4 Store Character (STC): RX Format . Source Fullword CC Setting . All rights reserved.BYTE2 1st Operand 2nd Operand BYTE2 00 C4 STC Target Byte The low order byte of GPR (1st Operand) R3 is placed in Indexed storage (2nd Operand) at location BYTE2.. 2000.OS/390 Assembler Programming Introduction Unit: Data Manipulation Instructions Topic: Load and Store Instructions Store Character Instruction What is the function of the Store Character (STC) Instruction? The Store Character (STC) instruction stores the low order byte of a GPR to a byte in main storage. Page 184 of 58 . 2004.Condition Code is Unchanged Concepts © Copyright IBM Corp. Note that it is the second operand that receives the result.Register to Index Storage STC R3. For example: STC R3.

are RS format register storage instructions. not a GPR.OS/390 Assembler Programming Introduction Unit: Data Manipulation Instructions Topic: Load and Store Instructions ICM and STCM Instructions The IC and STC instructions are limited in that they process only a single byte of data.. These two instructions. 2004. The second operand for these instructions is a mask field. and only use the low order byte of the GPR specified as the first operand. All rights reserved. The Insert Characters under Mask (ICM) and Store Characters under Mask (STCM) instructions provide more flexibility. The 4 bits of the mask field correspond. one for one. Page 185 of 58 . ICM and STCM. with the four bytes of the GPR specified as the first operand. 1310 = 11012 is translated to The mask field below MASK FIELD 0 BYTES 1 1 1 2 0 3 1 YES YES NO YES Remains unchanged Concepts © Copyright IBM Corp. 2000.

For example: ICM R4. into positions of the GPR specified as the first operand for which the corresponding mask bits are one. It inserts consecutive bytes starting at the third operand address. 2000.OS/390 Assembler Programming Introduction Unit: Data Manipulation Instructions Topic: Load and Store Instructions Insert Characters Under Mask Instruction What is the function of the ICM Instruction? The Insert Characters Under Mask (ICM) instruction is used for logical bit and byte operations. 2004.FLD1 Bytes 0 1 1 1 2 0 Insert Characters Under Mask (ICM): RS Format . All rights reserved.FLD1 3rd Operand 2nd Operand (MASK) FLD1 3C EA Source Bytes CC Setting .13.0 Mask is zero or all inserted bits are zero 1 Leftmost inserted bit is one 2 Leftmost inserted bit is zero and not all inserted bit zeros Concepts © Copyright IBM Corp. Other bytes in the first operand are unchanged..Register Storage ICM 1st Operand R4 Target Fullword 00 00 00 00 ICM 3 1 MASK FIELD 07 R4. Page 186 of 58 .13.

. to consecutive main storage locations starting at the address specified as the third operand. Page 187 of 58 . 2000.OS/390 Assembler Programming Introduction Unit: Data Manipulation Instructions Topic: Load and Store Instructions Store Characters Under Mask Instruction What is the function of the Store Characters Under Mask Instruction? The Store Characters Under Mask (STCM) instruction is used for logical bit and byte operations.6.Register Storage STCM 1st Operand R5 07 3C 00 EA STCM 0 0 1 1 2 1 3 0 MASK FIELD (6) R5. 2004.Condition Code is Unchanged Concepts © Copyright IBM Corp.FLD2 3rd Operand 2nd Operand (MASK) FLD2 00 00 Target Bytes Source Bytes Bytes CC Setting . For example : STCM R5. All rights reserved.6. This instruction stores the contents of those byte positions of the register indicated by a one bit in the mask.FLD2 Store Characters Under Mask (STCM): RS .

The actual number of bytes to be copied is Indicated by the first operand. MVC FLD1. FLD2 40 40 40 40 MVC 40 40 40 40 The Length can be explicitly stated as shown above. It is a one-length SS instruction. FLD2 2nd Operand When the format is used as shown above the Assembler supplies the understood length code. The Move Characters (MVC) instruction is used to move data from one location in main storage to another. 2004. FLD2 MVC 1st Operand FLD1. 2000.FLD2 Concepts © Copyright IBM Corp. All rights reserved. Then length is 4 byes. Page 188 of 58 . MVC FLD1(4). one byte at a time. For example: MVC FLD1. Data is moved. left to right from the second operand location to the first.OS/390 Assembler Programming Introduction Unit: Data Manipulation Instructions Topic: Move Instructions Move Characters Instruction Move Characters (MVC): SS(1 length) Storage to Storage. so up to 256 bytes of data can be moved with a single MVC instruction.. CC Setting – Condition Code is Unchanged.

a one-byte field. to the first operand location. For example: MVI FLD3. Page 189 of 58 .Storage Immediate Data MVI FLD3.C'*' 1st Operand C'*' * 2nd Operand FLD3 0 * Target Byte This instruction moves an asterisk to FLD3.OS/390 Assembler Programming Introduction Unit: Data Manipulation Instructions Topic: Move Instructions Move Immediate Instruction What is the function of the Move Immediate (MVI) Instruction? The Move Immediate (MVI) instruction is in SI format. 2004.C’*' Source Byte MVI Copies the Immediate Data '*' (one byte second operand field) to the first operand (one bite field) CC Settings . the one byte operand contained within the instruction itself.. It moves its immediate operand. Concepts © Copyright IBM Corp. All rights reserved.Condition Code is Unchanged Move Immediate (MVI): SI Format . 2000.

one byte at a time. both. PRTLINE+1.PRTLINE C‘’ b PRTLINE o First Position Sending MVC oooooooooooooooooooooooo Source byte b MVI Target byte Receiving MVC propagates 132 b characters MOVE BLANK TO FIRST POSTION PROPAGATE BLANK THROUGH FIELD b bbbbbbbbbbbbbbbbbbbbbbb You can take advantage of knowing that MVC works left to right. It works byte by byte.OS/390 Assembler Programming Introduction Unit: Data Manipulation Instructions Topic: Move Instructions Move Characters Instruction MVI PRTLINE. left to right.. 2004. Page 190 of 58 . Continued… Concepts © Copyright IBM Corp. to produce an initialization technique that does not require a long constant. All rights reserved. PRTLINE and PRTLINE+1 contain blanks. The MVI instruction sets the first byte of PRTLINE to blank. 2000.C ‘ ’ MVI PRTLINE+1(132). Consider the code above. Consider the operation of the MVC Instruction byte by byte. so the first byte that gets moved is the byte at PRTLINE to the destination. Now.

PRTLINE+2 contains a blank. Now.PRTLINE C‘‘ b PARTLINE o First Position Sending MVC oooooooooooooooooooooooo Source byte b MVI Target byte Receiving MVC propagates 132 b characters MOVE BLANK TO FIRST POSTION PROPAGATE BLANK THROUGH FIELD b bbbbbbbbbbbbbbbbbbbbbbb The next byte is moved from PRTLINE+1 to PRTLINE+2. 2004. The destination field on each cycle becomes the sending field on the next. without defining a long field to contain a constant. down through the field. Page 191 of 58 . The MVI moves in the first blank to the leftmost position.. one by one. The MVC moves the other 132 bytes. All rights reserved. Concepts © Copyright IBM Corp. The whole field is initialized.C ‘ ‘ MVC PRTLINE+1(132). 2000.OS/390 Assembler Programming Introduction Unit: Data Manipulation Instructions Topic: Move Instructions Move Characters Instruction (cont’d) MVI PRTLINE.

0 .Second Operand length high. 2000. it is an RR format instruction.First operand length low 2 . 3 . No Movement. Page 192 of 58 . Move Long (MVCL): RR Format . It could be done with multiple MVCs.Operand lengths equal. There are many situations when a programmer wants to move much larger blocks of data. and not very efficient.R6 1st Operand 2nd Operand CC Setting .Destructive Overlap. 1 . The first thing you will notice is that although MVCL is an instruction that specifies movement of one storage operand to another. but that would be tedious.215 bytes of data with a single instruction. All rights reserved.OS/390 Assembler Programming Introduction Unit: Data Manipulation Instructions Topic: Move Instructions Move Long Instruction The MVC instruction is only capable of moving up to 256 bytes.Register to Register MVCL R4. What is the function of the Move Long Instruction? The Move Long (MVCL) instruction allows moving up to 16. 2004.777. Continued… Concepts © Copyright IBM Corp..

Page 193 of 58 . 2004. The content of the receiving field is filled with the pad character if the length of the sending field is shorter than the receiving field. namely the length of the operands have to be specified in other registers.0 . Continued… Concepts © Copyright IBM Corp. The number of bytes to be moved has to be specified. 3 . The following pages explain this in detail.R6 1st Operand 2nd Operand CC Setting . 1 .Destructive Overlap.Operand lengths equal.. No Movement.First operand length low 2 .OS/390 Assembler Programming Introduction Unit: Data Manipulation Instructions Topic: Move Instructions Move Long Instruction (cont’d) The MVCL Instruction moves the content of the memory location whose address is in GPR (2nd operand) R6 to the memory location whose address is in GPR (1st operand) R4. Move Long (MVCL): RR Format . 2000. All rights reserved.Register to Register MVCL R4.Second Operand length high.

The second operand is moved to the first.OS/390 Assembler Programming Introduction Unit: Data Manipulation Instructions Topic: Move Instructions Move Long Instruction (cont’d) Both operands of MVCL are registers. All rights reserved. Operands: . the additional bytes on the right of the first operand are filled with the pad character. each of which in fact implies a pair of registers. the actual operands are the even numbered registers specified. Since each operand is a register pair.The usage of the registers is as shown on the right. If the length of the second operand is shorter than the length of the first. The operands must specify even numbered registers. 2000.Registers R1 / 01 1st Operand Address 31 1st Operand Length 8 2nd Operand Address 31 2nd Operand Length 8 31 31 R1 + 1 Unused 0 R2 / 01 R2 + 1 0 PAD Continued… Concepts © Copyright IBM Corp. and the odd numbered registers one higher than the registers specified . Page 194 of 58 .. 2004.

move 3000 bytes of data from a field called LONG3 to LONG4. Page 195 of 58 .=A(LONG3) R7.=A(LONG4) R5.=H‘3000' Move the data R6 R6 Address Op2 Sending Field R7 Length Op2 address of receiving field length of receiving field address of sending field length of sending field EVEN/ODD Register MVCL R4 R4 Address Op1 R5 Length op1 EVEN/ODD Register Receiving Field Continued… Concepts © Copyright IBM Corp. In the first case. 2000..=H‘3000' R6. 2004.R6 R4. L LH L LH MVCL R4. All rights reserved.OS/390 Assembler Programming Introduction Unit: Data Manipulation Instructions Topic: Move Instructions Move Long Instruction (cont’d) The Move Long (MVCL) instruction is best illustrated with some coding examples.

Page 196 of 58 . 2004.R6 initialize registers for MVCL to move the data MVCLDATA A (LONG4) F ‘3000' A (LONG3) ‘ F ‘3000' Another way to do this. One thing about coding in Assembler Language is that there are usually many different ways to do the same thing. Continued… Concepts © Copyright IBM Corp. you set up the initial data in four consecutive full words in storage.. . and use LM to put it into the four registers. 2000. with fewer executable instructions.R7. MVCLDATA R4. In this version. All rights reserved. . DC DC DC DC R4. . would be as shown above.OS/390 Assembler Programming Introduction Unit: Data Manipulation Instructions Topic: Move Instructions Move Long Instruction (cont’d) LM MVCL .

=H'1500' R7. 2000. All rights reserved. move a field 1500 bytes long at LONG3 into a 5000 byte field at LONG4 and fill the extra 3500 bytes at the end of LONG4 with EBCDIC zeros.=A(LONG3) R7.=H'5000' R6. L LH L LH ICM MVCL R4. 2004. Page 197 of 58 .=A(LONG4) R5.R6 address of receiving field length of receiving field address of sending field length of sending field pad character move data Concepts © Copyright IBM Corp.8.=C'0' R4.. This is accomplished as shown on the right.OS/390 Assembler Programming Introduction Unit: Data Manipulation Instructions Topic: Move Instructions Move Long Instruction (cont’d) For the second example of MVCL.

INIT LM MVCL . no alignment is done. . DC DC DC DC R4. 2004. All rights reserved..INIT R4. 2000.R6 A (LONG4) F '5000' A (LONG3) C '0' . Page 198 of 58 . you would use the code as shown on the right.R7. .OS/390 Assembler Programming Introduction Unit: Data Manipulation Instructions Topic: Move Instructions Using LM Instruction To set the previous example up with a LM instruction. FL3 '1500' Since there is a length modifier on the FL3’1500’. Concepts © Copyright IBM Corp. .

. use the code shown to the right. In this case. All rights reserved. To fill a 500 byte field called BUFF with binary zeros. 2000.R11. by making that character the pad character and specifying a sending field length of zero.OS/390 Assembler Programming Introduction Unit: Data Manipulation Instructions Topic: Move Instructions Using MVCL Instruction You can also use MVCL to initialize a field so that each byte contains a certain character.R10 ACBUFF F '500.0.0' Concepts © Copyright IBM Corp. .INIT1 R8. Page 199 of 58 . Here the second operand's address.. the address of the sending field is ignored and the whole receiving field is filled with the pad character. DC DC R8. 2004. length and the padding character are all zero. INIT1 LM MVCL .

One instruction tests a condition. a conditional branch. They implement looping with DOWHILE or other iterative constructs. Page 200 of 58 . 2000. awaiting subsequent conditional branch instruction. 2004. conditional execution is broken into parts. conditional execution and looping structures must be built from lower level instructions. Assembler Language does not have these high level control statements. EC Mode PSW 2 bit Field CC 18 20 Program Mask CC Possible Values: 00 01 10 11 Binary 0 1 2 3 Decimal Continued… Concepts © Copyright IBM Corp. alters the execution path.OS/390 Assembler Programming Introduction Unit: Comparing and Branching Topic: Decision Making in Assembler Implementing Conditional Execution How is conditional execution implemented? High Level Languages implement conditional execution with IF-THEN and IF-THEN-ELSE structures. The condition code. Rather.. A following instruction. All rights reserved. depending on the result of the test. a two-bit field in the Program Status Word (PSW) is where the result of the test is held. In Assembler Language.

. Page 201 of 58 . 2000. All rights reserved. that value remains in the condition code until a subsequent instruction changes it.OS/390 Assembler Programming Introduction Unit: Comparing and Branching Topic: Decision Making in Assembler Implementing Conditional Execution (cont’d) Some instructions set the condition code and some do not.Some Examples AP SP MVCL CC – is set MP DP MVC Condition Code is unchanged. If and how an instruction sets the condition code is an important part of the instruction description. 2004. Once the condition code is set by an instruction. Condition Code: . Continued… Concepts © Copyright IBM Corp.

These instructions compare two operands and set the condition code to indicate their relative magnitudes. 2000. The CC always contains one of these four values.. Another major group of instructions that set the condition code is the compare instructions. 0. Compare Instructions set CC as follows: You have seen that many arithmetic instructions set the condition code to indicate if the result is zero (CC=0). Relation of Operands Op1 = Op2 Op1< Op2 Op1 > Op2 CC Setting 0 1 2 Continued… Concepts © Copyright IBM Corp. so that it may take on 4 unique values. All rights reserved. The condition code set by compare instructions are shown on the right. positive (CC=2) or if overflow has occured (CC=3).OS/390 Assembler Programming Introduction Unit: Comparing and Branching Topic: Decision Making in Assembler Implementing Conditional Execution (cont’d) The condition code is a two-bit field. negative (CC=1). 2004.2 or 3. Page 202 of 58 . You have seen other instructions that set the condition code in other ways.1.

Equal 1 – First Operand is Low 2 – First Operand is High 3 – Not Used Continued… Concepts © Copyright IBM Corp. 2004. Page 203 of 58 . these settings will be referred to as CC setting . 2000..OS/390 Assembler Programming Introduction Unit: Comparing and Branching Compare Instructions A condition code setting of 3 does not occur after compare instructions. All rights reserved.Comparison in the instruction descriptions that follow. For brevity. Topic: Decision Making in Assembler CC Setting – Comparison: Condition Code Setting: 0 .

2004.. treating the operands simply as strings of bits. 2000. If the operands represent signed numeric quantities. On the other hand. 1st Operand 2nd Operand = Arithmetic NUMERIC NUMERIC TEXT TEXT = Logical Concepts © Copyright IBM Corp. Page 204 of 58 .OS/390 Assembler Programming Introduction Unit: Comparing and Branching Topic: Compare Instructions Numeric Comparison What is numeric comparison? Comparisons: When two operands are compared. then a numeric comparison is needed. All rights reserved. a logical comparison is performed. it is important that you be clear about their format. if the operands do not represent signed numeric data.

the register contents would be interpreted as -10. 2000. In a logical comparison. and the condition code is set to 1. so the first operand (the register) would be lower.. FFFFFFF6 is a higher hex value than 0000000A. Comparisons: 1st Operand R3 FFFFFFF6 -10 R3 FFFFFFF6 Higher Hex 2nd Operand FWD1 0000000A < FWD1 0000000A > Lower Hex = CC set to 2 +10 = CC set to 1 LOGICAL ARITHMETIC Concepts © Copyright IBM Corp. 2004. so the first operand would be higher and the condition code be set to 2. All rights reserved.OS/390 Assembler Programming Introduction Unit: Comparing and Branching Topic: Compare Instructions Kinds of Comparison If you compared R3 containing X'FFFFFFF6' and FDW1 containing X'0000000A'. In an arithmetic comparison. the condition code that will be set will depend on the type of comparison. The storage operand is interpreted as +10. Page 205 of 58 .

. All rights reserved. Page 206 of 58 . since the EBCDIC code for 5 (F5) is higher than the EBCDIC code for A (C1). 2000.OS/390 Assembler Programming Introduction Unit: Comparing and Branching Topic: Compare Instructions Logical Comparison What is Logical Comparison? Comparison of textual data would be a Logical Comparison. the second operand would be larger. 2004. based on the relative position of the characters in the EBCDIC code tables. If C'A' is compared with C'5'. as shown on the table in the right. EBCDIC CODE A 5 C1 F5 Concepts © Copyright IBM Corp.

All rights reserved. as shown in the table on the right. The condition code is set to indicate the result of the comparison. Neither operand is modified but the condition code is set to indicate the result of the comparison.1 If R4 < FWD1 -. 2004. are compared arithmetically to the contents of the fullword at location FWD1.. a fullword in GPR and the second operand.1 If R4 > FWD1 -. For example: C R4.FWD1 2nd Operand FWD1 FW COMPARE C CC Setting: If R4 = FWD1 -.2 © Copyright IBM Corp.FWD1 The contents of R4. Compare (C): RX Format – Register to Indexed Storage C 1st Operand R4 FW R4. Concepts Page 207 of 58 .OS/390 Assembler Programming Introduction Unit: Comparing and Branching Topic: Compare Instructions Compare Instruction What is the Compare (C) Instruction? The Compare (C) instruction is used to arithmetically compare the first operand. a fullword in main storage. 2000.

2000. The condition code is set to indicate the result of the comparison. . For example: CH R3. to a fullword by sign extension. is transparently expanded to a fullword through sign extension.OS/390 Assembler Programming Introduction Unit: Comparing and Branching Topic: Compare Instructions Compare Halfword Instruction What is the Compare Halfword (CH) Instruction? The Compare Halfword (CH) instruction is used to expand the second operand.0 -. All rights reserved.HWD1 2nd Operand HWD1 HW CC Setting: If R3 = HWD1 If R3 < HWD1 If R3 > HWD1 SIGN EXTENSION -.1 -. and compared arithmetically to the value in R3. a fullword in a GPR.. Neither operand is modified but the condition code is set to indicate the result of the comparison. HWD1 COMPARE The halfword at HWD1. 2004. S FW S HW CH Compare Half word (CH): RX Format – Register to Indexed Storage CH 1st Operand R3 FW R3. a halfword in main storage. and compare it arithmetically to the first operand. as shown in the table on the right.2 Page 208 of 58 Concepts © Copyright IBM Corp.

1 If R5 > R6 -. For example: CR R5.R6 2nd Operand R6 FW COMPARE CC Setting: If R5 = R6 -.OS/390 Assembler Programming Introduction Unit: Comparing and Branching Topic: Compare Instructions Compare Register Instruction What is the Compare Register (CR) Instruction? The Compare Register (CR) instruction is used to compare two operands. both fullwords in GPRs. as shown in the table on the right. Page 209 of 58 . 2004.2 CR Concepts © Copyright IBM Corp. arithmetically. All rights reserved. The condition code is set to indicate the result of the comparison.0 If R5 > R6 -. Neither operand is modified but the condition code is set to indicate the result of the comparison. 2000. Compare Register (CR): RR Format – Register to Register CR 1st Operand R5 FW R5.R6 The contents of R5 are compared arithmetically to the contents of R6..

Page 210 of 58 . All rights reserved. you will want to round the quotient up to the next higher integer if the remainder is equal to or greater than half the divisor..OS/390 Assembler Programming Introduction Unit: Comparing and Branching Topic: Compare Instructions Fixed-Point Compare Instruction Fixed-point compare instructions are used whenever the larger of the two fixed-point quantities is to be determined. In many applications. 2000. One common application is rounding after division. Half-Rounding: 1st Operand DIVIDEND EVEN/ODD Register Pair QUO REM 2nd Operand DIVISOR COMPARE APPLY HALF REM * 2 ROUNDING If Remainder is = or > than Divisor (ROUND UP) If Remainder is < than Divisor (DO NOT ROUND) Concepts © Copyright IBM Corp. This is called half rounding. Fixed-point division yields a fixed-point quotient and a fixed-point remainder. or if they are equal. 2004.

For example: CP PK1. Neither operand is modified. 2000.PK2 As shown in the example on the right.OS/390 Assembler Programming Introduction Unit: Comparing and Branching Topic: Compare Instructions Compare Decimal Instruction What is the Compare Decimal (CP) instruction? Packed decimal operands too have an arithmetic comparison operation. If the fields are of different lengths.0 If PK1 < PK2 -. but the condition code is set to indicate the result of the comparison. the shorter length is expanded by inserting leading zeroes. The condition code is set to indicate the result of the comparison.PK2 2nd Operand PK2 CONT.2 LEADING ZEROS If needed © Copyright IBM Corp. Concepts Compare Decimal (CP): SS Format – (2 length) Storage to Storage CP 1st Operand PK1 CONTENTS COMPARE 00 00 PK1.. both packed numbers in main storage arithmetically. Page 211 of 58 . CONT CP CC Setting: If PK1 = PK2 -.1 If PK1 > PK2 -. the contents of PK1 and PK2 are compared arithmetically. The Compare decimal (CP) instruction is used to compare two operands. All rights reserved. 2004.

REM REM. Page 212 of 58 .OS/390 Assembler Programming Introduction Unit: Comparing and Branching Topic: Compare Instructions Rounding Up – Example 1 ZAP DP AP CP BL AP EQU DS DS DS DS DS QUOREM. 2000. All rights reserved. = P ‘1’ * . COUNT NOROUND QUO. COUNT REM. Suppose a series of numbers have been summed into SUM. The average of the numbers. PL6 PL3 PL9 PL6 PL3 move sum work area divide to get quotient and remainder double the remainder is it less then divisor? Yes – don’t round no – round up NOROUND SUM COUNT DS QUOREM QUO REM You may want to implement half rounding with decimal arithmetic. SUM QUOREM. 2004. Concepts © Copyright IBM Corp. and the numbers have been counted into a field called COUNT.. half rounded would be calculated as shown above.

CALC move mark to calculate field multiply by 1. 64 –1.5 CALC. MARK CALC.1 to add 10% (10 times too large) divide by 10 and round is adjusted mark > 100? no (branch if first operand not high) yes – reduce to 100 move increased mark back to mark NOADJUST MARK CALC MARK CALC In this example. = P’100’ * MARK. Page 213 of 58 . = P’100’ NOADJUST CALC.OS/390 Assembler Programming Introduction Unit: Comparing and Branching Topic: Compare Instructions Rounding Up – Example 2 ZAP MP SRP CP BNH ZAP EQU ZAP . a teacher wants to raise student marks on a test by 10%. 2000. = P ’11’ CALC. but also wants to assure that no mark exceeds 100. 2004. the above code would perform the calculation for a single student. All rights reserved. DS PL2 DS PL2 CALC. Concepts © Copyright IBM Corp. If the original mark was in a field called MARK. ..

In each case. both 32 bit logical quantities in GPRs. 2000. treating them as logical quantities that are simply strings of bits.Comparison Concepts © Copyright IBM Corp. . Neither operand is modified but the condition code is set to indicate the result of the comparison..2 Page 214 of 58 Compare Logical Register (CLR): RR Format – Register to Register CLR 1st Operand R4. For example: CLR R4.R5 CLR The contents of R4 and the contents of R5 are compared logically. 2004.R5 2nd Operand R4 CONTENTS Register R5 CONTENTS Register COMPARE CC Setting . CC Setting: If R4 = R5 -.OS/390 Assembler Programming Introduction Unit: Comparing and Branching Topic: Compare Instructions Compare Logical Register What is the Compare Logical Register? There are several logical comparison instructions to handle the various types of operands. the instruction compares its two operands. The condition code is set to indicate the result of the comparison.0 If R4 < R5 -. All rights reserved.1 If R4 > R5 -. The Compare Logical Register (CLR) instruction is used to compare its operands logically.

Comparison Concepts © Copyright IBM Corp. a 32 bit logical quantity in a register.FWD2 The contents of R3 and the contents of FWD2 are compared logically.OS/390 Assembler Programming Introduction Unit: Comparing and Branching Topic: Compare Instructions Compare Logical Instruction What is the Compare Logical Instruction? The Compare Logical (CL) instruction is used to compare logically the first operand. 2000. All rights reserved. Neither operand is modified but the condition code is set to indicate the result of the comparison. with the second operand. a 32 bit logical quantity in main storage.FWD2 2nd Operand R3 CONTENTS Register FWD2 CONTENTS Main Storage COMPARE CL CC Setting: If R3 = FWD2 -.. . Compare Logical (CL): RX Format – Register to Indexed Storage CL 1st Operand R3.2 Page 215 of 58 CC Setting . The condition code is set to indicate the result of the comparison. 2004.1 If R3 > FWD2 -.0 If R3 < FWD2 -. For example: CL R3.

The second operand is a byte of immediate data in the instructions.1 If STATEMENT > C’*’ -.2 Continued… Concepts © Copyright IBM Corp.OS/390 Assembler Programming Introduction Unit: Comparing and Branching Topic: Compare Instructions Compare Logical Immediate Instruction What is the Compare Logical Immediate Instruction? The CLI instruction is used to compare the first operand logically with the second operand. Compare Logical Immediate (CLI): SI Format – Storage to Immediate Data CLI STATEMEMT.. For example: CLI STATEMENT.C’*’ 1st Operand STATEMENT BYTE Main Storage CLI CC Setting: If STATEMENT = C’*’ -. 2nd Operand * BYTE Immediate COMPARE Data Page 216 of 58 .C'*' The byte of main storage at STATEMENT is compared to an asterisk. 2000.0 If STATEMENT < C’*’ -. The condition code is set to indicate the result of the comparison. All rights reserved. 2004. The first operand is a byte in main storage. Neither operand is modified during comparison but the condition code is set to indicate the result of the comparison.

2000. Compare Logical Characters (CLC) SS Format (1 length) – Storage to Storage CLC 1st Operand FLD1.FLD2 2nd Operand FLD2 CONTENTS Main COMPARE Storage CLC CC Setting: If FLD1 = FLD2 -.2 Continued… Concepts © Copyright IBM Corp. Neither operand is changed.FLD2 The contents of FLD1 and FLD2 are compared logically. FLD1 CONTENTS Main Storage Page 217 of 58 . equal length character strings in storage. The condition code is set to indicate the result of the comparison. but the condition code is set to indicate the result of the comparison. For example: CLC FLD1..OS/390 Assembler Programming Introduction Unit: Comparing and Branching Topic: Compare Instructions Compare Logical Characters What is the Compare Logical Character? The Compare Logical Characters (CLC) instruction is used to compare logically the two operands. All rights reserved.1 If FLD1 > FLD2 -.0 If FLD1 < FLD2 -. 2004.

The operands are unchanged. but the condition code is set to indicate the results of the comparison. 2004. Concepts Page 218 of 58 .FWD3 FWD3 Compare Logical Characters Under Mask (CLM): RS Format – Register to Storage CLM 1st Operand R3 0 1 R3. BYTE BYTE Main Storage CC Setting: If R3 bytes = FWD3 -.FWD3 3rd Operand 2nd Operand Register 2 3 BYTES COMPARE Bytes 1 and 3 of R3 are compared logically with the two bytes in storage beginning at FWD3.OS/390 Assembler Programming Introduction Unit: Comparing and Branching Topic: Compare Instructions Compare Logical Characters Under Mask Instruction What is the CLM instruction? The Compare Logical Characters Under Mask (CLM) instruction is used to compare logically the bytes of the GPR specified by 1 bit in the mask. 2000. with an equal number of consecutive bytes in main storage beginning at the third operand location.5.0 If R3 bytes < FWD3 -.. All rights reserved.2 © Copyright IBM Corp. For example: CLM R3.1 If R3 bytes > FWD3 -. The condition code is set to indicate the results of the comparison.5.

Continued… Concepts © Copyright IBM Corp. The high order byte of R2+1 contains the padding byte.Comparison R2 + 1 (ODD) Length of OP1 CLCL R2. in their low order 24 bits. The even numbered registers contain the addresses of the two operands. The odd numbered registers contain the length of the operands. which.R4 1st Operand 2nd Operand EVEN – ODD REGISER PAIR R2 (EVEN) Address of OP2 R2 + 1 (ODD) Length of OP2 COMPARE If Lengths are not = the shorter one is extended with PAD Characters This instruction is analogous to the Move Long instruction (MVCL). in each case represent even-odd register pairs. 2004. 2000. Page 219 of 58 . both operands must specify even numbered GPRs using the Compare Logical Long (CLCL) instruction.. All rights reserved. Like Move Long.OS/390 Assembler Programming Introduction Unit: Comparing and Branching Topic: Compare Instructions Compare Logical Characters Long Instruction Compare Logical Long (CLCL): RR Format – Register to Register EVEN – ODD REGISER PAIR R1 (EVEN) Address of OP1 COMPARE CC Setting .

If the mask field corresponds to the setting of the condition code. This instruction tests the current setting of the condition code. Page 220 of 58 . Topic: Branching BC MASK Corresponds To Condition Code YES NO 2nd Operand of BC Next Sequential Instruction Concepts © Copyright IBM Corp. then the next instruction to be executed is the one at the address specified as the second operand of Branch on Condition.. then execution proceeds sequentially with the instruction following Branch on Condition. All rights reserved. 2000. If there is no correspondence. using a mask field in the instruction.OS/390 Assembler Programming Introduction Unit: Comparing and Branching Branch on Condition Instruction What is the Branch on Condition Instruction? Branch on Condition The way you implement conditional execution in Assembler Language is with the Branch on Condition (BC) Instruction. 2004.

2000. Page 221 of 58 . allowing 4 possible values. The condition code is 2 bits long. the branch is taken. 2004. If the mask value is 8. If the CC = 0..OS/390 Assembler Programming Introduction Unit: Comparing and Branching The Mask Field The mask field is 4 bits in length. Topic: Branching Mask Field: Condition Code Setting Corresponding Mask Bit Mask Value 0 0 8 1 1 4 2 2 2 3 3 1 BIT Value 8 4 2 1 X X X X MASK BIT (4 BITS) BIT Position 0 1 2 3 Continued… Concepts © Copyright IBM Corp. allowing 16 possible values. All rights reserved. the Branch on Condition instruction tests for a CC setting of zero. The 4 bits of the mask correspond to the 4 possible condition values. otherwise normal sequential execution occurs.

All rights reserved. A mask value of 15 tests if the CC is 0 or 1 or 2 or 3. the branch is taken. A mask value of 7 (4+2+1) tests if the CC is 1 or 2 or 3.OS/390 Assembler Programming Introduction Unit: Comparing and Branching The Mask Field (cont’d) Mask values can be any value in the range of 0 to 15. 2004.. Any combination of condition codes can be tested in a single Branch on Condition instruction. 2000. Otherwise it is not. If so. this constitutes an unconditional branch. Topic: Branching Mask Values: MASK = 710 = 01112 DECIMAL BINARY CC = 1 CC = 2 CC = 3 Concepts © Copyright IBM Corp. Page 222 of 58 . Since the CC must be one of these values.

OS/390 Assembler Programming Introduction
Unit: Comparing and Branching
BC – An Example
When using the Branch on Condition (BC) instruction the first operand of BC specifies a mask, not a GPR. If the bit in the mask corresponding to the current value of the condition code is on, then the address specified as the second operand replaces the next instruction address in the PSW. If not, the normal sequential instruction sequencing occurs. For example: BC 8,EQRTN If the condition code is zero, branch to EQRTN. Otherwise, continue with the next instruction after the BC. BC If CC = 0 Branch to EQRTN If CC is (1 or 2 or 3) Continue to Next Instruction CC Setting – Condition Code is Unchanged
Continued…
Concepts
© Copyright IBM Corp., 2000, 2004. All rights reserved.

Topic: Branching

Branch on Condition (BC): RX Format – Register to Indexed Storage BC 1st Operand 8 MASK 8, EQRTN 2nd Operand EQRTN ADDRESS TO BRANCH

Page 223 of 58

OS/390 Assembler Programming Introduction
Unit: Comparing and Branching Topic: Branching

Branch on Condition Register Instruction
When using the Branch on Condition Register (BCR) instruction, the first operand specifies a mask, not a GPR. If the bit in the mask corresponding to the current value of the condition code is on, then the address in the second operand register replaces the next instruction address in the PSW. If not, normal instruction sequencing occurs. However, if the second operand specifies 0, no branch is taken regardless of the mask and condition code values. For example: BCR 15,R11 Regardless of the condition code setting, branch to the address in register 11.

Branch on Condition Register (BCR): RR Format – Register to Register

BCR 1st Operand

15, R11

2nd Operand

UNCONDITIONAL BRANCH

CC Setting – Condition Code is Unchanged

Concepts

© Copyright IBM Corp., 2000, 2004. All rights reserved.

Page 224 of 58

OS/390 Assembler Programming Introduction
Unit: Comparing and Branching Topic: Branching

Extended Mnemonic Branch Instructions
What are Extended Mnemonic branch instructions? CR The two operands of the Branch on Condition instruction specify the conditions under which a branch is taken, and the branch address. It can be hard to remember the actual condition code for the various instructions and to calculate mask values, particularly when testing combination of condition codes. Therefore, the Assembler Program simplifies the process by introducing extended mnemonic branch instructions. R3,R4

? Branch if not high? What is CC? What is Mask?

Extended Mnemonics Branch Instructions Simplifies the Process

Continued…
Concepts
© Copyright IBM Corp., 2000, 2004. All rights reserved.

Page 225 of 58

OS/390 Assembler Programming Introduction
Unit: Comparing and Branching Topic: Branching

Extended Mnemonic Branch Instructions (cont’d)
The extended mnemonic branch instructions combine the operation code for branching and the mask, which specifies the conditions under which the branch is taken, into a simple extended mnemonic. For example, if you wanted to branch to NOROUND if the value in R3 was less than the value in R4, you would specify: CR R3,R4 BC 4,NOROUND With extended mnemonics, the code would be as follows: CR R3,R4 BL NOROUND The extended mnemonic BL (branch if first operand low) takes the place of the actual instruction BC and the mask value of 4.
Continued…
Concepts
© Copyright IBM Corp., 2000, 2004. All rights reserved.

Extended Mnemonic Branch Instructions: Using BC

BC

4, NOROUND

Using Extended Mnemonic

BL

NOROUND

Page 226 of 58

OS/390 Assembler Programming Introduction
Unit: Comparing and Branching
Extended Mnemonics (Logical)
Extended Mnemonics Branch Instructions: (Logical) Mask Value
2 4 7 8 11 13

Topic: Branching

RX Extended Mnemonic
BH BL BNE BE BNL BNH

RR Extended Mnemonic
BHR BLR BNER BER BNLR BNHR

Interpretation
Branch if Op1 High Branch if Op1 Low Branch if Not Equal Branch if Equal Branch if Op1 Not Low Branch if Op1 Not High

There is a set of extended mnemonics you can use after comparison instructions. They are shown above.

Concepts

© Copyright IBM Corp., 2000, 2004. All rights reserved.

Page 227 of 58

OS/390 Assembler Programming Introduction
Unit: Comparing and Branching
Extended Mnemonics (Arithmetic)
Extended Mnemonics Branch Instructions: (Arithmetic) Mask Value
1 2 4 7 8 11 13 14

Topic: Branching

RX Extended Mnemonic
BO BP BM BNZ BZ BNM BNP BNO

RR Extended Mnemonic
BOR BPR BMR BNZR BZR BNMR BNPR BNOR

Interpretation
Branch on Overflow Branch on Plus Branch on Minus Branch on Not Zero Branch on Zero Branch on Not Minus Branch on Not Plus Branch on No Overflow

After arithmetic instructions, you use the extended mnemonics shown above.

Concepts

© Copyright IBM Corp., 2000, 2004. All rights reserved.

Page 228 of 58

OS/390 Assembler Programming Introduction
Unit: Comparing and Branching
Test under Mask Instruction
Table1 Extended Mnemonics Branch Instructions

Topic: Branching

Mask Value
0 15 Table2

RX Extended Mnemonic
NOP B

RR Extended Mnemonic
NOPR BR

Interpretation
No Operation Unconditional Branch

Mask Value
1 4 7 8 11 14

RX Extended Mnemonic
BO BM BNZ BZ BNM BNO

RR Extended Mnemonic
BOR BMR BNZR BZR BNMR BNOR

Interpretation
Branch on Ones Branch on Mixed Branch on Not Zeros Branch on Zeros Branch on Not Mixed Branch on Not Ones

The general extended Mnemonics are shown in Table 1 above. The Test under Mask instruction that is used to test selected bits in a byte, has its own set of extended mnemonics, as shown in Table 2. This instruction is discussed in the Assembler Language (Advanced) Course. The use of extended branch mnemonics makes a program easier to read, as well as easier for the programmer to code.

Concepts

© Copyright IBM Corp., 2000, 2004. All rights reserved.

Page 229 of 58

. } The corresponding code in Assembler Language would look like this: CP A. 2000. 2004.B NOADD EQU * if (a=b) { YES IF NO Topic: Building Structured Constructs a=b ? } a=a+b NO ADD Concepts © Copyright IBM Corp.OS/390 Assembler Programming Introduction Unit: Comparing and Branching IF-THEN Structure in C A basic IF-THEN structure in C looks like this: IF – THEN Structure: if (a=b) { a:=a+b. All rights reserved.B BNE NOADD AP A. Page 230 of 58 .

B B CONDEND SUBTR EQU * } else { SP A.B if (a=b) { BNE SUBTR AP A. Page 231 of 58 . 2004. } The corresponding Assembler Language code would be: CP A. 2000. All rights reserved.OS/390 Assembler Programming Introduction Unit: Comparing and Branching IF-THEN-ELSE Structure A basic IF-THEN-ELSE structure in C looks like this: if(a=b) { a:=a+b..B CONDEND EQU * } IF – THEN – ELSE Structure: IF Topic: Building Structured Constructs YES a=b ? NO a=a+b a=a-b CONDEND Concepts © Copyright IBM Corp. } else { a:=a-b.

Like the conditional structures.. Page 232 of 58 . A DO – WHILE loop in C might look like this: while (i>1){ prod:=prod*i.=P'1' while (I >1) { BNH LOOPEND MP PROD.OS/390 Assembler Programming Introduction Unit: Comparing and Branching DO – WHILE Structure The most common and flexible looping structure is DO-WHILE. 2004.=P'1' B LOOPSTART LOOPEND EQU * } Topic: Building Structured Constructs DO – WHILE Structure: LOOPSTART l>1 ? YES NO Prod = prod*I I = i-1 LOOPEND Concepts © Copyright IBM Corp. } The equivalent Assembler Language code would look like this: LOOPSTART EQU * CP I. 2000. it must be built in Assembler Language using the Branch on Condition statement. i=i-1.I SP I. All rights reserved.

2000. 2004. Page 233 of 58 . All rights reserved. PRINT OUT Concepts © Copyright IBM Corp. which are Convert to Binary (CVB) and Convert to Decimal (CVD)..OS/390 Assembler Programming Introduction Unit: Fixed-Point Binary Arithmetic Storing Numeric Data How is numeric data read and stored? Numeric data can be read and stored in a computer in three formats: • • • Binary Packed Decimal Zoned decimal PACKED DECIMAL UNPACK (UNPK) ZONED DECIMAL PACK Topic: Decimal to Binary Conversion CONVERT TO DECIMAL (CVD) BINARY CONVERT TO BINARY (CVB) EDIT (ED) This unit will introduce you to the instructions that work with conversions.

then a data exception will occur. Conversion of data into fixed-point format requires that it first be in an 8 byte packed decimal field. All rights reserved. System /370 and earlier architectures required that it be aligned on a doubleword boundary. If the second operand is not a valid 8-byte packed number..OS/390 Assembler Programming Introduction Unit: Fixed-Point Binary Arithmetic Convert to Binary Instruction What is Convert to Binary instruction? The Convert to Binary (CVB) instruction converts a number from the packed decimal to fixed-point integer form. 2004. If the value being converted is too large to fit into a GPR. a fixed-point divide exception will occur. Page 234 of 58 .Register to indexed storage CVB 1st Operand PK1 00 00 00 00 00 R3 Conversion of positive number PK1 00 00 00 00 FF R3 00 FF 02 FF 5D E7 02 00 45 09 8C 9A R3. 2000. Convert to Binary (CVB): RX Format . PK1 2nd Operand Topic: Decimal to Binary Conversion Conversion of negative number Twos complement form of negative number CC Settings: Condition Code is Unchanged Continued… Concepts © Copyright IBM Corp.

All rights reserved.OS/390 Assembler Programming Introduction Unit: Fixed-Point Binary Arithmetic Convert to Binary Instruction (cont’d) The second operand.Register to indexed storage CVB 1st Operand R3. For example: CVB R3. PK1 2nd Operand Topic: Decimal to Binary Conversion Conversion of negative number Twos complement form of negative number CC Settings: Condition Code is Unchanged Concepts © Copyright IBM Corp.. is converted to fixed-point format and stored in GPR specified by the first operand. PK1 00 00 00 00 00 R3 Conversion of positive number PK1 00 00 00 00 FF R3 00 FF 02 FF 5D E7 02 00 45 09 8C 9A Convert to Binary (CVB): RX Format . 2000. Page 235 of 58 . 2004. an eight byte packed decimal number. PK1 The 8 byte packed value in PK1 is converted to a fixed point fullword and placed in R3.

11 31 0 CC Setting: Condition Code is Unchanged Continued… Concepts © Copyright IBM Corp..Register to indexed storage CVD 1st Operand R4 FULLWORD Sending Field CVD R4.. Convert to Decimal (CVD): RX Format .OS/390 Assembler Programming Introduction Unit: Fixed-Point Binary Arithmetic Convert to Decimal Instruction What is Convert to Decimal instruction? The Convert to Decimal (CVD) instruction performs the conversion from fixed point to packed format. is converted to an eight byte packed decimal number.. a fixed point fullword in a register. 2004. This is another instruction that works backwards.. System /370 and earlier architectures required that the storage location be aligned on a doubleword boundary. at the main storage location specified by the second operand... That is. Page 236 of 58 . The first operand.NUM 2nd Operand NUM DOUBLEWORD Receiving Field Topic: Decimal to Binary Conversion 00 00 02 14 74 83 64 7C Converts FULLWORD to packed Decimal Format R4 011. the second operand is the result field.... All rights reserved. 2000.

.. All rights reserved. 2000.OS/390 Assembler Programming Introduction Unit: Fixed-Point Binary Arithmetic Topic: Decimal to Binary Conversion Convert to Decimal Instruction (cont’d) For example: CVD R4.Register to indexed storage CVD 1st Operand R4.. Page 237 of 58 ....NUM 2nd Operand NUM DOUBLEWORD Receiving Field 00 00 02 14 74 83 64 7C Converts FULLWORD to packed Decimal Format R4 011.NUM The fullword in R4 is converted to a packed decimal number and stored in main storage in eight bytes beginning at NUM. 2004....11 31 0 CC Setting: Condition Code is Unchanged Continued… Concepts © Copyright IBM Corp. R4 FULLWORD Sending Field CVD Convert to Decimal (CVD): RX Format .

The code for this is shown at the right.DWD R2.DWD SUM. 2004.OS/390 Assembler Programming Introduction Unit: Fixed-Point Binary Arithmetic Topic: Decimal to Binary Conversion Convert to Decimal Instruction (cont’d) The code to take two 4 byte zoned numbers called Z1 and Z2. Page 238 of 58 .DWD+5 . ZL4 ZL4 X’4020206B20212060 D convert first number to fixed point F0 F0 F0 C5 bb bb b1 1b Character after EDIT Z1 Z2 SUM DWD 00 00 00 00 00 00 00 5C DS DS DC DS R2 00 00 00 05 00 00 00 6C 00 00 00 00 R3 00 00 00 06 00 00 00 0B F0 F0 F0 C6 convert second number to fixed point calculate sum convert sum to edited form 00 00 01 1C R2 00 00 00 00 Concepts © Copyright IBM Corp.. and then put the sum into an edited field called SUM.DWD DWD. PACK CVB PACK CVB AR CVD ED DWD.21 R2. then calculate their sum using fixed point arithmetic. . .R3 R2. All rights reserved. 2000.Z2 R3.

The remainder of the fixed-point number represents the magnitude. Continued… Concepts © Copyright IBM Corp. or high-order bit. with zero representing positive and 1 representing negative. All rights reserved. 2004.. the leftmost. fullwords (32 bits) or doublewords (64 bits). negative numbers in two's complement form.OS/390 Assembler Programming Introduction Unit: Fixed-Point Binary Arithmetic Number Representation S HALFWORD Topic: Addition and Subtraction S FULLWORD S DOUBLEWORD MAGNITUDE 1=(-) Negative (Two's Complement) High Order Bit (Sign) 0=(+) Positive (True Binary) The System/390 architecture provides 3 sets of arithmetic instructions: • Fixed-point arithmetic instructions deals with integers • Decimal arithmetic instructions deals with integers • Floating point arithmetic deals with real numbers (numbers with fractional parts) Fixed-point arithmetic is performed in the General Purpose Registers (GPRs). Positive numbers are represented in true binary. Operands for fixed-point arithmetic may be halfwords (16 bits). is the sign. 2000. For all three operand types. Page 239 of 58 .

Page 240 of 58 . and thus can represent values from -263 to 263-1 (-9.223.147.483. 2004. 2000.767).775.OS/390 Assembler Programming Introduction Unit: Fixed-Point Binary Arithmetic Number Representation (cont’d) S 01 S 01 S 01 63 31 DOUBLEWORD -263 to + 263.483.1 MAGNITUDE 15 FULLWORD -231 to + 231 .775.372.808 to 9.648 to 2. Continued… Concepts © Copyright IBM Corp. All rights reserved.147.647).372.1 Topic: Addition and Subtraction A halfword has 15 bits to represent the magnitude. and thus can represent values from -215 to +215-1 (32.854.768 to 32.1 HALFWORD -215 to + 215 .036. A doubleword has 63 bits to represent the magnitude.223. and thus can represent values from -231 to +231-1 (-2.854.036.. A fullword has 31 bits to represent the magnitude.807).

767 HALFWORD 2 Bytes STORAGE HALFWORD produces a smaller more efficient program. All rights reserved. It uses 2 bytes rather then 4 bytes in storage. 2000. Generally speaking.767 FULLWORD 4 Bytes Under 32. The Assembler Language programmer chooses a particular fixed-point data type for each variable. and the operations to be performed on it. As you look at the individual instructions. Topic: Addition and Subtraction Over 32. you will see what operand-operation combinations are allowed. Page 241 of 58 . Concepts © Copyright IBM Corp..OS/390 Assembler Programming Introduction Unit: Fixed-Point Binary Arithmetic Number Representation (cont’d) There is not a single instruction to handle all data types for all arithmetic operations. based on the range of values the variable can take on. using the smallest data type that provides the range of values you require will result in the smallest and fastest program. 2004.

Sets Condition Code and carries on Concepts © Copyright IBM Corp. If this bit is not set.Abnormal Termination Off . 2000.OS/390 Assembler Programming Introduction Unit: Fixed-Point Binary Arithmetic The Name Field If you choose a data type that is too small. 2004.. Topic: Addition and Subtraction Program Status Word (PSW) EC Mode: CC Program Mask 0 18 20 63 Fixed-point Overflow Bit On . 20) indicates that a program interrupt will occur causing an abnormal termination. Overflow occurs when a generated result is too large to fit into its destination field. All rights reserved. Page 242 of 58 . you may cause a condition known as overflow. the program may seem to execute correctly but produce incorrect numeric results. The setting of the fixed-point overflow bit in the program work field of the PSW (Bit no.

and the sum would be placed in R3.OS/390 Assembler Programming Introduction Unit: Fixed-Point Binary Arithmetic Add Instruction The first group of fixed-point arithmetic instructions to consider are the addition instructions. The Add Instruction (A) adds a fullword in main storage to a fullword in a GPR. AH and AR. All rights reserved. There are three instructions in this group: A. NUM1 2nd Operand A Sending FULLWORD Receiving In this case. with the sum replacing the value in the GPR. the fullword at NUM1 would be added to the fullword in R3.NUM1 Topic: Addition and Subtraction Add Instruction(A): RX Format – Register to Indexed Storage A 1st Operand R3. 2004. Page 243 of 58 .. For example: A R3. NUM1 + SUM FULLWORD R3 CC Setting – Arithmetic SUM replaces FULLWORD Continued… Concepts © Copyright IBM Corp. 2000.

For example : AH R5. except that the second operand is a halfword in main storage. the halfword at NUM3 would be added to the fullword in R5. The first operand is the whole 32 bits in the register. and the sum placed in R5. Sending HALFWORD NUM3 Receiving + SUM FULLWORD R5 CC Setting – Arithmetic SUM replaces FULLWORD Continued… Concepts © Copyright IBM Corp. 2000. Page 244 of 58 . and the sum is a fullword. 2004.NUM3 Topic: Addition and Subtraction Add Halfword Instruction(AH): RX Format – Register to Indexed Storage AH 1st Operand R5. NUM3 2nd Operand AH In executing this instruction. All rights reserved..OS/390 Assembler Programming Introduction Unit: Fixed-Point Binary Arithmetic Add Halfword Instruction The Add Halfword Instruction (AH) is similar to Add (A).

All rights reserved. with the sum being placed in R3. Page 245 of 58 . 2000. 2004. and the sum is placed in the first operand register. The Add Register (AR) Instruction..OS/390 Assembler Programming Introduction Unit: Fixed-Point Binary Arithmetic The Add Register Instruction The fullword in the second operand register is added to the fullword in the first operand register. For example: AR R3.R4 AR Sending CONTENTS R4 Receiving Topic: Addition and Subtraction Add Register Instruction(AR): RR Format – Register to Register AR 1st Operand R3. except that the second operand is in a register instead of main storage. R4 2nd Operand The contents of R4 are added to the contents of R3. is similar to Add (A). + SUM CONTENTS R3 CC Setting – Arithmetic SUM replaces CONTENTS Concepts © Copyright IBM Corp.

Page 246 of 58 . the fullword at NUM3 is subtracted from the fullword in R7.. a fullword in a GPR. They operate in a similar way to the Add instructions. 2000. and the difference is placed in the register. from the first operand. The Subtract Instruction (S) subtracts the second operand. SH and SR.NUM3 Topic: Addition and Subtraction Subtract Instruction(S): RX Format – Register to Indexed Storage S 1st Operand R7. a fullword in a main storage. except that the operation is subtraction rather than addition. All rights reserved. 2004.OS/390 Assembler Programming Introduction Unit: Fixed-Point Binary Arithmetic Subtract Instruction There are also three fixed-point subtraction instructions: S. and the difference is placed in R7. DIFF R7 CC Setting – Arithmetic DIFF replaces FULLWORD Concepts © Copyright IBM Corp. For example: S R7. NUM3 2nd Operand S Sending FULLWORD NUM3 Receiving FULLWORD In the example on the right.

2004. from the fullword in the GPR specified by the first operand..OS/390 Assembler Programming Introduction Unit: Fixed-Point Binary Arithmetic Subtract Halfword Instruction The Subtract Halfword Instruction (SH) subtracts the halfword at the main storage location specified by the second operand.=H'12' Topic: Addition and Subtraction Subtract Halfword Instruction(SH): RX Format – Register to Indexed Storage SH 1st Operand R4. =H’12’ 2nd Operand SH In the example on the right. the SH instruction subtracts 12 (specified as a literal) from the value in R4. For example: SH R4. The difference is placed in the GPR. All rights reserved. and the difference is placed in R4. 2000. Page 247 of 58 . Sending HALFWORD H’12’ Receiving FULLWORD DIFF R4 CC Setting – Arithmetic DIFF replaces FULLWORD Concepts © Copyright IBM Corp.

Page 248 of 58 . For example: SR R3. the fullword in R7 is subtracted from the fullword in R3. R7 In the example on the right. 2000.OS/390 Assembler Programming Introduction Unit: Fixed-Point Binary Arithmetic Subtract Register Instruction The Subtract Instruction (SR) subtracts a fullword in the second operand register.R7 1st Operand 2nd Operand SR Sending FULLWORD R7 Receiving FULLWORD Topic: Addition and Subtraction Subtract Instruction(SR): RR Format – Register to Register SR R3. DIFF R3 CC Setting – Arithmetic DIFF replaces FULLWORD Continued… Concepts © Copyright IBM Corp. All rights reserved. with the difference placed in R3. 2004. from a fullword in the first operand register.. and the difference is placed in the first operand register.

R4 0 Register R4 Uses 2 bytes of storage Regardless of the initial value of R4.=F'0' Uses 8 bytes of storage Topic: Addition and Subtraction ZERO a register: L R4. R4 Concepts © Copyright IBM Corp. for the RR instruction. SR R4. You could set a register to zero by loading a fullword of zero into it. This method only uses 2 bytes of storage. For example: L R4. = F’0’ This method requires 4 bytes for the instruction (L is an RX instruction) plus 4 bytes for the literal. SR R4. Page 249 of 58 . A better way to set R4 to zero is by subtracting its contents from itself. the result will be zero. All rights reserved.OS/390 Assembler Programming Introduction Unit: Fixed-Point Binary Arithmetic Subtract Register Instruction (cont’d) One application of SR is to zero a register. 2000.. 2004.

then. it makes sense that when you are adding two fullwords. or less than the largest of the operands. when you do multiplication. the number of digits in the product is roughly the sum of the number of digits in the multiplicand and multiplier. the result is of roughly the same magnitude. 2000. All rights reserved. and the products has four digits. it should provide for a product larger than the multiplier and the multiplicand. the sum also be a fullword. Topic: Multiplication Even-Odd Register Pair: 99 * 99 =9801 Multiplicand Multiplier Product 2 digits + 2 digits =4 digits Continued… Concepts © Copyright IBM Corp. It makes sense. The multiplier and multiplicand have two digits each. 2004.OS/390 Assembler Programming Introduction Unit: Fixed-Point Binary Arithmetic Multiplication When you perform addition and subtraction. that when a multiply instruction is designed as a part of a computer architecture.. Thus. However. Page 250 of 58 .

Page 251 of 58 .. All rights reserved. 2000. Continued… Concepts © Copyright IBM Corp. They are: • MH is analogous in operation to AH and SH M and MR use the first operand GPR specification in a non-intuitive way that requires some explanation Even-Odd Register Pair: Topic: Multiplication • 99 99 =9801 2 digits +2 digits = 4 digits Multiplicand Multiplier Product The Product is larger then both the Multiplicand and the Multiplier.OS/390 Assembler Programming Introduction Unit: Fixed-Point Binary Arithmetic Multiplication (cont’d) There are three fixed-point multiplication instructions. 2004. The hardware requires that the Product forms an EVEN-ODD Register Pair.

one greater than the first operand specification. the Low Order half of the Product replaces the Multiplicand Concepts © Copyright IBM Corp. Topic: Multiplication 1st Operand FULLWORD MULTIPLICAND Located in the ODD Register 2nd Operand FULLWORD MULTIPLIER 1st Operand specifies an Even Register for the High Order half of the Product = Even Odd Register Pair DOUBLEWORD PRODUCT Placed in the Even-Odd Register Pair. Page 252 of 58 . 2004. The product (64 bits) is placed in the even-odd register pair. The first operand must specify an even numbered GPR. The multiplicand must be located in the odd numbered GPR. The multiplier is the second operand. 2000.OS/390 Assembler Programming Introduction Unit: Fixed-Point Binary Arithmetic Multiplication (cont’d) For both M and MR. All rights reserved.. wiping out the multiplicand in the odd register of the pair. the multiplicand and multiplier are fullwords. The product is a doubleword.

The low order 32 bits of the product replace the multiplicand. If overflow occurs. 2000. 2004. but there is no indication of this truncation.=H'25' 2nd Operand Topic: Multiplication X R7 CC Setting Does not set the Condition Code PRODUCT Product replaces FULLWORD in R7 Multiply and divide instructions do not set the condition code. and the product placed in R7.=H'25' The value in R7 is multiplied by 25.. significant bits to the left of the 32 saved bits. Concepts © Copyright IBM Corp. All rights reserved. are lost. by the 32 bit multiplicand in the register specified as the first operand. For example: MH R7. Page 253 of 58 .OS/390 Assembler Programming Introduction Unit: Fixed-Point Binary Arithmetic Multiply Halfword Instruction What is the Multiply Halfword Instruction? The Multiply Halfword Instruction (MH) multiplies a halfword in main storage (which is the Multiplier specified by the second operand).Register to Indexed Storage MH 1st Operand MH Multiplier HALFWORD H’25’ Multiplicand FULLWORD R7. Multiply Halfword Instruction(MH): RX Format .

and in the register one greater. 2004. or a specification exception will occur. a 64 bit fixed point number is placed in the first operand register. Multiply Instruction (M): RX Format .. It is impossible for overflow to occur.Register to Indexed Storage M 1st Operand M Multiplier FULLWORD FWD4 Specifies Even Register Multiplicand FULLWORD R4. The product. All rights reserved. The first operand must specify an even numbered register. Page 254 of 58 . The 64-bit product is placed in GPRs 4 and 5. For example: M R4. 2000.Does not set the Condition Code Concepts © Copyright IBM Corp.OS/390 Assembler Programming Introduction Unit: Fixed-Point Binary Arithmetic Multiply Instruction What is the Multiply Instruction? The Multiply Instruction (M) multiplies a fullword in the GPR (one greater than the first operand register specified). by a fullword second operand storage. FWD4 The fullword in R5 is multiplied by the fullword at main storage location FWD4. FWD4 2nd Operand Topic: Multiplication X R4 Located in Odd Register (R5) PRODUCT placed in Even-Odd Register R5 Odd Register PRODUCT R4 Even Register High Order Low Order CC Setting .

Page 255 of 58 ..Does not set the Condition Code Continued… Concepts © Copyright IBM Corp. For example: MR R2. R5 2nd Operand op2 located in Odd Register (R3) FULLWORD Topic: Multiplication X Multiplicand High Order Low Order R3 Odd Register CC Setting . a 64 bit fixed point number. and in the register one greater.Register to Register Storage MR 1st Operand R5 Specifies Even Register FULLWORD Multiplier MR R2. The first operand must specify an even numbered register. by the fullword in the register specified as the second operand. All rights reserved. The 64 bit product is placed in GPRs 2 and 3. The product.R5 The fullword in R3 is multiplied by the fullword in R5. R2 Even Register PRODUCT PRODUCT placed in Even-Odd Register Multiply Register Instruction (MR): RR Format . 2000. is placed in the first operand register.OS/390 Assembler Programming Introduction Unit: Fixed-Point Binary Arithmetic Multiply Register Instruction What is the Multiply Register Instruction? The Multiply Register Instruction (MR) multiplies a fullword in the GPR one greater than the first operand register specified. 2004.

and the quotient goes into the odd numbered register one greater than the first operand. D and DR. There is no DH instruction. Page 256 of 58 .. 2000. so division produces both an integer quotient and an integer remainder. The divisor is a fullword.OS/390 Assembler Programming Introduction Unit: Fixed-Point Binary Arithmetic Fixed-Point Division What are the two fixed-point division operations? There are only two fixed-point division operations. 2004. the remainder is placed in the even numbered register.X 2nd Operand EVEN-ODD REGISTER PAIR DIVIDEND DOUBLEWORD BEFORE EXECUTION EVEN DOUBLEWORD REGISTER Specified by 1st Operand REMAINDER FULLWORD ODD REGISTER One Greater then 1st Operand QUOTIENT FULLWORD AFTER EXECUTION Continued… Concepts © Copyright IBM Corp. All rights reserved. Topic: Division D 1st Operand R2. specified by the first operand. After the division. The dividend is a 64-bit quantity in an even-odd register pair. Fixed-point arithmetic is integer arithmetic.

or the quotient is too large to fit into a fullword. 2000. The sign of the remainder is the same as the sign of the dividend. Page 257 of 58 . All rights reserved. if the signs of dividend and divisor are the same.OS/390 Assembler Programming Introduction Unit: Fixed-Point Binary Arithmetic Fixed-Point Division (cont’d) The sign of the quotient is determined by the rules of algebra. Topic: Division S DIVIDEND If… SIGN of Dividend = Then Quotient is Positive (Otherwise it is Negative) SIGN of Divisor Concepts © Copyright IBM Corp. a fixed-point divide exception occurs. That is. This will cause your program to terminate abnormally.. If the divisor is zero. 2004. the quotient is positive. otherwise it is negative.

. All rights reserved. Concepts © Copyright IBM Corp. Page 258 of 58 . showing which signs are generated for both quotient and remainder. 2000.OS/390 Assembler Programming Introduction Unit: Fixed-Point Binary Arithmetic Signs of Quotient and Remainder DIVIDEND 17 -17 17 -17 15 DIVISOR 5 5 -5 -5 5 QUOTIENT 3 -3 -3 3 3 REMAINDER 2 -2 2 -2 0 Topic: Division The table above indicates the results of some division operations. 2004.

Page 259 of 58 ..OS/390 Assembler Programming Introduction Unit: Fixed-Point Binary Arithmetic Divide Instruction What is the Divide instruction? The Divide Instruction (D) divides the 64 bit fixed point number in the even-odd register pair specified by the first operand (which must be even). DIVISOR The 64 bit fixed point number in registers R4 and R5 is divided by the fullword at DIVISOR. 2004. and a fullword quotient which is placed in the odd numbered register (R1 +1). For example: D R4. DIVISOR 2nd Operand D Dividend DOUBLEWORD R4 Specifies Even Register R4 Even Register Divisor ÷ FULLWORD DIVISOR Remainder Quotient R5 Odd Register CC Setting – Does not set the Condition Code Continued… Concepts © Copyright IBM Corp. The result consists of a fullword remainder that is placed in the even numbered register (R1). and the integer remainder is placed in R4 and the integer quotient in R5. 2000. Divide Instruction(D): RX Format – Register to Indexed Storage Topic: Division D 1st Operand R4. All rights reserved. by the fixed point fullword in the storage location specified by the second operand.

QUOTIENT LOAD MULTIPLE R2 32-bit R3 32-bit DIVIDEND HIGH ORDER Even Register LOW ORDER Odd Register DIVIDE .R3. to produce fullword QUOTIENT and REMAINDER. 2000. Topic: Division LM R2.OS/390 Assembler Programming Introduction Unit: Fixed-Point Binary Arithmetic Divide Instruction (cont’d) If you wanted to divide a 64-bit variable called DIVIDEND. you could use the code shown on the right.DIVISOR ST R3. Page 260 of 58 . 2004.R3) Dividend by Divisor STORE .DIVIDEND D R2. by a fullword variable called DIVISOR.(R2.Remainder into Even Register R2 Quotient into Odd Register R3 Concepts © Copyright IBM Corp.REMAINDER ST R3. All rights reserved..

2004. and a fullword quotient that is placed in the odd numbered register (R1+1). by the fixed point fullword in the GPR specified by the second operand.. The result consists of a fullword remainder that is placed in the even numbered register (R1).OS/390 Assembler Programming Introduction Unit: Fixed-Point Binary Arithmetic Divide Register Instruction What is the Divide Register instruction? The Divide Register Instruction (DR) divides a 64 bit fixed point number in the even-odd register pair specified by the first operand (which must be even). and the integer remainder is placed in R4 and in the integer quotient in R5.R7 The 64 bit fixed point number in registers R4 and R5 is divided by the fullword in R7. For example: DR R4. 2000. Divide Register Instruction(DR): RX Format – Register to Register D 1st Operand DR Dividend DOUBLEWORD R4 Specifies Even Register R4 Even Register Divisor R4. All rights reserved. Page 261 of 58 . R7 2nd Operand Topic: Division ÷ FULLWORD R7 Remainder Quotient R5 Odd Register CC Setting – Does not set the Condition Code Concepts © Copyright IBM Corp.

Page 262 of 58 . All rights reserved. There are three standard ways that this fullword to doubleword conversion can be done. However. 2000. Dividend must be Doubleword Convert Fullword TO DOUBLEWORD DIVIDEND Prepared for Division Continued… Concepts © Copyright IBM Corp. 2004.. You must convert the fullword to a doubleword prior to performing the division. There are many times when you will want to perform division on a value that is in a fullword variable. the division instructions require that the dividend be a doubleword. you are often working with fullword operands.OS/390 Assembler Programming Introduction Unit: Fixed-Point Binary Arithmetic Topic: Division Converting From Fullword to Doubleword for Division What are the three ways of converting from fullword to doubleword for division? In performing fixed-point arithmetic.

and the first half of the doubleword will be binary zeros. All rights reserved. 2004.Y low half of doubleword (positive) high half of doubleword (zero) perform division Positive LOAD FULLWORD R2 R3 Low Order EVEN High Order ODD Register 0…………….OS/390 Assembler Programming Introduction Unit: Fixed-Point Binary Arithmetic Topic: Division Converting From Fullword to Doubleword for Division (cont’d) First Method: Load (L) / Subtract Register (SR) For the first method.R2 R2.0 SUBTRACT R2 from R2 To ZERO the Register DOUBLEWORD prepared for Division Continued… Concepts © Copyright IBM Corp. Page 263 of 58 .X R2. just load the fullword into the odd register and set the even register to zero. Therefore. L SR D R3... you are only working with positive numbers. you could code as shown on the right. 2000. To divide fullword X by fullword Y.

Remember that multiplication multiplies two fullwords. 2000. giving a 64-bit result. Using this method to divide X by Y. All rights reserved. you do not change its value.. but u do change it to a 64-bit quantity. The second method uses multiplication.=F’1’ prepare for division R2. MULTIPLY R2 by 1 L M D R3. R2 F’1’ FULLWORD * R3 FULLWORD R2 High Order Low Order EVEN ODD Register DOUBLEWORD prepared for Division Continued… Concepts © Copyright IBM Corp. you could use the code shown on the right.OS/390 Assembler Programming Introduction Unit: Fixed-Point Binary Arithmetic Topic: Division Converting From Fullword to Doubleword for Division (cont’d) Second Method: Multiplication The second and third methods will handle both positive and negative dividends. 2004.X R2.Y If you multiply a fullword value by one. Page 264 of 58 .

2004.. producing a 64-bit dividend. the fullword dividend is loaded into the even numbered register of the even-odd pair. Using this instruction.OS/390 Assembler Programming Introduction Unit: Fixed-Point Binary Arithmetic Topic: Division Converting From Fullword to Doubleword for Division (cont’d) Third Method: Shift Right Double (SRDA) The third method uses an instruction you have not seen yet.Y FULLWORD LOAD into EVEN Register SRDA – Covert to Doubleword Propagate SIGN SSSSSS Magnitude Remains the same R2 High Order FULLWORD R3 Low Order EVEN Register ODD Register DOUBLEWORD prepared for Division Concepts © Copyright IBM Corp. 2000. and then shifted (double) 32 bits. All rights reserved.X fullword in even register R2. L SRDA D R2.32 convert to doubleword R2. Page 265 of 58 . SRDA (shift right double). the code to perform the division is shown on the right. With this third method.

Y NOROUND R3.. Page 266 of 58 . if the remainder is equal to or greater than half of the divisor. Often. To round. The code is shown above. so do not round up Round quotient up There is one more issue you should consider with regards to division. you increase the quotient by one. you decide that you do not want a remainder per se.32 R2.R2 R2.=H'1' * Get fullword dividend Convert to doubleword Divide Double the remainder Compare double the remainder to divisor Less.OS/390 Assembler Programming Introduction Unit: Fixed-Point Binary Arithmetic Rounding After Division Topic: Division L SRDA D AR C BL AH NOROUND EQU R2. If it is equal or greater. That is.Y R2. Concepts © Copyright IBM Corp. 2000. but rather a rounded quotient. 2004. perform the division. All rights reserved. double the remainder and compare it to the divisor. you add one to the quotient.X R2.

What is an iterative loop? Unlike situations where the end condition is unknown until execution time. an iterative loop is coded when its known how many times the loop is needed. 2004. Array Month1 Month2 .OS/390 Assembler Programming Introduction Unit: Looping Topic: The Iterative Loop Uses of Iterative Structure What is looping? Looping is a coding technique that enables to repeatedly execute the same sequence of machine instructions.. . All rights reserved. Month12 Next Entry Process Result < Loop Compare Counter = Store Results Continued… Concepts © Copyright IBM Corp. . The example shows processing of an array with one entry for each month. . Page 267 of 58 . 2000.

All rights reserved. 2004. The example shows the code used to process the array of 12 months..OS/390 Assembler Programming Introduction Unit: Looping Topic: The Iterative Loop Uses of Iterative Structure (cont’d) How is an iterative loop built? Iterative loop structure can be built by using a counter and a comparison followed by a Branch on Condition.=H’1’ MTHLOOP EQU * * Process data for * month number * which is in R3 AH R3. 2000. LH R3.=H’12’ Increment month number Have you processed all the months No Initialize counter to 1 BNH MTHLOOP Concepts © Copyright IBM Corp.=H’1’ CH R3. Page 268 of 58 .

All rights reserved.. If the result is zero. If the result is non-zero. One is subtracted from the first operand register and the result is saved in the register. 2004.Register and Indexed Storage BCT R6. the main storage address specified by the second operand replaces the next instruction address in the PSW. Page 269 of 58 . following BCT. then normal instruction sequencing occurs at the instruction. 2000.Condition Code is Unchanged Continued… Concepts © Copyright IBM Corp.LOOP Loop Counter Register R6 10 Counter Branch Address (Main Storage) • Reduces the counter by 1 each time program loops • Falls through to next instruction when counter reaches 0 CC Setting .OS/390 Assembler Programming Introduction Unit: Looping Topic: The Iterative Loop Branch on Count What is Branch on Count? The Branch on Count (BCT) instruction is designed to handle iterative looping. Branch on Count (BCT): RX Format . no branching occurs and execution continues with the next instruction. If second operand is 0 (zero).

2004. * Process data for Month 13(value in R3) * BCT R3. with the last instruction being a BCT.MTHLOOP Continued… Concepts © Copyright IBM Corp. Code the body of the loop.OS/390 Assembler Programming Introduction Unit: Looping Topic: The Iterative Loop Branch on Count (cont’d) How is a BCT used? LH R3. using the initialized register and the address at the start of the loop The code on the right shows how monthly processing is repeated 12 times using BCT. 2000.. All rights reserved. Immediately before the body of the loop. Page 270 of 58 .=H’12’ Using BCT involves the following steps: Loop count for 12 months MTHLOOP EQU * 1. load a General Purpose Register (GPR) with the number of times the loop needs to be executed 2.

2000.=H'1' Code subtracts the Literal Value 1 from the contents of R7. 0 SH R7. 2004.OS/390 Assembler Programming Introduction Unit: Looping Topic: The Iterative Loop Branch on Count (cont’d) What happens when BCT does not branch? The fact that BCT does not branch when its second operand is 0. (requires 2+4=6 bytes) Use: BCTR R7. (requires 2 bytes) Concepts © Copyright IBM Corp. All rights reserved. allowing it to subtract 1 from R7. Page 271 of 58 .0 The only difference between these two codes is that the BCTR cannot cause overflow and it will not set the condition code. allows it to be used as a way to subtract one from a register with no literal value needed. That means. Code does not branch when the 2nd Operand is 0. instead of using the following code: SH R7.=H’1’ BCTR R7..

each iteration of the loop processes a different element of the array. 2000. The address of the second operand is placed in the first operand location.Condition Code is Unchanged Concepts © Copyright IBM Corp.. All rights reserved. 2004.Register and Indexed Storage LA R4. Load Address (LA): RX Format .ARRAY 2nd Operand (Base Displacement) ARRAY Address 1st Operand R4 Contents Replaces Contents of R4 with Address at location ARRAY LA CC Setting . Page 272 of 58 . The process of manipulating the addresses of data is called address arithmetic. The Assembler programmer must adjust the address of the current element each time through the loop.OS/390 Assembler Programming Introduction Unit: Looping Topic: Address Arithmetic Address Arithmetic While processing arrays in a loop. The condition code is unaltered. The most important instruction used in writing address arithmetic is the Load Address (LA) instruction.

2004.ARRAY Calculate Effective Address – Sum Of Displacement. Example: LA R4. specified by the first operand.ARRAY LA R4. the effective address is placed in the GPR specified by the first register. Page 273 of 58 . the effective address of the second operand is calculated by adding the displacement to the sum of the contents of the base. 2000.. and Index Storage The address of the storage location ARRAY is placed into R4. and index registers. For Load.ARRAY L R4.OS/390 Assembler Programming Introduction Unit: Looping Topic: Address Arithmetic Load Address Instruction What is the difference between Load and Load Address? In both cases. the contents of the effective address are placed into the GPR. while Load Address does not. Base. All rights reserved. Load makes a storage reference. Contents Of Effective Address In Storage Continued… Concepts © Copyright IBM Corp. But in the case of Load Address.

10(R4. LA R3. Page 274 of 58 .R5) No Base or Index No Index No Base Both Base and Index If either or both of the base and index registers specify R0.. All rights reserved. adding the displacement. and the contents of the index register. contents of the base register.R4) R3. like Load Address. 10(R4) R3. 2004. then that component is not used in address formation. 2000. forms the effective address.OS/390 Assembler Programming Introduction Unit: Looping Topic: Address Arithmetic Load Address Instruction (cont’d) How effective addresses are formed? For an RX format instruction. LA LA LA Concepts © Copyright IBM Corp. 10(. 10 R3.

the address arithmetic deals with numbers in the range of 0.. All rights reserved. 2000.777. the maximum number in address arithmetic is 2 ³¹ – 1 Continued… Concepts © Copyright IBM Corp. which are non-negative integers less than the maximum storage size. 2004.OS/390 Assembler Programming Introduction Unit: Looping Topic: Address Arithmetic Address Arithmetic What does address arithmetic deal with? Address arithmetic deals with storage addresses.215. In BC mode. Page 275 of 58 .16. In EC mode.

instead of using: LH R5.R7) It can be used for placing the address of a named storage area into a register It can be used to initialize a register Concepts © Copyright IBM Corp. LA R5. instead of using: AH R7. 2000.=H’10’ Use. LA R7.. Page 276 of 58 .OS/390 Assembler Programming Introduction Unit: Looping Topic: Address Arithmetic Address Arithmetic (cont’d) What are the uses of load address? Load address can be used for the following purposes: • • Example: To place the value 10 into R5. 2004. All rights reserved.=H’5’ Use.5(.10 To add 5 to the contents of R7.

2000. 2004. Comma Indicates Index Register is not specified The result is placed in the first operand R7. for address arithmetic to work 1st Operand R1 D2 X2 B2 2nd Operand • Basic Instruction Format: OP R1.5(. the effective address is formed by adding the basic contents of the base register R7 and the displacement 5.. All rights reserved.R7) What are the limitations of address arithmetic? Following are the limitations of address arithmetic: • Displacements must be in the range 04095 The arithmetic must deal with nonnegative integers less than the storage size.B2) Concepts © Copyright IBM Corp. Page 277 of 58 . LA R7. Displacement Base Register The effect is to add 5 to R7.OS/390 Assembler Programming Introduction Unit: Looping Topic: Address Arithmetic Address Arithmetic: Example In the example.(X2.D2.

consisting of multiple elements of some base type.OS/390 Assembler Programming Introduction Unit: Looping Defining Arrays An array is a repetitive data structure. In the example shown to record a a company’s gross sales for each day in January. All rights reserved. 2000. or 31 packed decimal numbers have been used. an array of 31 fullwords. Topic: Processing Arrays Fixed-Point Array: FDSALES DS 31F Array of 31 Fullwords Packed Decimal: PDSALES DS 31PL4 31 Packed Decimal Fields of Length 4 Continued… Concepts © Copyright IBM Corp. Page 278 of 58 . 2004..

31. It shows an array to hold the number of days in each month of a common (not a leap) year. Here a duplication factor has not been specified.31. the Assembler has been told that the array has 12 elements.30.30. 2004.30. All rights reserved.30.OS/390 Assembler Programming Introduction Unit: Looping Topic: Processing Arrays Defining Arrays (cont’d) DAYSINMTH DC H‘31. Page 279 of 58 .28.31. 2000. by defining twelve constants.31.. Concepts © Copyright IBM Corp.31. Rather.31” 12 Constants – Each Being a Halfword 31 28 31 30 31 30 31 31 30 31 30 31 Main Storage – 12 Elements The example shows how to create an array of constants.

. 2004. In this algebra. 0 often represents false and 1 represents true. All rights reserved. The internal operation of computers is based on Boolean logic.OS/390 Assembler Programming Introduction Unit: Logical and Shift Instructions Boolean Algebra Boolean algebra is an algebra that deals with the binary values of zero and one. and most computer architectures provide some Boolean instructions in their instruction set. 2000. AND (N) AND REGISTER (NR) AND CHARACTER (NC) AND IMMEDIATE (NI) Topic: Boolean Operations 1 2 2 OR (O) OR REGISTER (OR) OR CHARACTER (OC) OR IMMEDIATE (OI) 3 3 EXCLUSIVE OR (X) EXCLUSIVE OR REGISTER (XR) EXCLUSIVE OR CHARACTER (XC) EXCLUSIVE OR IMMEDIATE (XI) Continued… Concepts © Copyright IBM Corp. Page 280 of 58 .

Result is all zero bits 1 – Result is not all zero bits Continued… Concepts © Copyright IBM Corp. Page 281 of 58 . 2004. The result replaces the first operand. R3 FULLWORD AND (N): RX Format – Register and Indexed Storage N R3. which is a fullword in main storage. FWD8 1st Operand N 2nd Operand FWD8 FULLWORD Result Placed in R3 CC Setting: 0 .. Here.OS/390 Assembler Programming Introduction Unit: Logical and Shift Instructions Topic: Boolean Operations Machine Instructions with Boolean AND AND (N) Instruction Here is an example of AND (N) instruction. the 32 bits of the first operand (in a GPR) are bit-wise ANDed with the 32 bits of the second operand. All rights reserved. 2000. which is an RX format instruction.

R8 1st Operand NR R7 FULLWORD 2nd Operand R8 FULLWORD Result Placed in R7 CC Setting: 0 . The result replaces the first operand.Result is all zero bits 1 – Result is not all zero bits Continued… Concepts © Copyright IBM Corp. the 32 bits in the first operand register are bit wise ANDed with the 32 bits in the second operand register. AND (NR): RR Format – Register and Register NR R7. In this RR format instruction.OS/390 Assembler Programming Introduction Unit: Logical and Shift Instructions Topic: Boolean Operations Machine Instructions with Boolean AND (cont’d) AND (NR) Instruction Here is an example of AND (NR) instruction. 2004. All rights reserved.. 2000. Page 282 of 58 .

Result is all zero bits 1 . Page 283 of 58 . All rights reserved. In this SI format instruction. and the result replaces the first operand. 2004. the eight bits of the first operand are bit-wise ANDed with the 8 bits of the immediate operand..Result is not all zero bits Continued… Concepts © Copyright IBM Corp. X’7F’ 1st Operand NI SWITCH 1 Byte 2nd Operand (Immediate Data) X’7F’ 1 Byte Replaces contents At location switch Turn bit 0 off 0 Result 1234567 Unchanged Effect(Result) CC Setting: 0 . 2000.OS/390 Assembler Programming Introduction Unit: Logical and Shift Instructions Topic: Boolean Operations Machine Instructions with Boolean AND (cont’d) AND (NI) Instruction The AND (NI) instruction is shown in the example. AND (NI): SI Format – Storage and Immediate Data NI SWITCH.

2000. FLD2 1st Operand NC FLD1 Bits 2nd Operand FLD2 Bits Result Replaces contents at location FLD1 CC Setting: 0 . the bits of the first operand are bit-wise ANDed with the bits of the second operand.OS/390 Assembler Programming Introduction Unit: Logical and Shift Instructions Topic: Boolean Operations Machine Instructions with Boolean AND (cont’d) AND (NC) Instruction The AND (NC) instruction is shown in the example. AND (NC): SS Format – Storage and Storage NC FLD1.Result is all zero bits 1 – Result is not all zero bits Concepts © Copyright IBM Corp. In this SS format instruction. All rights reserved. with the result replacing the first operand. Page 284 of 58 . 2004..

R3 FULLWORD OR (O): RX Format – Register and Indexed Storage O R3. Page 285 of 58 . FWD8 1st Operand O 2nd Operand FWD8 FULLWORD Result Placed in R3 CC Settings: 0 .OS/390 Assembler Programming Introduction Unit: Logical and Shift Instructions Topic: Boolean Operations Machine Instructions with Boolean OR OR (O) Instruction The OR (O) instruction is shown in the example. 2004. witch is a fullword in main storage.. 2000.Result is all zero bits 1 – Result is not all zero bits Continued… Concepts © Copyright IBM Corp. the 32 bits of the first operand (in a GPR) are bit-wise ORed with the 32 bits of the second operand. All rights reserved. In this RX format instruction. The result replaces the first operand.

. All rights reserved.Result is all zero bits 1 – Result is not all zero bits Continued… Concepts © Copyright IBM Corp.OS/390 Assembler Programming Introduction Unit: Logical and Shift Instructions Topic: Boolean Operations Machine Instructions with Boolean OR (cont’d) OR (OR) Instruction The OR (OR) instruction is shown in the example. R8 1st Operand OR 2nd Operand R8 FULLWORD Result Placed in R7 CC Settings: 0 . 2004. 2000. Page 286 of 58 . R7 FULLWORD OR (OR): RR Format – Register and Register O R7. The result replaces the first operand. In this RR format instruction. the 32 bits of the first operand register are bit-wise ORed with the 32 bits in the second operand register.

Result is all zero bits 1 . Page 287 of 58 . X’10’ 1st Operand OI SWITCH 1 Byte 2nd Operand (Immediate Data) X’7F’ 1 Byte Replaces contents At Location SWITCH 0 1 2 Result Turn bit 3 on 3 4 5 6 7 Unchanged CC Settings: 0 . OR (OI): SI Format – Storage and Immediate Data OI SWITCH.Result is not all zero bits Continued… Concepts © Copyright IBM Corp. 2004.OS/390 Assembler Programming Introduction Unit: Logical and Shift Instructions Topic: Boolean Operations Machine Instructions with Boolean OR (cont’d) OR (OI) Instruction The OR (OI) instruction is shown in the example. the eight bits of the first operand are bit-wise ORed with the 8 bits of the immediate operand. the result replaces the first operand. 2000. All rights reserved.. In this SI format instruction.

FLD2 1st Operand OC FLD1 Bits 2nd Operand FLD2 Bits Result Replaces Contents at Location FLD1 CC Settings: 0 . 2000. with the result replacing the first operand. In this SS format instruction.OS/390 Assembler Programming Introduction Unit: Logical and Shift Instructions Topic: Boolean Operations Machine Instructions with Boolean OR (cont’d) OR (OC) Instruction The OR (OC) instruction is shown in the example.. OR (OC): SS (1 length) Format – Storage and Storage OC FLD1.Result is all zero bits 1 – Result is not all zero bits Continued… Concepts © Copyright IBM Corp. Page 288 of 58 . the bits of the first operand are bit-wise ORed with the bits of the second operand. 2004. All rights reserved.

2000.=20X’40’ Result Space JOHNbSMITH CAPS Lower Case REPLY john smith D1 96 88 95 40 E2 94 89 A3 88 40 40 40 40 40 40 40 40 40 40 X’40’ is the EBCDIC code for blank. The example shows a user reply into a 20-byte field called REPLY. All rights reserved.. Page 289 of 58 . To convert the field to uppercase. following code can be used. 2004. OC REPLY. The technique of using OC to change to uppercase works because the EBCDIC codes for the lower case letters is almost identical to the codes for the uppercase.=CL20’ ‘ © Copyright IBM Corp. so it can be coded as: OC Concepts REPLY.OS/390 Assembler Programming Introduction Unit: Logical and Shift Instructions Topic: Boolean Operations Machine Instructions with Boolean OR (cont’d) OR (OC) Instruction One use of the OC instruction is to convert text in mixed case to all upper case.

Page 290 of 58 . the 32 bits of the first operand (in a GPR) are bit-wise XORed with the 32 bits of the second operand. 2000. which is a fullword in main storage. FWD8 1st Operand X 2nd Operand FWD8 FULLWORD Result Placed in R3 CC Settings: 0 .. In this RX format instruction.OS/390 Assembler Programming Introduction Unit: Logical and Shift Instructions Topic: Boolean Operations Machine Instructions with Boolean Exclusive OR EXCLUSIVE OR (X) Instruction The EXCLUSIVE OR (X) instruction is shown in the example. R3 FULLWORD EXCLUSIVE OR (X): RX Format – Register and Indexed Storage X R3. All rights reserved.Result is all zero bits 1 – Result is not all zero bits Continued… Concepts © Copyright IBM Corp. The result replaces the first operand. 2004.

R7 FULLWORD EXCLUSIVE OR (XR): RR Format – Register and Register XR R7. The result replaces the first operand.OS/390 Assembler Programming Introduction Unit: Logical and Shift Instructions Topic: Boolean Operations Machine Instructions with Boolean Exclusive OR (cont’d) EXCLUSIVE OR (XR) Instruction The EXCLUSIVE OR (XR) instruction is shown in the example. 2004. In this RR format instruction.Result is all zero bits 1 – Result is not all zero bits Continued… Concepts © Copyright IBM Corp. R8 1st Operand XR 2nd Operand R8 FULLWORD Result Placed in R7 CC Settings: 0 . the 32 bits of the first operand register are bit-wise XORed with the 32 bits in the second operand register. Page 291 of 58 . All rights reserved. 2000..

the eight bits of the first operand are bit-wise XORed with the 8 bits of the immediate operand. X’01’ 1st Operand XI SWITCH 1 Byte 2nd Operand (Immediate Data) X’01’ 1 Byte Replaces contents At Location SWITCH Effect (Result) Result 0123456 7 Flip Bit Unchanged CC Settings: 0 . EXCLUSIVE OR (XI): SI Format – Storage and Immediate Data XI SWITCH. 2000.Result is all zero bits 1 . In this SI format instruction..OS/390 Assembler Programming Introduction Unit: Logical and Shift Instructions Topic: Boolean Operations Machine Instructions with Boolean Exclusive OR (cont’d) EXCLUSIVE OR (XI) Instruction The EXCLUSIVE OR (XI) instruction is shown in the example. 2004.Result is not all zero bits Continued… Concepts © Copyright IBM Corp. All rights reserved. the result replaces the first operand. Page 292 of 58 .

In this SS format instruction. the bits of the first operand are bit-wise XORed with the bits of the second operand. 2004.OS/390 Assembler Programming Introduction Unit: Logical and Shift Instructions Topic: Boolean Operations Machine Instructions with Boolean Exclusive OR (cont’d) EXCLUSIVE OR (XC) Instruction The EXCLUSIVE OR (XC) instruction is shown in the example. with the result replacing the first operand. Page 293 of 58 .. EXCLUSIVE OR (XR): SS Format – Storage and Storage XC FLD1. All rights reserved.Result is all zero bits 1 – Result is not all zero bits Continued… Concepts © Copyright IBM Corp. 2000. FLD2 1st Operand XC FLD1 Bits 2nd Operand FLD2 Bits Result Replaces Contents at Location FLD1 CC Settings: 0 .

. 2000. All rights reserved. the result will be all zeros. Page 294 of 58 . 2004. 1 1 0 1 Flips the bit 0 retains the bit 0 XOR 0 = 0 1 XOR 1 = 0 Continued… Concepts © Copyright IBM Corp.OS/390 Assembler Programming Introduction Unit: Logical and Shift Instructions Topic: Boolean Operations Machine Instructions with Boolean Exclusive OR (cont’d) EXCLUSIVE OR (XC) Instruction There are two important applications of EXCLUSIVE OR. It shows that after a field is Exclusive ORed with itself. They are: • • To set a field to binary zeros To write code to sort data Op 1 Op 2 0 0 1 0 1 To Set A Field To Binary Zeros The first application is shown in the truth table for Exclusive OR.

2000. 1 RESULT1 FLD2 CONTENTS2 2 CONTENTS1 FLD1 3 CONTENTS CONTENTS2 FLD1 CONTENTS1 1 2 3 XC FLD1. FLD1 XC FLD1. FLD2 XC FLD2.. it is possible to exchange values with the same number of instructions. FLD2 FLD2 CONTENTS2 XC FLD1 RESULT1 XC TEMP CONTENTS1 FLD2 RESULT CONTENTS2 CONTENTS1 The contents are now switched Continued… Concepts © Copyright IBM Corp. 2004. but with no intermediate data area. thus saving storage. REPLACE REPLACE REPLACE XC FLD1 Page 295 of 58 .OS/390 Assembler Programming Introduction Unit: Logical and Shift Instructions Topic: Boolean Operations Machine Instructions with Boolean Exclusive OR (cont’d) Using the XC instruction. All rights reserved. The code is shown in the example.

Shifting instructions move the content of GPRs to the left or the right. The amount of data shifted can be 32 bits in a single GPR or 64 bits in an even-odd register pair. Topic: Shifting Instructions Logical Instructions: Arithmetic Shift: Shift Left Single (Algebraic) Shift Left Double (Algebraic) Shift Right Single (Algebraic) Shift Right Double (Algebraic) (SLA) (SLDA) (SRA) (SRDA) Logical Shaft: Shift Left Single Logical Shift Left Double Logical Shift Right Single Logical Shift Right Double Logical (SLL) (SLDL) (SRL) (SRDL) Concepts © Copyright IBM Corp. 2004. producing 2 x 2 x 2 or 8 shift instructions. The data can be interpreted as an unsigned logical quantity (logical shift) or as a signed arithmetic quantity (arithmetic shift). 2000.OS/390 Assembler Programming Introduction Unit: Logical and Shift Instructions Shifting Instructions Shifting instructions help in handling applications that require altering bits of data in registers and storage. All combinations of the 3 types of shifting are allowed. All rights reserved. Page 296 of 58 . by a specified number of bits..

Continued… Concepts © Copyright IBM Corp. 2000. All rights reserved. 2004. These instructions shift the contents of GPRs on a bit-wise basis. The eight instructions are shown here. Page 297 of 58 .OS/390 Assembler Programming Introduction Unit: Logical and Shift Instructions Types of Shifting Direction right right right right Left Left Left Left Size single single double double single single double double Type logical arithmetic logical arithmetic logical arithmetic logical arithmetic Instruction SRL SRA SRDL SRDA SLL SLA SLDL SLDA Topic: Shifting Instructions There are eight shifting instructions in total. Registers contents can be shifted left or right..

all of the bits participate. vacated bit positions are filled with zero bits. Page 298 of 58 . An overflow can occur in a left shift. bits equal to the sign bit replace vacated bit positions. Bits that are shifted out of the register at the right end for a right shift and at the left end for a left shift disappear. Concepts Arithmetic Shift: 0 s Lost Bits SRL s 0 1 Lost Bits 31 1 SLA 31 0’s Continued… © Copyright IBM Corp. The condition code is set in a similar way to arithmetic instructions. 2004. 0’s Logical Shift: 0 SLL 31 0’s Topic: Shifting Instructions Lost Bits 0 SRL 31 Vacated bit positions are filled with zero bits.OS/390 Assembler Programming Introduction Unit: Logical and Shift Instructions Types of Shifting (cont’d) What happens during a logical shift? In a logical shift. In a right arithmetic shift.. Bits shifted out of the register disappear. when a significant bit is shifted out of the register. The condition code is not changed in logical shifts. 2000. All rights reserved. only the 31 or 63 bits to the right of the sign bit participate. In a left arithmetic shift. Lost Bits What happens during an arithmetic shift? In an arithmetic shift.

The second operand does not specify a field in main storage. A double shift instruction must specify an even numbered register. and is ignored in the Machine Language format. Normally in Assembler language source statements. 2000. this field is specified as a displacement. 2004. A single shift instruction can specify any register as the first operand.. The address arithmetic is done.OS/390 Assembler Programming Introduction Unit: Logical and Shift Instructions Types of Shifting (cont’d) The shift instructions are all RS type. but it is used to represent the magnitude of the shift. Page 299 of 58 . Topic: Shifting Instructions Shift Instructions: RS Format – Register and Storage OP R1 R3 B2 D2 2nd Operand Unused Register to be shifted Concepts © Copyright IBM Corp. indicating the number of bit positions to move the register contents. All rights reserved. implying that particular register and the next higher register. and the rightmost 6 bits of that result specifies how many bit positions to shift the first operand. The R3 field is not used in shift instructions.

an RS format instruction. 2004. With the SLL. Zero bits replace the displaced bits on the right. All rights reserved. Page 300 of 58 . Example: Contents of R5 Is Changed Shift Left Single Logical (SLL): RS Format – Register and Storage SLL R5 7 Topic: Shifting Instructions 1st Operand R5 FULLWORD 2nd Operand Bit Shift Count SLL SLL R5.7 Shift Left – 7 BITS Low Order 7 bits of R5 are Filled with 0 bits CC Settings – Condition Code is Unchanged Continued… Concepts © Copyright IBM Corp.. the 32 bits in the first operand shift left by the amount specified by the rightmost 6 bits of the effective address of the second operand.OS/390 Assembler Programming Introduction Unit: Logical and Shift Instructions Logical Shifting Instructions Shift Left Single Logical Instruction The Shift Left Single Logical (SLL) instruction is shown in the example. 2000.

Zero bits replace the displaced bits on the left.. an RS format instruction. Page 301 of 58 .OS/390 Assembler Programming Introduction Unit: Logical and Shift Instructions Topic: Shifting Instructions Logical Shifting Instructions (cont’d) Shift Right Single Logical Instruction The Shift Right Single Logical (SRL) instruction is shown in the example. Example: Contents of R9 Is Changed Shift Right Single Logical (SRL): RS Format – Register Storage SRL R9 5 1st Operand R9 FULLWORD 2nd Operand Bit Shift Count SRL SRL R9. 2000. With the SRL. the 32 bits in the first operand shift right by the amount specified by the rightmost 6 bits of the effective address of the second operand.5 Shift Right – 5 BITS High Order 5 bits of R9 are Filled with 0 bits CC Settings – Condition Code is Unchanged Continued… Concepts © Copyright IBM Corp. All rights reserved. 2004.

The instruction shifts 64 bits in the first operand register. by the rightmost 6 bits of the effective address of the second operand. 2000. The SLDL. Zero bits replace the displaced bits on the right. 2004.11 Contents of R4 and R5 are Changed Shift Left Double Logical (SLDL): RS Format – Register and Storage SLDL R4 11 1st Operand R4 and R5 Even/Odd Doubleword 2nd Operand Bit Shift Count SLDL Shift Left – 11 BITS Low Order 11 bits of R5 are Filled with 0 bits CC Settings – Condition Code is Unchanged Continued… Concepts © Copyright IBM Corp.OS/390 Assembler Programming Introduction Unit: Logical and Shift Instructions Topic: Shifting Instructions Logical Shifting Instructions (cont’d) Shift Left Double Logical Instruction The Shift Left Double Logical (SLDL) instruction is shown in the example. Example: SLDL R4. All rights reserved.. The magnitude of the shift is specified. an RS format instruction. and the next higher register to the left. is similar to the SLL instruction. except that it uses paired registers. Page 302 of 58 .

The SRDL. 2000. This instruction. is similar to the SRL instruction. and to the next higher register to the right. Page 303 of 58 . All rights reserved.. however. shifts 64 bits in the first operand register.3 Contents of R6 and R7 are Changed Shift Right Double Logical (SRDL): RS Format – Register Storage SRDL R6 3 1st Operand R6 and R7 Even/Odd Pair Doubleword 2nd Operand Bit Shift Count SRDL Shift Right – 3 BITS High Order 3 bits of R6 are Filled with 0 bits CC Settings – Condition Code is Unchanged Continued… Concepts © Copyright IBM Corp.OS/390 Assembler Programming Introduction Unit: Logical and Shift Instructions Topic: Shifting Instructions Logical Shifting Instructions (cont’d) Shift Right Double Logical Instruction The Shift Right Double Logical (SRDL) instruction is shown in the example. Zero bits replace the displaced bits on the left. Example: SRDL R6. 2004. The rightmost 6 bits of the effective address of the second operand specify the magnitude of the shift. an RS format instruction.

2004. a doubleword boundary. that is. The example shows how it is done using SRL and SLL instructions. To find the boundary. Page 304 of 58 .3 Remove low order 3 bits Replace with zeros Concepts © Copyright IBM Corp. If R5 contains a storage address. 2000. to determine the first address at or below the address in R5..OS/390 Assembler Programming Introduction Unit: Logical and Shift Instructions Topic: Shifting Instructions Logical Shifting Instructions (cont’d) There are many applications of the logical shift instructions that involve bit manipulation and related application.3 SLL R5. All rights reserved. Doubleword Boundaries: SRL R5. the low order 3 bits of the address should be replaced by zeros.

The rightmost 6 bits of the effective address of the second operand. SLA.OS/390 Assembler Programming Introduction Unit: Logical and Shift Instructions Arithmetic Shifting Instructions Shift Left Single (Algebraic) Instruction The Shift Left Single (Algebraic) (SLA) instruction is shown in the example. All rights reserved. 2000. specify the magnitude of the shift. shifts numeric bits of the signed first operand to the left. Example: SLA R7.5 Contents of R7 Is Changed CC Settings – Arithmetic Continued… Concepts © Copyright IBM Corp. an RS format instruction. Zero bits replace the displaced bits on the right. 2004. Topic: Shifting Instructions Shift Left Single (SLA): RS Format – Register and Storage SLA R7 5 1st Operand R7 FULLWORD 2nd Operand Bit Shift SLA Shift Left all but Sign Bit Vacated 5 bits right of R7 are Filled with zeros Page 305 of 58 ..

Zero bits replace the displaced bits on the right.7 Contents of R8 and R9 are Changed CC Settings – Arithmetic Continued… Concepts © Copyright IBM Corp. 2004.7 BITS Vacated 7 bits right of R9 are Filled with zeros Page 306 of 58 . All rights reserved. is similar to SLA. Example: SLDA R8. The 63 bits are shifted left. by the second operand. The magnitude of the shift is specified. Shift Left Double Algebraic (SLDA): RS Format – Register and Storage SLDA R8 7 1st Operand R8 and R9 Doubleword 2nd Operand Bit Shift Count SLDA Shift Left all but Sign . The SLDA. 2000. an RS format instruction.OS/390 Assembler Programming Introduction Unit: Logical and Shift Instructions Topic: Shifting Instructions Arithmetic Shifting Instructions (cont’d) Shift Left Double (Algebraic) (SLDA) Instruction: The Shift Left Double Algebraic (SLDA) instruction is shown in the example. but operates on the data in an even-odd register pair..

Page 307 of 58 .5 Contents of R7 Is Changed Shift Right all but SIGN BITS Vacated 5 bits left of R7 are Filled with equal to the SIGN BIT Shift Right Single Algebraic (SRA): RS Format – Register and Storage SRA R7 5 1st Operand R7 FULLWORD 2nd Operand Bit Shift Count SRA CC Settings – 0 – Result is zero 1 – Result is less then zero 2 – Result is greater then zero Continued… Concepts © Copyright IBM Corp.. shifts 31 numeric bits of the signed operand to the right. All rights reserved. an RS format instruction.OS/390 Assembler Programming Introduction Unit: Logical and Shift Instructions Topic: Shifting Instructions Arithmetic Shifting Instructions (cont’d) Shift Right Single (Algebraic) Instruction The Shift Right Single (Algebraic) (SRA) instruction is shown in the example. 2004. The rightmost 6 bits of the effective address of the second operand. Bits equal to the sign bit replace the displaced bits on the left. Example: SRA R7. 2000. SRA. specify the magnitude of the shift.

2004.OS/390 Assembler Programming Introduction Unit: Logical and Shift Instructions Topic: Shifting Instructions Arithmetic Shifting Instructions (cont’d) Shift Right Double (Algebraic) Instruction The Shift Right Double (Algebraic) (SRDA) instruction is shown in the graphic. Bits equal to the sign bit replace the displaced bits on the left. SRDA. The magnitude of the shift is specified by the second operand. All rights reserved.23 BITS Vacated 23 bits left of R10 are Filled with bits equal to the SIGN BIT Shift Right Double Algebraic (SRDA): RS Format – Register and Storage SRDA R10 23 1st Operand R10 and R11 Even/Odd Pair Doubleword 2nd Operand Bit Shift SRDA CC Settings – 0 – Result is zero 1 – Result is less then zero 2 – Result is greater then zero Continued… Concepts © Copyright IBM Corp. Page 308 of 58 .. 2000. an RS format instruction. The 63 bits are shifted right. but operates on the data in an even-odd register pair. Example: SRDA R10.23 Contents of R10 and R11 are Changed Shift all Right but SIGN . is similar to SRA.

X’02’ 1st Operand TM SWITCH TEST BITS 2nd Operand (Immediate Data) X’02’ MASK Page 309 of 58 . which is the second operand. In the TM instruction. Topic: Testing Bit Values TEST UNDER MASK (TM): SI Format – Register and Immediate Data TM SWITCH. 2000. All rights reserved.X’02’ SETS CONDITION CODE CC Settings – 0 – Mask is zero or all selected bits are zero 1 – Some selected bits are zeros and some are ones 2 – All selected bits are ones Continued… Concepts © Copyright IBM Corp. is an 8-bit mask. Bits to be tested in the first operand are specified by placing a 1 in the corresponding mask position. Example: TM SWITCH. the immediate operand. but the condition code is set... 2004. Neither operand is changed.OS/390 Assembler Programming Introduction Unit: Logical and Shift Instructions Test Under Mask The Test under Mask instruction has been summarized as shown.

2000. Page 310 of 58 . The reason for these settings is to enable the extended branch mnemonics Branch if Zeros (BZ). Branch if Mixed (BM) and Branch if Ones (BO) to be used.. or multiple bits. A condition code of 1 is only possible if multiple bits are being tested.OS/390 Assembler Programming Introduction Unit: Logical and Shift Instructions Test Under Mask (cont’d) The TM instruction can test a single bit. All rights reserved. Topic: Testing Bit Values MASK Specifies Bits to Test Concepts © Copyright IBM Corp. 2004. The condition code values assigned to the various conditions may seem arbitrary.

2000.. the operating system defines certain conventions for passing and returning control and data between modules. 2004.OS/390 Assembler Programming Introduction Unit: Modular Programming Topic: Using General Purpose Registers Conventional Use of Registers General Purpose Register (GPR): R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 16 GPRs Control Passes and Returns Control Between Modules MODULE 1 MODULE 1 MODULE 1 MODULE 1 In order to provide consistency and ease of linkage between programs written in different languages. Continued… Concepts © Copyright IBM Corp. as control passes from module to module. These conventions concern the standard use of the General Purpose Registers (GPRs) and the procedure for saving and restoring them. All rights reserved. Page 311 of 58 .

2000. R13. Continued… Concepts © Copyright IBM Corp. Page 312 of 58 . five of the GPRs (R0. R1.. 2004. These five registers are also used by many of the system macro instructions. All rights reserved. R14 and R15) are used in conventional ways.OS/390 Assembler Programming Introduction Unit: Modular Programming Topic: Using General Purpose Registers Conventional Use of Registers (cont’d) R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 When passing and returning control and data between modules.

Used to pass the address of a parameter list from a calling program to its called program. it contains a return code. R13. R14. This value normally indicates the success of the called program. The area used to save registers is called a saved area.OS/390 Assembler Programming Introduction Unit: Modular Programming Topic: Using General Purpose Registers Conventional Use of Registers (cont’d) Here is a list of the five GPRs with their description: R0 . 2000. it contains the address of the instructions in the called module where execution is to begin. 2004.Used for two purposes: • When control is passed. ..Used to hold the save area address.Used to hold the return address in the caller when control is passed. When the called module completes processing. R15. Page 313 of 58 Concepts © Copyright IBM Corp.Returns a single fullword value from a called program to its caller. with 0 representing success. it returns control to this address. and the address of the save area is held in R13. • When control is returned. All rights reserved. R1. then R0 is used to return the function result. If the called program is a function. The address of the parameter list is passed in R1. and the type of the function is a fullword or smaller type.

SUB Topic: Using General Purpose Registers Return Control Control MODULE B CSECT Save Registers in SA . 2004. All rights reserved. Restore Registers from SA RETURN SUB Continued… Concepts © Copyright IBM Corp. Page 314 of 58 . Each module is responsible for defining a save area for its called programs.OS/390 Assembler Programming Introduction Unit: Modular Programming Save Areas and Linkage Save areas (SA) are 18 fullword areas that are used to hold register contents when control is passed from module to module. Save Areas: MODULE A MAIN CALL CSECT .. 2000. in order to save the caller’s registers.

All rights reserved. which is the return address in the caller. R14 holds the contents of R14. 2000. PSA is the address of the previous SA. which is the entry point in the called program. Page 315 of 58 . Continued… Concepts © Copyright IBM Corp.OS/390 Assembler Programming Introduction Unit: Modular Programming Topic: Using General Purpose Registers Save Areas and Linkage (cont’d) 18 FULLWORD SAVE AREA (SA) WD1 PSA NSA FULLWORD (4 bytes) R14 R15 R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 The format of the SA is shown in the here. 2004.. NSA is the address of the next SA. R0 – R12 contain the contents of registers R0 through R12. R15 holds the contents of R15.

OS/390 Assembler Programming Introduction Unit: Modular Programming Topic: Using General Purpose Registers Save Areas and Linkage (cont’d) What is a Store Multiple? The Store Multiple (STM) instruction stores the contents of registers in their correct positions. All rights reserved. 2000. Example: Store Multiple (STM) RS Format – Register and Storage STM R14. 2004.R12. This is why it is the first instruction one encounters in almost every program. Page 316 of 58 . 12(R13) 2nd Operand 1st Operand Registers 3nd Operand STM R14.R12.12(R13) R14 R15 R0 STM to R12 Main Storage ADDRESS STARTS 12 Bytes FROM SAVE AREA (SA) R13 15 CONSECUTIVE FULLWORDS Continued… Concepts © Copyright IBM Corp..

2000.. Linkage: For this reason. for active programs. All rights reserved.OS/390 Assembler Programming Introduction Unit: Modular Programming Topic: Using General Purpose Registers Save Areas and Linkage (cont’d) Each SA points to the Previous Save Area (PSA) and the Next Save Area (NSA). SA1 WD1 PSA NSA R14 R12 SA2 WD1 PSA NSA R14 R12 SA3 WD1 PSA NSA R14 R12 Concepts © Copyright IBM Corp. If a program fails. when control passed from module to module. all of the SAs. 2004. Page 317 of 58 . are linked together in a doubly linked list. it is possible to determine the register contents at each point.

2000. All rights reserved. The address specified as the second operand is placed in the next instruction address field of the PSW.OS/390 Assembler Programming Introduction Unit: Modular Programming Branch and Link The Assembler Language instructions that implement subroutine linkage are called Branch and Link (BAL).SUBRTN Next Instruction Address PSW Next Instruction Address Field Replace Contents of R11 CC Settings – Condition Code is Unchanged Continued… Concepts © Copyright IBM Corp. 2004. Page 318 of 58 ..SUBRTN Topic: Using General Purpose Registers 1st Operand 2st Operand CONTROL SUBRTN ADDRESS BAL BAL R11. The next instruction address from the Program Status Word (PSW) is loaded into the GPR specified as the first operand. Example: R11 Branch and Link (BAL): RX Format – Register and Indexed Storage BAL R11.

All rights reserved.OS/390 Assembler Programming Introduction Unit: Modular Programming Branch and Link (cont’d) The code at SUBRTN performs its function. SAVER11 R11. SAVER11 R11 F Continued… Concepts © Copyright IBM Corp. 2004. . and then control can be returned to the caller (the instruction after the BAL). This can be coded as: SUBRTN Topic: Using General Purpose Registers BR R11 SAVER11 EQU ST . 2000. Page 319 of 58 . by branching to the address saved in R11.. . L BR DS * R11.

but no branch takes place. IF R2 = R0 ? NO YES NEXT INSTRUCTION AFTER BALR PASS CONTROL TO SUBROUTINE PASSES CONTROL Store Linkage Information in R1 CC Settings – Condition Code is Unchanged Concepts Page 320 of 58 © Copyright IBM Corp. Store Linkage Information in R.R15 2st Operand Topic: Using General Purpose Registers LOAD SUBROUTINE ADDRESS INTO R. If R₂ specifies R0. 2004. the subroutine address must be loaded into the second operand register before the BALR instruction is executed. Branch and Link (BALR): RR Format – Register to Register BALR 1st Operand R14. 2000. then the linkage information is stored in the first operand. .OS/390 Assembler Programming Introduction Unit: Modular Programming Branch and Link (cont’d) RR Form of BAL instruction In the RR form of Branch and Link (BALR) instruction. All rights reserved..

to which the control is being passed.OS/390 Assembler Programming Introduction Unit: Modular Programming Passing Control Passing module control involves the use of two GPRs. Page 321 of 58 . V – Type External Address Constant (VCON) Topic: Passing and Receiving Control In cases where the entry point.. The Linkage Editor adjusts the value of the VCON. Object Module Source Module DC V(ENTPT) 00000000 Load Module 00005000 Location X’5000’ In Load Module ENTPT Continued… Concepts © Copyright IBM Corp. or in a separately assembled module. a special way is required to reference it. is in a separate control section. Assembler Language provides a V-Type external address constant (VCON) to define entry points. 2000. All rights reserved. 2004.

The example shows how the control passed to the module CALLED. and then BALR should be used to pass control. All rights reserved. This places the address of the next instruction (the return point) into R14..=V(CALLED) R15 Contents =V(CALLED) Entry Point Address Topic: Passing and Receiving Control Replace Contents with Address BALR R14. 2004. 2000.OS/390 Assembler Programming Introduction Unit: Modular Programming Passing Control (cont’d) To pass control from one module to another. L R15.R15 R14 Return Address L R15 Address of ‘CALLED’ Save Return Address in R14 BALR Pass Control to Module ‘CALLED Page 322 of 58 Concepts © Copyright IBM Corp. . the address constant should be loaded into R15.

First.R13) ST R13.4(.12(R13) BALR R12. The program must then set up its own SA and chain the two SAs. All rights reserved.R0 USING *. R13 LA R13. Next.R12 LR R11. Page 323 of 58 .8(. addressability is established by designing a base register and loading it with an initial value 3.OS/390 Assembler Programming Introduction Unit: Modular Programming Receiving Control CALLED CSECT STM R14. 2000. 2004.R11) Save caller’s registers Establish addressability Save previous save area address Put our SA address into R13 Chain save areas together Topic: Passing and Receiving Control The code to receive control in Assembler Language has the following responsibilities: 1.R12.. the program must save the callers registers 2.SAVEAREA ST R11. the PSA slot and the NSA slot together (so that its SA points to the PSA which then points to the NSA) Addressability is established as shown. Continued… Concepts © Copyright IBM Corp.

Instead of BALR and USING.R12 Addressability USING CALLED. . passed in R15. this variant uses the following: Addressability: Topic: Passing and Receiving Control LR R12. . All rights reserved.R12 MAIN . 2004. Page 324 of 58 .R15 Establish USING CALLED. 2000.OS/390 Assembler Programming Introduction Unit: Modular Programming Receiving Control (cont’d) Another way to establish addressability uses the entry point address.. CSECT Establishes Addressability Concepts © Copyright IBM Corp.

12(13) Restores callers registers BR R14 Return to caller Concepts © Copyright IBM Corp.4(. 2004.R13) Restores previous SA address LM R14. In this example.R15 Set return code to zero Topic: Passing and Receiving Control L R13.R12. the return code is set to zero. Page 325 of 58 . SR R15.OS/390 Assembler Programming Introduction Unit: Modular Programming Returning Control The code to return control back to the caller. Set the return code 3.. must do the following three things: 1. Return control through the address that was passed in R14 The code to return control is shown in the graphic. 2000. Restore the caller’s registers 2. All rights reserved.

Continued… Page 326 of 58 . 2004. the code will be a little more complex. Suppose a return code set to 4 is required. this instruction has restored the caller’s registers..4 LA R15. the base register needs to be properly set. wiping out the proper contents of the base register.OS/390 Assembler Programming Introduction Unit: Modular Programming Returning Control (cont’d) For Return Code Other Than Zero If a return code is specified to be other than zero. Concepts © Copyright IBM Corp.=H’4’ In order to access the literal. However.Displacement Effective Address = Displacement 4 R15 CONTENTS ‘4’ LA Loads Address 4 into R15 This code does not require a base register. 2000.4 Topic: Passing and Receiving Control D2 . To get around this problem of setting the return code to 4 the following code should be used: LA R15. All rights reserved. the following code is used: LH R15.

All rights reserved. return code can be placed in a variable in storage. without overwriting the value in R15. 2004. so that there is a separate copy for each possible return code. say a halfword called RC. 2000. Without Overwriting Contents of R15 Continued… Concepts © Copyright IBM Corp. Since you cannot address RC after restoring the caller’s registers. this can cause addressability problems. Addressability Problems: Topic: Passing and Receiving Control Instead. the code to return control should not be duplicated. • RC Cannot Be Restored After Restore Caller’s Registers • R15 Cannot Be Set Prior To Restoring Registers. Page 327 of 58 . set R15 and then restore registers.OS/390 Assembler Programming Introduction Unit: Modular Programming Returning Control (cont’d) For Multiple Possible Return Code In this case. However. A single return sequence places this value into R15..

the value can be set into R15.R12. © Copyright IBM Corp.R13) Restores the old SA pointer L R14.OS/390 Assembler Programming Introduction Unit: Modular Programming Topic: Passing and Receiving Control Returning Control: Solution to Addressability Problem First Method: LH R15.20(R13) Restores R0 to R12 BR R14 Returns to the caller Second Method: LH R3.RC Gets the return code L R4.RC Sets return code L R13. except for R15 The other method is to put the desired return code value not into R15. It will then be restored when the Load Multiple is completed prior to returning.R4) Stores RC in R15 slot in old SA (There may be other instruction here) L R13. 2004.16(.4(.12(. All rights reserved. Page 328 of 58 Concepts . The methods are explained here: • • In the first method.12(R13) Restores the caller’s regs BR R14 Returns to the caller There are two possible methods to solve addressability problem. but into R15 slot in the caller’s save area.R13) Restores R14 LM R0.4(.R13) Gets the old SA address ST R3. 2000.R13) Restores the old SA address LM R14.4(.R12. and then the registers can be restored..

2004. Page 329 of 58 .OS/390 Assembler Programming Introduction Unit: Modular Programming Topic: Passing and Receiving Control Single and Multiple Assemblies While creating a multi-modular Assembler Language program. modules can be assembled in a single assembly or assembled separately. The main disadvantage is that names must be unique within an assembly. FILE 1 FILE 1 A A CSECT FILE 2 B Single Assembly CSECT Multiple Assembly CSECT B CSECT Continued… Concepts © Copyright IBM Corp. All rights reserved. 2000. Assembling the modules together provides the advantage of only having a single source file to manage..

it is better to use separate source files. It does this by matching external references (Vtype adcons in your program). All rights reserved. L R15. 2004. Main CSECT . . with external CSECT names in your program. executable module. .=V(SUB) BALR R14. Page 330 of 58 ..OS/390 Assembler Programming Introduction Unit: Modular Programming Topic: Passing and Receiving Control Single and Multiple Assemblies (cont’d) When the number of modules exceeds 3 or 4. FILE 1 The linkage editor combines individual object modules into a single. 2000.R15 FILE 2 SUB CSECT Identical Names Concepts © Copyright IBM Corp.

or many thousands of bytes. A parameter can be defined as a list of the addresses of the data being passed from caller to called module. Regardless of whether the actual data is a single byte in length. containing the address of the corresponding data. 2004. All rights reserved. and this fits in a fullword. 2 Entry Parameter List: PLIST Address of DATA 1 Address of DATA 2 DATA1 DATA2 Continued… Concepts © Copyright IBM Corp.OS/390 Assembler Programming Introduction Unit: Modular Programming Topic: Passing and Receiving Data Parameter Lists The mechanism used for passing data between modules is the parameter list. it is the address of the data that is passed. Each entry in the parameter list is a fullword. 2000. Page 331 of 58 ..

All rights reserved. a module is designed to accept a fixed number of parameters. Consider a module to determine the length of a string. Consider a module to calculate the maximum value of a group of fullwords. It might be designed to use two parameters: one to contain the string. Page 332 of 58 . It might receive 2. Variable Length Parameter List In other cases modules are designed to accept any number of parameters.. or 100 fullwords as parameters. Fixed Parameter List: Parameter List = Address of STRING Address of LENGTH Parameter 1 Parameter 2 Variable Length Parameter List: Parameter List = Address of FW 1 Parameter 1 1 Address of FW n Parameter n High Order Bit Continued… Concepts © Copyright IBM Corp.OS/390 Assembler Programming Introduction Unit: Modular Programming Topic: Passing and Receiving Data Parameter Lists (cont’d) Fixed-Length Parameter List In some cases. the other to hold the length. 2004. or 10. The parameter list to this module is fixed in length with two entries. 2000. The parameter list for this module is variable in length.

All rights reserved. 2000. Passing Control: R1 @ of PL PL @ of STRING @ of LENGTH STRING LENGTH Concepts © Copyright IBM Corp. 2004. the address of the parameter list is placed in R1. So. which itself is a list of addresses. R1 contains the address of the parameter list.. Page 333 of 58 .OS/390 Assembler Programming Introduction Unit: Modular Programming Topic: Passing and Receiving Data Parameter Lists (cont’d) When control is passed from one module to another.

This module receives three parameters. A separate module. 2000.. All rights reserved. 2004. Module: ADDPD INPUT – 2 6-byte PACKED NUMBERS (Parameters 1 and 2) RESULT – 8-byte SUM OF NUMBERS (Parameters 3) Continued… Concepts © Copyright IBM Corp.OS/390 Assembler Programming Introduction Unit: Modular Programming Topic: Passing and Receiving Data Fixed Length Parameter Lists Consider a case of adding two packed decimal numbers. Page 334 of 58 . and returning the sum. is used here to perform this simple operation. called ADDPD. The first two parameters are the two 6-byte packed decimal numbers to be added together. and the third parameter is an eight byte result field.

PARMLST L R15. the parameter list has been set up and its address has been placed in R1. DC A(NUM1. All rights reserved. 2000.SUM) DS PL8 DS PL6 DS PL6 Parameter list address in R1 Call ADDPD PARMLST SUM NUM1 NUM2 This example shows the code necessary to call ADDPD module..NUM2. Page 335 of 58 .OS/390 Assembler Programming Introduction Unit: Modular Programming Topic: Passing and Receiving Data Fixed Length Parameter Lists (cont’d) LA R1. In addition to the code for passing control. . Continued… Concepts © Copyright IBM Corp. .R15 .=V(ADDPD) BALR R15. here. 2004.

R5).R5.R12.R4) R13.R13) R14.0(R1) 0(8. 2004.12(R13) R12.0(6..R15 R14 Saves callers regs Establishes addressability Saves PSA address Put the SA address into R13 Chain save areas together Loads addresses of 3 parameters Moves first number to sum Adds second number to sum Restores PSA address Restores registers Sets return code to zero Return to the caller This example shows how to code ADDPD. it must load them into registers.OS/390 Assembler Programming Introduction Unit: Modular Programming Topic: Passing and Receiving Data Fixed Length Parameter Lists (cont’d) ADDPD CSECT STM BALR USING LR LA ST ST LM ZAP AP L LM SR BR R14.R11) R3.R12 R11.4(.R0 *. Since ADDPD is receiving the addresses of the parameters.12(R13) R15.R13) R13.0(6.8(.R12.R13 R13. Concepts © Copyright IBM Corp. and then use explicit base displacement addresses. All rights reserved. with length.R3) 0(8. 2000.4(.SAVEAREA R11. Page 336 of 58 . to access them.R5).

The code to call ADDPD1 passes it 4 numbers to add.NUM3..OS/390 Assembler Programming Introduction Unit: Modular Programming Topic: Passing and Receiving Data Variable Length Parameter Lists LA L BALR R1. . plus the result field.=V(ADDPD) R15. All rights reserved. A(NUM1. .NUM2. ADDPD1 sums a set of 6-byte packed fields into an 8-sum field.NUM4) A(SUM+X’80000000’) PL8 PL6 PL6 PL6 PL6 Parameter list address in R1 Calls ADDPD1 PARMLST SUM NUM1 NUM2 NUM3 NUM4 DC DC DS DS DS DS DS Turns the High Order Bit On A module called ADDPD1 has been shown in the example.R15 . This illustrates the variable-length parameter list. provided as the last parameter. Page 337 of 58 . 2000. but the code of ADDPD1 will work with any number of parameters from 1 up. Continued… Concepts © Copyright IBM Corp.PARMLST R15. 2004.

2004.. for accessing parameter list Saves caller’s regs Establishes Addressability This example shows the code for ADDPD1.12(R13) R12.R4 Saves PSA address Puts SA address into R13 Chain saves areas together Zeros index reg.8(.R13 R13.R12 R11.4(.R0 *.R13) R13. All rights reserved.R11) R4. Continued… Concepts © Copyright IBM Corp.R12. Page 338 of 58 . 2000.SAVEAREA R11.OS/390 Assembler Programming Introduction Unit: Modular Programming Topic: Passing and Receiving Data Variable Length Parameter Lists (cont’d) ADDPD1 CSECT STM BALR USING LR LA ST ST SR R14.

R4) B PARMLOOP Next..0(R4.R1) Loads next parameter address in R3 Is it the last parameter? Yes No-add number to sum Increments index for next parm list entry LTR R3.OS/390 Assembler Programming Introduction Unit: Modular Programming Topic: Passing and Receiving Data Variable Length Parameter Lists (cont’d) PARMLOOP EQU * L R3.4(. the high order bit is one. All rights reserved. This example shows the code information. If a fullword is negative. the last parameter needs to be detected by testing each address to see if it is negative. 2004.0(6. Page 339 of 58 Concepts .R3) LA R4. 2000.R3 BM LAST AP TEMPSUM. Continued… © Copyright IBM Corp.

4(. In this case. the programmer must sum the numbers into a temporary sum field.R3).12(R13) R15.R12.R13) R14. and then move that field to the result field.OS/390 Assembler Programming Introduction Unit: Modular Programming Topic: Passing and Receiving Data Variable Length Parameter Lists (cont’d) LAST EQU ZAP L LM SR BR * 0(8. 2004.. Concepts © Copyright IBM Corp. All rights reserved. Page 340 of 58 .TEMPSUM R13.R15 R14 PL8’0’ Moves the sum to the result field Restores the PSA address Restores the callers registers Sets the return code to zero Returns to the caller TEMPSUM DC The address of the result field remains unknown till the end of the parameter list. 2000. after it is found.

It is because.. the technique of defining the whole record with a zero duplication factor has been used. consisting of name. city. two lines of address. rather than simple variables. The example. 2004. All rights reserved. In the module where this record was defined. and zip code as a parameter.OS/390 Assembler Programming Introduction Unit: Modular Programming Topic: Passing and Receiving Data Dummy Sections Sometimes processed parameters are complex data structures. Consider the case of a customer record. state. or any of its fields. shows one such record. the whole record can be referred to. 2000. Record: CREC CNAME CADDR1 CADDR2 CCITY CSTATE CZIP DS DS DS DS DS DS DS OCL96 CL30 CL20 CL20 CL15 CL2 CL9 Continued… Concepts © Copyright IBM Corp. Page 341 of 58 . here.

though there is a need to access the data.. This is because the storage already exists in another module.R3) Base Called Module: CREC CNAME CADDR1 CADDR2 CCITY CSTATE CZIP DS DS DS DS DS DS DS OCL96 CL30 CL20 CL20 CL15 CL2 CL2 Address of CREC in R3 70-bytes of Combined Address Lengths from CREC Address Length of CCITY Continued… Concepts © Copyright IBM Corp. the need is to specify the structure of data. 2004. All rights reserved. It is done with dummy section (DSECT). it is not defined here. in the called module. CCITY Displacement Address Length 70(15. 2000. The definitions is in the calling module. The problem that occurs here is that. without actually setting up any storage for it.OS/390 Assembler Programming Introduction Unit: Modular Programming Topic: Passing and Receiving Data Dummy Sections (cont’d) Consider a case where this customer record is passed to another module. In this case. Page 342 of 58 .

Page 343 of 58 .. 2000. CREC CNAME CADDR1 CADDR2 CCITY CSTATE CZIP DSECT DS DS DS DS DS DS CL30 CL20 CL20 CL15 CL2 CL9 Storage Template Continued… Concepts © Copyright IBM Corp. a structure that defines names and relationships. All rights reserved. as shown in the example.OS/390 Assembler Programming Introduction Unit: Modular Programming Topic: Passing and Receiving Data Dummy Sections (cont’d) A DSECT allows the Assembler Language programmer to define a storage template. without allocating any storage. Called Module: A DSECT to represent the fields in the customer record can be defined in the separately assembled called module. 2004.

.0(.OS/390 Assembler Programming Introduction Unit: Modular Programming Topic: Passing and Receiving Data Dummy Sections (cont’d) How to use DSECT Given the example of customer record. If the address of the actual storage of CREC is passed in a parameter list. before referring to CREC or any of its fields.R1) CREC USING CREC. it needs to be made addressable. Page 344 of 58 .0(. R3 points to CREC R3 makes the CREC addressable DSECT (Dummy Section): L R3. the following code can be used to make it addressable: L R3. This is done with a USING instruction. All rights reserved.R3 R3 Addresses Parameter list CREC and USING makes DSECT Addressable Continued… Concepts © Copyright IBM Corp. 2004.R1) R3 USING CREC. 2000.

2004. since it uses a symbol. The Assembler translates a reference to CCITY as 70(15.OS/390 Assembler Programming Introduction Unit: Modular Programming Topic: Passing and Receiving Data Dummy Sections (cont’d) At this point. and Assembler has been told that R3 contains the base address of CREC. and passed as a parameter.R3) Displacement Address Length Symbols: Base Symbols CREC CNAME CADDR1 CADDR2 CCITY DSECT DS DS DS DS CL30 CL20 CL20 CL15 Concepts © Copyright IBM Corp. Page 345 of 58 .R3). All rights reserved. Fields: 70(15.. fields of CREC can be referred to by name. The use of DSECTs should always be considered while dealing with structured data defined in another module. 2000. The same Machine Language code can be generated without the DSECT. The use of DSECT makes the code clearer. rather than a base displacement address. This is because CCITY is 70 bytes beyond CREC.

. THE TEMPERATURE FORMAT IS SDDDD IN THE * FIRST 5 POSITIONS OF EACH RECORD. 2000.OS/390 Assembler Programming Introduction Unit: Creating a Complete Program Topic: Coding the Program The Main Module ********************************************************************** * THIS PROGRAM READS A SET OF 24 HOURLY TEMPERATURE READING AND THEN * * DETERMINES AND PRINTS THE HIGH AND LOW TEMPERATURES (WITH THEIR * TIMES OF OCCURENCE). WITH ONE IMPLIED DECIMAL PLACE. THE ARRAY IS SORTED ON ASCENDING TEMPERATURES TO * AID IN THE CALCULATIONS OF LOW. * * * * * * * * * * * *********************************************************************** Each module should start with a block of comments explaining its purpose. All rights reserved. ALONG WITH CORRESPONDING * ENTRY NUMBER. 2004. WITH * ONE READING PER RECORD. * THE 24 READINGS START AT 1:00 AM AND GO THROUGH. RIGHT JUSTIFIED. HIGH AND MEDIAN TEMPERATURES. The header comments for the main module are shown in the example. AT HOURLY * INTERVALS. Page 346 of 58 . THE MEAN AND THE MEDIAN TEMPERATURE FOR THE * DAY. WHERE S IS THE SIGN AND DDDD IS * THE TEMPERATURE. Continued… Concepts © Copyright IBM Corp. UNTIL MIDNIGHT. THE TEMPERATURES ARE READ FROM 80 BYTE INPUT RECORDS. * THE 24 READINGS ARE PLACED IN AN ARRAY.

R12 LR R11.SAVE1 ST R11.8(.=V(GETINPUT) BALR R14.R12.R0 USING * .R11) SUPPRESSES MACRO EXPANSION PRINTING GENERATES REGSITER EQUATES SAVES REGSITERS ESTABLISHES ADDRESSABILITY SAVES THE OLD AREA ADDRESS POINTS TO THE NEW SAVE AREA CHAIN SAVES AREAS SETS UP THE RETURN CODE OF ZERO IN THE OLD SAVE AREA POINTS TO THE PARAMETER LIST LINKS TO THE INPUT MODULE WAS THE INPUT MODULE SUCCESSFUL? YES NO.R11) B RTRN This example shows a part of the coding for main module.R13) ST R13.4(.R15 ST R15.R13 LA R13. All rights reserved.R11) SR R15.PARMLST L R15.SAVES THE RETURN CODE OF INPUT AND RETURNS MAIN LA R1.R15 BZ OK L R11.12(R13) BALR R12.4(R13) ST R15. Page 347 of 58 . CSECT STM R14.16(.OS/390 Assembler Programming Introduction Unit: Creating a Complete Program Topic: Coding the Program The Main Module (cont’d) PRINT NOGEN YREGS . Continued… Concepts © Copyright IBM Corp.16(.. 2000. 2004.R15 LTR R15.

2004. 2000.OS/390 Assembler Programming Introduction Unit: Creating a Complete Program Topic: Coding the Program The Main Module (cont’d) OK EQU * LA R1.R15 EQU * L R13.R15 LA R1..TEMP) SAVE1 TEMPARR PARMLST This example shows the remaining half of the coding for main module.12(R13) BR R14 DS 18F DC 24H ‘0.4(.PARMLST L R15.0’ DC A (TEMPARR) LTORG END RTRN POINTS TO THE PARAMETER LIST LINKS TO THE SORT ROUTINE POINTS TO THE PARAMETER LIST LINKS TO THE PRINTS TO THE ROUTINE RESTORES REGISTERS AND RETURNS ARRAY OF 24 ENTRIES (TIME. Continued… Concepts © Copyright IBM Corp.R13) LM R14. Page 348 of 58 .R12. All rights reserved.=V(SORTARR) BALSR R14.PARMLST L R15.=V(PRINT) BALR R14.

Otherwise. 2004. If it is nonzero. and on return..OS/390 Assembler Programming Introduction Unit: Creating a Complete Program Topic: Coding the Program The Main Module (cont’d) Control is then passed to the GETINPUT module. control is successively passed on to the SORTARR and PRINT modules. NO RC>0 ? YES CALL SORTARR SAVE RC IN CALLERS SAVE ADDRESS CALL PRINT RETURN TO CALLER Concepts © Copyright IBM Corp. All rights reserved. and return control to the caller. it is placed into the caller’s save area. and then return control to the caller. 2000. the return code is tested. Page 349 of 58 .

SAVE1 ST R11.8(.12(R13) BALR R12. AND A TEMPERATURE.R13) ST R13.R0 USING *. Continued… Concepts © Copyright IBM Corp. 2000.R4 Suppresses Macro Expansions Printing Generates Register Equates Saves Registers Establishes Addressability Saves the Old Save Area Points to the New Save Area Chain Saves Areas Sets the Return Code Of Zero in the Old Save Area Gets the First Parameter Address Opens the Input Dcb Sets the Loop Counter to 24 Calculates the Entry Number A part of the code of GETINPUT module is shown in the example.R1) OPEN (IN. GETINPUT CSECT STM R14.R15 ST R15.* * STARTING AT A 0 AND UP TO 23.R12 LR R11..0(.(INPUT)) LA R4.24 SR R5.16(. 2004.R11) L R3.R12. * ********************************************************************** PRINT NOGEN YREGS . EACH ARRAY ENTRY IS AN ENTRY NUMBER.OS/390 Assembler Programming Introduction Unit: Creating a Complete Program Topic: Coding the Program The GETINPUT Module *********************************************************************** * THIS MODULE READS 24 TEMPEARTURES INTO AN ARRAY.4(.R11) SR R15.R13 LA R13. Page 350 of 58 .24 LOOP EQU * LA R5. All rights reserved.

Page 351 of 58 .R13) LM R14.R3) EQU * (IN) L R13.0(.OS/390 Assembler Programming Introduction Unit: Creating a Complete Program Topic: Coding the Program The GETINPUT Module (cont’d) STH R5. Continued… Concepts © Copyright IBM Corp. 2000.C’-’ BNE LOOPING MH R6..DWD CLI RECSIGN. 2004.R12.R3) LA R3.12(R13) BR R14 Places in First Half of Array Entry Gets the next Temperature Converts the Absolute Value to Fixed Point Is it Negative? No Yes – Change the Sign Stores in Second Half of Array Entry Points to the Next Array Entry LOOPING RTRN CLOSE Restores Registers And Returns * * THIS END OF DATA ROUTINE IS ONLY EXECUTED IF THERE ARE LESS THAN * 24 INPUT RECORDS – AN ERROR CONDITION * Another part of the code of GETINPUT module is shown in the example.RECTEMP CVB R6. All rights reserved.4(.R3) GET IN.REC PACK DWD.2(.4(.=H’-1’ EQU * STH R6.

R11) B RTRN DS 18F DCB Sets the Error Return Code Stores it in the Old Save Area Branches to Return SAVE1 IN DDNAME=IN.16(. All rights reserved.12 L R11.EODAD=ERR REC DS RECSIGN DS RECTEMP DS DS DWD DS LTORG END 0CL80 C ZL4 CL75 D Inputs Work Area Sign Temperature Unused The remaining part of the code of GETINPUT module is shown in the example.R13) ST R15.DSORG=PS.RECF=FB.4(. Page 352 of 58 .LRECL=80. 2000. Continued… Concepts © Copyright IBM Corp.MACRF=GM.OS/390 Assembler Programming Introduction Unit: Creating a Complete Program Topic: Coding the Program The GETINPUT Module (cont’d) ERR EQU * LA R15.. 2004.

The value in R4 decreases from 24 to 1. If the sign is negative. each time through the loop. 2000. the absolute value of the temperature is converted to a fixed point.OS/390 Assembler Programming Introduction Unit: Creating a Complete Program Topic: Coding the Program The GETINPUT Module (cont’d) To generate the entry number for each array entry. To handle negative numbers on input. the fixed-point value is multiplied by -1.. the value of the loop counter in R4 is subtracted from 24. Therefore. so the entry number will range from 0 to 23. -0013 CONVERT TO BINARY MULTIPLY BY -1 0000000D FFFFFFF3 Concepts © Copyright IBM Corp. All rights reserved. 2004. the array can be processed by incrementing R3 by 4. Page 353 of 58 . and each array is 4 bytes in length. The parameter passed to this routine is the address of the array.

with the value in the first position. INNER LOOP: Finds smallest Value being sorted ELEMENT 1 ELEMENT 2 ELEMENT 3 SMALLEST ELEMENT 24 Find Smallest SMALLEST ELEMENT 1 ELEMENT 23 SORTARR module sorts the array by using a selection sort algorithm. which starts at the next element. the procedure is repeated for the array.. it is assumed that the first item is the smallest. All rights reserved. and selects the smallest. This inner loop is controlled by R6. 2004. controlled by R4. This algorithm looks at all the elements of the array.OS/390 Assembler Programming Introduction Unit: Creating a Complete Program Topic: Coding the Program The SORTARR Module OUTER LOOP: Sorts 23 items Continue sort on Array of 23 items and So on. This is the outer loop of the code. After all items have been compared and the smallest item is found. 2000. Each of the other items are then compared and if one smaller than the current smallest one is found. its value and location is saved. Within the outer loop. It then swaps the smallest value. When the first element of the sorted array is in place. it should be swapped with the first. Page 354 of 58 . one position smaller. Continued… Concepts © Copyright IBM Corp.

and R8 holds the address of that entry. All rights reserved. 2004. using EXCLUSIVE OR. Page 355 of 58 .. As for the other registers. 2000. R9 is used to hold the value of the currently lowest entry. they perform the following functions: R3: It holds the address of First Unsorted Array Element R4: It holds the Counter for Outer Loop (starts at 23) R5: It holds the address of Current Array Entry being Checked R6: It holds the Counter for Inner Loop (start = Outer Loop Counter) Continued… Concepts © Copyright IBM Corp.OS/390 Assembler Programming Introduction Unit: Creating a Complete Program Topic: Coding the Program The SORTARR Module (cont’d) Swapping is done without an intermediate work area.

2004. All rights reserved.R3) LR R6.R4 Get the Address of the Array Set Outer Loop Counter First Value is Initially the Lowest Save Address of the First Entry Point to Next Entry Set Inner Loop Counter = Outer A part of the code of the SORTARR module is shown in the example.8(.0(.R1) LA R4.R13) ST R13.R12 LR R11.4(. Continued… Concepts © Copyright IBM Corp. 2000.OS/390 Assembler Programming Introduction Unit: Creating a Complete Program Topic: Coding the Program The SORTARR Module (cont’d) ********************************************************************* * THIS MODULE SORTS AN ARRAY OF 24 PAIRS OF HALFWORDS. Page 356 of 58 ..R11) Suppresses Macro Expansions Printing Generate Register Equates Saves Registers Establish Addressability Save Old Save Area Points to the New Save Area Chain Save Areas LOOP1 L R3.SAVE1 ST R11.R3) LR R8.2(.4(. THE * SORT ALOGORITHM IS SELECTION SORT.R3 LA R5. IN ASCENDING * ORDER OF THE CONTENTS OF THE SECOND HALFWORD OF EACH PAIR.R0 USING *.R13 LA R13.R12. * * * ********************************************************************* PRINT NOGEN YREGS . SORTARR CSECT STM R14.12(R13) BALR R12.23 EQU * LH R9.

Page 357 of 58 ..R3) BCT R4. All rights reserved.0(R8) XC 0(4. Concepts Concepts © Copyright IBM Corp.R5) BNH NOSWAP LH R9.R5 Is Entry Lower than Lowest So Far? No Yes – Make This the Lowest So Far NOSWAP EQU * LA R5.R8 BE NOSWAP1 XC 0(4.R5) LR R8.R3). 2004.2(.4(.4(.2(. 2000.R15 BR R14 SAVE1 DS 18F LTROG END Point to Next Entry (Inner Loop) Loop to Process Next Entry (Inner) Is Lowest Other than First? No Yes – Swap Lowest With First Point to Next Entry (Outer Loop) Loop to Process Next Entry (Outer) Restore Regs Set Return Code of Zero Return The remaining part of the code of the SORTARR module is shown in the example.0(R3) NOSWAP1 EQU * LA R3.0(R3) XC 0(4.R5) BCT R6.OS/390 Assembler Programming Introduction Unit: Creating a Complete Program Topic: Coding the Program The SORTARR Module (cont’d) LOOP2 EQU * CH R9.4(.R8).R13) LM R14.R12(R13) SR R15.LOOP2 CR R3.LOOP1 L R13.R8).

and dividing by 24. The average temperature is determined by adding all 24 temperatures. The temperature is edited into the output line. Continued… Concepts © Copyright IBM Corp. 2000.. and then rounding. It determines the following four things: • • • • Lowest temperature Highest temperature Average temperature Median temperature It first gets the lowest temperature. The array has been sorted into ascending order by temperature. The highest temperature is also processed in a similar manner. so the fist entry is the lowest. The median temperature is the average of the two middle entries in the array. All rights reserved. and then the corresponding time is added. 2004. Page 358 of 58 .OS/390 Assembler Programming Introduction Unit: Creating a Complete Program Topic: Coding the Program The PRINT Module The print module is the longest in the program.

Continued… Concepts © Copyright IBM Corp.R11) L R3.2(.SAVE1 ST R11. AND THE MEDIAN WHICH IS THE MEAN OF THE TWO MIDDLE VALUES.R13) ST R13. THEN CALCULATES AND PRINTS THE MEAN OF ALL 24 ENTRIES. The code of PRINT module is shown in the example.DWD ED LOWTEMP.OS/390 Assembler Programming Introduction Unit: Creating a Complete Program Topic: Coding the Program The PRINT Module (cont’d) THIS MODULE PRINTS THE RESULTS OF THE CALCULATION.R12.R1) OPEN (OUT. 2004.12(R13) BALR R12.0(. 2000.R12 LR R11. THE HIGHEST TEMPERATURE (LAST ENTRY) AND CORRESPONDING TIME.4(.R3) CVD R4.(OUTPUT) LH R4.8(..DWD+5 Suppresses Macro Expansions Printing Generate Register Equates Saves Registers Establish Addressability Save Old Save Area @ New Save Area @ Chain Save Areas Get the Array Address Open the Output DCB Get the Lowest Temperature Edit The Temperature Like other modules. Page 359 of 58 .R0 USING *. PRINT PRINT NOGEN YREGS . IT PRINTS THE LOWEST TEMPERATURE (FIRST ENTRY) AND CORRESPONDING TIME. CSECT STM R14.R13 LA R13. All rights reserved. PRINT module too starts with a block of comments explaining its purpose.

Continued… Concepts © Copyright IBM Corp.LOWLINE LH R4.R3) MH R4. All rights reserved.=H’10” LA R4.2(R5.DWD ED HIGHTEMP.0(.TIMETAB(R4) MVC HIGHTIME.R3) Zero sum Zero index for Array Entries Set Loop Counter to 24 Add Current Entry to Sum AVGLOOP The continued code of PRINT module is shown in the example. 2000.DWD+5 LH R4. Page 360 of 58 .R5 LA R6.R4 SR R5.94(.0(R4) PUT OUT.=H’10’ LA R4.R3) MH R14..0(R4) PUT OUT.24 EQU * AH R4.OS/390 Assembler Programming Introduction Unit: Creating a Complete Program Topic: Coding the Program The PRINT Module (cont’d) LH R4.HIGHLINE * * CALCULATE THE AVERAGE TEMPERATURE Get the Entry Number for Low Temp The Entries are 10 bytes Long Get @ of Corresponding Time Entry Move Time to Output Line Write Low Temp Line Get Highest Temp 94=23*4+2 Edit The Temperatures Get the Entry Number for High Temp Time Entries are 10 Bytes Long Get @ of Corresponding Time Entry Move Time to Output Line Write High Temp Line * SR R4.R3) CVD R4.R3) MVC LOWTIME. 2004.TIMETABLE(.92(.

DWD AVGTEMP.=F’24’ C R4. Continued… Concepts © Copyright IBM Corp. 2000.DWD+5 Get 12th Temperature Add 13th Temperature Divide by 2 Round Edit Median Temp The continued code of PRINT module is shown in the example.R3) SRDL R4.DWD+5 OUT. 2004.AVGLINE Increment Index to Point to Next Loop Prepare for Division Calculate Mean Round Edit Mean Temp Print Mean Temp * * CALCULATE THE MEDIAN TEMPERATURE * LH R4.31 AR R4.=H’1’ * R5.50(.R5) BCT R6.OS/390 Assembler Programming Introduction Unit: Creating a Complete Program Topic: Coding the Program The PRINT Module (cont’d) LA R5.AVGLOOP SRDA R4.R3) AH R4.R5 CVD R4. Page 361 of 58 .46(. All rights reserved.DWD ED MEDTEMP.=F’12’ BL NOROUND AH NOROUND EQU CVD ED PUT R5.4(.1 SRL R5..32 D R4.

2004.’ CL10’6:00 A.’ CL10’3:00 A.M.OS/390 Assembler Programming Introduction Unit: Creating a Complete Program Topic: Coding the Program The PRINT Module (cont’d) PUT OUT.R12.’ CL10’2:00 A.’ CL10’4:00 A.M.M..’ CL10’8:00 A.MEDLINE CLOSE (OUT) L R13. THE POSITION OF THE ENTRIES IN THE TABLE CORRESPONDS TO THE POSITION NUMBERS (0.’ CL10’7:00 A. Page 362 of 58 .1.M.) OF THE ENTRIES IN THE UNSORTED ARRAY.’ The continued code of the PRINT module is shown in the example.4(.R15 BR R14 SAVE1 DS 18F Print Median Temp Close Output DCB Restore Regs Zero Return Code Return THIS TABLE CONTAINS PRINTABLE TIME ENTRIES.M. 2000.M. All rights reserved.’ CL10’5:00 A.M. TIMETAB DC DC DC DC DC DC DC DC DC DC CL10’1:00 A.12(R13) SR R15.M.R13) LM R14.’ CL10’9:00 A.M.M. Continued… Concepts © Copyright IBM Corp.’ CL10’10:00 A.

’ DC CL10’9:00 P. Page 363 of 58 .’ DC CL10’MIDNIGHT’ DWD DS D LOWLINE DS 0CL133 DC C’1’ DC C’THE DAILY LOW TEMPERATURE WAS LOWTEMP DC X’40202021204B2060 DC C’ AT ‘ LOWTIME DS CL10 DC CL83’ ‘ The continued code of the PRINT module is shown in the example.M..’ DC CL10’11:00 P.M.M.M.M.’ DC CL10’2:00 P. 2000. Continued… Concepts © Copyright IBM Corp.’ DC CL10’10:00 P.’ DC CL10’5:00 P.M.’ DC CL10’8:00 P.’ DC CL10’7:00 P.’ DC CL10’4:00 P.M. All rights reserved.M.OS/390 Assembler Programming Introduction Unit: Creating a Complete Program Topic: Coding the Program The PRINT Module (cont’d) DC CL10’11:00 A.M.M.M. 2004.’ DC CL10’NOON’ DC CL10’1:00 P.’ DC CL10’6:00 P.’ DC CL10’3:00 P.M.

RECFM=FBA. Page 364 of 58 . All rights reserved.LRECL=133 X BLKSIZE=6650 LTORG END The continued code of the PRINT module is shown in the example.MACRF=PM.DSPRG=PS.OS/390 Assembler Programming Introduction Unit: Creating a Complete Program Topic: Coding the Program The PRINT Module (cont’d) HIGHLINE DS OCL133 DC C’ ‘ DC C’THE DAILY HIGH TEMPERATURE WAS’ HIGHTEMP DC X’40202021204B2060’ DC C’ AT ‘ HIGHTIME DS CL10 DC CL82’ ‘ AVGLINE DS OCL133 DC C’ ’ DC C’THE EVRAGE TEMPERATURE WAS’ AVGTEMP DC X’40202021204B2060’ DC CL97 MEDLINE DS OCL133 DC C’ ‘ DC C’THE EMDIAN TEMPERATURE WAS’ MEDTEMP DC X’40202021204B2060 DC CL98’ ’ OUT DCB DDNAME=OUT.. Concepts © Copyright IBM Corp. 2004. 2000.

• Concepts © Copyright IBM Corp. Page 365 of 58 . and link it to the source files with the Assembler code. and point to the source code in the DD statements. the following two processing techniques can be used to assemble and link programs: • Background Processing: Here the necessary Job Control Language (JCL) is used to perform the assemble. 2000.. the programmer can put JCL in a separate file. or the foreground processing dialogs provided in Interactive System Productivity Facility (ISPF). specifying the assembler input. 2004.OS/390 Assembler Programming Introduction Unit: Creating a Complete Program Topic: Assembling and Linking the Program Methods Under Time Sharing Option/ Extended (TSO/E). All rights reserved. Alternatively. It is then submitted for batch processing. Foreground Processing: Here the programmer can use either TSO/E assemble and link commands directly.

4(.R0 R:C 00006 30 USING *.12(R13) 000004 05C0 29 BALR R12. All rights reserved.R1) Regardless of the processing techniques. These listings provide useful data to help you when you test and debug your program.16(. 2004.SAVE1 00000C 50B0 D004 00004 33 ST R11. Page 366 of 58 . A small section of the listing for GETINPUT module is shown in the example. 2000.R11) 000014 1BFF 35 SR R15.06 1 THIS MODULE READS 24 TEMPERATURES INTO AN ARRAY..OS/390 Assembler Programming Introduction Unit: Creating a Complete Program Topic: Assembling and Linking the Program Listings Loc Object Code Addr1 Addr2 Stmt Source Statement HLASM R2.R11) 00001A 5830 1000 00000 L R3. Continued… Concepts © Copyright IBM Corp. AND A TEMPERATURE.R13 000008 41D0 C072 00084 32 LA R13. Assembler and linker listings need to be produced.0(.R13) 000010 50D0 B008 00008 34 ST R13.8(. 3 3 STARTING AT 0 AND UP TO 23.R12. 4 5 6 7 PRINT NOGEN 26 YREGS 000000 27 GETINPUT CSECT ‘ 000000 90EC D00C 0000C 28 STM R14.0 1999/06/20 14.R15 000016 50F0 BO10 00010 36 ST R15. 2 EACH ARRAY ENTRY CONTAINS AN ENTRY NUMBER.R12 000006 18BD 31 LR R11.

.06 26 GETINPUT 19 R10 11 R2 16 R7 17 R8 18 R9 There are other parts of an Assembler listing. 49 LOOP 00000001 0000002E 00000002 U 44 62B LOOPING00000001 0000005E 00000002 U 59 57B REC 00000080 0000012C 00000002 C 118 50 SAVE1 00000004 00000084 00000002 F 76 31 =H’-1’ 00000002 00000188 00000002 H 124 58 Unreferenced Symbols Defined in CSECTs Page 7 Defn Symbol HLASM R2. Page 367 of 58 . All rights reserved.55 ERR 00000001 00000074 00000002 U 71 93 IN 00000004 000000CC 00000002 F 81 41. The cross-reference listing for GETINPUT is shown in the example. Continued… Concepts © Copyright IBM Corp.06 DWD 00000008 00000180 00000002 D 122 54M.OS/390 Assembler Programming Introduction Unit: Creating a Complete Program Topic: Assembling and Linking the Program Listings (cont’d) Ordinary Symbol and Literal Cross References Page 6 Symbol Len Value Id R Type Defn References HLASM R2.0 1999/06/20 14. 2000.0 1999/06/20 14. 2004. such as the cross-reference listing.

2000.OS/390 Assembler Programming Introduction Unit: Creating a Complete Program Topic: Assembling and Linking the Program Listings (cont’d) The cross-reference listing shows every symbol defined in your program. All rights reserved. and to determine a free register to use for calculation. To modify program. The reference entries indicate whether the symbol is modified or not. Unreferenced Symbols listing can be used. you can easily determine the instructions that modify that variable. as well as where it is defined. Page 368 of 58 .. If a particular variable has the wrong value. 2004. and where it is referenced. Continued… Concepts © Copyright IBM Corp. This information can be very useful in debugging.

Concepts © Copyright IBM Corp. The example here shows a section of the module. four separately assembled modules were written and then combined with the linkage editor. the module map will help. All rights reserved. 2000. in relation to the beginning of the whole machine language program.OS/390 Assembler Programming Introduction Unit: Creating a Complete Program Topic: Assembling and Linking the Program Listings (cont’d) SECTION OFFSET CLASS OFFSET NAME 0 MAIN 110 GETINPUT 2A0 SORTARR 358 PRINT TYPE CSECT CSECT CSECT CSECT ------------SOURCE ----------LENGTH 110 190 B8 4D0 DDNAME SYSLIN SYSLIN SYSLIN SYSLIN SEQ 01 01 01 01 MEMBER **NULL** **NULL** **NULL** **NULL** The linkage editor also produces listings. In the case of the example of temperature. which can be valuable.. 2004. To determine where the four modules are located. Page 369 of 58 .

2(. with some errors. DWD 60 STH R6.4(.PK 000048 4F60 C172 000058 4060 3002 00005C 4130 3004 000060 0000 00178 00002 00004 62 55 CVB R6.R3) BCTR R4..R13 31 LA R13.LOOP Chain saves area Gets the next temp Converts the absolute Value to fixed point Stores in 2nd half of array entry Points to next array entry Loops to process next entry ASMA029E *** ERROR *** Incorrect register or mask specification 000062 63 RTRN EQU * Messages describing syntax errors appear in the program listing.R13) 000010 50DO BOOB 00006 33 ST R13. In each case.OS/390 Assembler Programming Introduction Unit: Testing and Debugging Program Listings 000006 18BD 000008 0000 0000 30 00000 LR R11. and consists of an error number and an error description. along with the statement error. Concepts © Copyright IBM Corp. All rights reserved.4(. Page 370 of 58 .REC 54 PK DWD.RECTEMP ASMA057E *** ERROR *** Undefined operation code .SAVE 00000C 50BO D004 00004 32 ST R11.R3) 61 LA R3. 2000. the error message follows the statement in error. 2004. The listing for a version of GETINPUT. is shown in the example.SAVE Saves old save area Points to new save area Topic: Finding Assembly Errors ASMA044E *** ERROR *** Undefined symbol .R11) 000038 4110 C0BE 00004 48 GET IN.8(.

so that the problem can be corrected. Often the information necessary to diagnose and correct the problem is present in the symptom dump. you know there is a problem. All rights reserved. In such cases what needs to be determined is at which point in the program the error has occurred.. In testing. In some cases. which produces predictable output. while testing the program. When the actual output produced by your program. it does not run to completion and terminates with a program exception. Continued… Concepts © Copyright IBM Corp. Page 371 of 58 . you run the program using test data. and must begin to debug the program. 2000. you can start the process of testing and debugging.OS/390 Assembler Programming Introduction Unit: Testing and Debugging Symptom Dump Test Data Source Program Assemble And Link Correct Results Incorrect Results Abnormal End Program Exception Topic: Finding Execution Errors Load Module Once the syntax errors have been removed from a program. which is part of the system log for the job. 2004. differs from the expected values.

. 2004.18. Page 372 of 58 . Concepts © Copyright IBM Corp.14 SEQ=00138 CPU=0000 ASID=0015 PSW AT TIME OF ERROR 078D2000 ACTIVE LOAD MODULE NAME=GO DATA AT PSW 00006934 – C1274F60 C17A9560 C1264770 GPR 0-3 GPR 4-7 00000001 00000018 00006A14 00000000 00000040 009BBFF8 00006874 FD000000 0000682C 0000693A ILC 4 INTC 07 ADDRESS=000067D8 OFFSET=00000162 GPR 8-11 009FD080 809DE628 00000000 The example shows an excerpt from a symptom dump. All rights reserved.OS/390 Assembler Programming Introduction Unit: Testing and Debugging Symptom Dump (cont’d) Symptom Dump Output Topic: Finding Execution Errors SYSTEM COMPLETION CODE=0c7 REASON CODE=00000007 TIME=14. 2000.

relative to the beginning of GETINPUT. Continued… Concepts © Copyright IBM Corp. The example of a module map. here. is 15E – 110 = 4E. shows that the address 15E falls within GETINPUT. 2004. 2000.. Page 373 of 58 .OS/390 Assembler Programming Introduction Unit: Testing and Debugging Module Map SECTION OFFSET CLASS OFFSET NAME 0 MAIN 110 GETINPUT 2A0 SORTARR 358 PRINT ---------SOURCE---------TYPE LENGTH 110 190 B8 4DO DDNAME SEQ MEMBER SYSLIN SYSLIN SYSLIN SYSLIN 01 **NULL** 01 **NULL** 01 **NULL** 01 **NULL** Topic: Finding Execution Errors CSECT CSECT CSECT CSECT After you view the symptom dump. All rights reserved. The displacement of the failing instruction. it is important to take a look at the module map to determine which module the error occurred in. and at what displacement.

OS/390 Assembler Programming Introduction Unit: Testing and Debugging Module Map (cont’d) 0002E 44 LOOP EQU * Calculates entry number Places in first half of array entry Gets the next temp Converts the absolute value to a fixed point Is it negative? No Yes.R3) 000CC 4B GET IN.DWD 0012C 0005E 00188 56 CLI RECSIGN.0(.REC 000048 F273 C17A C127 00180 0012D 54 PACK DWD. 2004. The relevant portion of the listing is shown in the example.C’-’ 57 BNE LOOPING 58 MH R6.=H’-1’ After viewing the module map. Page 374 of 58 .change the sign Topic: Finding Execution Errors 00002E 4150 0018 000032 1B54 000034 4050 3000 000038 4110 C0C6 00018 45 LA R5.24 46 SR R5.RECTEMP 00004E 4F60 C17A 000052 9560 C126 000056 4770 CO5B 00005A 4C60 C182 00180 55 CVB R6. All rights reserved. you then look at the listing of GETINPUT. to find what instruction failed.R4 00000 47 STH R5. Concepts © Copyright IBM Corp.. 2000.

the program can be re-run with a SYSUDUMP DD statement. it is possible that the symptom dump would not contain enough information to determine the root cause of the problem. In such cases.. User Dump: Topic: Finding Execution Errors TEXT DATA LOAD MODULE JCL SPECIFIES //SYSUDUMP DO…. USER DUMP Continued… Concepts © Copyright IBM Corp. 2000. All rights reserved. 2004. Page 375 of 58 .OS/390 Assembler Programming Introduction Unit: Testing and Debugging Batch Debugging In some cases. in order to produce a full user dump.

and then continue execution. the following methods for debugging can be applied: • The code for logic errors should be checked and additional print statements should be included to display intermediate results. The system macro SNAP is used to produce a storage dump. Areas of storage. The system macro ABEND is used to produce a dump and terminate execution. Storage and Terminate (ABEND) Concepts © Copyright IBM Corp. Page 376 of 58 . Topic: Finding Execution Errors Debugging Techniques: • Check Program Logic • • Addition Print Statements • Dump Registers. Storage and Continue (SNAP) • Dump Registers. 2004.OS/390 Assembler Programming Introduction Unit: Testing and Debugging Batch Debugging (cont’d) If the program does run to completion.. 2000. All rights reserved. but produces incorrect results. or register contents or system control blocks should be dumped at specific points in the program.

You can monitor specified variables to ensure that only certain ranges of values are assigned.OS/390 Assembler Programming Introduction Unit: Testing and Debugging Interactive Debugging A very powerful interactive debugging facility is provided by the IBM Interactive Debug Facility (IDF). 2000. Page 377 of 58 . Topic: Finding Execution Errors Concepts © Copyright IBM Corp. You can set break points. and then run IDF in the TSO/E environment. so that your program runs until it reaches a specific address. All rights reserved. You can single step through your program. and interactively examine register and storage contents.. IDF allows you to control the execution of your program. You compile and link the program with IDF included. and then pause. 2004. executing one instruction at a time.