/INTEGER MATH PACKAGE                         OS8 FORTRAN II LIBRARY
/
/
/
/
/
/
/
/
/
/COPYRIGHT  (C)  1974,1977 BY DIGITAL EQUIPMENT CORPORATION
/
/
/
/
/
/
/
/
/
/
/THE INFORMATION IN THIS DOCUMENT IS SUBJECT TO CHANGE WITHOUT NOTICE
/AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT
/CORPORATION.  DIGITAL EQUIPMENT CORPORATION ASSUMES NO RESPONSIBILITY
/FOR ANY ERRORS THAT MAY APPEAR IN THIS MANUAL.
/
/THE SOFTWARE DESCRIBED IN THIS DOCUMENT IS FURNISHED TO THE PURCHASER
/UNDER A LICENSE FOR USE ON A SINGLE COMPUTER SYSTEM AND CAN BE COPIED
/(WITH INCLUSION OF DIGITAL'S COPYRIGHT NOTICE) ONLY FOR USE IN SUCH
/SYSTEM, EXCEPT AS MAY OTHERWISE BE PROVIDED IN WRITING BY DIGITAL.
/
/DIGITAL EQUIPMENT CORPORATION ASSUMES NO RESPONSIBILITY FOR THE USE
/OR RELIABILITY OF ITS SOFTWARE ON EQUIPMENT THAT IS NOT SUPPLIED BY
/DIGITAL.
/
/
/
/
/
/
/
/
/
/
/	VERSION 5A
/	APRIL 28, 1977
/	VERSION NUMBER IS AVAILABLE AT ENTRY POINTS
/
/
	ENTRY	IREM
	ENTRY	IABS
	ENTRY	DIV
	ENTRY	MPY
	ENTRY	IRDSW
	ENTRY	CLEAR
	ENTRY	SUBSC

/THE FOLLOWING DEFINITIONS ARE TO ENABLE LIBRARY
/OPTIMIZATIONS WHERE CRITICAL TIMING CONSIDERATIONS
/EXIST.  THEY SHOULD BE USED WITH EXTREME CAUTION,
/AND MUST REFERENCE CURRENT PAGE AND PAGE ZERO SYMBOLS
/ONLY.

	OPDEF	TADI	1400
	OPDEF	DCAI	3400
	OPDEF	JMSI	4400
	OPDEF	JMPI	5400

	LAP		/LV AUTO PAGING FOR PAL-III LIKE CODE

AC,	0		/LOCATIONS USED BY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P	LOOP2
	TAD	LOC
	JMP	LOOP3
DONE,	CLA
	TAD	SIGN
	RAR
	CLA
	DCA	SIGN
	TAD	AC
	SZL
	CIA
	RETRN	DIV

IREM,	BLOCK	1
	5		/INTEGER REMAINDER SUBROUTINE
	CLA		/ CALL 1,IREM
	INC	IREM#	/ ARG <UNUSED VARIABLE>
	INC	IREM#
	INC	SAV	/IREM MUST HAVE AN ARGUMENT
	TAD	MQ	/BECAUSE IT IS A FUNCTION.
	SPA		/IREM CAN BE CALLED ONLY ONCE
	TAD	LOC	/AFTER EACH DIVISION ...
	SKP		/SUBSEQUENT CALLS WILL RETURN ZERO.
LOP,	CLL RAR
	ISZ	SAV
	JMP	LOP
	RETRN	IREM
/
	PAGE

IABS,	BLOCK	1
	5		/INTEGER ABS VALUE FUNCTION
	TAD	IABS	/ CALL 1,IABS
	DCA	IAB1	/ ARG <INTEGER VARIABLE>
IAB1,	NOP
	TADI	IABS#
	INC	IABS#
	DCA	IAB2
	TADI	IABS#
	INC	IABS#
	DCA	IRDSW
IAB2,	NOP		/CDF TO ARGUMENT FIELD
	TADI	IRDSW
	SPA
	CIA
	RETRN	IABS

IRDSW,	BLOCK	1
	5		/READ SWITCH REGISTER FUNCTION
	CLA OSR
	INC	IRDSW#
	INC	IRDSW#
	RETRN	IRDSW

DIVZ,   CALL    1,ERROR	/ZERO DIVIDE ERROR
        ARG     DVERR
	CLA CLL CMA RAR
        RETRN   DIV

/THE FLOATING POINT CLEAR ROUTINE WAS ADDED TO "INTEGR"
/SO THAT PROGRAMS WHICH DO NOT USE FLOATING POINT MATH
/CAN RUN WITHOUT LOADING THE F.P. MATH PACKAGE.

CLEAR,	BLOCK	1
	5		/FLOATING POINT CLEAR FUNCTION
	DCA	IRDSW
	DCA	ACH
	DCA	ACM
	DCA	ACL
	TAD	IRDSW
	RETRN	CLEAR


/ THE FOLLOWING CAN BE USED FOR DOUBLY OR SINGLY
/ SUBSCRIPTED ARRAYS.  ON ENTRY THE AC SHOULD BE
/ NEGATIVE FOR FLOATING POINT VARIABLES.  THIS MAY
/ BE ANY NEGATIVE NUMBER FOR SINGLY SUBSCRIPTED
/ VARIABLES, AND MUST BE THE FIRST DIMENSION FOR
/ DOUBLY SUBSCRIPTED VARIABLES.  SOME EXAMPLES
/ FOLLOW:	(TO LOAD THE I,JTH ELEMENT OF AN FP ARRAY)

/	TAD (-M		/DIMENSIONS ARE M BY N
/	CALL 3,SUBSC
/	ARG J
/	ARG I
/	ARG ARRAY
/	LOC		/MUST BE A DUMMY VARIABLE
/	CALL 1,IFAD
/	ARG LOC

/ TO LOAD THE JTH ELEMENT OF AN INTEGER ARRAY:

/	CALL 2,SUBSC
/	ARG J
/	ARG INTARR
/	LOC		/STILL A DUMMY VARIABLE
/	TAD I LOC


S1,	BLOCK 1		/ADDR OF 1ST SUBSC
S2,	BLOCK 1		/ADDR OF 2ND SUBSC
A,	BLOCK 2		/ADDR OF ARRAY
R,	BLOCK 1		/ADDR FOR RESULT
TM,	0
FL,	0		/DOUBLE SUBSC FLAG
N,	0		/DIMENSION -- NEGATIVE IF FLOATING
MQA,	MQ		/FOR INDIRECT DCA

SUBSC,	BLOCK	1
	5			/FORTRAN SUBSCRIPTING ROUTINE
	DCA N		/SAVE THE DIMENSION
	TAD N
	SPA		/... ALSO ABS VALUE
	CMA
	DCAI MQA	/WARNING **THIS ASSUMES DF=CURR FIELD**
	CLA CLL CMA RAL /HOW MANY ARGS?
	TAD SUBSC#
	DCA 10
	TAD SUBSC
	DCA SUB1
SUB1,	NOP		/REPLACED BY CDF
	TADI 10
	AND (100
	SNA CLA		/DOUBLE SUBSCRIPTS?
	JMP SB0
	TADI 10		/YES, PICK UP ARGS...
	DCA SB2
	TADI 10
	DCA S2
	CMA
SB0,	DCA FL		/SET DBL SUBSC FLAG
	TADI 10
	DCA SB1
	TADI 10
	DCA S1
	TADI 10
	DCA A
	TADI 10
	DCA A#
	TAD SUBSC
	DCA SUB2
	TADI 10
	DCA R
	TAD 10
	IAC
	DCA SUBSC#
	ISZ FL		/DBL SUBSCRIPTING?
	JMP SB1
	CLA CMA		/GET THE 2ND SUBSC
SB2,	NOP		/CDF TO FIELD OF 2ND SUBSCRIPT
	TADI S2
	SZA		/IS IT A 1?
	JMSI MPYSBA	/NO, MULTIPLY BY DIMENSION
SB1,	NOP		/CDF TO FIELD OF 1ST SUBSCRIPT
	TADI S1
	TAD (-1		/MINUS ONE
	DCA TM
SUB2,	NOP		/REPLACED BY CDF
	TAD A
	DCAI R
	INC R
	TAD N
	SPA CLA		/FIXED OR FLOATING
	TAD TM
	CLL RAL
	TAD TM
	TAD A#
	DCAI R
	STL CLA RTL	/FAST 'RETRN SUBSC'
	TAD	SUBSC
	DCA	SUB3
SUB3,	NOP		/REPLACED BY 'CDF CIF'
	JMPI	SUBSC#

MPYSBA,	MPYSB

	END

