qa.hlp (Table of Contents; Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
GetStr
   Example  Back  Contents  Index
──────────────────────────────────────────────────────────────────────────────
 
;* GetStr - Gets a string of up to 128 characters from the user. Since
;* this function uses the DOS input mechanism, it can use the DOS editing
;* keys or the keys of a DOS command-line editor if one is loaded.
;*
;* Shows:   DOS Function - 0Ah (Buffered Keyboard Input)
;*
;* Params:  buffer - Pointer to area where input string will be placed
;*          maxlen - Maximum length (up to 128 characters) of string
;*
;* Return:  0 if successful, 1 if error (maxlen is too long)
 
        .DATA
MAXSTR  EQU     128
max     DB      MAXSTR
actual  DB      ?
string  DB      MAXSTR DUP (?)
 
        .CODE
GetStr  PROC \
        USES si di, \
        strbuf:PTR BYTE, maxlen:WORD
 
        mov     ax, 1                   ; Assume error
        mov     cx, maxlen              ; Copy length to register
        jcxz    exit                    ; Error if maxlen is zero
        cmp     cx, MAXSTR
        ja      exit                    ; Error if maxlen is too long
 
        mov     max, cl                 ; Load maximum length
        mov     ah, 0Ah                 ; Request DOS Function 0Ah
        mov     dx, OFFSET max          ; Load offset of string
        int     21h                     ; Buffered Keyboard Input
 
        mov     bl, actual              ; Put number of characters read
        sub     bh, bh                  ;   in BX
        mov     string[bx], 0           ; Null-terminate string
        mov     cx, bx                  ; Put count in CX
        inc     cx                      ; Plus one for the null terminator
 
        LoadPtr es, di, strbuf          ; ES:DI points to destination buffer
        mov     si, OFFSET string       ; DS:SI points to source string
        rep     movsb                   ; Copy source to destination
        sub     ax, ax                  ; Return 0 for success
 
exit:   ret
 
GetStr  ENDP
                                    -♦-