CT
APPENDIX B, "standard" assembler sample program.
PP
This example program reads an integer from the terminal attached
to the micro and stores the value in r1.
LD
;		Read an Integer from the Terminal
;
;	This program reads the decimal representation of a signed
;	integer in its character representation from the terminal
;	and stores its value (in 2's complement representation)
;	in R1.  If the values cannot be stored in 16 bits using
;	2's complement representation, an error message is written
;	to the terminal.
;
;
;	CONSTANTS
MS	EQU	>2D;	ASCII '-'
PS	EQU	>2B;	ASCII '+'
D0	EQU	>30;	ASCII '0'
D9	EQU	>39;	ASCII '9'
;
;
;	Initialize R0, R1, R2 and R15.
	CLR	R0;	R0 and R1 are used for multiplication
	CLR	R1;
	LI	R2,10;
	CLR	R15;
;
;
;	Read the first character.
	XOP	R3,11;
	SWPB	R3;	Put character into low byte of R3.
	CI	R3,MS;
	JNE	L1;
		INC	R15;	Set a flag.
		JMP	LP;
L1	EQU	$
	CI	R3,PS;
	JNE	CK;	Jump into the main loop (sick!)
;
;
;	Main loop--read a character, check it and update the value in R1.
LP	EQU	$
		XOP	R3,11;
		SWPB	R3;
;		Check for a valid character.
CK		CI	R3,D0;
		JLT	DN;
		CI	R3,D9;
		JGT	DN;
;		Update R1.
		AI	R3,-D0;
		MOV	R1,R0;
		MPY	R2,R0;
		MOV	R0,R0;
		JNE	OV;
		MOV	R1,R1;
		JLT	OV;
		A	R3,R1;
		CI	R1,>8000;
	JEQ	LP;
	JNO	LP;
;
;
;	Overflow.
OV	EQU	$;
	XOP	@ER,14;
	JMP	RT;
;
;
;	Done.  We need to check for the minint case.  Then we
;	check for a negative value.
DN	EQU	$;
	CI	R1,>8000;
	JNE	OK;
	MOV	R15,R15;
	JEQ	OV;
	JMP	RT;
OK	EQU	$;
	MOV	R15,R15;
	JEQ	RT;
	NEG	R1;
RT	B	@>3000;
;
;
;	DATA
ER	TEXT	'OVERFLOW'
DE