/MPAK--MULTI-PRECISION PACKAGE	11-18-69
/GENERAL FORMAT OF OPERATION CALLS
/ CALL MP(<N>OP,ARG,M)
/ N- NEGATE PSUEDO ACCUMULATOR BEFORE OPERATION-OP
/ OP- ARITHMETIC OPERATION
/ ARG- ARGUMENT
/ M- ARGUMENT SIZE
/ OP'S USED MUST APPEAR IN EXTERNAL LIST IN F4
/ CALL ZRA  0 TO ACCUMULATOR
/ CALL NEG  NEGATE ACCUMULATOR
/
	.GLOBL .DA,.BA,.AP,.AO,.AW,.MF,.AV
	.GLOBL .AQ,.XCH,.ZS,.AI,.AS,.APH
	.GLOBL LD,ST,ADD,SUB,MUL,DIV,RDIV,NEG
	.GLOBL NST,NADD,NSUB,NMUL,NDIV,NRDIV,ZRA
	.GLOBL SETUP,MP,.MA
/
ASP1	7	/MAX ACC SIZE + 1
MAS1	-3	/INIT. FOR ACC SIZE=2
CAC	REG1	/CURRENT ACC POINTER
CMQ	REG2	/CURRENT MQ POINTER
CTP	REG3	/CURRENT TEMP POINTER
REG1	.BLOCK 25
REG2	.BLOCK 25
REG3	.BLOCK 25
/
/STEMS
NAP=SVMP
.MA=CAC
MP1=SETUP
WCT=OUTP
WCT2=ZRA
MQCT=NEG
LOW=OP
/
/SETUP- SETUP MULTI-PRECISION & SET ACC SIZE = N
SETUP	XX
	JMS*	.DA
	JMP	.+2
ASIZE	-2		/ACC SIZE
	LAC*	ASIZE
	CMA!STL
SU1	DAC	MAS1
	DAC	ASIZE
	ISZ	ASIZE	/-ACC SIZE  SKP IF 0
	TAD	ASP1
	SMA!SNL		/ACC>MAX SIZE OR .LE. 0?
	JMP*	SETUP	/SIZE 0K
	JMP	DIAG1	/ERR MESSAGE
/
/MP- GENERAL OP ROUTINE
MP	XX
	JMS*	.DA
	JMP	.+4
OP	0	/ALSO LOW
XX	0
NN	0
	LAC	XX
	DAC	ARG
	LAC*	NN
	SPA!SNA
	JMP	DIAG2	/WCT=0 OR -
	TAD	MAS1
	SMA!CMA!SZA
	JM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LOW
	JMP*	MP
/
SUB	JMS	NEG	/-ACC
NSUB	JMS	SVMP	/SAVE EXIT
	JMP	ADD
	JMS	NEG
	JMP*	MP1
/
SVMP	XX
	LAC	MP
	DAC	MP1
	LAC	SVMP
	DAC	MP
	ISZ	MP
	JMP*	SVMP
/
/STANDARDIZE & ADD TO ACC
.STD	XX
	LAC	CAC
	DAC	AP1
	DAC	AP2	/ST POINTER
	LAC	MAS1
	DAC	NAP	/N0 OF ACC WDS
STD1	JMS*	.AQ	/+ NEW VALUE
AP1		AP1
	LAC	AP1
	SAD	CAC	/FIRST WD?
	ISZ*	.MF	/YES,SET MULTI-PASS FLAG
	DZM*	AP1	/0 TO ACC WD
	ISZ	AP1	/NEXT WD
	DZM*	AP1
	ISZ	AP1
	DZM*	AP1
	ISZ	AP1
	JMS*	.XCH	/FLIP FAC & HAC
	JMS*	.ZS	/TEST FOR 0
	SZL
	JMP	STD2	/RES=0
	JMS*	.APH	/ST HAC = HI
AP2		AP2	/IF RES.NE.0
	JMS*	.AI	/NORM RES BY ADDING 0
		.MF+400000
	JMS	INC3	/ADV ST POINTER
	ISZ	AP2
	SKP
STD2	JMS*	.XCH	/FLIP FAC & HAC
	ISZ	NAP	/LAST WD OF ACC?
	JMP	STD1	/NO
	LAC	AP2
	SAD	AP1
	JMP	STD3	/EXIT IF AP1=AP2
	JMS*	.AP	/ELSE ST LAST PIECE
		AP2+400000
STD3	LAC	.STD
	SPA!CLA		/DONE IF +
	LAC*	.MF
	SZA		/DONE IF .NE. 0
	ISZ	.STD
	JMP*	.STD	/GO BACK THRU .STD
/
/
/MULTIPLY
NMUL	JMS	NEG
MUL	JMS	EXCH	/EXCHANGE AC & MQ POINTERS
	JMS	ZRA	/0 TO ACC
	JMS	.MDR	/COM ROUTINE FOR MUL&DIV
MUL2	NOP
	NOP
	JMP	EXIT	/COMMON EXIT
/
/DIVISION
NDIV	JMS	NEG
DIV	JMS	.MDR
	JMP	DV1
	JMS*	.BA
	JMS	EXCH	/PUT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CR
	CLL!CLC!RTL	/L=1,AC=-3
	JMP	SU1
DIAG2	JMS	OUTP
	536104		/WD
	406061		/AC CR
	LAC	ASIZE
	JMP	MPD
MES	011002	/ERROR MESSAGE HEADER
ACTR	0
 .ASCII '  ILLEGAL WD SIZE-- '
 .ASCII <136>'P SETS SIZE = '
	0
	500000
/
OUTP	XX	/WRITE ERROR MESSAGE
	LAC*	OUTP
	DAC	MES+6
	ISZ	OUTP
	LAC*	OUTP
	DAC	MES+20
	ISZ	OUTP
	.INIT	-3,1,RA
	CAL	02775	/.WRITE
		11
		MES
ARG	0
	.CLOSE	-3
	JMP	.	/IDLE
RA	JMP*	OUTP
/
	.END
