Decimal Arithmetic
Decimal arithmetic operates on data in the packed
format. In this format, two decimal digits are placed
in one eight-bit byte. Since data are often communi­
cated to or from external devices in the zoned format
(which has one digit in an eight-bit byte), the neces­
sary format-conversion operations are also provided
in this instruction group.
Data are interpreted as integers, right-aligned in
their fields. They are kept in true notation with a sign
in the low-order eight-bit byte.
Processing takes place right to left between main­
storage locations. All decimal arithmetic instructions
use a two-address format. Each address specifics the
leftmost byte of an operand. Associated with this ad­
dress is a length field, indicating the number of addi­
tional bytes that the operand extends beyond the first
byte.
The decimal arithmetic instruction set provides for
adding, subtracting, comparing, multiplying, and di­
viding, as well as the format conversion of variable­
length operands. Most decimal instructions are part of
the decimal feature.
The condition code is set as a result of all add-type
and comparison operations.
Data Format
Decimal operands reside in main storage only. They
occupy Helds that may start at any byte address and
are composed of one to 16 eight-bit bytes.
Lengths of the two operands specified in an instruc­
tion need not be the same. If necessary they are con­
sidered to be extended with zeros to the left of the
high-order digits. Results never exceed the limits set
by address and length specification. Lost carries or
lost digits from arithmetic operations are signaled as
a decimal overflow exception. Operands arc either in
the packed or zoned format.
Packed Decimal Number I Digit I Digit I Digit Digit I Digit I Digit I Digit I Sign I In the packed format, two decimal digits normally are
placed adjacent in a byte, except for the rightmost
byte of the field. In the rightmost byte a sign is placed
34
to the right of decimal digit. Both digits and a sign
arc encoded and occupy four bits each. Zoned Decimal Number I Zone I Digit I Zone [-_- Digit I Zone I Digit I Sign In the zoned format the low-order four bits of a byte,
the numeric, are normally occupied by a decimal digit.
The four high-order bits of a byte are called the zone,
except for the rightmost byte of the field, where nor­
mally the sign occupies the zone position.
Arithmetic is performed with operands and results
in the packed format. In the zoned format, the digits
are represented as part of an alphameric character
set. A PACK instruction is provided to transform zoned
data into packed data, an an UNPACK instruction per­
forms the reverse transformation. Moreover, the edit­
ing instructions may be used to change data from
packed to zoned.
The fields specified in decimal arithmetic other than
in PACK, UNPACK, and MOVE WITH OFFSET either should
not overlap at all or should have coincident rightmost
bytes. In ZERO AND ADD, the destination field may also
overlap to the right of the source field. Because the
code configurations for digits and sign are verified
during arithmetic, improper overlapping fields are
recognized as data exceptions. In move-type oper­
ations, the operand digits and signs are not checked,
and the operand fields may overlap without any re­
strictions.
The rules for overlapped fields are established for
the case where operands are fetched right to left from
storage, eight bits at a time, just before they are pro­
cessed. Similarly, the results are placed in storage,
eight bits at a time, as soon as they are generated.
Actual processing procedure may be considerably dif­
ferent because of the use of preferred storage for in­
termediate results. Nevertheless, the same rules are
observed.
Number Representation
Numbers are represented as right-aligned true integ­
ers with a plus or minus sign.
The digits 0-9 have the binary encoding 0000-1001. The codes 1010-1111 are invalid as digits. This set of
codes is interpreted as sign codes, with 1010, 1100, 1110, and 1111 recognized as plus and with 1011 and 1101 recognized as minus. The codes 0000-1001 are
invalid as sign codes. The zones are not tested for
valid codes as they are eliminated in changing data
from the zoned to the packed format.
The sign and zone codes generated for all decimal
arithmetic results differ for the extended binary-coded­
decimal interchange code (EBCDIC) and the American
Standard code for information interchange ( ASCII) .
The choice between the two codes is determined by
bit 12 of the psw. When bit 12 is zero, the preferred
EBCDIC codes are generated; these are plus, 1100; minus, 1101; and zone, 1111. When bit 12 is one, the
preferred ASCII codes are generated; these are plus, 1010; minus, 1011; and zone, 0101. Condition Code
The results of all add-type and comparison operations
are used to set the condition code. All other decimal
arithmetic operations leave the code unchanged. The
condition code can be used for deciSion-making by
subsequent branch-on-condition instructions.
The condition code can be set to reflect two types
of results for decimal arithmetic. For most operations
the states 0, 1, and 2 indicate a zero, less than zero,
and greater than zero content of the result field; the
state 3 is used when the result of the operations over­
flows.
For the comparison operation, the states 0, 1, and 2
indicate that the first operand compared equal, low,
or high.
CONDITION CODE SETTING FOR DECIMAL ARITHMETIC 0 1 2 3
Add Decimal zero < zero > zero overflow Compare Decimal equal low high
Subtract Decimal zero < zero > zero overflow
Zero and Add zero < zero > zero overflow
Instruction Format
Decimal instructions use the following format: 55 Format Op Code B1 I D1 I B2 7 8 11 12 1516 1920 31 32 35 36 47
For this format, the contents of the general register
specified by Bl is added to the content of the Dl field
to form an address. This address specifies the leftmost
byte of the first operand field. The number of operand
bytes to the right of this byte is specified by the Ll
field of the instruction. Therefore, the length in bytes
of the first operand field is 1-16, corresponding to a
length code in Ll of 0000-1111. The second operand
field is specified similarly by the L1, B2, and D2 in­
struction fields.
A zero in the Bl or B2 field indicates the absence of
the corresponding address component.
Results of operations are always placed in the first
operand field. The result is never stored outside the
field specified by the address and length. In the event
the first operand is longer than the second, the second
operand is extended with high-order zeros up to the
length of the first operand. Such extension never modi­
fies storage. The second operand field and the con­
tents of all general registers remain unchanged.
Instructions
The decimal arithmetic instructions and their mne­
monics and operation codes follow. All instructions
use the ss format and assume packed operands and
results. The only exceptions are PACK, which has a
zoned operand, and UNPACK, which has a zoned result.
The table indicates the feature to which each instruc­
tion belongs, when the condition code is set, and the
exception that causes a program interruption.
NAME MNEMONIC
Add Decimal AP Subtract Decimal SP Zero and Add ZAP Compare Decimal CP Multiply Decimal MP Divide Decimal DP Pack PACK Unpack UNPK Move with Offset MVO NOTES Addressing exception Condition code is set
TYPE SS T,C SS T,C SS T,C SS T,C SS T SS T SS SS SS A C D
DF
DK P S T
Data exception
Decimal-overflow exception
Decimal-divide exception
Protection exception
Specification exception
Decimal feature
Programming Note
EXCEPTIONS CODE P,A, D,DF FA P,A, D,DF FB P,A, D,DF F8
A, D F9 P,A,S,D FC P,A,S,D,DK FD P,A F2 P,A F3 P,A Fl
The moving, editing, and logical comparing instruc­
tions may also be used in decimal calculations.
Add Decimal AP 55 FA B1 I D1 1 B2 IJ[5] 7 8 11 12 1516 1920 31 32 35 36 47
The second operand is added to the first operand, and
the sum is placed in the first operand location.
Decimal Arithmetic 35
Previous Page Next Page