}
Multiply
A$ and
B$
and align products
Input
values for A$. B$
}
If
multiplicand or
multiplier
= 0 then
answer
(C$)
= 0
}sOl
di.;d"
PO;"' f
At
the end of step
3,
the program looks Iike this:
213.
INPUT
A$,
B$
313
IF
VAL(A$)=a
OR
VAL(B$)=a
THEN
C$:.::"a" :
GOTO
1190
40
ZERO$=10a000000a0aaa000"
113013
X=LEN(A$):Y=LEN(B$)
10132
IF
X>Y
THEN
F=X/2:GOTO
100e
1004
F='T'/2
1006
IF
F>INT<F)THEN
F=INT(F)+l
11308
F$=LEFT$(ZERO$,F)
1010
IF
X<=F
THEN
AH=0:AL=VAL(A$):GOTO
1040
10213
AH=VAL<LEFT$<A$,X-F»
1030
AL=VAL(RIGHT$(A$,F»
1040
IF
Y<=F
THEN
BH=0:BL=VAL(B$):GOTO
1070
1050
BH=VAL(LEFT$(B$,Y-F»
1060
BL=VAL(RIGHT$(B$,F»
1070
P1$=STR$(BL*AL)
1080
P2$=STR$(BL$AH)+F$
1090
P3$=STR$(BH*AL)+F$
1100 P4$=STR$(BH$AH)+F$+F$
Divide A$ and
B$
into parts:
high and low
Step
4:
Add
the
four
products
together.
This
is
the most complicated part
of the
"Multiple
Integer
Multiplication"
program because parameters are passed
back and forth from the main program to an addition subroutine.
We
will
use a
portion of the
"Addition
via Numeric Strings" program
as
a subroutine to add the
products together (page 190). Below
is
the portion of the addition program we
will
convert into a subroutine:
2000
REM$$ADD
PRODUCTS$$
2010
BLANK$="
2020
X=LEN(A$):Y=LEN(B$)
2030
IF
X<Y
THEN
A$=LEFT$(BLANK$,Y-X)+A$
2040
IF
X>Y
THEN
B$=LEFT$(BLANK$,X-Y)+B$
2050
D=0:N=1:C$="1
2060
FOR
I=LEN(A$)
TO
1
STEP-l
2070
A=VAL(MID$(A$,I,l»
2080
A=A+D:D=0
2090
B=VAL(MID$(B$,
1,1»
2100
C=A+B
2110
IF
C>=10
THEN
D=l
2120
IF
D=l
AND
1=1
THEN
N=2
2130
C$=RIGHT$(STR$(C),N)+C$
2140
NEXT
1
At
line 1110 the contents of P1$ and P2$ are passed to the parameters
A$
and
B$,
which
are used in the addition subroutine (Iines 2000 to 2140).
1110
A$=Pl$:B$=P2$
A$
19191918101010111
B$
1919191810101011101010101
220