; NOECHO.ASM
;
; Purpose:
;     Read characters without echo until a 'd' is seen,
;     then start a new line and print a message that contains
;     the last character input, and exit.
;
; Algorithm PseudoCode:
;     initialize the input character to anything not a 'd'
;     while ( input character is not the letter 'd' )
;         read next input character without echo to screen
;     endwhile
;     start a new line and print a message containing input character
;     exit
;
;     NOTE: This should be using a DO/WHILE loop, not a WHILE loop.
;           The variable names used aren't very appropriate.
;
; Some comments in this file are intended to teach students about the
; meaning of various assembler instructions.  They are NOT suitable
; for students documenting their own code, since they do not refer to
; any process or problem being solved.
;
; Students: Do NOT copy the teacher-style comments into your own code.
;
; -Ian! D. Allen - idallen@idallen.ca - www.idallen.com
;  July 2000, November 2009
;----------------------------------------------------------------------
; Both the Code Segment (CS) and Data Segment (DS) are the same.
Noecho  segment
        assume  CS:Noecho,DS:Noecho ; .COM format uses only one segment
        org     100h            ; .COM format executable starts at 100h
;----------------------------------------------------------------------
start:
        ; initialize variables used: "dog" is the input character
        ;
        mov     dog,'x'         ; put some non-'d' junk in input character

        ; read characters without echo until 'd' is seen in input
        ;
while:  cmp     dog,'d'         ; looking for 'd' byte to exit loop
        je      barkout         ; found it

        mov     ah,07h          ; input character without screen echo
        int     21h
        mov     dog,al          ; save the character in output msg

        jmp     while
barkout:                        ; found 'd' - end of WHILE loop

        ; print the BARK message on a new line and return to DOS
        ;
        mov     dx,offset barkmsg
        mov     ah,09h          ; print ASCII$ bark msg, offset in DX
        int     21h

        mov     al,0h           ; return 0 code from NOECHO in AL
        mov     ah,4Ch          ; code for "terminate NOECHO program"
        int     21h

;----------------------------------------------------------------------
; The BARK ASCII message is made up of several pieces, including
; an input "dog" byte that is the last character read in:
;
barkmsg db      0Dh,0Ah         ; CR+LF bytes start the BARK message
        db      'Bark! Bark! Bark! Ended on: '
dog     db      ?               ; one byte "dog" for the input character
        db      0Dh,0Ah         ; CR+LF bytes end the BARK message
        db      "$"             ; terminate the BARK ASCII$ string
;----------------------------------------------------------------------
Noecho  ends
        end start       ; "start" is the label on the first instruction

