Google
 

Trailing-Edge - PDP-10 Archives - decuslib10-01 - 43,50161/mdiv.mp
There are no other files named mdiv.mp in the archive.
	TITLE MDIV
	ENTRY MDIV
	EXTERN MNORM,MSHIFT
MDIV:	Z
	MOVEM 17,STORE+17	;SAVE
	MOVEI 17,STORE		;THE
	BLT 17,STORE+16		;AC'S
	MOVE 1,(16)	;AC1=ADDR OF CHAR WORD, FIRST NO.
	MOVE 2,1(16)	;AC2=ADDR OF CHAR WORD, SECOND NO.
	MOVE 3,@2(16)	;AC3=PRECISION
	MOVE 4,3(16)	;AC4=ADDR OF CHAR WORD, RESULT
	MOVEI 6,TEMPX
	ADD 6,3		;AC6=ADDR OF N+1 OF TEMP (X)
	MOVEM 6,KEEP+2
	HRRZI 10,TEMPX
	HRL 10,1
	BLT 10,(6)	;MOVE FIRST NO. TO TEMP WORK AREA
	MOVEI 7,TEMPY
	ADD 7,3		;AC7=ADDR OF N+1 OF TEMP (Y)
	MOVEM 7,KEEP
	HRRZI 10,TEMPY
	HRL 10,2
	BLT 10,(7)	;MOVE SEC NO. TO TEMP WORK AREA
	JSA 16,MSHIFT	;MAKE SURE THAT WHEN DIV  X/Y,
	EXP TEMPX,3,-1	;FRACT X>FRACT Y TO GIVE FRACT RESULT
	MOVE 5,TEMPX	;AC5=CHAR OF FIRST NO.
	JUMPG 5,.+3	;ADJUST CHAR OF FIRST NO. DUE TO SHIFT
	SOJ 5,0
	JRST .+2
	AOJ 5,0
	MOVEM 5,TEMPX
	MOVE 6,TEMPY	;AC6=CHAR OF SECOND NO.
	SETZB 7,10
	JUMPGE 5,.+3
	SETO 7,0	;IF FIRST NO. NEG. SET AC7
	MOVN 5,5	;AC5=ABS VALUE OF CHAR WORD FIRST NO.
	JUMPGE 6,.+3
	SETO 10,0	;IF SEC. NO. NEG., SET AC10
	MOVN 6,6	;AC6=ABS VALUE OF CHAR WORD SEC. NO.
	JFCL 17,.+1
	HRLZI 11,200000	;AC11=2**34
	SUB 5,6
	ADD 5,11	;AC5=NEW CHAR OF RESULT
	JOV ERROR	;IF DIFFERENCE BTWN EXPONENTS TOO LARGE
	JUMPL5,ERROR	;TAKEERRORRETURN
	CAME 7,10	;IF AC7=AC10, SIGN OF RESULT IS +
	MOVN 5,5	;IF AC7 NOT =AC10, SIGN OF RESULT IS -
	MOVEM 5,(4)	;STORE NEW CHAR CARRYING SIGN OF RESULT
	JRST OK
ERROR:	HRLZI 17,STORE	;RESTORE AC'S
	BLT 17,17
	JRA 16,4(16)	;TAKE ERROR RETURN
OK:	AOJ 4,0
	MOVE 5,[POINT 1,(4),0] ;BYTE POINTER TO DEPOSIT RESULT BITS
	MOVE 6,KEEP+2
	MOVE 7,KEEP
	SETZM 0,TEMPX	;ONLY INTERESTED IN FRAC PART
	SETZM 0,TEMPY
	MOVEI 10,TEMPMY
	ADD 10,3	;AC10=ADDR OF N+1 OF TEMP (-Y)
	MOVEM 10,KEEP+1
	MOVN 12,(7)	;MOVE NEG. OF N+1 WORD OF TEMP (+Y)
	MOVEM 12,(10)	;TO N+1 WORD OF TEMP (-Y) STORAGE
	MOVE 14,7
	MOVE 15,10
ONE:	SOJ 14,0
	SOJ 15,0
	CAIGE 15,TEMPMY	;MOVE THE 1'S COMPLEMENT OF REST OF THE NO.
	JRST SHIFTO	;FROM TEMP (+Y) TO TEMP (-Y)
	SETCM 13,(14)
	MOVEM 13,(15)
	JRST ONE
SHIFTO:	MOVEI 11,TEMPX
	SOJ 11,0
	MOVEM 11,SHIFT+2
	MOVEI 0,43	;AC0=BIT COUNTER FOR DEPOSITING BITS
	MOVE 7,3	;AC7=WORD COUNTER FOR ALGORITHM
SHIFT:	AOJ 3,0
	JSA 16,MSHIFT
	EXP 0,3,1	;SHIFTING LEFT 1 BIT=MULTIPLYING BY 2
	SOJ 3,0
	MOVEI 11,TEMPX
	MOVEI 12,TEMPY
	MOVE 15,3
	AOJ 15,0
LOOP:	MOVE 13,(11)	;AC13=FIRST WORD OF TEMP (X)
	MOVE 14,(12)	;AC14=FIRST WORD OF TEMP (Y)
	CAMN 13,14
	JRST TWO
	CAML 13,14
	JRST SUBT	;IF NO. OF TEMPX>NO. IN TEMPY,ADD TEMPX+TEMPY
	SETZ 17,0
	IDPB 17,5	;DEPOSIT A 0 INTO RESULT IF TEMPX<TEMPY
	JRST THREE
TWO:	SOJE 15,SUBT	;IF 2 NO.S ARE EQUAL, MUST ADD TEMPX+TEMPMY
	AOJ 11,0
	AOJ 12,0
	JRST LOOP
SUBT:	MOVEI 17,1
	IDPB 17,5	;DEPOSIT A 1 INTO RESULT IF TEMPX >=TEMPY
	MOVE 16,3
	AOJ 16,0
	SETZ 15,0
LOOP1:	MOVE 13,(6)
	ADD 13,(10)
	ADD 13,15	;AC15 CONTAINS ANY CARRIES
	TLZN 13,400000	;MAKE SIGN 0, SKIP IF NO OVERFLOW
	JRST .+3
	SETZ 15,0
	JRST .+2	;IF NO CARRY SET AC15=0
	MOVEI 15,1	;IF A CRRY SET AC15=1 [IGNORE CARRY FROM LAST
	MOVEM 13,(6)	;WORD]    STORE IN TEMPX
	SOJ 6,0
	SOJ 10,0
	SOJG 16,LOOP1
	MOVE 6,KEEP+2
	MOVE 10,KEEP+1	;RESTORE ADDR OF (N+1) WORDS OF TEMPX TEMPMY
THREE:	SOJG 0,SHIFT
	IBP 0,5		;SKIP SIGN BIT
	MOVEI 0,43	;RESET BIT COUNTER
	SOJG 7,SHIFT
	SOJ 4,0
	MOVEM 4,NORM+1
NORM:	JSA 16,MNORM	;NORMALIZE RESULT
	EXP 0,3
	HRLZI 17,STORE	;RESTORE AC'S
	BLT 17,17
	JRA 16,5(16)	;TAKE NORMAL RETURN
STORE:	BLOCK 20
TEMPX:	BLOCK 200
TEMPY:	BLOCK 200
TEMPMY:	BLOCK 200
KEEP:	BLOCK 3
	END