A signed binary integer of either sign,
except for zero and the maximum negative number, can be changed to a number of
the same magnitude but opposite sign by
forming its two's complement. Forming
the two's complement of a number is
equivalent to subtracting the number
from zero. The two's complement of zero
is zero.
The two's complement of the maximum
negative number cannot be represented in
the same number of bits. When an opera­
tion, such as LOAD COMPLEMENT, attempts
to produce the two's complement of the
maximum negative number, the result is
the maximum negative number, and a
fixed-paint-overflow exception is recog­
nized. An overflow does not result,
however, when the maximum negative
number is complemented as an intermedi­
ate result but the final result is
within the representable range. An example of this case is a subtraction of
the maximum negative number from -1.
The product of two maximum negative
numbers of a given length is represent­
able as a positive number of double that
length.
In discussions of signed binary integers
in this publication, a signed binary
integer includes the sign bit. Thus,
the expression "32-bit signed binary integer" denotes an integer with 31
numeric bits and a sign bit, and the
expression "64-bit signed binary
integer" denotes an integer with 63
numeric bits and a sign bit.
In an arithmetic operation, a carry out
of the numeric field of a signed binary
integer is carried into the sign bit.
However, in algebraic left-shifting, the
sign bit does not change even if signif­
icant numeric bits are shifted out.
1. An alternate way of forming the
two's complement of a signed binary
integer is to invert all bits to
the left of the rightmost one bit,
leaving the rightmost one bit and
all zero bits to the right of it
unchanged.
2. The numeric bits of a signed binary
integer may be considered to repre­
sent a positive value, with the
sign representing a value of either
zero or the maximum negative
number. BINARY ARITHMETIC
SIGNED BINARY ARITHMETIC Addition and Subtraction
Addition of signed binary integers is
performed by adding all bits of each
operand, including the sign bits. When
one of the operands is shorter, the
shorter operand is considered to be
extended on the left to the length of
the longer operand by propagating the
sign-bit value.
Subtraction is performed by adding the
one's complement of the second operand
and a value of one to the first operand.
Fixed-Point Overflow
A fixed-point-overflow condition exists
for signed binary addition or
subtraction when the carry out of the
sign-bit position and the carry out of
the leftmost numeric bit position disa­
gree. Detection of an overflow does not
affect the result produced by the addi­
tion. In mathematical terms, signed
addition and subtraction produce a
fixed-point overflow when the result is
outside the range of representation for
signed binary integers. Specifically,
for ADD and SUBTRACT, which operate on
32-bit signed binary integers, there is
an overflow when the proper result would
be greater than or equal to +2
31
or less
than -2
31
The actual result placed in
the general register after an overflow
differs from the proper result by 232. A fixed-point overflow causes a program
interruption if allowed by the program
mask.
The instructions SHIFT LEFT SINGLE and
SHIFT LEFT DOUBLE produce an overflow
when the result is outside the range of
representation for signed binary inte­ gers. The actual result differs from
that for addition and subtraction in
that the sign of the result remains the
same as the original sign.
UNSIGNED BINARY ARITHMETIC
Addition of unsigned binary integers is
performed by adding all bits of each
operand. When one of the operands is
shorter, the shorter operand is consid­
ered to be extended on the left with
zeros. Unsigned binary arithmetic is
used in address arithmetic for adding
the X, B, and D fields. (See the Chapter 7. General Instructions 7-3
section "Address Generation" in Chapter 5, "Program Execution.") It is also used
to obtain the addresses of the function bytes in TRANSLATE and TRANSLATE AND TEST. Furthermore, unsigned binary
arithmetic is used on 32-bit unsigned
binary integers by ADD LOGICAL and SUBTRACT LOGICAL. Given the same two
operands, ADD and ADD LOGICAL produce
the same 32-bit result. The
instructions differ only in the inter­
pretation of this result. ADD
interprets the result as a signed binary
integer and inspects it for sign, magni­
tude, and overflow to set the condition
code accordingly. ADD LOGICAL inter­ prets the result as an unsigned binary integer and sets the condition code
according to whether the result is zero
and whether there was a carry out of bit
position o. Such a carry is not consid­
ered an overflow, and no program
interruption for overflow can occur for
ADD LOGICAL. SUBTRACT LOGICAL differs from ADD LOGICAL in that the one's complement of
the second operand and a value of one
are added to the first operand.
Programming Notes 1. Logical addition and subtraction
may be used to perform arithmetic
on multiple-precision binary-
integer operands. Thus, for
multiple-precision addition, ADD LOGICAL can be used to add the
corresponding parts of the operands
beginning with the lowest-order
parts. If the condition code indi­
cates a carry, a value of one
should be added to the sum of the
next-higher-order parts. If the
multiple-precision operands are
signed, ADD should be used on the
highest-order parts. The condition
code then indicates any overflow or
the proper sign and magnitude of
the entire result; an overflow is also indicated by a program inter­
ruption for fixed-point overflow if
allowed by the program mask. If
the multiple-precision operands are
unsigned, ADD LOGICAL should be
used throughout.
2. Another use for ADD LOGICAL is to
increment values representing bina­
ry counters, which are allowed to
wrap around from all ones to all
zeros without indicating overflow. SIGNED AND LOGICAL COMPARISON Comparison operations determine whether
two operands are equal or not and, for
7-4 System/370 Principles of Operation most operations, which of two unequal
operands is the greater (high).
Signed-binary-comparison operations are
provided which treat the operands as signed binary integers, and logical­
comparison operations are provided which
treat the operands as unsigned binary
integers or as unstructured data. COMPARE and COMPARE HALFWORD are
signed-binary-comparison operations.
These instructions are equivalent to SUBTRACT and SUBTRACT HALFWORD without
replacing either operand, the resulting
difference being used only to set the
condition code. The operations permit comparison of numbers of opposite sign
which differ by 2
31
or more. Thus,
unlike SUBTRACT, COMPARE cannot cause
overflow.
Logical comparison of two operands is
performed byte by byte, in a left-to­
right sequence. The operands are equal
when all their bytes are equal. When
the operands are unequal, the comparison
result is determined by a left-to-right
comparison of corresponding bit posi­
tions in the first unequal pair of
bytes: the zero bit in the first
unequal pair of bits indicates the low
operand, and the one bit the high oper­
and. Since the remaining bit and byte
positions do not change the comparison,
it is not necessary to continue compar­
ing unequal operands beyond the first
unequal bit pair. INSTRUCTIONS The general instructions and their
mnemonics, formats, and operation codes are listed in the figure "Summary of General Instructions." The figure also
indicates when the condition code is set
and the exceptional conditions in oper­
and designations, data, or results that
cause a program interruption.
A detailed definition of instruction
formats, operand designation and length,
and address generation is contained in the section "Instructions" in Chapter 5,
"Program Execution." Exceptions to the
general rules stated in that section are
explicitly identified in the individual
instruction descriptions.
Note: In the detailed descriptions of
the individual instructions, the mnemon­
ic and the symbolic operand designations
for the assembler language are shown
with each instruction. For LOAD AND TEST, for example, LTR is the mnemonic
and Rt, R2 the operand designation.
Previous Page Next Page