
/COPYRIGHT 1969, DIGITAL EQUIPMENT CORP., MAYNARD, MASS.
/%DIP	/DECIMAL INTEGER PRINT
/
/	THIS ROUTINE PRINTS THE SIGNED DECIMAL EQUIVALENT
/	OF AN 18-BIT BINARY NUMBER.  THE BINARY NUMBER
/	TO BE PRINTED MUST BE LOADED INTO THE AC
/	BEFORE CALLING THE ROUTINE.
/
/CALLING SEQUENCE:
/
/	JMS	%DIP		/SUBR CALL
/	NEXT INSTR		/RETURN HERE
/
/	THE BINARY NUMBER IS CONVERTED TO DECIMAL BY
/	A SERIES OF SUBTRACTIONS WHICH ACT AS A DIVIDE
/	INSTRUCTION. THE RANGE OF THE BINARY NUMBER
/	IS DETERMINED BY STEPPING DOWN A TABLE. AFTER
/	ITS RANGE IS DETERMINED, THE NUMBER IS DIVIDED
/	(SUBTRACT LOOP) BY THE RANGE BASE. THE
/	RESULT IS A 4-BIT NUMBER (DECIMAL) AND A
/	REMAINDER. THE DECIMAL CHARACTER IS PRINTED.
/	THE PROGRAM CONTINUES WITH THE REMAINDER
/	AS THE NEW NUMBER UNTIL THE DECIMAL EQUIVALENT
/	OF THE ORIGINAL 18-BIT BINARY NUMBER HAS
/	BEEN PRINTED.
/
/
%DIP	0
	DAC	%DIP1		/SAVE ORIGINAL NUMBER
	SPA			/IF ALREADY NEGATIVE,
	JMP	%DIPA		/DO NOT NEGATE
	CMA
	TAD	(1
%DIPA	DAC	%DIP3
	LAW	-5		/GO THROUGH SUBTRACTION
	DAC	%DIP2		/LOOP FIVE TIMES
%DIPB	JMS	%DIPG		/GET 1ST DIGIT
	LAC	%DIP4		/IF(AC.EQ.0) SPACE
	SZA			/IF(AC.NE.0) PRINT SIGN, THEN DIGIT
	JMP	%DIPE
	JMS	%OPSP
	ISZ	%DIP2		/5 SPACES?
	JMP	%DIPB
%DIPC	JMS	%DIPF		/PRINT SIGN
%DIPD	LAC	%DIP3		/PRINT LAST DIGIT
	CMA
	TAD	(261
	JMS	%OPOUT
	LAC	(TAD %DIPTB	/RESTORE RANGE TABLE
	DAC	%DIPG2		/FOR NEXT TIME
	LAC	%DIP1
	JMP*	%DIP		/BEFORE EXITING.
%DIPE	JMS	%DIPF		/PRINT SIGN
	LAC	%DIP4		/DIGIT JUST BUILT
	TAD	(260		/COMPLETE THE ASCII CHAR
	JMS	%OPOUT
	ISZ	%DIP2		/5 CHARACTER?
	SKP
	JMP	%DIPD		/YES...PRINT THE LAST DIGIT
	JMS	%DIPG
	JMP	%DIPE+1
/
%DIPF	0			/PRINT THE SIGN
	LAC	%DIP1
	RAL
	LAW	240		/PLUS
	SZL
	LAW	255		/MINUS
	JMS	%OPOUT
	JMP*	%DIPF
%DIPG	0			/BUILD A DECIMAL DIGIT
	DZM	%DIP4		/CLEAR BUILDER WORD
	LAC	%DIP3
	JMP	%DIPG2
%DIPG1	DAC	%DIP3		/SUM BECOMES NEW WORD
	ISZ	%DIP4		/BUILD DIGIT
%DIPG2	TAD	%DIPTB		/IF THE SUM OF THIS ADD
	SPA!SNA			/IS POSITIVE THE RANGE HAS
	JMP	%DIPG1		/NOT BEEN REACHED YET OR IT
	ISZ	%DIPG2		/HAS BEEN REACHED AND THEN
	JMP*	%DIPG		/SURPASSED-EXIT
%DIP1	0
%DIP2	0
%DIP3	0
%DIP4	0
%DIPTB	303240		/DECIMAL TABLE -	100,000
	023420		/		10,000
	001750		/		1,000
	000144		/		100
	000012		/		10
	000001		/		1
%OPOUT	0
	TSF
	JMP	.-1
	TLS
	JMP*	%OPOUT
/
/
%OPSP	0
	LAW	240
	JMS	%OPOUT
	JMP*	%OPSP
/%OPZ/%OPT/%OPS		/OCTAL PRINT SUBROUTINES
/THE OCTAL PRINT SUBROUTINES TYPE THE CONTENTS OF
/THE ACCUMULATOR IN OCTAL MODE WITH LEADING
/ZEROES SUPPRESSED IF DESIRED.
/
/CALLING SEQUENCE:
/	JMS	%OPS/%OPT/%OPZ	/SUBR CALL
/	NEXT INSTR		/RETURN HERE
/
/OPTIONS:	THE (JMS %OPS) ENTRY CAUSES NON-SIGNIFICANT
/	LEADING ZEROES TO BE SUPPRESSED; THE PRINTED
/	NUMBER OCCUPYING ONLY THE NUMBER OF SPACES
/	NEEDED TO PRINT ALL SIGNIFICANT DIGITS.
/
/	THE (JMS %OPT) ENTRY CAUSES NON-SIGNIFICANT
/	LEADING ZEROES TO BE SUPPRESSED BY BLANKS; THE
/	PRINTED NUMBER IS RIGHT JUSTIFIED IN SIX SPACES.
/
/	THE (JMS %OPZ) ENTRY CAUSE NO ZERO SUPPRESSION.
%OPT	0			/ENTRY-EXIT
	DAC	%OP1		/SAVE AC FOR RETURN
	LAW	240		/PRINT SPACES UNTIL
	DAC	%OPPE		/A SIGNIFICANT DIGIT IS FOUND
	JMS	%OPPA		/GO TO COMMON ROUTINE
	JMP*	%OPS		/EXIT
/
/
%OPS	0			/ENTRY - EXIT
	DAC	%OP1		/SAVE AC FOR RETURN
	LAC	%OPPE+1		/DO NOT MOVE PRINT CARRIAGE
	DAC	%OPPE
	JMS	%OPPA		/GO TO COMMON ROUTINE
	JMP*	%OPT		/EXIT
/
/
%OPZ	0			/ENTRY - EXIT
	DAC	%OP1		/SAVE AC FOR RETURN
	LAC	%OPPE-1		/PRINT ZEROES
	DAC	%OPPE
	JMS	%OPPA		/GO TO COMMON ROUTINE
	JMP*	%OPZ		/EXIT
%OPPA	0			/COMMON ROUTINE
	LAC	%OP1		/GET STARTING VALUE
	RCL			/CLEAR LINK AND DO THE
	DAC	%OP2		/FIRST SHIFT TO PREPARE
	LAW	-5		/FOR LOOP
	DAC	%OP3		/LOOP 5 TIMES
	DZM	%OP4		/1ST SIGNIFICANT DIGIT FLAG
%OPPB	LAC	%OP2		/LOOP
	RTL
	RAL
	DAC	%OP2
	AND	(7		/KEEP ONLY RIGHTMOST 3-BITS
	SNA
	JMP	%OPPD
	ISZ	%OP4		/TURN ON SIGNIFICANT DIGIT FLAG
%OPPC	TAD	(260
	JMS	%OPOUT
	ISZ	%OP3		/FINISHED
	JMP	%OPPB		/NO...LOOP AGAIN
	LAC	%OP1		/YES...PRINT THE LAST DIGIT
	AND	(7		/REGARDLESS OF OUTPUT MODE
	TAD	(260
	JMS	%OPOUT		/PRINT IT
	LAC	%OP1		/RESTORE AC
	JMP*	%OPPA		/EXIT
%OPPD	LAC	%OP4		/GET SIG. DIGIT FLAG
	SZA!CLA			/IF NUMBER IS 0 AND THE SIG. DIGIT
	JMP	%OPPC		/FLAG IS ON PRINT A ZERO
%OPPE	XX			/JMP (%OPPC+1=NO MOVE, % OPSP=SPAC,%OPPC=0)
	JMP	%OPPC+1
/
/
/
%OP1	0			/SAVE INPUT HERE
%OP2	0			/SHIFT THROUGH HERE
%OP3	0			/LOOP COUNT
%OP4	0			/SIGNIFICANT DIGIT FLAG
	.EOT
	.EOT
