home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / advmsdos / chap15 / proto.asm < prev    next >
Encoding:
Assembly Source File  |  1988-10-01  |  2.8 KB  |  98 lines

  1.          name      proto
  2.          page      55,132
  3.          title     PROTO.ASM --- prototype filter
  4. ;
  5. ; PROTO.ASM:  prototype character-oriented filter
  6. ;
  7. ; Copyright 1988 Ray Duncan
  8. ;
  9. ; Build:  MASM PROTO;
  10. ;         LINK PROTO;
  11. ;
  12. ; Usage:  PROTO
  13. ;
  14.  
  15. stdin   equ     0               ; standard input handle
  16. stdout  equ     1               ; standard output handle
  17. stderr  equ     2               ; standard error handle
  18.  
  19. cr      equ     0dh             ; ASCII carriage return
  20. lf      equ     0ah             ; ASCII linefeed
  21.  
  22.  
  23. _TEXT   segment word public 'CODE'
  24.  
  25.         assume  cs:_TEXT,ds:_DATA,ss:STACK
  26.  
  27. main    proc    far             ; entry point from MS-DOS
  28.  
  29.         mov     ax,_DATA        ; set DS = our data segment
  30.         mov     ds,ax
  31.  
  32. main1:                          ; read char. from stdin...
  33.         mov     dx,offset char  ; DS:DX = buffer address
  34.         mov     cx,1            ; CX = length to read
  35.         mov     bx,stdin        ; BX = standard input handle
  36.         mov     ah,3fh          ; Fxn 3FH = read 
  37.         int     21h             ; transfer to MS-DOS
  38.         jc      main3           ; if error, terminate
  39.  
  40.         cmp     ax,1            ; any character read?
  41.         jne     main2           ; if end of file, terminate
  42.  
  43.         call    translate       ; translate character 
  44.  
  45.                                 ; write char. to stdout...
  46.         mov     dx,offset char  ; DS:DX = buffer address
  47.         mov     cx,1            ; CX = length to write
  48.         mov     bx,stdout       ; BX = standard output handle
  49.         mov     ah,40h          ; Fxn 40H = write
  50.         int     21h             ; transfer to MS-DOS
  51.         jc      main3           ; if error, terminate
  52.  
  53.         cmp     ax,1            ; was character written?
  54.         jne     main3           ; if disk full, terminate 
  55.  
  56.         jmp     main1           ; get another character
  57.  
  58. main2:                          ; end of file reached
  59.         mov     ax,4c00h        ; Fxn 4CH = terminate
  60.                                 ; return code = 0
  61.         int     21h             ; transfer to MS-DOS
  62.  
  63. main3:                          ; error or disk full    
  64.         mov     ax,4c01h        ; Fxn 4CH = terminate
  65.                                 ; return code = 1
  66.         int     21h             ; transfer to MS-DOS
  67.  
  68. main    endp
  69.  
  70. ;
  71. ; Perform any necessary translation on character 
  72. ; from standard input stored in variable 'char'.
  73. ; This example just leaves character unchanged.
  74. ;
  75. translate proc  near
  76.  
  77.         ret                     ; does nothing
  78.  
  79. translate endp
  80.  
  81. _TEXT   ends
  82.  
  83.  
  84. _DATA   segment word public 'DATA'
  85.  
  86. char    db      0               ; storage for input character
  87.  
  88. _DATA   ends
  89.  
  90.  
  91. STACK   segment para stack 'STACK'
  92.  
  93.         dw      64 dup (?)
  94.  
  95. STACK   ends
  96.  
  97.         end     main            ; defines program entry point
  98.