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

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