📄 kcsj1.asm
字号:
include kcsj.mac
.model small
.386
.stack 200h
public prog1
.data
menu db 30 dup(' '),'1.Display text file',0ah,0dh
db 30 dup(' '),'2.Copy text file',0ah,0dh
db 30 dup(' '),'3.Delete text file',0ah,0dh
db 30 dup(' '),'4.The end',0ah,0dh
db 30 dup(' '),'Please select one(1~4):','$'
prompt1 db 0ah,0dh,'File name:$'
prompt2 db 0ah,0dh,'Lines of page(1~25):$'
FNAME db 15,?,15 dup(' ') ;存放文件名的缓冲区
out1 db 0ah,0dh,'Can not open file!$'
out2 db 0ah,0dh,'Can not read file!$'
out3 db 0ah,0dh,'Can not creat file!$'
out4 db 0ah,0dh,'Can not write file!$'
out5 db 0ah,0dh,'Can not delete file!$'
out6 db 0ah,0dh,'The file has been copyed!$'
out7 db 0ah,0dh,'The file has been deleted!$'
buffer db ?
endcode db 0 ;错误标志
end1 db 0 ;结束标志
code1 dw ? ;原文件的代号
code2 dw ? ;新建文件的代号
sign db 0
ask1 db 0ah,0dh,'Input source file name:$'
ask2 db 0ah,0dh,'Input dest file name:$'
row db 23
info db 'Press ESC to quit,p to change page,anykey to continue!$'
.code
prog1 proc far
init
call mainshow
L1:mov ah,1
int 21h
cmp al,'1'
je display
cmp al,'2'
je copy
cmp al,'3'
je delete
jmp rtn1
display:call fdisp
call mainshow
mov end1,0
mov [row],23
mov endcode,0
jmp L1
copy:call fcopy
call mainshow
mov endcode,0
mov sign,0
jmp L1
delete:call fdel
call mainshow
jmp L1
rtn1:ret
prog1 endp
mainshow proc near
scroll 0
cursor 10,0
strdisp menu
ret
mainshow endp
fdisp proc near ;分页显示
strdisp prompt1
call fopen
scroll 0 ;清屏
cursor 0,0 ;置光标
cmp endcode,1
jne cont
mov ah,7
int 21h
jmp ext0
cont:mov bx,code1
call fread
cmp endcode,1
je ext1
call fshow ;显示
cmp end1,1
je ext1
jmp cont
ext1:mov ah,3eh ;关闭文件
mov bx,code1
int 21h
ext0:mov endcode,0
ret
fdisp endp
fopen proc near ;打开文件
call in_name
mov ah,3dh
mov al,0
int 21h
jnc next
mov endcode,1
strdisp out1
ret
next:mov bx,ax
mov code1,ax
ret
fopen endp
in_name proc near ;输入文件名
lea dx,FNAME
mov ah,0ah
int 21h
lea bx,FNAME+2
mov ah,0
mov al,FNAME+1
add bx,ax
mov byte ptr [bx],0
add dx,2
ret
in_name endp
fread proc near ;读取文件
mov ah,3fh
mov cx,1
lea dx,buffer
int 21h
jnc past
strdisp out2
jmp exit
past:cmp ax,0
je exit
ret
exit:mov ah,3eh
int 21h
mov endcode,1
ret
fread endp
fshow proc near ;显示文件
mov dl,[buffer]
mov ah,2
int 21h
mov ah,3
mov bh,0
int 10h
cmp dh,[row]
jae d1
ret
d1:strdisp info
d2:mov ah,7
int 21h
cmp al,0
jz d2
cmp al,1bh ;按ESC退出
jz d4 ;退出关闭文件endcode=1
cmp al,70h ;按P提示输入每页行数
jnz d3
strdisp prompt2
call chtonum
mov [row],al
d3:scroll 0
cursor 0,0
ret
d4:mov end1,1
ret
fshow endp
chtonum proc near
mov bx,0
newchar:mov ah,1 ;输入数字并转换为十进制
int 21h
sub al,30h
jl goon
cmp al,9
jg goon
cbw
xchg ax,bx
mov cx,10d
mul cx
xchg ax,bx
add bx,ax
jmp newchar
goon:mov al,bl ;行数传给AL
ret
chtonum endp
fcopy proc near ;文件拷贝
scroll 0
cursor 0,0
strdisp ask2
call fcreat
cmp endcode,1
je over
mov code2,ax
strdisp ask1
call fopen
cmp endcode,1
je etn0
again:call fread
cmp endcode,1
je etn0
mov sign,1
push bx
cmp ax,0
je next2
mov cx,ax
mov bx,code2
mov ah,40h
int 21h
pop bx
jnc again
strdisp out4
ret
next2:mov ah,3eh
mov bx,code1
int 21h
etn0:mov ah,3eh
mov bx,code2
int 21h
cmp sign,1
jne over
strdisp out6
over:mov ah,7
int 21h
ret
fcopy endp
fcreat proc near ;创建文件
call in_name
mov ah,3ch
mov cx,00
int 21h
jnc next1
mov endcode,1
strdisp out3
next1:ret
fcreat endp
fdel proc near ;删除文件
scroll 0
cursor 0,0
strdisp prompt1
call in_name
mov ah,41h
int 21h
cmp ax,0
jnz quit
strdisp out5
mov ah,7
int 21h
ret
quit:strdisp out7
mov ah,7
int 21h
ret
fdel endp
end prog1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -