Divide Dec:imal (DP)
Assume that the signed, packed-decimal field at storage lo­ cations 2000-2004 (the dividend) is to be divided by the
signed, packed-decimal field at locations 3000-3001 (the
divisor). Also assume:
Instruction address: 005000 Location 5000 contains: FD 41 C 000 D 000 DP 0(5,12),0(2,13)
Register 12 contains 00 00 20 00 Register 13 contains 00 00 30 00 Storage locations 2000-2004 contain 01 23 45 67 8C
Storage locations 3000-3001 contain 32 1D
After the instruction at location 5000 is executed, the
dividend field is entirely replaced by the signed quotient
and remainder fields, as follows: 2000 2004 Locations 2'000-2004 \ 38 \46 \ 00 \ 01 lac I Quotient I Remainder I Notes:
1. Because the signs of the dividend and divisor are differ­ ent, the quotient receives a negative sign.
2. The remainder receives the sign of the dividend and the
length of the divisor.
3. If an attempt is made to divide the dividend by the one­ byte field at location 3001, the quotient will be too long
to fit within the four bytes allotted to it. A decimal­ divide exception exists, causing a program interruption.
Edit (ED)
Because the decimal-feature instructions operate only on
packed-decimal data, it is necessary to convert the data to
the zoned format before a legible report can be printed.
Moreover, if the report is to be useful to a great many peo­ ple, certain punctuation marks, such as commas and decimal
points, should be inserted in appropriate places. The highly
flexible EDIT instruction performs these two functions in a
single instruction execution.
This example shows step-by-step one way in which the
EDIT instruction can be used. The field to be edited (the
source) is four long; it is edited against a pattern 13
bytes long. The follOWing symbols are used: Svmbol b (Hexadecimal 40) ( (Hexadeci mal 21)
d (Hexadecimal 20) Meaning Blank character
Significance starter
Digit selector Assume that the source and pattern fields are: Source 1200 1203 306 System/370 Principles of Operation Pattern 1000 100C \40 120 120 16B 120 120 121 14B 120 1
20
\40 I C31 09
1
b d d d d ( d db C R
Execution of the instruction (assume that register 12 con­ tains 00 00 10 00) Machine Format Op Code
DE OC 1 C 1 000 Assembler Format Op Code D1 (L, B
1
), O
2
(B
2
)
ED 0(13,12),X'200'(12)
alters the pattern field as follows:
Significance
Indicator
Pattern Digit Before/After Rule
b off/off leave(1 )
d 0 off/off fill d 2 off/on(2) digit
on/on leave d 5 on/on digit
d 7 on/on digit
( 4 on/on digit
on/on leave d 2 on/on digit
d 6+ on/off(3) digit
b off/off fill C off/off fill R
off/off fill Notes: 200 Location 1000-100C bdd,dd( .ddbCR
bbd,dd( .ddbCR
bb2,dd( .ddbCR
same
bb2,5d(.ddbCR
bb2,57(.ddbCR
bb2,574.ddbCR
same
bb2,574.2dbCR
bb2,574.26bCR
same
bb2,574.26bbR
bb2,574.26bbb
(1) This character becomes the fill character.
(2) First nonzero decimal source digit turns on significance
indicator.
(3) Plus sign in the four low-order bits of the byte turns
off significance indicator.
Thus, after the instruction is executed, the source is un­ changed, and the pattern is as follows:
Pattern 1000 100C 140 140 1 F216B I F51 F71 F414B 1 F21 F6140 1
40
1
40
, b b 2 5 7 4 2 6 b b b Condition code = 2: result is greater than zero.
When printed, this new pattern field appears as:
2,574.26
If the number in the source field is changed to 000002 6D,
a negative number, and the original pattern is used, the edited
result this time is:
Pattern 1000 100C 1
40
1
40
1
40
1
40
1
40
1
40
1
40
14B 1 F2 I F6140 I ciEJ b b b b b b b 2 6 b C R Condition code = 1: result is less than zero.
The significance starter forces the significance indicator to
the on state and hence causes the decimal point to be pre­
served. Because the minus-sign code has no effect on the
significance indicator, the CR symbol is also preserved.
Edit and Mark (EDMK)
After an EDIT AND MARK operation, a symbol (such as a
dollar sign) can be inserted at the appropriate position in the
edited result. Usually a currency symbol is inserted to the
immediate left of the first significant digit in the amount;
however, if a decimal point appears in an amount less than
one, the currency symbol must be inserted to the immediate
left of the decimal point. A typical operation would leave no
blank between the currency symbol and the amount, thus
protecting against one form of alteration when the result is
printed on a check.
If significance is not forced by the significance starter, the
EDIT AND MARK operation inserts into general register 1
an address one more than the address at which a currency
symbol would normally be inserted. After one is subtracted
from the value in general register 1 (for example, by using a BRANCH ON COUNT instruction with R 1 set to one and
R2 set to zero), a MOVE instruction (MV!) may be used to
position the symbol in main storage.
Machine Format Op Code
92 5B I 000 Assembler Format Op Code 01 (B1), 12 MVI O(1),C'$'
If significance is forced, general register 1 remains un­
changed. Therefore, the address of the character following
the Significance starter should be placed in the register be­
fore the EDIT AND MARK instruction is performed. Multiply Decimal (MP)
Assume that the signed, packed-decimal field in storage lo­
cations 1202-1204 (the multiplicand) is to be multiplied by
the signed, packed-decimal field in locations 500-501 (the
multiplier). 1202 1204 Multiplicand 138 146 I 00 I 500 501 Multiplier Because there is a total of eight significant digits in the
multiplier and multiplicand, a field at least five bytes in
length must be reserved for the signed result. As indicated in
the programming note for MULTIPLY DECIMAL, a ZERO AND ADD into a larger field can provide the required space.
If it is assumed
Register 4 contains 00 00 12 00 Register 6 contains 00 00 05 00 then execution of the assembler instruction ZAP X'100'(5,4),2(3,4)
sets up a new multiplicand in storage locations 1300-1304 as follows. 1300 1304 Multiplicand (new) I 00 I 00 I 38 1 46 1 00 I Now, after the instruction
Machine Format Op Code L1 L2 B1
FC I 4 11 I 4 100 6 000 Assembler Format Op Code 01 (L
1
, B
1
), 02 (L2' B
2
) MP X'1 00'(5,4) ,0(2,6)
is executed, storage locations 1300-1304 contain the prod­
uct 01 2345 66 OC. Shift and Round Decimal (SRP) The SRP instruction can be used for shifting decimal fields
in main storage. When the field is shifted right, rounding can
also be done.
Decimal Left Shift
In this example, the contents of storage location FIELD 1
are shifted three places to the left, effectively multiplying
the contents of FIELD 1 by 1000. FIELD! is six bytes long,
and its contents are shown in "FIELDI (before)" below.
The following SRP instruction performs the above operation:
Machine Format Op Code
L1 13 S1 B2
°2 FO 5 I 0 **** 0 003 Assembler Format Op Code S1 S2' 13 SRP FIELOH6),3,0 Appendix I. Number Representation and Instruction-Use Examples 307
Previous Page Next Page