ALI1Il7890121
BLI1Il943572!
If the value of
B$
is
larger than the value of A$. the contents of A$ and B$
are switched at lines 40 to
5'0
before
B$
is
subtracted from A$. to ensure that the
smaller number
is
subtracted from the larger one. A marker
is
set to indicate that
the variables have been switched,
For a detailed explanation of this routine. refer to step 3 of
"Numeric
String
Subtraction" (page
203).
Step
3:
Divide
A$
and
B$
into
two
smaller
segments. high and low,
1000
X=LEN(A$):Y=LEN(B$)
1002
1F
X>Y'
THEN
F=x,.~2:
GOTO
10136
113134
F=Y/2
11306
IF
F>INT(F)
THEN
F=INT(F)+l
1010
IF
X(=F
THEN
AH=e:AL=VAL(A$):GOTO
11340
10213
AH=VAL(LEFT$(A$,X-F»
10313
AL=VAL(RIGHT$(A$,F»
1040
IF
Y(=F
THEN
BH=0:BL=VAL(B$);GOTO
113713
11350
BH=VAL(LEFT$(B$,Y-F»
10613
BL=VAL(RIGHT$(B$,F»
Statements 1010 and 1040 compare the string lengths
with
the divider
point
F.
F
is
determined at lines 1002 and 1006. These lines
are
identical to lines
1002 and 1006
of
the
"Multiple
Integer
Addition"
program (page 198). If the string
is
shorter than
F.
AH
(or
BH)
is
assigned a zero value. leaving AL
(or
BU
with
the
entire string
as
its value. If the string
is
longer than F
it
must
be
divided into high
and
low
segments.
AH
is
assigned the leftmost LEN(AH) minus F digits.
A$111213141516171819IoI1121
B$
15171914131517121
AH
11Il1234561
BHIIIllllllllll1ll571
Lines 1000 through 1060
are
also similar to lines 1000 through 1060 of the
"Multiple
Integer
Addition"
program,
which
divides
A$
and B$ into AH. AL,
BH,
and
BL.
Refer to step 2 of
"Multiple
Integer
Addition"
(page 199) for review and
further expianation.
Step
4:
Calculate
the
differences
for
the
high-order and
low-order
seg-
ments.
BL
is
subtracted from AL, and
BH
is
subtracted from AH:
AH
11Il1234561
-BH\1Il1ll1ll1ll1ll571
ALI1Il7890121
-BLI1Il9435721
Before
the
segments
are
subtracted.
the
minuend
and subtrahend
must
be
compared.
If
the
value
of
BL is larger than
AL
the
difference
is
negative.
This crea tes problems because a negative
CL
cannot
be
concatenated onto
CH:
CHllIlxxxxxxl
=CLI-
y.xxxxxl=
CIlIlxxxxxx-xxxxxx 1 1ncorrect
209