;
; EVAL10 --
; Convert the string of ASCII decimal 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.
;
EVAL10::
PUSH B ; SAVE BC
LXI D,0 ; SET DE=0 INITIALLY
; Get next digit and check for '0' - '9'
E10L:
MOV A,M ; GET BYTE
SUI '0' ; CHECK FOR RANGE
JC DONE
CPI 10
JNC DONE
PUSH PSW ; SAVE VALUE
; Multiply DE by 10
MUL10:
PUSH H ; SAVE HL
LXI H,0 ; ACC=0
MVI B,10 ; 10 LOOPS
MUL10L:
DAD D ; HL=HL+DE
DCR B ; COUNT DOWN
JNZ MUL10L
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 E10L
; Done -- Result already in DE; Set A=E
DONE:
MOV A,E ; A=E
POP B ; RESTORE BC