bB>HHH>~HHH0>HHH>~BBB<~RRBB<BBB$<BBB$<BB<~HHH0``~HHL2B~B<BJJ,~~@@~@@"~0JJJ<@@^`<BJR<@
/BASIC 8
*200

/INITIALIZATION

START,	CLA CLL
	TLS
	TAD	BUFF		/SET UP STORAGE AREA
	DCA	BUFFPT
	DCA	AMOUNT		/SET AMOUNT TO 0.
/ACCEPT ONE DIGIT.
ACCECPT,	JMS	CRLF
	TAD	M4		/SET COUNTER
	DCA	DIGCTR		/FOR 4 DIGITS
	TAD	TEMP1
	DCA	TEMP		/TEMPORARY INPUT STORAGE.
NEWDIG,	JMS	LISN		/GET A CHAR.
	DCA I	TEMP		/STORE IT
/CHECK THE CHARACTER.
CHECK,	TAD I	TEMP
	TAD	MDOLLAR
	SNA CLA
	JMP	ORDER		/YES, ORDER INPUT.
	TAD I	TEMP		/NO, CHECK FOR OCTAL INPUT.
	TAD	M260		/LESS THAN 260?
	SPA
	JMP	ERROR		/YES, ERROR.
	TAD	M10
	SNA CLA
	JMP	ERROR
	ISZ	TEMP		/INCREMENT STORAGE POINTER
	ISZ	DIGCTR		/4 DIGITS YET?
	JMP	NEWDIG		/NO, GET ANOTHER
/YES: PACK THE 4 DIGITS INTO ONE NUMBER.
PACK,	TAD	TEMP1
	DCA	TEMP
	DCA	HOLD		/CLEAR
	TAD	M4
	DCA	DIGCTR
DIGPCK,	TAD	HOLD		/CONTENTS OF HOLD IN AC
	CLL RAL			/ROTARE
	RTL
	TAD I	TEMP
	TAD	M260
	DCA	HOLD
	ISZ	TEMP
	ISZ	DIGCTR
	JMP	DIGPCK
	TAD	HOLD
	DCA I	BUFFPT
	TAD I	BUFFPT		/NEGATIVE INPUT?
	TAD	K4000
	SNA CLA
	JMP	ERROR		/YES: REJECT ENTRY.
	ISZ	AMOUNT		/NO: COUNT THE ENTRIES
	ISZ	BUFFPT		/SET UP FOR A NEW ENTRY
	JMP	ACCEPT
/PUT THE NUMBERS IN INCREASING ORDER.

ORDER,	TAD	AMOUNT		/SET UP A TALLY.
	CIA			/COUNT THE
	IAC			/NUMBER OF
	DCA	TALLY		/COMPARISONS
	DCA	FLAG
	TAD	BUFF
	DCA	X1
	TAD	BUFF
	IAC
	DCA	X2
TEST,	TAD I	X2
	CIA
	TAD I	X1
	SMA SZA CLA
	JMS	REVERSE
	ISZ	X1
	ISZ	X2
	ISZ	TALLY		/DONE COMPARING?
	JMP	TEST
	TAD	FLAG
	SZA CLA
	JMP	ORDER
	JMP	PRINT
REVERSE,0
ITAD I	X1
	DCA	HOLD
	TAD I	X2
	DCA I	X1
	TAD	HOLD
	DCA I	X2
	CLA CLL CMA
	DCA	FLAG
	JMP I REVERSE
/PRINT OUT THE ORDERED NUMBERS
PRINT,	JMS	CRLF		/RETURN THE CARRIAGE
	TAD	BUFF
	DCA	BUFFPT
	TAD	AMOUNT
	CIA
	DCA	PRNTCT
ANOTHR,	JMS	CRLF
	TAD	M4
	DCA	DIGCTR
	DCA	HOLD
	TAD I	BUFFPT
	CLL RAL

MORE,	TAD	HOLD
	RAL
	RTL
	DCA	HOLD
	TAD	HOLD
	AND	MASK7
	TAD	K260
	JMS	TYPE
	ISZ	DIGCTR
	JMP	MORE
	ISZ	BUFFPT
	ISZ	PRNTCT
	JMP	ANOTHR
	JMS	CRLF
	JMP	START
ERROR,	CLA
	TAD	QUEST
	JMS	TYPE
	JMP	ACCEPT
END=.

*100

TYPE,	0
	TSF
	JMP	.-1
	TLS
	CLA
	JMP I	TYPE
CRLF,	0
	TAD	K215
	JMS	TYPE
	TAD	K212
	JMS	TYPE
	JMP I	CRLF
LISN,	0
	KSF
	JMP	.-1
	KRB
	TLS
	JMP I LISN
BUFF,	END
BUFFPT,	0
M4,	7774
DIGCTR,	0
TEMP1,	.+2
TEMP,	0
	0
	0
	0
	0
MDOLAR,	7534
M10	-10
K4000,	4000
HOLD,	0
M260,	-260
AMOUNT,	0
FLAG,	0
TALLY,	0
X1,	0
X2,	0
PRNTCT,	0
MASK7,	7
K260,	260
K212,	212
K215,	215
QUEST,	277

$
*U*+B$$BB$$BB$$BL