CHAPTER DECIMAL INSTRUCTIONS Decimal-Number Formats ••.•.•••..•.••••...•.•.••..•.•....•. 8-1 Zoned Format ••..•...•••••••...••.•••........••••.....•.• 8-1
Packed Format •...•.....•.•..•....••.........•.•......... 8-1
Decimal Codes •.•.•.....•••.•.•.•...•.......••.•.•....•.. 8-2
Decimal Operations ••...•••••.•.•.....•.•.•••.•••..••.•.... 8-2
Deci mal-Ari thmeti c Instructi ons .•.••.•.••....•.••••.•... 8-2
Editing Instructions .................................... 8-3
Execution of Decimal Instructions •.............•........ 8-3 Other Instructions for Decimal Operands •....•....••.•.•. 8-3
Instructions ••.••.••••.....•.•....•.••...•..••...•.•...•.. 8-3
ADD DECIMAL ....•••.......•.•.....•.........••...••.•.... 8-5 COMPARE DECIMAL ......................................... 8-5
DIVIDE DECIMAL .•••...•..••...•..•...........••..•....•.. 8-5
EDIT .....•...•..•••..••...•.••••.••....•...•.••••....•.. 8-6
EDIT AND MARK ..••.......••.•......•...........•..•...•.. 8-9
MUl TIPl Y DECIMAL ......•....•............................ 8-10 SHIFT AND ROUND DECIMAL •••........•....•...•...••..•.•.. 8-10 SUBTRACT DECIMAL .••...••.••..•.•.....•.•.•.•.......••... 8-11 ZERO AND ADD ••...••..•.•••••....••.......•.•.••.•.....•. 8-12
The decimal instructions of this chapter
perform arithmetic and editing oper­
ations on decimal data. Additional
operations on decimal data are provided
by several of the instructions in Chap­ ter 7, "General Instructions." Decimal
operands always reside in storage, and
all decimal instructions use the SS instruction format. Decimal operands
occupy storage fields that can start on
any byte boundary.
DECIMAL-NUMBER FORMATS Decimal numbers may be represented in
either the zoned or packed format. Both
decimal-number formats are of variable
length; the instructions used to operate
on decimal data each specify the length
of their operands and results. Each
byte of either format consists of a pair
of four-bit codes; the four-bit codes
include decimal-digit codes, sign codes, and a zone code. ZONED FORMAT N IZ/SI N Z N Z N Z In the zoned format, the rightmost four
bits of a byte are called the numeric
bits (N) and normally consist of a code
representing a decimal digit. The left­
most four bits of a byte are called the
zone bits eZ), except for the rightmost
byte of a decimal operand, where these
bits may be treated either as a zone or
a s a sign (S).
Decimal digits in the zoned format may
be part of a larger character set, which
includes also alphabetic and special
characters. The zoned format is, there­
fore, suitable for input, editing, and
output of numeric data in human-readable
form. There are no decimal-arithmetic
instructions which operate directly on
decimal numbers in the zoned format;
such numbers must first be converted to
the packed format.
The editing instructions produce a
result of up to 256 bytes; each byte may
be a decimal digit in the zoned format, a message byte, or a fill byte. PACKED FORMAT D
D D
D
D
D
D S In the packed format, each byte contains
two decimal digits (D), except for the
rightmost byte, which contains a sign to
the right of a decimal digit. Decimal
arithmetic is performed with operands in
the packed format and generates results
in the packed format.
The packed-format operands and results
of decimal-arithmetic instructions may
be up to 16 bytes (31 digits and sign), except that the maximum length of a
multiplier or divisor is eight bytes (15
digits and sign). In division, the sum
of the lengths of the quotient and Chapter 8. Decimal Instructions 8-1
remainder may be from two to 16 bytes.
The editing instructions can fetch as
many as 256 decimal digits from one or
more decimal numbers of variable length, each in the packed format. DECIMAL CODES The decimal digits 0-9 have the binary
encoding 0000-1001. The preferred sign codes are 1100 for
plus and 1101 for minus. These are the
sign codes generated for the results of
the decimal-arithmetic instructions and
the CONVERT TO DECIMAL instruction.
Alternate sign codes are also recognized
as valid in the sign position: 1010, 1110, and 1111 are alternate codes for
plus, and 1011 is an alternate code for
minus. Alternate sign codes are
accepted for any decimal source operand,
but are not generated in the completed
result of a decimal-arithmetic instruc­
tion or CONVERT TO DECIMAL. This is
true even when an operand remains other­
wise unchanged, such as when adding zero
to a number. An alternate sign code is,
however, left unchanged by MOVE NUMERICS, MOVE WITH OFFSET, MOVE ZONES, PACK, and UNPACK. When an invalid sign or digit code is
detected, a data exception is
recognized. For the decimal-arithmetic
instructions and CONVERT TO BINARY, the
action taken for a data exception
depends on whether a sign code is inval­
id. When a sign code is invalid, the
operation is suppressed regardless of
whether any other condition causing a
data exception exists. When an invalid
digit code is detected but no sign code
is invalid, the operation is terminated.
For the editing instructions EDIT and
EDIT AND MARK, an invalid sign code is
not recognized. The operation is termi­
nated for a data exception due to an
invalid digit code. No validity check­
ing is performed by MOVE NUMERICS, MOVE WITH OFFSET, MOVE ZONES, PACK, and UNPACK. The zone code 1111 is generated in the
left four bit positions of each byte
representing a zone and a decimal digit in zoned-format results. Zoned-format
results are produced by EDIT, EDIT AND MARK, and UNPACK. For EDIT and EDIT AND
MARK, each result byte representing a
zoned-format decimal digit contains the
zone code 1111 in the left four bit
positions and the decimal-digit code in the right four bit positions. For UNPACK, zone bits with a coding of 1111
are supplied for all bytes except the
rightmost byte, the zone of which
receives the sign.
8-2 System/370 Principles of Operation The meaning of the decimal codes is
summarized in the figure "Summary of
Digit and Sign Codes." Programming Note
Since 1111 is both the zone code and an
alternate code for plus, unsigned (posi­
tive) decimal numbers may be represented in the zoned format with 1111 zone codes in all byte positions. The result of
the PACK instruction converting such a
number to the packed format may be used
directly as an operand for decimal
instructions.
Recognized As Code Digit Sign 0000 0 Invalid 0001 1 Invalid 0010 2 Invalid 0011 3 Invalid 0100 4 Invalid 0101 5 Invalid 0110 6 Invalid 0111 7 Invalid 1000 8 Invalid 1001 9 Invalid 1010 Invalid Plus 1011 Invalid Minus 1100 Invalid Plus (preferred) 1101 Invalid Minus (preferred) 1110 Invalid Plus 1111 Invalid Plus (zone)
Summary of Digit and Sign Codes DECIMAL OPERATIONS The decimal instructions in this chapter
consist of two classes, the decimal­ arithmetic instructions and the editing
instructions. DECIMAL-ARITHMETIC INSTRUCTIONS The decimal-arithmetic instructions
perform addition, subtraction, multipli­
cation, division, comparison, and shift­
ing. Operands of the decimal-arithmetic
instructions are in the packed format
and are treated as signed decimal inte­
gers. A decimal integer is represented
in true form as an absolute value with a
separate plus or minus sign. It
contains an odd number of decimal
Previous Page Next Page