代码在emu8086调试成功!
assume cs:code,ds:data,es:data
data segment
readlen equ 60000
buf db readlen dup(0)
filename db 20,0,20 dup(0)
reallen dw 0
msg db 0dh,0ah,'please input filename:','$'
err db 0dh,0ah,'open error!','$'
data ends
code segment
start proc
mov ax,data
mov ds,ax
mov es,ax
mov dx,offset msg
mov ah,9
int 21h
mov dx,offset filename ;输入文件名
mov ah,0ah
int 21h
mov si,offset filename+2
mov bl,filename+1
mov bh,0
mov byte ptr [si+bx],0 ;结尾部填0,便于识别尾部
mov ax,3d02h ;打开文件供读写
lea dx,filename+2
int 21h
jnc read_file
lea dx,err ;打开文件出错!
mov ah,9
int 21h
mov ax,4c00h ;返回dos
int 21h
read_file:
mov bx,ax ;句柄传送
mov cx,readlen
mov dx,offset buf
mov ah,3fh ;读文件
int 21h
mov reallen,ax ;实际读入的字节数
lea si,buf
lea di,buf
mov cx,reallen
call chg
mov cx,0 ;移动文件指针
mov dx,0
mov ax,4200h
int 21h
mov dx,offset buf ;写文件
mov cx,reallen
mov ah,40h
int 21h
mov ah,3eh ;关闭文件
int 21h
;mov ax,4c00h
;int 21h
start endp ;结束一段子程序
chg proc ;另一段子程序,变换大小写
cld
redo:lodsb
cmp al,61h
jb s
cmp al,7ah
ja s
and al,11011111b
s:stosb
loop redo
ret
chg endp
code ends
end start