	ORG 0100H ;STANDARD CP/M ORIGIN
	LXI SP,STACK
I10:
	LHLD ZA$
	MVI A,32!MOV M,A
	LXI H, 1 !SHLD ZA$+2
	LXI H,ZA$!SHLD ZB
	MOV E,M!INX H!MOV D,M!XCHG!SHLD ZC
	JMP I10B
I10A: DB 53,48,32,73,84,69,82,65,84,73,79,78,83
I10B:LXI H,I10A
	LXI D,13
	LXI B,2
	CALL PSTR
	CALL PLNE
	LXI H,1
	SHLD ZM
FOR1: LXI D,-51
	DAD D! JC NXT1
	LXI H,0
	SHLD ZCOUNT
	LXI D,8191!LXI H,8191!SHLD ZA$+2
	LHLD ZA$!dad d!xchg!ora a
	MVI A, 1 !lxi b,-1
	stax d!DCX D!dad b!JC $-3
I20:
	LHLD ZC
	DCX H
	SHLD ZD
I80:
	LXI H,0
	SHLD ZI
FOR2: LXI D,-8191
	DAD D! JC NXT2
I90:
	LHLD ZD!INX H!SHLD ZD
	MOV L,M!MVI H,0!        SHLD ZB
	LXI D,-1! DAD D! JNC I170
I100:
	LHLD ZI
	DAD H
	LXI D, 3 
	DAD D
	SHLD ZPRIME
	XCHG
	LHLD ZI
	DAD D
	SHLD ZK
I120:
	LHLD ZK
	LXI D,8190
	XCHG
	MOV A,D! CPI 128! JNC I130! SUB H! JM I130! JNZ I160
	MOV A,L! CMP E! JC I160
I130:
	LHLD ZC
	XCHG
	LHLD ZK
	DAD D
	SHLD ZE
	MVI M, 0
	LHLD ZK
	XCHG
	LHLD ZPRIME
	DAD D
	SHLD ZK
	JMP I120
I160:
	LHLD ZCOUNT!INX H!SHLD ZCOUNT
I170:
	LHLD ZI!INX H!SHLD ZI!JMP FOR2
NXT2:
I180:
	LHLD ZM!INX H!SHLD ZM!JMP FOR1
NXT1:
I190:
	LHLD ZCOUNT
	LXI B,2
	CALL PNUM
	JMP I190B
I190A: DB 32,80,82,73,77,69,83,46
I190B:LXI H,I190A
	LXI D,8
	LXI B,2
	CALL PSTR
	CALL PLNE
I200:
	JMP 000H
	CALL 0000H
PSTR:	MOV	A,D! ORA A! JNZ PLOOP! MOV A,E! ORA A! RZ
PLOOP:	PUSH	D! PUSH B! MOV E,M! PUSH H! PUSH PSW
	CALL	0005H
	POP	PSW! POP H! POP B! POP D! INX H! DCX D! MOV A,E! ORA A
	JNZ	PLOOP
	MOV	A,D! ORA A! JNZ PLOOP
	RET
PLNE:	PUSH	B! MVI E,13
	CALL	0005! POP B! PUSH B! MVI E,10
	CALL	0005! POP B! RET
PNUM:	LXI	D,SAREA! PUSH B! MOV A,H! ANI 080H! JZ PNUM2
	MOV	A,H! CMA! MOV H,A! MOV A,L! CMA! MOV L,A! INX H
	MVI	A,'-'! STAX D! JMP PNUM3
PNUM2:	MVI	A,'+'! STAX D
PNUM3:	INX	D
	LXI	B,-10000! CALL DECDIG
	LXI	B,-1000! CALL DECDIG
	LXI	B,-100! CALL DECDIG
	LXI	B,-10! CALL DECDIG
	MOV	A,L! ORI '0'! STAX D
	LXI	D,0006H! LXI H,SAREA
	POP	B! JMP PSTR
DECDIG:	MVI	A,'0'-1
DECLP:	INR	A! DAD B! JC DECLP
	STAX	D! INX D! MOV A,B! CMA
	MOV	B,A! MOV A,C! CMA
	MOV	C,A! INX B! DAD B! RET
ARITH2:	MOV	A,H! CMA! MOV H,A
	MOV	A,L! CMA! MOV L,A! INX H! DAD D! RET
NC:	MOV	A,H! CMP D! JNZ NNE! MOV A,L! CMP E! JNZ NNE
NEQ:	MVI	A,0FFH! RET
NNE:	MVI	A,00H! RET
NC2:	mov a,h! adi 128! mov h,a! mov a,d! adi 128
	cmp h! jc NEQ! jnz NNE
	mov a,e! cmp l! jc NEQ! jmp NNE
NC4:	XCHG! JMP NC2
ZA$: DW STACK+257,0
ZB: DW 0
ZC: DW 0
ZM: DW 0
ZCOUNT: DW 0
ZD: DW 0
ZI: DW 0
ZPRIME: DW 0
ZK: DW 0
ZE: DW 0
	DS 64
STACK:
SAREA: DW 0
	END
