Programming Note
The moving and logical comparing instructions may
also be used in decimal calculations.
Add Decimal AP [SS] L---I F __ A --L-L1 --L--L2 --'---,IB1 I o 8 1 2 16 20 32 36 47
The secood operand is added to the first operand,
and the sum is placed in the first-operand location.
Addition is algebraic, taking into account the
signs and all digits of both operands. All sign and
digit codes are checked for validity. If necessary,
high-order zeros are supplied for either operand.
When the first-operand field is too short to contain
all significant digits of the sum, a decimal overflow
occurs, and a program interruption is taken, provid­
ed that the decimal-overflow mask bit is one.
Overflow has two possible causes. The first is the
loss of a carry out of the high-order digit position of
the result field. The second cause is an oversized
result, which occurs when the second-operand field
is larger than the first-operand field and significant
result digits are lost. The field sizes alone are not an
indication of overflow.
The first-operand and second-operand fields may
overlap when their low-order bytes coincide; there­
fore, it is possible to add a number to itself.
The sign of the sum is determined by the rules of
algebra. When the operation is completed without an
overflow, a zero sum has a positive sign, but when
high-order digits are lost because of an overflow, a
zero sum may be either positive or negative, as de­
termined by what the sign of the correct sum would
have been.
Resulting Condition Code:
o Sum is zero
1 Sum is less than zero
2 Sum is greater than zero
3 Overflow
Program Exceptions:
Operation (if the decimal feature is not installed)
Access (fetch, operand 2; fetch and store, oper­
and 1)
Data
Decimal Overflow
Compare Decimal
The first operand is compared with the second, and
the condition code indicates the comparison result.
Comparison is algebraic, taking into account the
sign and all digits of both operands. All sign and
digit codes are checked for validity, and any valid
plus or minus sign is considered equal to any other
valid plus or minus sign, respectively. If the fields are
unequal in length, the shorter is extended with high­
order zeros. A field with a zero value and positive
sign is considered equal to a field with a zero value
but negative sign. Neither operand is changed as a
result of the operation. Overflow cannot occur in
this operation.
The first-operand and second-operand fields may
overlap when their low-order bytes coincide. It is
possible, therefore, to compare a number with itself.
Resulting Condition Code:
o Operands equal
1 First operand is low
2 First operand is high
3 -
Program Exceptions: , Operation (if the decimal feature is not installed)
Access (fetch, operands 1 and 2)
Data
Divide Decimal DP I o
The dividend (the first operand) is divided by the
divisor (the second operand) and replaced by the
quotient and remainder.
The quotient field is placed leftmost in the first­
operand field. The remainder field is placed right­
most in the first-operand field and has a size equal to
the divisor size. Together, the quotient and remain­
der occupy the entire dividend field; therefore, the
address of the quotient field is the address of the
first operand. The size of the quotient field in eight­
bit bytes is Lt-L2, and the length code for this field
is one less (L t -L2-1 ). When the divisor length code
is larger than seven (15 digits and sign) or larger
Decimal Instructions 149
than or eq[ual to the dividend length code, a specifi­
cation exception is recognized. The operation is sup­
pressed, and a program interruption occurs.
The dividend, divisor, quotient, and remainder are
all signed integers, right-aligned in their fields. The
sign of quotient is determined by the rules of
algebra from dividend and divisor signs. The sign of
the remainder has the same value as the dividend
sign. These rules are true even when the quotient or
remainder is zero. Overflow cannot occur. A quotient larger than the
number of digits allowed is recognized as a dedmal­
divide exception. The operation is suppressed, and a
program interruption occurs. The divisor and divi­
dend remain unchanged in their storage locations.
The divisor and dividend fields may overlap only
if their low-order bytes coincide.
Condition Code: The code remains unchanged.
Program Exceptions: Operation (if the decimal feature is not installed)
Access (fetch, operand 2; fetch and store, oper-
and 1) Specification Data
Decimal Divide
Programming Notes
The maximum dividend size is 31 digits and sign. Since the smallest remainder size is one digit and
sign, the maximum quotient size is 29 digits and sign.
The condition for a decimal divide exception can
be determined by a trial subtraction. The leftmost
digit of the divisor field is aligned with the leftmost­
less-one digit of the dividend field. When the divisor,
so aligned" is less than or equal to the dividend, a
divide exception is indicated.
A decimal-divide exception occurs if the dividend
does not have at least one leading zero.
Edit
ED [SS] _L -.1-.-
8
----'--(,
I 8 16 20 32 36 47 o
The format of the source (the second operand) is
changed from packed to zoned, and is modified un­
der control of the pattern (the first operand). The
edited result replaces the pattern.
Editing includes sign and punctuation control, and
the suppressing and protecting of leading zeros. It 150 System/370 Principles of Operation
also facilitates programmed blanking of all-zero
fields. Several fields may be edited in one operation,
and numeric information may be combined with
text.
The length field applies to the pattern (the first
operand). The pattern has the zoned format and may
contain any character. The source (the second oper­
and) has the packed format. The leftmost four bits
of a source byte must specify a decimal digit code (0000-1001); a sign code (1010-1111) is recognized
as a data exception and causes a program interrup­
tion. The rightmost four bits may specify either a
sign or a decimal digit.
The result is obtained as if both operands were
processed left to right one byte at a time. Overlap­ ping pattern and source fields give unpredictable
results.
During the editing process, each character of the
pattern is affected in one of three ways:
1. It is left unchanged.
2. It is replaced by a source digit expanded to
zoned format.
3. It is replaced by the first character in the pat­
tern, called the fill character.
Which of the three actions takes place is deter­
mined by one or more of the following: the type of
the pattern character, the state of the significance
indicator, and whether the source digit examined is
zero. Pattern Characters: There are four types of pattern
characters: digit selector, significance starter, field
separator, and message character. Their coding is as
follows:
Name
Digit selector Significance starter Field separator
Message character Code 0010 0000 0010 0001 0010 0010 Any other
The detection of either a digit selector or a signifi­
cance starter in the pattern causes an examination to
be made of the significance indicator and of a source
digit. As a result, either the expanded source digit or
the fill character, as appropriate, is selected to re­
place the pattern character. Additionally, encounter­
ing a digit selector or a significance starter may
cause the significance indicator to be changed.
The field separator identifies individual fields in a
multiple-field editing operation. It is always replaced
in the result by the fill character, and the significance
indicator is always off after the field separator is
encountered.
Previous Page Next Page