;
; SYSLIB Module Name:  SEVAL3
; Author:  Richard Conn
; SYSLIB Version Number:  2.0
; Module Version Number:  1.0
; Module Entry Points:
;	EVAL8
; Module External References:
;	None
;

;
;  EVAL8 --
;	Convert the string of ASCII octal digits pointed to by HL
; into a binary value; string is converted until invalid digit is
; encountered.
;	On return, HL points to error character, DE=value, A=E (low
; order 8 bits of value).  BC not affected.
;

EVAL8::
	PUSH	B	; SAVE BC
	LXI	D,0	; SET DE=0 INITIALLY

;  Get next digit and check for '0' - '9'
E8L:
	MOV	A,M	; GET BYTE
	SUI	'0'	; CHECK FOR RANGE
	JC	DONE
	CPI	8
	JNC	DONE

	PUSH	PSW	; SAVE VALUE

;  Multiply DE by 8
MUL8:
	PUSH	H	; SAVE HL
	LXI	H,0	; ACC=0
	MVI	B,8	; 8 LOOPS
MUL8L:
	DAD	D	; HL=HL+DE
	DCR	B	; COUNT DOWN
	JNZ	MUL8L
	MOV	D,H	; NEW DE
	MOV	E,L
	POP	H	; RESTORE HL

;  Add in A
	POP	PSW	; GET LATEST DIGIT
	ADD	E	; A=A+E
	MOV	E,A
	MOV	A,D	; ADD TO D IF NECESSARY
	ACI	0

;  Continue
	INX	H	; PT TO NEXT CHARACTER
	JMP	E8L

;  Done -- Result already in DE; Set A=E
DONE:
	MOV	A,E	; A=E
	POP	B	; RESTORE BC

	RET

	END
