TITLE "SEVAL3 - Syslib 4.3" NAME ('EVAL8') ;================================================================= ; The Libraries, Version 4, (C) 1989 by Alpha Systems Corp. ;----------------------------------------------------------------- ; Author : Harold F. Bower ; Derived from SEVAL3.Z80 Ver 1.1 by Richard Conn ; Date : 17 Sep 89 ; Version : 1.2 ; Module : SEVAL3 ; Abstract: This module contains the routine EVAL8 which scans ; an ASCII character string of Octal digits and returns the ; evaluated value. A pointer to the first invalid Octal ; character is also returned. ; Revision: ; 1.3 - 28 May 90 - Return Carry Set (C) if overflow Error. HFB ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ; Module Entry Points PUBLIC EVAL8 .Z80 CSEG ;=============================================================== ; NAME - EVAL8 ; Entry: HL - Points to char string of ASCII Octal digits ; Exit : HL - Points to first invalid Octal digit ; DE - Contains the evaluated number ; A = E, Carry Set (C) if Exit due to Overflow condition ; Uses : AF,DE,HL ; Special Requirements: None ;=============================================================== EVAL8: PUSH BC ; Save BC LD DE,0 ; Set DE = 0 initially LD B,D ; ..and clear B for 16-bit math ; Get next digit and check for '0' - '7' E8L: LD A,(HL) ; Get byte SUB '0' ; Check for range CCF ; ..reverse sense of Carry Flag JR NC,DONE CP 8 JR NC,DONE LD C,A ; Move digit for 16-bit math ; Multiply DE by 8 EX DE,HL ; Swap registers ADD HL,HL ; * 2 JR C,DONE ; ..exit if Overflow ADD HL,HL ; * 4 JR C,DONE ADD HL,HL ; * 8 JR C,DONE ; Add in A ADD HL,BC EX DE,HL ; Swap registers back INC HL ; Pt to next character JR E8L ; ..and continue ; Done -- Result in DE; Set A=E. Carry Set (C) if overflow error. DONE: LD A,E ; A = E POP BC ; Restore BC RET END