.model small
.stack
.data


.code


main    proc

        mov     ax,@data                ;set standard data segment
        mov     ds,ax


start:

        mov     ah,1                    ;test for a key press
        int     16h
        jnz     key_was_pressed
        jmp     start                   ;keep looping till a key is pressed


key_was_pressed:
        mov     ah,0                    ;get the key
        int     16h

                                        ;ah = scan code
                                        ;al = ascii char

        cmp     ah,1                    ;if scan code = 1 (esc key), exit
        je      xit


        mov     ah,2                    ;print the char
        mov     dl,al
        int     21h

        jmp     start                   ;loop back to start

xit:
        mov     ax,4C00h
        int     21h

main    endp


        end main

