TITLE "SEVAL4 - Syslib 4.3" NAME ('EVAL2') ;================================================================= ; The Libraries, Version 4, (C) 1989 by Alpha Systems Corp. ;----------------------------------------------------------------- ; Author : Harold F. Bower ; Derived from SEVAL4.Z80 Ver 1.1 by Richard Conn ; Date : 17 Sep 89 ; Version : 1.2 ; Module : SEVAL4 ; Abstract: This module contains the routine EVAL2 which scans ; an ASCII character of binary digits and returns the ; evaluated number. The routine also returns a pointer to ; the first invalid binary digit encountered. ; Revision: ; 1.3 - 28 May 90 - Return Carry Set (C) if overflow, else NC. HFB ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ; Module Entry Points PUBLIC EVAL2 .Z80 CSEG ;=============================================================== ; NAME - EVAL2 ; Entry: HL - Points to an ASCII char string of binary digits ; Exit : HL - Points to first invalid binary digit encountered ; DE - Contains the evaluated number ; A = E ; Uses : AF,DE,HL ; Special Requirements: None ;=============================================================== EVAL2: PUSH BC ; Save BC LD DE,0 ; Set DE = 0 initially ; Get next digit and check for '0' - '1' E2L: LD A,(HL) ; Get byte SUB '0' ; Check for range CCF ; ..flip Carry sense in case exitting JR NC,DONE CP 2 JR NC,DONE ; Multiply DE by 2 and add in the bit EX DE,HL ; Swap registers RRA ; Put Bit 0 in Carry Flag ADC HL,HL ; * 2 + Carry JR C,DONE ; ..exit Carry Set of Overflow EX DE,HL ; Swap registers back INC HL ; Pt to next character JR E2L ; ..and continue ; Done -- Result already in DE; Set A=E DONE: LD A,E ; A = E POP BC ; Restore BC RET END