/FOCAL PATCHES FOR 8/E EAE  JVZ

/THESE PATCHES SUBSTANTIALLY REWRITE FOCAL'S MULTIPLY AND
/NORMALIZE ROUTINES IN ORDER TO USE EAE INSTRUCTIONS.  THE
/HARDWARE ASSUMED IS A PDP-8/E EXTENDED ARITHMETIC ELEMENT
/TYPE KE8-E.  MODE B INSTRUCTIONS ARE USED EXTENSIVELY. THE
/MEASURED EXECUTION TIME FOR A 36 BIT BY 36 BIT MULTIPLY
/IS ONLY 155 MICROSECONDS - ABOUT HALF THE TIME NEEDED FOR
/ONE 12 BIT PRODUCT (OF WHICH THERE ARE 9) USING THE STAN-
/DARD SOFTWARE ROUTINES AND FASTER BY A FACTOR OF 4.5 THAN
/THE PATCH SHOWN ON P. 89 OF THE FOCAL LISTING.  SIMILARLY
/THE TIME FOR A 1 BIT NORMALIZE HAS BEEN DECREASED BY A
/FACTOR OF 2.  FOR NEGATIVE NUMBERS A FACTOR OF 3 IS OB-
/TAINED SINCE NO INVERSION IS REQUIRED.  DIVIDE AND SOME
/OTHER ROUTINES HAVE ALSO BEEN REWRITTEN IN ORDER TO CON-
/SOLIDATE EMPTY AREAS.  THESE MODIFICATIONS MAKE AVAILABLE
/76 WORDS AND CHANGE THE ZERO-DIVISOR ERROR CODE TO 28.<1.

/EAE INSTRUCTIONS:

	MUY=7405
	DVI=7407
	NMI=7411
	SHL=7413
	MQL=7421
	SWAB=7431
	SCA=7441
	DST=7445
	SWBA=7447
	DPSZ=7451
	SWP=7521
	DCM=7575
	CAM=7621
	ACL=7701

	FIXTAB

/FOCAL INSTRUCTIONS:

	NEGATE=4451	/JMS I  51
	SHIFTL=4527	/JMS I 127
	PRINTC=4551	/JMS I 151
	ERROR2=4566	/JMS I 166

/FOCAL SYMBOLS:

	FLOP=40		/OPERAND
	FLAC=44		/ACCUMULATOR
	SIGNF=50	/SIGN OF RESULT
	P177=106
	P4000=124
	ODG=2501
	FPNT=6400

	REKOVR=5756	/FIELD 0
	FIELD 0

	*REKOVR
	SWBA		/RESET MODE FOR ERROR PRINTOUT


	FIELD 1

	*2442
PRNT,	0		/PRINT TWO DECIMAL DIGITS
	AND P177
	MQL DVI		/DIVIDE BY TEN
	    12
	SWP		/GET QUOTTENT
	JMS I ODG
	SWP		/GET REMAINDER
	JMS I ODG
	JMP I PRNT

	ZBLOCK 14	/TWELVE LEFT OVER

	*6113		/EXPONENT OUTPUT ROUTINE
	MQL DVI		/DIVIDE BY ONE HUNDRED
	    144
	SWP		/PRINT QUOTIENT
	SZA		/UNLESS IT'S ZERO
	JMS OUTDG
	SWP		/NOW PRINT REMAINDER
	JMS I .+2
	JMP I 6101	/FGO6
	PRNT

	ZBLOCK 7	/+1 IF "=" SIGN DELETED
OUTDG=.+1

/POINTERS REQUIRING CHANGES:

	*6304
RESOL5,	RESOLV		/FOR FLOATING INPUT

	*6314
	3147		/COMPENSATE PTEN

	*6565
OPMINS,	MINUS		/FOR SUBTRACTION

	*6576
	FLDV		/FOR DIVISION

	*6752
RESOL,	RESOLV		/FOR FIX
/THREE WORD BY THREE WORD UNSIGNED MULTIPLY ROUTINE

/  (A+B+C)*(D+E+F) = (ONE+TWO+THREE+FOUR+FIVE+SIX)

/THE METHOD GENERATES ALL 6 WORDS, BUT IS MODIFIED
/HERE TO PRESERVE ONLY THE 3 MOST SIGNIFICANT ONES.
/ADDITIONALLY THE RESULT IS ROUNDED OFF RATHER THAN
/SIMPLY TRUNCATED WHICH IMPROVES THE ACCURACY.

	*7004

MULT,	0
	TAD EX1
	JMS SIGN	/ADD EXPONENTS (PLUS 1)
	SNA		/TEST FOR ZERO OPERAND
	JMP ZER0
	SPA CLA		/POSITIVE OPERAND REQUIRED
	JMS MINUS
	SWAB		/SET MODE B

CF,	TAD C		/(STL RAR) FOR 2X2
	MQL MUY		/(JMP BE-1) FOR 2X2
	F
	MQL		/SAVE HIGH ORDER & ERASE SIX

BF,	TAD B
	SWP MUY		/USE PREVIOUS HIGH ORDER AS
	F		/REMAINDER IN THIS POSITION
	TAD P4000	/ROUND OFF
	DCA FOUR	/SAVE INTERMEDIATE RESULT
	RAL
	DCA THREE	/SAVE CARRY AND/OR CLEAR THREE

CE,	TAD C
	SWP MUY		/ADD IN PREVIOUS
	E		/PARTIAL PRODUCT
	TAD FOUR	/SUM HIGH ORDER PARTS
	MQL		/DISCARD FIVE AND SAVE CARRY
	SZL
	ISZ THREE	/ACCUMULATE CARRIES

AF,	TAD A
	SWP MUY
	F
	TAD THREE	/BUILD UP LEAST SIGNIFICANT
	DCA THREE	/PART OF FINAL RESULT

CD,	TAD C
	SWP MUY
	D
	TAD THREE
	DCA THREE	/ENTRY POINT FOR 2X2
BE,	TAD B
	SWP MUY
	E
	TAD THREE
	MQL		/DISCARD FOUR
	RAL
	DCA TWO		/SAVE CARRY

AE,	TAD A
	SWP MUY
	E
	TAD TWO		/SUM CARRY BITS
	DCA TWO		/WITH CARRY WORD

BD,	TAD B
	SWP MUY
	D
	TAD TWO
	SWP		/(MQL) FOR 2X2
	DCA OVER2	/SAVE THREE

AD,	TAD A
	SWP MUY
	D
	SWP DST		/SAVE ONE & TWO
	    HORD

	JMS I NORM	/NORMALIZE IF REQUIRED
	JMS RESOLV	/RESTORE PROPER SIGN
	JMP I MULT	/AND RETURN
NORM,	DNORM

	ZBLOCK 13	/ELEVEN FREE WORDS

/STANDARD DEFINITIONS:

	EX1=FLOP
	AC1H=FLOP+1
	AC1L=FLOP+2
	OVER1=FLOP+3

	EXP=FLAC
	HORD=FLAC+1
	LORD=FLAC+2
	OVER2=FLAC+3

/LETTER ASSIGNMENTS:

	A=HORD		/FLAC
	B=LORD
	C=OVER2

	D=AC1H		/OPERAND
	E=AC1L
	F=OVER1
/THESE SUBROUTINES PREPARE MULTIPLY AND DIVIDE FOR
/ANY COMBINATION OF SIGNED ARGUMENTS, OR FOR ZERO.
/THE RESULT OF EITHER IS ZERO IF FLAC IS ZERO; IF
/THE OPERAND IS ZERO THE PRODUCT IS ALSO ZERO, BUT
/ATTEMPTED DIVISION BY ZERO RETURNS WITH AN ERROR.

/THE SIGN ROUTINE IS ENTERED WITH THE OPERAND EXPO-
/NENT IN THE AC AND EXITS WITH THE SIGN OF THE OP-
/ERAND THERE TO FACILITATE FURTHER TESTING. THE
/SIGN OF THE RESULT IS STORED IN SIGNF.

SIGN,	0
	IAC		/ADD 1 TO EXPONENT OF OP.
	TAD EXP		/COMPUTE EXPONENT OF RESULT
	DCA EXP
	STL RAR		/SET BIT 0
	AND AC1H	/EXTRACT SIGN
	TAD HORD	/FORM XOR OF SIGNS
	DCA SIGNF	/SIGN OF RESULT
	TAD HORD
	SNA		/TEST IF RESULT = ZERO
	JMP ZER0
	SPA CLA		/ABSOLUTE VALUE REQUIRED
	NEGATE
	TAD AC1H	/CHECK THE OPERAND
	JMP I SIGN	/FOR VARIOUS THINGS

ZER0,	DCA FLAC
	DCA HORD
	DCA LORD
	JMP I .+1	/CLEARS 'OVER2'
	FPNT+3

MINUS,	0		/NEGATES OPERAND
	TAD OVER1
	SWAB
	TAD AC1L
	DCM
	SWP DST
	    AC1L
	SWBA
	CLA CML RAL
	TAD AC1H
	CIA
	DCA AC1H
	JMP I MINUS

RESOLV,	0		/SET PROPER SIGN
	TAD SIGNF
	SPA CLA
	NEGATE
	JMP I RESOLV

M43,	-43		/SHIFT COUNT FOR DIVIDE
/THIS IS THE FLOATING DIVIDE ROUTINE (THREE WORDS)

FLDV,	TAD EX1		/GET OPERAND EXPONENT
	CIA		/AND NEGATE
	JMS SIGN	/CHECK SIGNS & ZERO
	SNA		/CHECK FOR ZERO DIVISOR
	ERROR2		/THAT'S A NO-NO!
	SMA CLA
	JMS MINUS	/NEGATIVE OPERAND REQUIRED
	TAD M43		/SET UP LOOP COUNT
	DCA EX1
	SWAB		/CLEAR RESULT
	SKP

DLOOP,	SHIFTL		/SHIFT FLAC LEFT
	CLL		/THREE WORD SUBTRACTION
	TAD OVER1
	TAD OVER2
	DCA DNORM	/TEMPORARY STORAGE
	RAL
	TAD AC1L
	TAD LORD
	DCA SCNT
	RAL
	TAD AC1H
	TAD HORD
	SNL		/LINK=1 IF SUCCESSFUL (EG >0)
	JMP .+6
	DCA HORD	/SAVE RESULT
	TAD SCNT
	DCA LORD
	TAD DNORM
	DCA OVER2
	ACL		/SAVE LINK BITS IN QHI,QLO,MQ
	RAL
	MQL
	TAD QLO
	RAL
	DCA QLO
	TAD QHI
	RAL
	DCA QHI
	ISZ EX1		/INCREMENT STEP COUNTER
	JMP DLOOP

	TAD QHI		/SAVE RESULT AT THE END
	DCA HORD
	TAD QLO
	SWP DST
	    LORD
	JMS DNORM	/NORMALIZE IF NECESSARY
	JMS I RSLV	/SET PROPER SIGN
	JMP I .+1
	FPNT+1
RSLV,	RESOLV
	ZBLOCK 56	/FREE SPACE

/EAE SIGNED NORMALIZE ROUTINE: (THREE WORDS)

GT13,	NMI		/NORMALIZE LOWER PART
	SWP DST
	    HORD
	CAM SCA		/GET NEW SHIFT COUNT
	TAD P14		/PLUS TWELVE
	JMP ALL0-2
P14,	14

DNORM,	0
	CLA CLL		/CLEAR LINK FOR LATER
	TAD LORD
	MQL		/LOAD AC, MQ
	TAD HORD
	SWBA		/SET MODE A TO
	NMI		/PROTECT 4000 0000
	SWAB		/SAVE RESULT IN MQ
	SCA		/GET SHIFT COUNT
	DPSZ		/CHECK FOR ZERO
	CLL CIA
	TAD P14		/SET LINK IF < TWELVE
	CLA SCA
	DCA SCNT	/SAVE SHIFT COUNT
	TAD OVER2
	SWP DPSZ	/CHECK FOR ZERO
	SKP		/AC=RESULT
	JMP ALL0

	DCA HORD
	TAD LORD
	SNL		/.GE. TWELVE ?
	JMP GT13	/YES: IGNORE SIGN BITS
	SHL		/MODE B
SCNT,	0
	DCA LORD
	TAD SCNT	/CORRECT EXPONENT
	CIA
	TAD EXP
ALL0,	DCA EXP
	SWP		/CLEAR MQ
	DCA OVER2	/SAVE OR CLEAR LAST WORD
	SWBA		/RESTORE MODE A
	JMP I DNORM

QHI,	0
QLO,	0

TWO=	SIGN
THREE=	MINUS
FOUR=	RESOLV
	$
