home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / dos_ency / 14 / protoc.asm < prev    next >
Encoding:
Assembly Source File  |  1988-08-11  |  2.8 KB  |  89 lines

  1.         name    protoc
  2.         title   'PROTOC.ASM --- template character filter'
  3. ;
  4. ; PROTOC.ASM: a template for a character-oriented filter.
  5. ;
  6. ; Ray Duncan, June 1987
  7. ;
  8.  
  9. stdin   equ     0               ; standard input
  10. stdout  equ     1               ; standard output
  11. stderr  equ     2               ; standard error
  12.  
  13. cr      equ     0dh             ; ASCII carriage return
  14. lf      equ     0ah             ; ASCII linefeed
  15.  
  16.  
  17. DGROUP  group   _DATA,STACK     ; 'automatic data group'
  18.  
  19.  
  20. _TEXT   segment byte public 'CODE'
  21.  
  22.         assume  cs:_TEXT,ds:DGROUP,ss:STACK
  23.  
  24. main    proc    far             ; entry point from MS-DOS
  25.  
  26.         mov     ax,DGROUP       ; set DS = our data segment
  27.         mov     ds,ax
  28.  
  29. main1:                          ; read a character from standard input
  30.         mov     dx,offset DGROUP:char   ; address to place character
  31.         mov     cx,1            ; length to read = 1
  32.         mov     bx,stdin        ; handle for standard input
  33.         mov     ah,3fh          ; function 3FH = read from file or device
  34.         int     21h             ; transfer to MS-DOS
  35.         jc      main3           ; error, terminate
  36.         cmp     ax,1            ; any character read?
  37.         jne     main2           ; end of file, terminate program
  38.  
  39.         call    translt         ; translate character if necessary
  40.  
  41.                                 ; now write character to standard output
  42.         mov     dx,offset DGROUP:char   ; address of character
  43.         mov     cx,1            ; length to write = 1
  44.         mov     bx,stdout       ; handle for standard output
  45.         mov     ah,40h          ; function 40H = write to file or device
  46.         int     21h             ; transfer to MS-DOS
  47.         jc      main3           ; error, terminate
  48.         cmp     ax,1            ; was character written?
  49.         jne     main3           ; disk full, terminate program
  50.         jmp     main1           ; go process another character
  51.  
  52. main2:  mov     ax,4c00h        ; end of file reached, terminate 
  53.         int     21h             ; program with return code = 0
  54.  
  55. main3:  mov     ax,4c01h        ; error or disk full, terminate 
  56.         int     21h             ; program with return code = 1 
  57.  
  58. main    endp                    ; end of main procedure
  59.  
  60. ;
  61. ; Perform any necessary translation on character from input,
  62. ; stored in 'char'.  Template action: leave character unchanged.
  63. ;
  64. translt proc    near
  65.  
  66.         ret                     ; template action: do nothing 
  67.  
  68. translt endp
  69.  
  70.  
  71. _TEXT   ends
  72.  
  73.  
  74. _DATA   segment word public 'DATA'
  75.  
  76. char    db      0               ; temporary storage for input character
  77.  
  78. _DATA   ends
  79.  
  80.  
  81. STACK   segment para stack 'STACK'
  82.  
  83.         dw      64 dup (?)
  84.  
  85. STACK   ends
  86.  
  87.  
  88.         end     main            ; defines program entry point
  89.