;; GetFP--translate a decimal FP number read from the keyboard ;; into its equivalent internal FP number on top of the FPU stack ;; ;; Input: ;; none ;; ;; Output: ;; If there is no error, the carry flag is clear and we have: ;; ST = value translated ;; If an error occurs, carry flag is set, and ST is meaningless, ;; ;; The routine skips over leading white space--blanks and tabs ;; it also handles backspace erasures unless the number gets too long ;; ;; Errors: All sorts--but checking isn't all that great. ;; ;; Library source text from "Assembly Language for the IBM PC Family" by ;; William B. Jones, (c) Copyright 1997, Scott/Jones Inc. ;; INCLUDE PCMAC.INC .MODEL SMALL .DATA BUFFLEN EQU 50 InBuff DB BUFFLEN+1 DUP (?) .CODE PUBLIC GetFP EXTRN Dec2FP : NEAR GetFP PROC push ds ; Save registers to be used push es push cx push dx ; Used by _PutCh push si push di pushf ; ...and flags cld ; Set direction flag upwards mov ax, @data mov ds, ax mov es, ax lea di, InBuff ; The sign--Guess + = 0 mov cx, BUFFLEN ; Character count SkipWhiteSpace: _GetCh cmp al, ' ' je SkipWhiteSpace cmp al, 8 ; Backspace jne TryTab DoBack: _PutCh ' ', 8 ; Erase char jmp SkipWhiteSpace TryTab: cmp al, 9 ; Tab je SkipWhiteSpace cmp al, '+' ; Number has been found; check for sign je StoreIt cmp al, '-' jne CheckDig ; Must be a digit jmp StoreIt NextDig: _GetCh cmp al, 8 ; Backspace jne CheckDig inc cx dec di cmp cx, BUFFLEN je DoBack ; We've erased the whole number _PutCh ' ', 8 jmp NextDig CheckDig: cmp al, '.' je StoreIt cmp al, '+' je StoreIt cmp al, '-' je StoreIt cmp al, 'e' je StoreIt cmp al, 'E' je StoreIt cmp al, '0' ; Is the character a digit? jl Done cmp al, '9' jg Done StoreIt: stosb loop NextDig Error: popf stc ; Set Carry to indicate error jmp Restore ; Restore regs and exit Done: stosb cmp al, 13 ; If carriage return ... jne NoLF _PutCh 10 ; ... also display line feed NoLF: popf lea si, InBuff call Dec2FP Restore: pop di pop si pop dx pop cx pop es pop ds ret GetFP ENDP END