Procedural Assembly Program

Demonstration of assembly-language procedures, which perform simple I/O operations. All the procedures are kept in a single source file. (See procdemo.multi-file.html for a version of this program that uses multiple source files.)

;---------------------------------------------------------------------------
; Demo of character I/O in assembly from class examples of 2001-02-14
; Also demonstrates some EQUates.
;
; Convention:
;   all subroutines expect any arguments to be passed in AX (or AL).
;
; 2001-02-14 -bob,mon.
;---------------------------------------------------------------------------

        .model small
        .stack 100h

        .data
msg1    db  "Enter a character: $"
ch1     db  ?
msg2    db  "You entered '$"
msg3    db  "'.$"

        .code

getChr  proc            ; Get a DOS-processed keyboard character, w/ echo
        mov  ah, 01h
        int  21h
        ret
getChr  endp
;---------------------------------------------------------------------------

DOSstr  proc            ; Emit a ('$'-terminated) DOS string
        mov  dx, ax
        mov  ah, 09h
        int  21h
        ret
DOSstr  endp
;---------------------------------------------------------------------------

; This is the primary program; execution starts here.
;
main    proc
        mov  dx, @data
        mov  ds, dx

        mov  ax, offset msg1
        call DOSstr

        call getChr
        mov  ch1, al
        call doCRLF

        mov  ax, offset msg2
        call DOSstr
        mov  al, ch1
        call putChr
        mov  ax, offset msg3
        call DOSstr
        call doCRLF

        mov  al, 0
        mov  ah, 4Ch
        int  21h
main    endp
;---------------------------------------------------------------------------

doCRLF  proc            ; Put out a Carriage-Return & a LineFeed
        mov  al, 0Dh
        call putChr
        mov  al, 0Ah
        call putChr
        ret
doCRLF  endp
;---------------------------------------------------------------------------

putChr  proc            ; Put an ASCII char on the console output
        mov  dl, al
        mov  ah, 02h
        int  21h
        ret
putChr  endp
;---------------------------------------------------------------------------

        end main
;---------------------------------------------------------------------------