home *** CD-ROM | disk | FTP | other *** search
- name lc
- title 'LC.ASM --- lowercase filter'
- ;
- ; LC.ASM: a simple character-oriented filter to translate
- ; all uppercase {A-Z} to lowercase {a-z}.
- ;
- ; Ray Duncan, June 1987
- ;
-
- stdin equ 0 ; standard input
- stdout equ 1 ; standard output
- stderr equ 2 ; standard error
-
- cr equ 0dh ; ASCII carriage return
- lf equ 0ah ; ASCII linefeed
-
-
- DGROUP group _DATA,STACK ; 'automatic data group'
-
-
- _TEXT segment byte public 'CODE'
-
- assume cs:_TEXT,ds:DGROUP,ss:STACK
-
- main proc far ; entry point from MS-DOS
-
- mov ax,DGROUP ; set DS = our data segment
- mov ds,ax
-
- main1: ; read a character from standard input
- mov dx,offset DGROUP:char ; address to place character
- mov cx,1 ; length to read = 1
- mov bx,stdin ; handle for standard input
- mov ah,3fh ; function 3FH = read from file or device
- int 21h ; transfer to MS-DOS
- jc main3 ; error, terminate
- cmp ax,1 ; any character read?
- jne main2 ; end of file, terminate program
-
- call translt ; translate character if necessary
-
- ; now write character to standard output
- mov dx,offset DGROUP:char ; address of character
- mov cx,1 ; length to write = 1
- mov bx,stdout ; handle for standard output
- mov ah,40h ; function 40H = write to file or device
- int 21h ; transfer to MS-DOS
- jc main3 ; error, terminate
- cmp ax,1 ; was character written?
- jne main3 ; disk full, terminate program
- jmp main1 ; go process another character
-
- main2: mov ax,4c00h ; end of file reached, terminate
- int 21h ; program with return code = 0
-
- main3: mov ax,4c01h ; error or disk full, terminate
- int 21h ; program with return code = 1
-
- main endp ; end of main procedure
-
- ;
- ; Translate uppercase {A-Z} characters to corresponding
- ; lowercase characters {a-z}. Leave other characters unchanged.
- ;
- translt proc near
-
- cmp byte ptr char,'A'
- jb transx
- cmp byte ptr char,'Z'
- ja transx
- add byte ptr char,'a'-'A'
- transx: ret
-
- translt endp
-
-
- _TEXT ends
-
-
- _DATA segment word public 'DATA'
-
- char db 0 ; temporary storage for input character
-
- _DATA ends
-
-
- STACK segment para stack 'STACK'
-
- dw 64 dup (?)
-
- STACK ends
-
-
- end main ; defines program entry point
-