Google
 

Trailing-Edge - PDP-10 Archives - decuslib10-02 - 43,50242/posqrt.mac
There are no other files named posqrt.mac in the archive.
00010	        TITLE   POSQRT - POOMAS SQUARE ROOT OF 1/25/71.
00020	        SUBTTL  LIFTED FROM FORTRAN.
00030	;
00040	;    MODIFIED TO BLISS CALLING SEQUENCE AND STACK.
00050	;    ASSUMES BLISS RUN-TIME REGISTERS TO BE 0,1,2,3.
00060	;
00070		;TITLE	SQRT  V.022 
00080		;SUBTTL	10-DECEMBER-1969	ED YOURDON/NSR/KK
00090
00100
00110	;FROM V.020
00120	;FLOATING POINT SINGLE PRECISION SQUARE ROOT FUNCTION
00130
00140	;THE SQUARE ROOT OF THE  ARGUMENT IS CALCULATED.
00150	;THE ARGUMENT IS WRITTEN IN THE FORM
00160	;	X=	F*(2**2B)	WHERE 0<F<1
00170	;SQRT(X) IS THEN CALCULATED AS (SQRT(F))*(2**B)
00180	;SQRT(F) IS CALCULATED BY A LINEAR APPROXIMATION, THE NATURE
00190	;OF WHICH DEPENDS ON WHETHER 1/4 < F < 1/2 OR 1/2 < F < 1,
00200	;FOLLOWED BY TWO ITERATIONS OF NEWTON'S METHOD.
00210
00220	;THE CALLING SEQUENCE FOR THE SQUARE ROOT IS AS FOLLOWS:
00230	;	PUSH    0,<ARGUMENT>
00240	;	PUSHJ   0,POSQRT
00250	;THE ANSWER IS RETURNED IN ACCUMULATOR 3, THE VALUE-REGISTER.
00260
00270	        SREG=0;
00280	        FREG=2;
00290	        VREG=3;
00300		A=	VREG;
00310		B=	16;
00320		C=	17;
00330
00340		EXTERNAL	BLIPPE;
00350		ENTRY	POSQRT
00360
00370
00380	POSQRT:	PUSH    SREG,FREG;      STANDARD PROLOG.
00390		HRRZ	FREG,SREG;
00400		PUSH	SREG,B;
00410		PUSH	SREG,C;
00415		MOVE	B,-2(FREG);	PICK UP ARGUMENT FROM STACK.
00420	SQRT1:	JUMPE	B,SQ2		;IS B ZERO, YES GO TO SQ2
00430		JUMPL	B,NEGARG	;IS B LT 0, YES GO TO ERROR RETURN.
00440		ASHC	B, -33		;PUT EXPONENT IN B, FRACTION IN C
00450		SUBI	B, 201		;SUBTRACT 201 FROM EXPONENT
00460		ROT	B, -1		;CUT EXP IN HALF, SAVE ODD BIT
00470		HRRM	B, SQ1		;SAVE FOR FUTURE SCALING OF ANS
00480		LSH	B, -43		;GET BIT SAVED BY PREVIOUS INST.
00490		ASH	C, -10		;PUT FRACTION IN PROPER POSITION
00500		FSC	C, 177(B)	;PUT EXPONENT OF FRACT TO -1 OR 0
00510		MOVEM	C, A		;SAVE IT. 1/4 < F < 1
00520		FMP	C, S1(B)	;LINEAR FIRST APPROX,DEPENDS ON
00530		FAD	C, S2(B)	;WHETHER 1/4<F<1/2 OR 1/2<F<1.
00540		MOVE	B, A		;START NEWTONS METHOD WITH FRAC
00550		FDV	B, C		;CALCULATE X(0)/X(1)
00560		FAD	C, B		;X(1) + X(0)/X(1)
00570		FSC	C, -1		;1/2(X(1) + X(0)/X(1))
00580		FDV	A, C		;X(0)/X(2)
00590		FADR	A, C		;X(2) + X(0)/X(2)
00600	SQ1:	FSC	A, 0		;SCALE ANSWER FOR NEWTON AND EXP
00610		JRST	EXIT;
00620	SQ2:	MOVEI A,0		;ZERO ARGUMENT
00630	EXIT:	POP	SREG,C;		STANDARD EPILOG.
00640		POP	SREG,B;
00650		POP	SREG,FREG;
00660		POPJ	SREG,0;
00670
00680	NEGARG:	PUSH	SREG,ERRMSG;	ERROR MESSAGE FOR NEGATIVE ARG.
00690		PUSHJ	SREG,BLIPPE;
00700		SUB	SREG,[1000001];
00710		SETZ	VREG,0;
00720		JRST	EXIT;
00730
00740	S1:	0.8125			;CONSTANT, USED IF 1/4<FRAC<1/2
00750		0.578125		;CONSTANT, USED IF 1/2<FRAC<1
00760	S2:	0.302734		;CONSTANT, USED IF 1/4<FRAC<1/2
00770		0.421875		;CONSTANT, USED IF 1/2<FRAC<1
00780
00790	ERRMSG:	22;
00800
00810		END
00820