Professional Documents
Culture Documents
Assembler Part 2
Assembler Part 2
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Introduction
Assembler Language Part 2 provides instruction and practice in the use of the standard
Assembler Language instructions. The course covers executable instructions for data manipulation, including
loading and storing data, moving in main storage, bit manipulation, binary and decimal arithmetic, data
conversions and data editing.
The first unit, Data Manipulation Instructions, explains the syntax and function of Load, Store and Move
instructions.
The second unit, Basic MVS I/O Facilities, explains the characteristics of Data Set Definitions, syntax and
purpose of Data Control Blocks (DCBs) and the use of OPEN and CLOSE macros.
The third unit, Decimal Arithmetic, explains the use of Decimal Arithmetic, conversion and operation
decimal Arithmetic functions, Editing decimal data.
The fourth unit, Comparing and Branching explains the use of Condition Codes, numerical and logical
comparisons, the function of Branching Instructions and the framework of Structure Constructs.
The fifth unit, Fixed-Point Binary Arithmetic, explains the conversion between decimal and binary, and
functions of Fixed Point Binary Arithmetic Instructions.
1
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Topics:
Load and Store Instructions
Move Instructions
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Data Manipulation Instructions
Unit Introduction
Using the General Purpose Registers (GPRs) is an important part of Assembler programming. You will use
GPRs as base registers in addressing, and as index registers. You will also use them as counters, or in
performing fixed-point binary arithmetic operations. This unit will describe machine instructions that are used
to load, store and move data between Main Storage and GPRs.
• Direct the movement of data from one main storage location to another or to a register
2
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Topics:
Load and Store Instructions
Move Instructions
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Data Manipulation Instructions Topic: Load and Store Instructions
Load Operation
A load operation moves data from main storage Load (L) Instruction:
into a GPR. You will find this useful when RX Format – Register and Indexed Storage
FWD1
R3
00 00 00 00 07 3C EA 00
Target
Full word Source
Full word
07 3C EA 00
3
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Data Manipulation Instructions Topic: Load and Store Instructions
Load Operation
Load L
Example :
• The four bytes at the storage address specified by
operand-2 is loaded into the register specified by
operand-1 LEX1 L R1,REG1
REG1 DC F'80'
R1 EQU 1
* R1 before '00000000'
* R1 after '00000080'
58 RX BDDD
Format :
L R1,D2(X2,B2)
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Data Manipulation Instructions Topic: Load and Store Instructions
Load Operation
Load Register LR
Example :
• The value of register operand-2 loaded into the register
specified by operand-1
LEX1 LR R4,R6
R4 EQU 4
R6 EQU 6
18 RR
Format :
LR R1,R2
4
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Data Manipulation Instructions Topic: Load and Store Instructions
Load Operation
Load Halfword LH
Example :
• The two bytes (halfword) located at the address specified
by operand-2 is loaded into the rightmost two bytes (bits
16-31) of the register specified by operand-1
• The left half of the register is loaded with zeros or LH R3,STDATA
ones according to the sign (leftmost bit) of the halfword
STDATA DS H
R3 EQU 3
48 RX BDDD
Format :
LH R1,D2(X2,B2)
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Data Manipulation Instructions Topic: Load and Store Instructions
Load Operation
LPR R3,R4
R3 EQU 3
R4 EQU 4
10 RR
Format :
LPR R1,R2
5
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Data Manipulation Instructions Topic: Load and Store Instructions
Load Operation
LNR R3,R4
R3 EQU 3
R4 EQU 4
11 RR
Format :
LNR R1,R2
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Data Manipulation Instructions Topic: Load and Store Instructions
Load Operation
Load Multiple LM
Example :
• The set of registers starting with operand-1 and ending
with operand-3 are loaded from storage location specified
by operand-2 EXMP1 LM R4,R6,REG1
• Register numbers are referred in cyclic way REG1 DS F
• R14,R5 means R14,R15,R0,R1,R2,R3,R4,R5 REG2 DS F
REG3 DS F
R4 EQU 4
R6 EQU 6
Format :
LM R1,R3,D2(B2)
6
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Data Manipulation Instructions Topic: Load and Store Instructions
Load Operation
Load Address LA
Example :
• The actual value of operand-2 (effective address) is
loaded into the register specified by operand-1 .
LA R8,REG1+6
REG1 DS F
R8 EQU 8
41 RX BDDD
Format :
LA R1,D2(X2,B2)
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Data Manipulation Instructions Topic: Load and Store Instructions
R7 R3
00 00 00 00 07 3C EA 00
Target Source
Fullword Fullword
LTR
7
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Data Manipulation Instructions Topic: Load and Store Instructions
Store Instruction
Store ST
Example :
• The register specified by operand-1 (R1) is stored at the
storage address specified by operand-2 . ST R4,STGAREA
• Operand-2 should be full word storage area
STGAREA DS F
R4 EQU 4
50 RX BDDD
Format :
ST R1,D2(X2,B2)
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Data Manipulation Instructions Topic: Load and Store Instructions
Store Instruction
R4 EQU 4
REGWORK DC XL4’00000000’
42 RX BDDD
Format :
STC R1,D2(X2,B2)
8
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Data Manipulation Instructions Topic: Load and Store Instructions
Store Instruction
STCM R1,M3,D2(X2,B2)
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Data Manipulation Instructions Topic: Load and Store Instructions
Store Instruction
Store Halfword SH
Example :
• The rightmost two bytes or halfword (bits 16-31) of the
register specified by operand-1 are stored at the storage
address specified by operand-2
SH R3,STHDATA
STHDATA DC XL2’0000’
R3 EQU 3
Format :
STH R1,D2(X2,B2)
9
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Data Manipulation Instructions Topic: Load and Store Instructions
Store Instruction
Format :
STM R1,R3,D2(B2)
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Data Manipulation Instructions Topic: Load and Store Instructions
Store Instruction
the caller.
10
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Data Manipulation Instructions Topic: Load and Store Instructions
Inserting Characters
Insert Character IC
Example :
• The byte at address specified by operand-2 is
inserted into bit positions 24-31 of operand-1
• The remaining bits of R1 remain unchanged IC R8,=C’B’
R8 EQU 8
43 RX BDDD
Format :
IC R1,D2(X2,B2)
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Data Manipulation Instructions Topic: Load and Store Instructions
Inserting Characters
BF RM BDDD
Format :
ICM R1,M3,D2(B2)
11
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Topics:
Load and Store Instructions
Move Instructions
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Data Manipulation Instructions Topic: Move Instructions
Moving data
92 I BDDD
Format :
MVI D1(B1),I2
12
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Data Manipulation Instructions Topic: Move Instructions
Moving data
D2 L BDDD BDDD
Format :
MVC D1(L,B1),D2(B2)
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Data Manipulation Instructions Topic: Move Instructions
Moving data
Move Characters Long MVCL
• The data string identified by operand-2 is moved to the Example :
storage location identified by operand-1
• Both operands are EVEN-ODD register-pairs. The first R6 EQU 6
register needs to be loaded with the addresses of the data
strings. The second register needs to be loaded with the R7 EQU 7
length of each operand. R8 EQU 8
• The data strings may be different length. The operation ends R9 EQU 9
when the number of bytes specified by bits 40-63 of RECV DC C’SOMEDATA’
general register R1 + 1 have been moved SEND DC C’A LONGER FIELD’
• The high-order byte of the second register of operand-2 is
treated as the padding character LA R6,RECV
• As each character is moved the length registers are LH R7,=H’8’
decremented
LA R8,SEND
LH R9,=H‘14’
0E RR ICM R9,8,=C’ ‘ padding char
MVCL R6,R8
Format :
MVCL R1,R2
13
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Data Manipulation Instructions Topic: Move Instructions
PRTLINE
PRTLINE DS CL133
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Data Manipulation Instructions Topic: Move Instructions
PRTLINE (cont’d)
You could eliminate the named constant by using MVC PRTLINE, BLANKS
a literal: .
.
MVC PRTLINE,=CL133‘ ' .
.
.
BLANKS DC CL133
14
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Topics:
Defining Data Sets
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Basic MVS I/O Facilities
Unit Introduction
The main purpose of most assembler programs is to input data, process it, and then print out
the resulting data. MVS provides a vast range of input/output (I/O) facilities and options that
help you accomplish this.
In this unit, a very small subset of these facilities will be presented, I/O macros that sequentially
read 80-byte input records and sequentially write 133-byte output records. These macros
enable you to read data from an input data set you create, and to write data to the printer.
15
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Topics:
Defining Data Sets
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Basic MVS I/O Facilities Topic: Defining Data Sets
The major steps for processing input and output I/O PROCESSING TASKS MVS MACRO
data in a program are shown. I/O macros are 1. Define the data set DCB
used to accomplish all of these tasks, except for
2. Define I/O areas DS,DC
the definition of I/O areas, which is done with
assembler instructions. 3. Make the data set available OPEN
16
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Basic MVS I/O Facilities Topic: Defining Data Sets
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Basic MVS I/O Facilities Topic: Defining Data Sets
Name Field
DCB Name
Data Control Block
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
17
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Basic MVS I/O Facilities Topic: Defining Data Sets
Parameters
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Basic MVS I/O Facilities Topic: Defining Data Sets
Kinds of Parameters
18
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Basic MVS I/O Facilities Topic: Defining Data Sets
The LRECL parameter specifies the length of logical records in the data set. You specify 80 for input and 133
for output.
The BLKSIZE parameter specifies the size of physical records, or blocks, in the data set. Omit this parameter
for input data sets and use 6650 for output.
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. This parameter is only specified for input data
sets.
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Basic MVS I/O Facilities Topic: Defining Data Sets
19
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Basic MVS I/O Facilities Topic: Defining Data Sets
CLOSE (INFILE)
CLOSE (OUTFILE)
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Topics:
Defining Data Sets
20
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Basic MVS I/O Facilities Topic: Data Transfer Macros
Move Mode
B LOOP
The Move Mode data transfer macro for input,
moves the record from the data set to a buffer in ENDDATA EQU *
main storage and from the buffer to the work area
named INAREA. CLOSE (INFILE,,OUTFILE)
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Basic MVS I/O Facilities Topic: Data Transfer Macros
21
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Basic MVS I/O Facilities Topic: Data Transfer Macros
GET Macro
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Basic MVS I/O Facilities Topic: Data Transfer Macros
PUT Macro
22
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Basic MVS I/O Facilities Topic: Data Transfer Macros
- Triple space
The most common ANSI printer control
Suppress space
characters and their meanings are shown on +
(overprint last line)
the right. Skip to top
1
of next page
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Basic MVS I/O Facilities Topic: Data Transfer Macros
INAREA DS CL80
OUTAREA DS 0CL133 specify double spacing
OUTASA DC C'0' copy of input goes here
OUTREC DS CL80 make the rest spaces
DC CL52 ' ' RECORD
INFILE DCB DDNAME=IN,RECFM=FB,LRECL=80,DSORG=PS,MACRF=GM, X
EODAD=ENDDATA
OUTFILE DCB DDNAME=OUT,RECFM=FBA,LRECL=133,BLKSIZE=6650, X
DSORG=PS,MACRF=P
To put all of this I/O information together, you code a program segment to read data from an input data
set, and then print it out, double spaced, on the printer.
23
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Topics:
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Decimal Arithmetic
Unit Introduction
The components of an Assembler Language program are similar to that of a High Level Language program.
They include:
• Input/output
• Arithmetic operations
• Data manipulation
• Instructions to control the program logic and flow
Arithmetic operations are performed in Assembler Language with either fixed-point binary or decimal
instructions. This unit presents packed decimal instructions, which only operate on whole
numbers.
24
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Topics:
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Decimal Arithmetic Topic: Decimal Type Conversion
25
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Decimal Arithmetic Topic: Decimal Type Conversion
Pack PACK
Example :
• The data string located at the address specified by
operand-2 is changed from zoned-decimal to packed PACK NUM,DATA
and the result is put into the address specified by
operand-1 .
• Operand-2 remains unchanged. The operands may be
different lengths with a maximum length of 16 bytes
(31 digits) for each operand
• If the length of the operand-2 is greater, left truncation
occurs. If it is less, left padding with zeroes occurs
F2 L1 L2 BDDD BDDD
Format :
PACK D1(L1,B1),D2(L2,B2)
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Decimal Arithmetic Topic: Decimal Type Conversion
Source
Target
UNPK
Conversion
Result
F0 F1 F2 F3 C4
26
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Decimal Arithmetic Topic: Decimal Type Conversion
Unpack UNPK
Example :
• The data string located at the address specified by
operand-2 is changed from packed to zoned-decimal UNPK DATA,NUM
and the result is put into the address specified by
operand-1 .
• Operand-2 remains unchanged. The operands may be
different lengths with a maximum length of 16 bytes
(31 digits) for each operand
• If the length of the operand-2 is greater, left truncation
occurs. If it is less, left padding with zeroes occurs
F3 L1 L2 BDDD BDDD
Format :
UNPK D1(L1,B1),D2(L2,B2)
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Decimal Arithmetic Topic: Decimal Type Conversion
0I DATA + 2, X ‘F0’
Prints as 123
DATA C3
F1 F2 F3
F0
F3
Result
27
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Decimal Arithmetic Topic: Decimal Type Conversion
PRTFLD
OR immediate
Changes the
Prints
F1 F2 F3 F4 F5 F6 C7 sign nibble
As
123456C
C7
F0
0I PRTFLD + 6, X ‘F0’
F7
PRTFLD
Prints
F1 F2 F3 F4 F5 F6 F7 as
1234567
Result
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Topics:
28
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Decimal Arithmetic Topic: Decimal Arithmetic Operations
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Decimal Arithmetic Topic: Decimal Arithmetic Operations
F8 L1 L2 BDDD BDDD
Format :
ZAP D1(L1,B1),D2(L2,B2)
29
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Decimal Arithmetic Topic: Decimal Arithmetic Operations
Add Decimal
AP
Example :
• The data string located at the address specified by
operand-2 is added to the data string located at the
address specified by operand-1. AP D1,D2
• Operand-2 remains unchanged.
• The operands may be different lengths with a D1 DC XL8'000000000000001C'
maximum length of 16 bytes (31 digits ) D2 DC XL8'000000000000002C'
• The condition code is set as shown below
D5 L1 L2 BDDD BDDD
Format :
AP D1(L1,B1),D2(L2,B2)
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Decimal Arithmetic Topic: Decimal Arithmetic Operations
Add Logical
AL
Example :
• The full word operand-2 is added to the full word at
address specified by operand-1, and the sum is
placed in the operand-1 L R4,FW00XX02
• The operands and the sum are treated as 32-bit AL R4,FW00XX01
unsigned binary integers AL R4,FW80XX05
• The condition code is set as shown below
R4 EQU 4
0 – zero nocarry , 1 – not-zero no carry
2 – zero carry , 3 – not-zero carry FW00XX01 DC XL4'00000001'
FW00XX02 DC XL4'00000002‘
FW00XX05 DC XL4'00000005'
5E RX BDDD
Format :
AL R1,D2(X2,B2)
30
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Decimal Arithmetic Topic: Decimal Arithmetic Operations
Subtract Decimal
SP
Example :
• The data string located at the address specified by
operand-2 is subtracted from the data string located
at the e address specified by operand-1. SP D1(5),D2
• Operand-2 remains unchanged.
• The operands may be different lengths with a D1 DC XL8'000000000000001C'
maximum length of 16 bytes (31 digits ) D2 DC XL8'000000000000002C'
• The condition code is set as shown below
FB L1 L2 BDDD BDDD
Format :
SP D1(L1,B1),D2(L2,B2)
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Decimal Arithmetic Topic: Decimal Arithmetic Operations
Subtract Logical
SL
Example :
• The full word operand-2 is subtracted from the full
word at address specified by operand-1, and the
result is placed in the operand-1 L R4,FW00XX02
• The operands and the result are treated as 32-bit SL R4,FW00XX01
unsigned binary integers SL R4,FW80XX05
• The condition code is set as shown below
R4 EQU 4
0 – zero noborrow , 1 – not-zero borrow
2 – zero borrow , 3 – not-zero borrow FW00XX01 DC XL4'00000001'
FW00XX02 DC XL4'00000002‘
FW00XX05 DC XL4'00000005'
5F RX BDDD
Format :
SL R1,D2(X2,B2)
31
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Decimal Arithmetic Topic: Decimal Arithmetic Operations
Multiply Decimal
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Decimal Arithmetic Topic: Decimal Arithmetic Operations
Multiply Decimal
MP
Example :
• The data string located at the address specified by
operand-2 is multiplied with the data string located at
the e address specified by operand-1 and the product MP D1,D2
put in operand-1
• Operand-2 remains unchanged. D1 DC XL8'000000000000001C'
• The operands may be different lengths with a D2 DC XL3’00002C'
maximum length of 16 bytes (31 digits )
• The condition code remains unchanged
FC L1 L2 BDDD BDDD
Format :
MP D1(L1,B1),D2(L2,B2)
32
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Decimal Arithmetic Topic: Decimal Arithmetic Operations
Field Lengths
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Decimal Arithmetic Topic: Decimal Arithmetic Operations
Divide Decimal
33
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Decimal Arithmetic Topic: Decimal Arithmetic Operations
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Decimal Arithmetic Topic: Decimal Arithmetic Operations
QUOREM 0 0 0 0 0 0 0 0 1 4 2 C 006C
QUO REM
34
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Topics:
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Decimal Arithmetic Topic: Editing Decimal Data
ED L B DDD B DDD
DE L1 L2 BDDD BDDD
Length 1st Operand 2nd Operand
Format :
ED D1(L,B1),D2(B2)
35
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Decimal Arithmetic Topic: Editing Decimal Data
Edit Instruction
0001234 12.34
0000123 1.23
0000012 0.12
0000001 0.01
-1234567 12,345.67-
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Decimal Arithmetic Topic: Editing Decimal Data
Edit
However, not all of the digits are significant in all 0123456 1,234.56
Punctuation
Sign (-) Significant
Digit
Not a
Significant
Digit
36
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Decimal Arithmetic Topic: Editing Decimal Data
Edit (cont’d)
0001234 ****12.34
0000123 *****1.23
0000012 *****0.12
0000001 *****0.01
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Decimal Arithmetic Topic: Editing Decimal Data
Significance Indicator
37
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Decimal Arithmetic Topic: Editing Decimal Data
Fill Character
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Decimal Arithmetic Topic: Editing Decimal Data
Edit Mask
38
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Decimal Arithmetic Topic: Editing Decimal Data
Message Characters
A digit select character specifies a position where
a source digit is to be placed if the Significance MASK
Indicator is set, or the fill character is placed
otherwise. A significance start character has the Fill ds ds , ds ss ds . ds ds -
same effect as a digit select, but also forces the
Significance Indicator on, after the digit or fill
character is placed. The field separator character
is only used if the Edit operation is editing multiple
numbers. It causes the significance indicator to be
turned off.
12,345.67-
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Decimal Arithmetic Topic: Editing Decimal Data
Turned ON
It is turned off when a positive sign is encountered
in the second operand, and when a field separator
character is found in the mask. Significance
Indicator
(Initially OFF)
Turned OFF
+ ve Sign Field
Separator
39
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Decimal Arithmetic Topic: Editing Decimal Data
decimal data. The first operand is an edit mask. 1st Operand 2nd Operand
The second operand is a field containing one or
more packed decimal numbers. PD1
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Decimal Arithmetic Topic: Editing Decimal Data
PD1
Replace
RESULT MASK
40
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Decimal Arithmetic Topic: Editing Decimal Data
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Decimal Arithmetic Topic: Editing Decimal Data
The mask will need to contain the following Comma Message character
characters in the order shown in the table in the X’20’ Digit select
right.
X’21’ Significance start
41
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Decimal Arithmetic Topic: Editing Decimal Data
There are seven digits being edited in this example, so the total number of digit selects and significance start
character is seven. When you add the fill character and message characters, the total length of the mask is
11 bytes. It is always a good idea to check that your masks have the proper number of digit selects and
significance starts. Having too many may cause a data exception. Having too few will cause truncated values
to be generated.
Assuming that the number to be edited was called PK1 and the field where you wanted to place the edited
number was called PRTAMT, the code to do the editing is as shown above.
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Decimal Arithmetic Topic: Editing Decimal Data
Example Code
A complete code segment, to read 3 seven digit numbers from a dataset, add them and then
print the edited sum, is shown below
42
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Decimal Arithmetic Topic: Editing Decimal Data
INAREA DS 0CL80
DS CL73
NUM DS CL7
WKAREA DS PL4
SUM DS PL5
MASK DC X’402020206B2020206B202120’
OUTAREA DS 0CL133
OUTASA DC C’0’ specify double spacing
DC CL10’The Sum is’
OUTNUM DS CL12
DC CL110’ ‘ make the rest spaces
INFILE DCB DDNAME=IN,RECFM=FB,LRECL=80,DSORG=PS,MACRF=GM, X
EODAD=ENDDATA
OUTFILE DCB DDNAME=OUT,RECFM=FBA,LRECL=133,BLKSIZE=6650, X
DSORG=PS,MACRF=PM
The EBCDIC codes for blank, comma, period and minus are 40, 6B, 4B and 60 respectively.
These are codes that you should memorize if you are going to be doing a lot of editing.
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Topics:
Decision Making in Assembler
Compare Instructions
Branching
43
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Comparing and Branching
Unit Introduction
In order to write programs that take full advantage of the computer's capabilities, you must be able to do more
than execute a series of instructions sequentially. Interesting programs, programs that model significant real
world processes, must also make decisions and repeat sequences of instruction multiple times.
In this unit, we will cover conditional execution and looping which are basic programming components. You
will also learn how to implement these structures in Assembler Language.
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Topics:
Decision Making in Assembler
Compare Instructions
Branching
44
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Comparing and Branching Topic: Decision Making in Assembler
2 bit Field
In Assembler Language, conditional execution is
broken into parts. One instruction tests a
condition. A following instruction, a conditional CC Program Mask
branch, alters the execution path, depending on
the result of the test. The condition code, a two-bit 18 20
field in the Program Status Word (PSW) is where
the result of the test is held, awaiting subsequent
conditional branch instruction. CC Possible Values:
00 01 10 11 Binary
0 1 2 3 Decimal
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Comparing and Branching Topic: Decision Making in Assembler
MP Condition Code is
DP unchanged.
MVC
45
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Comparing and Branching Topic: Decision Making in Assembler
Compare Instructions
0 - Equal
3 – Not Used
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Topics:
Decision Making in Assembler
Compare Instructions
Branching
46
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Comparing and Branching Topic: Compare Instructions
Numeric Comparison
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Comparing and Branching Topic: Compare Instructions
Kinds of Comparison
R3 FWD1 LOGICAL
In a logical comparison, FFFFFFF6 is a higher
hex value than 0000000A, so the first operand
FFFFFFF6 0000000A
would be higher and the condition code be set to
2. Higher Hex > Lower Hex
= CC set to 2
47
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Comparing and Branching Topic: Compare Instructions
Comparing data
• Operand-1 is compared with the data • Operand-1 is compared with the operand-2
string located at the storage address
specifed by operand-2
59 RX BDDD 19 RR
Format : Format :
C R1,D2(X2,B2) CR R1,R2
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Comparing and Branching Topic: Compare Instructions
• Operand-1 is compared with the data • The data string located at the address
string located at the storage address specified by operand-2 is compared to
specifed by operand-2 the data string located at the address
specified by operand-1
• The operands may be different lengths
with a maximum length of 16 bytes (31
digits) for each operand.
• This is an arithmetic comparison
Format : Format :
CH R1,D2(X2,B2) CP D1(L1,B1),D2(L2,B2)
48
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Comparing and Branching Topic: Compare Instructions
Compare Logical CL
Example :
• The compare logical instruction does a logical Left Right CC
compare instead of a mathematical or arithmetic
comparison 00000222 00000222 0
• The compare is done left to right and stops as soon 00000000 00000222 1
as a non-equal value is found. 00000999 00000222 2
Format :
CL R1,D2(X2,B2)
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Comparing and Branching Topic: Compare Instructions
95 I BDDD
Format :
CLI D1(B1),I2
49
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Comparing and Branching Topic: Compare Instructions
D5 L BDDD BDDD
Format :
CLC D1(L,B1),D2(B2)
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Comparing and Branching Topic: Compare Instructions
Format :
CLCL R1,R2
50
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Comparing and Branching Topic: Compare Instructions
To find out how many 100 byte fields called DATA1 and DATA2 are initially equal, you could use the code
shown above.
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Topics:
Decision Making in Assembler
Compare Instructions
Branching
51
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Comparing and Branching Topic: Branching
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Comparing and Branching Topic: Branching
BIT Value 8 4 2 1
MASK BIT
X X X X (4 BITS)
BIT Position 0 1 2 3
52
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Comparing and Branching Topic: Branching
CC = 1 CC = 2 CC = 3
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Comparing and Branching Topic: Branching
BC – An Example
BC
47 MX BDDD
If CC = 0
Branch to EQRTN
Format :
If CC is (1 or 2 or 3)
Continue to Next Instruction
BC M1,D2(X2,B2)
53
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Comparing and Branching Topic: Branching
BC – An Example (cont’d)
EQRTN EQU *
EQRTN LR R7,R2
This instruction equates the label EQRTN to the
current value of the location counter. This is the LR R2,R3
value of EQRTN regardless, so the instruction
really does nothing. The reason you set up labels
this way is to ensure ease in maintenance.
Add New Instruction
Suppose you put the label on a machine
instruction as follows:
2 Instructions Change
EQRTN LR R2,R3
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Comparing and Branching Topic: Branching
BC – An Example (cont’d)
LR R7,R2
EQRTN EQU *
LR R2,R3
LR R2,R3
To add a new instruction, you simply insert it in
between the EQU and the LR instruction, as
shown on the right.
New Instruction
54
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Comparing and Branching Topic: Branching
BCR M,R0
07 M R
* No branching occurs
Format :
BCR M1,R2
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Comparing and Branching Topic: Branching
55
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Comparing and Branching Topic: Branching
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Comparing and Branching Topic: Branching
Set of extended mnemonics which can be used after comparison instructions are shown below
56
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Comparing and Branching Topic: Branching
After arithmetic instructions, you use the extended mnemonics shown above.
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Topics:
Decision Making in Assembler
Compare Instructions
Branching
57
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Comparing and Branching Topic: Building Structured Constructs
Conditional Structures
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Comparing and Branching Topic: Building Structured Constructs
IF-THEN Structure in C
CP A,B YES
BNE NOADD
AP A,B
NOADD EQU * a=a+b
NO ADD
58
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Comparing and Branching Topic: Building Structured Constructs
IF-THEN-ELSE Structure
IF
if(a == b) {
a = a + b;
YES
} a=b NO
else { ?
a = a - b;
}
The corresponding Assembler Language code
would be: a=a+b a=a-b
CP A,B
BNE SUBTR
AP A,B
B CONDEND
SUBTR EQU * CONDEND
SP A,B
CONDEND EQU *
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Comparing and Branching Topic: Building Structured Constructs
DO – WHILE Structure
while (I > 1) {
prod = prod * i; l>1 NO
I = I - 1; ?
}
YES
Assembler Language code:
LOOPSTART EQU *
CP I,=P'1' Prod = prod*I
BNH LOOPEND I = i-1
MP PROD,I
SP I,=P'1'
B LOOPSTART
LOOPEND
LOOPEND EQU *
59
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Topics:
Decimal to Binary Conversion
Multiplication
Division
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Fixed-Point Binary Arithmetic
Unit Introduction
Arithmetic operations concerned with S/390 Architecture and the Assembler Language are needed to perform
input/output operations, data manipulation and program control of logic and flow.
This unit introduces instructions associated with fixed-point arithmetic, which manipulates binary data.
60
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Topics:
Decimal to Binary Conversion
Multiplication
Division
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Fixed-Point Binary Arithmetic Topic: Decimal to Binary Conversion
ZONED
DECIMAL
61
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Fixed-Point Binary Arithmetic Topic: Decimal to Binary Conversion
PK1 00 00 00 00 00 02 5D
4F RX BDDD
FF FF FF E7
Format : R3 Conversion of negative number
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Fixed-Point Binary Arithmetic Topic: Decimal to Binary Conversion
4E RX BDDD 00 00 02 14 74 83 64 7C
62
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Fixed-Point Binary Arithmetic Topic: Decimal to Binary Conversion
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Topics:
Decimal to Binary Conversion
Multiplication
Division
63
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Fixed-Point Binary Arithmetic Topic: Addition and Subtraction
Number Representation
S HALFWORD
S FULLWORD
S DOUBLEWORD
MAGNITUDE
High Order Bit (Sign) 0=(+) Positive (True Binary) 1=(-) Negative (Two's Complement)
Fixed-point arithmetic is performed in the General Purpose Registers (GPRs). Operands for fixed-point
arithmetic may be halfwords (16 bits), fullwords (32 bits) or doublewords (64 bits). For all three
operand types, the leftmost, or high-order bit, is the sign, with zero representing positive and 1
representing negative. The remainder of the fixed-point number represents the magnitude. Positive
numbers are represented in true binary, negative numbers in two's complement form.
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Fixed-Point Binary Arithmetic Topic: Addition and Subtraction
S HALFWORD
-215 to + 215 - 1
01 15
FULLWORD
S
-231 to + 231 - 1
01 31
DOUBLEWORD
S -263 to + 263- 1
01 63
MAGNITUDE
A halfword has 15 bits to represent the magnitude, and thus can represent values from -215 to +215-1
(32,768 to 32,767).
A fullword has 31 bits to represent the magnitude, and thus can represent values from -231 to +231-1
(-2,147,483,648 to 2,147,483,647).
A doubleword has 63 bits to represent the magnitude, and thus can represent values from -263 to 263-1
(-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807).
64
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Fixed-Point Binary Arithmetic Topic: Addition and Subtraction
Add Instruction
Add A
Example :
• The full word (4 bytes) located at the address
specified by operand-2 is added to the register
specified by operand-1. L R1,REG1
• Operand-2 remains unchanged. A R1,REG2
• The condition code is set as shown below ST R1,REG1
REG1 DC XL4'00000001'
REG2 DC XL4’02010405’
5A RX BDDD
* REG1 = REG1 + REG2
Format :
A R1,D2(X2,B2)
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Fixed-Point Binary Arithmetic Topic: Addition and Subtraction
appear as 0000000B. R4
00 00 00 11
ADD
+
NUM2 Replace R4 with SUM
FF FF FF FA = 00 00 00 0B
65
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Fixed-Point Binary Arithmetic Topic: Addition and Subtraction
Add Registers AR
Example :
• The register specified by operand-2 ( is added to the
register specified by operand-1. Operand-2 remains
unchanged.
• The condition code is set as shown below AR R3,R4
ST R3,REG1
0 - op1=0, 1 - op1<0, 2 - op1>0, 3 - overflow
R3 EQU 3
R4 EQU 4
1A RR
Format :
AR R1,R2
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Fixed-Point Binary Arithmetic Topic: Addition and Subtraction
Add Halfword AH
Example :
• The half word (2 bytes) located at the address
specified by operand-2 is added to the register
specified by operand-1 .
• Operand-2 remains unchanged. AH 5,X'6B0'(13,12)
• The condition code is set as shown below
4A RX BDDD
Format :
AH R1,D2(X2,B2)
66
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Fixed-Point Binary Arithmetic Topic: Addition and Subtraction
00 00 00 05 00 05
COUNTER
+
Replace
00 01 = 00 00 00 06 00 06
AH Literal R1 STH
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Fixed-Point Binary Arithmetic Topic: Addition and Subtraction
DATA1 00 00 20 D0
Computer adds
the Halfword
AH R3,DATA1 which starts at
DATA1 to R3
67
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Fixed-Point Binary Arithmetic Topic: Addition and Subtraction
Subtract instruction
Subtract S
Example :
• The full word (4 bytes) located at the address
specified by operand-2 is subtracted from the register
specified by operand-1. L R1,REG1
• Operand-2 remains unchanged. S R1,REG2
• The condition code is set as shown below ST R1,REG1
REG1 DC XL4'00000001'
REG2 DC XL4’02010405’
5B RX BDDD
* REG1 = REG1 - REG2
Format :
S R1,D2(X2,B2)
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Fixed-Point Binary Arithmetic Topic: Addition and Subtraction
Subtract Halfword SH
Example :
• The half word (2 bytes) located at the address
specified by operand-2 is subtracted from the register
specified by operand-1 .
• Operand-2 remains unchanged. SH 5,X'6B0'(13,12)
• The condition code is set as shown below
4B RX BDDD
Format :
SH R1,D2(X2,B2)
68
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Fixed-Point Binary Arithmetic Topic: Addition and Subtraction
Subtract Registers SR
Example :
• The register specified by operand-2 is subtracted
from the register specified by operand-1. Operand-2
remains unchanged.
• The condition code is set as shown below SR R3,R4
ST R3,REG1
0 - op1=0, 1 - op1<0, 2 - op1>0, 3 - overflow
R3 EQU 3
R4 EQU 4
1B RR
Format :
SR R1,R2
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Fixed-Point Binary Arithmetic Topic: Addition and Subtraction
This method requires 4 bytes for the instruction (L Uses 8 bytes of storage
is an RX instruction) plus 4 bytes for the literal.
69
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Topics:
Decimal to Binary Conversion
Multiplication
Division
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Fixed-Point Binary Arithmetic Topic: Multiplication
Multiplication
Multiplier
The multiplier and multiplicand have two digits
each, and the products has four digits. It makes Product
sense, then, that when a multiply instruction is
designed as a part of a computer architecture, it
2 digits
should provide for a product larger than the +
multiplier and the multiplicand. 2 digits
=4 digits
70
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Fixed-Point Binary Arithmetic Topic: Multiplication
Multiply Instruction
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Fixed-Point Binary Arithmetic Topic: Multiplication
Multiply Instruction
Multiply M
Example :
• The value located at the storage address specified by
operand-2 is multiplied with the 2nd-word (the second
register of the pair) of operand-1.
• The double word result is put in operand-1 M 4,X‘150'(11,12)
• Operand-2 remains unchanged.
* The contents of R4 are not significant.
* R5 contains 00 00 00 9A (multiplicand)
* R11 contains 00 00 06 00.
* R12 contains 00 00 30 00.
* Location 14160 contains 00 00 00 83
M R1,D2(X2,B2)
71
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Fixed-Point Binary Arithmetic Topic: Multiplication
Multiplying Fullwords
If you want to multiply two fullwords, such as NUM5 and NUM6, and put the product in NUM7, which is also a
fullword, assuming that the absolute value of the product will not be greater than 231 - 1
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Fixed-Point Binary Arithmetic Topic: Multiplication
Multiply Halfword MH
Example :
• The half word (2 bytes) located at the address
specified by operand-2 is multiplied by the register
specified by operand-1
• The product is put in operand-1 MH 5,X'6B0'(13,12)
• Operand-2 remains unchanged.
* R5 contains 00 00 00 19 = 2510.
* R12 contains 00 00 18 00.
* R13 contains 00 00 01 50
* Locations 2000 contains 210 (decimal).
* R5 after execution 527100 (decimal)
4C RX BDDD
Format :
MH R1,D2(X2,B2)
72
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Fixed-Point Binary Arithmetic Topic: Multiplication
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Fixed-Point Binary Arithmetic Topic: Multiplication
Multiply Registers MR
Example :
• The value in operand-2 is multiplied with the 2nd-
word (the second register of the pair) of operand-1.
• The double word result is put in operand-1
• Operand-2 remains unchanged. MR R3,R4
R3 EQU 3
R4 EQU 4
Format :
MR R1,R2
73
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Topics:
Decimal to Binary Conversion
Multiplication
Division
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Fixed-Point Binary Arithmetic Topic: Division
Fixed-Point Division
There are only two fixed-point division operations, 1st Operand 2nd Operand
D and DR. There is no DH instruction.
EVEN-ODD REGISTER PAIR
Fixed-point arithmetic is integer arithmetic, so DIVIDEND
division produces both an integer quotient and an DOUBLEWORD
integer remainder. The dividend is a 64-bit
BEFORE EXECUTION
quantity in an even-odd register pair. The divisor
EVEN ODD
is a fullword. DOUBLEWORD
REGISTER REGISTER
After the division, the remainder is placed in the Specified by One Greater then
1st Operand 1st Operand
even numbered register, specified by the first
operand, and the quotient goes into the odd REMAINDER QUOTIENT
74
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Fixed-Point Binary Arithmetic Topic: Division
-17 5 -3 -2
17 -5 -3 2
-17 -5 3 -2
15 5 3 0
The table above indicates the results of some division operations, showing which signs are generated for both
quotient and remainder.
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Fixed-Point Binary Arithmetic Topic: Division
75
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Decimal Arithmetic Topic: Arithmetic Operations
Divide Instruction
Divide D
Example :
• Operand-1 is an even/odd pair of registers (dividend)
that is divided by the location specified by operand-2 . L R8,HEX0
• The remainder is put in R1-even and the quotient is L R9,HEX5
put in R1-odd. D R8,HEX2
R8 EQU 8
R9 EQU 9
HEX0 DC XL4'00000000'
HEX2 DC XL4'00000002'
HEX5 DC XL4'00000005‘
D R1,D2(X2,B2)
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Fixed-Point Binary Arithmetic Topic: Division
LOAD MULTIPLE
R2 32-bit R3 32-bit
DIVIDEND
76
12/12/2009
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Decimal Arithmetic Topic: Arithmetic Operations
Divide Registers DR
Example :
• Operand-1 is an even/odd pair of registers
(dividend) that is divided by by operand-2 . L R8,HEX5
• The remainder is put in R1-EVEN and the quotient SRDA R8,32(0) Shift value to R9
is put in R1-ODD L R3,HEX2
D R8,R3
R3 EQU 3
R8 EQU 8
R9 EQU 9
HEX2 DC XL4'00000002'
1D RR HEX5 DC XL4'00000005’
Assembler
AssemblerProgramming
Programming Part 2
Intermediate
Unit: Fixed-Point Binary Arithmetic Topic: Division
77