Divide (DIV)/OP=06

Format

OP AF BF A Syllable B Syllable C Syllable

OP = 06

AF is the length of the A Syllable field. AF may be indirect or may indicate the A Syllable is a literal. A value of 00 is equal to a length of 100 units.
BF is the length of the B Syllable field. BF may be indirect. A value of 00 is equal to a length of 100 units.

The A Syllable is the address of the divisor field. Address may be indexed, indirect or extended. The final address controller data type may be UN, SN or UA.
The B Syllable is the address of the dividend and remainder fields. Address may be indexed, indirect or extended. The final address controller data type may be UN, SN or UA.
The C Syllable is the address of the quotient field. Address may be indexed, indirect or extended. The final address controller data type may be UN, SN or UA.

Function

The Divide instruction divides the contents of one memory location B by the contents of a second memory location A storing the remainder in the B data field and storing the quotient in a third memory location C.

The length of the dividend field must be greater than the length of the divisor field (BF greater than AF). The length of the quotient field is the difference in length of the A and B fields (BF - AF). If the result is too large to fit into the quotient field or if BF is not greater than AF, the division is not performed, the contents of B and C are unchanged, the Comparison Flags are unchanged and the Overflow Flag is set.

If the absolute value of the divisor is not greater than the absolute value of the equivalent number of leading digits of the dividend, the division is not performed and the Overflow Flag is set with the Comparison Flags remaining unchanged. Note that a divisor which is zero will fail this test and the Overflow Flag will be set.

Store the absolute value of the quotient when the quotient field data type is unsigned (UN or UA). Store the standard EBCDIC form of the result sign as the first digit of the result when the quotient field data type is SN. Fill the zone digit with the EBCDIC numeric subset code (F) when the quotient field data type is alphanumeric (UA).

Store the absolute value of the remainder when the remainder field data type is unsigned (UN or UA). Fill the zone digit with the EBCDIC numeric subset code (F) when the remainder field data type is alphanumeric (UA). When the remainder field data type is signed numeric (SN), then the absolute value of the remainder is stored after the remainder sign digit, leaving the remainder sign digit with the original contents of the dividend sign digit.

Only the numeric digits of an alphanumeric field enter into the operation.

Unsigned (UN or UA) operands are assumed to be positive.

The sign of a quotient is positive if the sign of the divisor and the dividend are the same or the quotient is zero, otherwise the sign is negative.

If the dividend data type is SN, the sign of the dividend will be left unchanged in memory and will thus become the sign of the remainder. Therefore this final remainder sign could be other than *C* or *D* and a remainder of zero magnitude could have a negative sign.

If the operand data contains undigits other than in the sign digit, cause an Invalid Arithmetic Data fault. See Compatibility Notes A.16.

Comparison Flags

In all cases except overflow, set the Comparison Flags to indicate whether the sum is greater than (HIGH), equal to (EQUAL) or less than (LOW) zero.

Overlap

Partial overlap of the dividend field (B) and either of the other operands may produce inconsistent results.

If the address of the dividend field is the same as the address of the quotient field (B = C) and the respective address controllers are equal (BC = CC), a result will be produced that consists of the quotient followed by the least significant AF units of the remainder. In the case of SN data, the sign of the quotient will be stored in the first digit of the result followed by the quotient and the least significant AF digits of the remainder.

Examples

Example (1) Divide two signed numbers

OP AF BF A Syllable B Syllable C Syllable
06 01 04 A field SN B field SN C Field SN
                    BEFORE         AFTER
  A FIELD              +9        unchanged
  B FIELD           +0101           C0002  Remainder
  C FIELD            nnnn           C011   Quotient
  COMPARISON          nn            HIGH
  OVERFLOW            nn         unchanged

Example (2) Divide two signed fields, negative numbers

OP AF BF A Syllable B Syllable C Syllable
06 02 05 A field SN B field SN C Field SN
                    BEFORE         AFTER
  A FIELD             D12        unchanged
  B FIELD          D00187         D00007
  C FIELD            nnnn           C015
  COMPARISON          nn            HIGH
  OVERFLOW            nn         unchanged

Example (3) Divide producing overflow (Length problem)

OP AF BF A Syllable B Syllable C Syllable
06 04 03 A field SN B field SN C Field SN
                    BEFORE         AFTER
  A FIELD           D1014        unchanged
  B FIELD            D123        unchanged
  C FIELD            nnnn        unchanged
  COMPARISON          nn         unchanged
  OVERFLOW            nn            ON

Example (4) Divide producing overflow (Data problem)

OP AF BF A Syllable B Syllable C Syllable
06 02 03 A field SN B field SN C Field SN
                    BEFORE         AFTER
  A FIELD             D11        unchanged
  B FIELD            D125        unchanged
  C FIELD            nnnn        unchanged
  COMPARISON          nn         unchanged
  OVERFLOW            nn            ON

Example (5) Divide by zero

OP AF BF A Syllable B Syllable C Syllable
06 02 03 A field SN B field SN C Field SN
                    BEFORE         AFTER
  A FIELD             +00        unchanged
  B FIELD            D125        unchanged
  C FIELD            nnnn        unchanged
  COMPARISON          nn         unchanged
  OVERFLOW            nn            ON

Example (5) Total overlap of B and C

OP AF BF A Syllable B Syllable C Syllable
06 02 04 A field UN B field UN C Field UN
                    BEFORE         AFTER
  A FIELD              13        unchanged
  B FIELD            1127           8609
  COMPARISON          nn            HIGH
  OVERFLOW            nn         unchanged
instructions/div.txt · Last modified: 2008/05/13 07:22 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki