Remainder (REM)

Instruction Syntax

Op Code (Hex) Extender Operand 1 Operand 2 Operand 3 Operand [4-6]
REM 1073 Remainder Dividend Divisor
REMI 1873 Indicator options Remainder Dividend Divisor Indicator targets
REMB 1C73 Branch options Remainder Dividend Divisor Branch targets
Operand 1: Numeric variable scalar.

Operand 2: Numeric scalar.

Operand 3: Numeric scalar.

Operand 4-6:

• Branch Form–Branch point, instruction pointer, relative instruction number, or absolute instruction number.
• Indicator Form–Numeric variable scalar or character variable scalar.

Short forms

Op Code (Hex) Extender Operand 1 Operand 2 Operand [3-5]
REMS 1173 Remainder/Dividend Divisor
REMIS 1973 Indicator options Remainder/Dividend Divisor Indicator targets
REMBS 1D73 Branch options Remainder/Dividend Divisor Branch targets
Operand 1: Numeric variable scalar.

Operand 2: Numeric scalar.

Operand 3-5:

• Branch Form–Branch point, instruction pointer, relative instruction number, or absolute instruction number.
• Indicator Form–Numeric variable scalar or character variable scalar.

Description:

The remainder is the result of dividing the dividend by the divisor and placing the remainder in operand 1.

Operands can have packed or zoned decimal, signed or unsigned binary type.

Source operands are the dividend and divisor. The receiver operand is the remainder.

If operands are not of the same type, source operands are converted according to the following rules:

1. If any one of the operands has zoned or packed decimal type, source operands are converted to packed decimal.
2. Otherwise, the binary operands are converted to a like type. Note: unsigned binary(2) scalars are logically treated as signed binary(4) scalars.

Source operands are divided according to their type. Packed decimal operands are divided using packed decimal division. Unsigned binary division is used with unsigned source operands. Signed binary operands are divided using two's complement binary division.

Better performance can be obtained if all operands have the same type. Signed and unsigned binary division execute faster than packed decimal division.

The operands must be numeric with any implicit conversions occurring according to the rules of arithmetic operations as outlined in the Arithmetic Operations.

Floating-point is not supported for this instruction.

If the divisor has a numeric value of 0, a zero divide (hex 0C0B) exception is signaled. If the dividend has a value of 0, the result of the division is a zero value remainder.

For a decimal operation, the internal quotient value produced by the divide operation is always calculated with a precision of zero fractional digit positions. If necessary, internal alignment of the assumed decimal point for the dividend and divisor operands is performed to insure the correct precision for the resultant quotient value. These internal alignments are not subject to detection of the decimal point alignment exception. An internal quotient and the corresponding remainder value will be calculated for any combination of decimal attributes which may be specified for the instruction's operands. However, as described below, the assignment of the remainder value is limited to that portion of the remainder value which fits in the remainder operand.

If the dividend is shorter than the divisor, it is logically adjusted to the length of the divisor.

The division operation is performed according to the rules of algebra. Unsigned binary is treated as a positive number for the algebra. Before the remainder is calculated, an intermediate quotient is calculated. The attributes of this quotient are derived from the attributes of the dividend and divisor operands as follows:

Dividend   Divisor Intermediate Quotient
IM,SIM or SBIN(2) IM,SIM or SBIN(2) SBIN(2)
IM,SIM or SBIN(2) SBIN(4) SBIN(4)
IM,SIM,SBIN(2) or UBIN(2) DECIMAL(P2,Q2) DECIMAL(5+Q2,0)
IM,SIM,SBIN(2) or SBIN(4) UBIN(2) or UBIN(4) UBIN(4)
UBIN(2) or UBIN(4) IM,SIM,SBIN(2) or SBIN(4) UBIN(4)
UBIN(2) or UBIN(4) UBIN(2) or UBIN(4) UBIN(4)
SBIN(4) IM,SIM or SBIN(2) SBIN(4)
SBIN(4) or UBIN(4) DECIMAL(P2,Q2) DECIMAL(10+Q2,0)
DECIMAL(P1,Q1) IM,SIM,SBIN(2) or UBIN(2) DECIMAL(P1,0)
DECIMAL(P1,Q1) SBIN(4) or UBIN(4) DECIMAL(P1,0)
DECIMAL(P1,Q1) DECIMAL(P2,Q2) DECIMAL(P1-Q1+Q,0)

Where Q = Larger of Q1 or Q2

Note:
IM = IMMEDIATE
SIM = SIGNED IMMEDIATE
SBIN = SIGNED BINARY
UBIN = UNSIGNED BINARY
DECIMAL = PACKED OR ZONED

After the intermediate quotient numeric value has been determined, the numeric value of the remainder operand is calculated as follows:

```
Remainder = Dividend - (Quotient*Divisor)

```
When signed arithmetic is used, the sign of the remainder is the same as that of the dividend unless the remainder has a value of 0. When the remainder has a value of 0, the sign of the remainder is positive.

The resultant value of the calculation is copied into the remainder operand. If this operand is not the same type as that used in performing the operation, the resultant value is converted to its type. If necessary, the resultant value is adjusted to the length of the remainder operand, aligned at the assumed decimal point of the remainder operand, or both before being copied to it. Length adjustment and decimal point alignment are performed according to the rules of arithmetic operations as outlined in Arithmetic Operations.

If significant digits are truncated on the left end of the resultant value, a size (hex 0C0A) exception is signaled for those programs that request to be notified of size exceptions.

If a decimal to binary conversion causes a size (hex 0C0A) exception to be signaled in programs that request to be notified of size exceptions, the binary value contains the correct truncated result only if the decimal value contains 15 or fewer significant nonfractional digits.

Resultant Conditions

• Positive–The algebraic value of the numeric scalar remainder is positive.
• Negative–The algebraic value of the numeric scalar remainder is negative.
• Zero–The algebraic value of the numeric scalar remainder is zero.

• None

• None

Exceptions

• 0602 Boundary Alignment
• 0603 Range
• 08 Argument/Parameter
• 0801 Parameter Reference Violation
• 0C Computation
• 0C02 Decimal Data
• 0C0A Size
• 0C0B Zero Divide
• 10 Damage Encountered
• 1004 System Object Damage State
• 1044 Partial System Object Damage
• 1C Machine-Dependent
• 1C03 Machine Storage Limit Exceeded
• 20 Machine Support
• 2002 Machine Check
• 2003 Function Check
• 22 Object Access
• 2202 Object Destroyed
• 2203 Object Suspended
• 2208 Object Compressed
• 24 Pointer Specification
• 2401 Pointer Does Not Exist
• 2402 Pointer Type Invalid
• 2C Program Execution
• 2C04 Branch Target Invalid
• 2E Resource Control Limit
• 2E01 User Profile Storage Limit Exceeded
• 36 Space Management
• 3601 Space Extension/Truncation
• 44 Protection Violation
• 4401 Object Domain or Hardware Storage Protection Violation
• 4402 Literal Values Cannot Be Changed