IBM 1130 User Manual page 514

Computing system
Hide thumbs Also See for 1130:
Table of Contents

Advertisement

The Decimal Arithmetic Subroutines
The IBM 1130 Commercial Subroutine Package fur-
nishes subroutines to perform the following four
arithmetic operations:
ADD to add two decimal values
SUB to subtract two decimal values
MPY to multiply two decimal values
DIV to divide two decimal values
All four have similar calling sequences, requiring
three basic elements:
The identification of the first variable
The identification of the second variable
An error code
Since the identification of each variable requires
three parameters (e.g. ,NUMBR, 1,6), each sub-
routine has a total of seven parameters.
If
no error conditions occur, the subroutine
leaves the error code, NER, set to whatever value
it had when the subroutine was called. Note that the
subroutines merely set the indicator NER. They
do not pause, print a message, or take any other
definite action. It is up to you to set NER before
calling the subroutines, and to test it after each is
complete.
Addition. The general form of the ADD sub-
routine is
CALL ADD (addend, augend, error code)
where the addend is added to the augend, and the
result is left in the augend.
There are two possible error conditions. Both
are illustrated in the accompanying examples (Fig-
ures 70.1 through 70.6).
Subtraction. The general form of the Subtract
subroutine is
CALL SUB (subtrahend, minuend, error code)
where the subtrahend is subtracted from the minuend,
and the result replaces the minuend.
There are two possible error conditions. Both
are included in the accompanying examples (Figures
70.7 through 70.11).
Multiplication. Because of its nature, multiplica-
tion is somewhat more involved than addition and
subtraction. For example, if you multiply two
Section
Subsections
Page
70
10
I
30
02
two-digit numbers, 95 and 86, your result is 8220,
a four-digit number.
If
you multiply a three-digit
number, 666, by a two-digit number, 55, your
answer is 36630, a five-digit number. The result
of a multiplication, the product, may have as many
digits as the sum of the number of digits in the
multiplier and the multiplicand. Therefore, you
must provide that many digits for the result.
The MPY subroutine accomplishes this in a very
straightforward manner. The multiplicand field,
which will be the eventual location of the product,
is extended to the left the same number of digits as
are contained in the multiplier.
For example, if
you multiply a four-digit number by a two-digit
number, the subroutine will extend the four-digit
field to the left two places, to hold the six-digit
product.
It does this regardless of what was in these posi-
tions previously. Obviously, you must consider this
fact when laying out your data areas in core storage.
Figures 70.12 and 70. 13 present several ex-
amples of the use of the MPY subroutine.
Division. The divide subroutine, DIV, has the
calling sequence
CALL DIV (divisor, dividend, error code)
with the result placed in the dividend field.
Before covering the DIV subroutine, a quick re-
view of division might be in order.
If
you divide
13 by 4, the result i!3 3 1/4, where
13 is the dividend
4 is the divisor
3 is the quotient
1 is the remainder
In other words:
dividend
divisor
quotient
+
remainder
divisor
This is the form of the result after use of DIV --
a quotient of 3 and a remainder of 1. Note that the
result is not 3.25. For this reason special care
must be taken when half-adjusting the result of a
division. Also note in Figures 70.14 through 70.17
that the length of the remainder field will be the
same as the length of the divisor.

Advertisement

Table of Contents
loading

Table of Contents