TITLE "SEVAL1 - Syslib 4.3" NAME ('EVAL10') ;================================================================= ; The Libraries, Version 4, (C) 1989 by Alpha Systems Corp. ;----------------------------------------------------------------- ; Author : Harold F. Bower ; Derived from SEVAL1.Z80 Ver 1.1 by Richard Conn ; Date : 17 Sep 89 ; Version : 1.2 ; Module : SEVAL1 ; Abstract: This module contains the routine EVAL10 which con- ; verts a string of ASCII decimal digits to a binary value. ; It scans the addressed string until an invalid character ; is found. ; Revision: ; 1.3 - 28 May 90 - Return Carry Set (C) if Overflow Error. HFB ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ; Module Entry Points PUBLIC EVAL10 .Z80 CSEG ;=============================================================== ; NAME - EVAL10 ; Entry: HL - Points to an ASCII character string ; Exit : HL - Points to first invalid decimal digit encountered ; DE - Binary value accumulated up to invalid character ; A = E, Carry Flag Set (C) if Exit caused by Overflow. ; Uses : AF,DE,HL ; Special Requirements: None ;=============================================================== EVAL10: PUSH BC ; Save BC LD DE,0 ; Set DE = 0 initially LD B,D ; ..and set B zero for 16-bit math ; Get next digit and check for '0' - '9' E10L: LD A,(HL) ; Get byte SUB '0' ; Convert to binary checking lower range CCF ; .complementing Carry JR NC,DONE ; ..exit if less than Zero CP 10 ; Greater than '9'? JR NC,DONE ; ..exit if so w/Carry Clear (NC) LD C,A ; Move digit for 16-bit add ; Multiply DE by 10 PUSH HL ; Save HL LD H,D ; HL = DE LD L,E ADD HL,HL ; *2 JR C,DONE0 ; ..exit if Overflow ADD HL,HL ; *4 JR C,DONE0 ADD HL,DE ; *5 JR C,DONE0 ADD HL,HL ; *10 JR C,DONE0 ADD HL,BC ; Add in new digit JR C,DONE0 EX DE,HL ; ..result back to DE POP HL ; Restore HL INC HL ; Pt to next character JR E10L ; ..and continue ; Done -- Result in DE; Set A=E, Carry set if Exit due to overflow DONE0: POP HL ; Clear stack for internal aborts DONE: LD A,E ; A = E POP BC ; Restore BC RET END