📄 file.asm
字号:
;----------------------------------------------------------------------
;Program:
;Created by:
;Finished Date & Time:
;----------------------------------------------------------------------
SSEG SEGMENT PARA STACK 'stack'
dw 100h dup(0) ;Resize the stack by changing the number '100'
SSEG ENDS
DSEG SEGMENT
;TO DO: Add your program's data here
handle1 dw ?
handle2 dw ?
pathname1 db 'd:\file1.txt',0
pathname2 db 'd:\file2.txt',0
init db 'Please enter the string you want to write in the file1',0dh,0ah,'$'
outit db 'The next is the searching answer',0dh,0ah,'$'
openmsg db '***open error***',0dh,0ah,'$'
readmsg db '***read error***',0dh,0ah,'$'
creatmsg db '***creat error***',0dh,0ah,'$'
writemsg db '***write error***',0dh,0ah,'$'
aimpar label byte
maxlen db 14
aimlen db ?
aimrec db 14 dup(' '),0dh,0ah;fang mu biao chuan
transpar label byte
mlen db 14
translen db ?
transrec db 14 dup(' '),0dh,0ah;fang ti huan chuan
ioarea label byte
malen db 14
iolen db ?
iorec db 14 dup(' '),0dh,0ah;fang shu ru de yi ge huan chong qu
buf db 16 dup(' ');cong wen jian zhong du chu lai hou xian fang zai zhe ge di fang
buf1 db 14 dup(' '),0dh,0ah,'$'
row1 dw ?
row dw ?;ji lu shu
out1 db 'row:','$'
out2 db 'byte:','$'
string db 0dh,0ah,'$'
string1 db 0dh,0ah,'Enter the aim string you want to search',0dh,0ah,'$'
string2 db 'Find it, there are ? line',0dh,0ah,'$'
string3 db 0dh,0ah,'Enter the string you want to replace',0dh,0ah,'$'
string4 db 'Do not find the string',0dh,0ah,'$'
string5 db 0dh,0ah,'Do you want to replace y/n ?',0dh,0ah,'$'
a db 0
b db 0;xiang pi pei de ge shu
c db 0
bi db 0
recg db 0;all the file wrong
endcde db 0;EOF
DSEG ENDS
CSEG SEGMENT
assume cs:CSEG, ds:DSEG, es:DSEG, ss:SSEG
; INIT PROC ;Initialize procedure
; mov ax, dseg
;mov ds, ax
;mov es, ax
;TO DO: Add your initialize code here (as your requirement)
;ret ;return to the MAIN procedure
;INIT ENDP
MAIN PROC ;Here is your program entry point
;call INIT ;call the INIT procedure to initialize the program
;**TO DO: Add your main code here**
;****************shou xian jian li yi ge wen jian****************************
;*****************di yi ge wen jian da kai han shu zhi jie xie zai zhu han shu li mian*****************************
mov ax, dseg
mov ds, ax
mov es, ax
mov ax, 3c00h
mov cx, 0
mov dx, offset pathname1
int 21h
jc error1
mov handle1, ax
jmp do4
error1:
mov dx, offset creatmsg
mov ah, 09h
int 21h
jmp exit
do4:
mov dx, offset init
mov ah, 09h
int 21h
do:
mov ah, 0ah
mov dx, offset ioarea
int 21h
cmp iolen, 0
jne a1
jmp next
a1:
mov al, 20h
sub ch, ch
mov cl, iolen
mov di, offset iorec
add di, cx
neg cx
add cx, 14
cld
rep stosb
mov ah, 40h
mov bx, handle1
mov cx, 16
mov dx, offset iorec
int 21h
jc error2
inc row;ji lu shu
inc row1
jmp do
next: ;********ying gai guan diao wen jian file1********
mov iorec, 1ah
mov ah, 40h
mov bx, handle1
mov cx, 16
mov dx, offset iorec
int 21h
jc error2
jmp n1
error2:
mov dx, offset writemsg
mov ah, 09h
int 21h
jmp exit
n1:
mov ah, 3eh
mov bx, handle1
int 21h
call display
call search
cmp c, 0
jnz exit1
jmp n2
exit1:
mov ax, 4c00h
int 21h
n2:
mov bx, handle1
mov ax, 3e00h
int 21h
call choose
cmp bi, 0
jne exit2
jmp n3
exit2:
mov ax, 4c00h
int 21h
n3:
mov recg, 0
mov endcde, 0
;***********************open the file******************************
mov ax, 3c00h
mov cx, 0
mov dx, offset pathname2
int 21h
jc error5
mov handle2, ax
jmp goon
error5:
mov dx, offset creatmsg
mov ah, 09h
int 21h
jmp exit
goon:
call openh
cmp recg, 0
jne exit
to:
call readh
cmp recg, 0
jne exit
cmp endcde, 0
jne endit
mov si, offset buf
mov di, offset aimrec
mov cx, 16
cld
repe cmpsb
cmp cx, 0
jz f1
jmp f2
f1:
mov ah, 40h
mov bx, handle2
mov cx, 16
mov dx, offset transrec
int 21h
jmp to
f2:
mov ah, 40h
mov bx, handle2
mov cx, 16
mov dx, offset buf
int 21h
jmp to
endit:
mov bx, handle1
mov ax, 3e00h
int 21h
mov bx, handle2
mov ax, 3e00h
int 21h
jmp do7
do7:
call display2
cmp endcde, 0
jne do7
jmp exit
exit:
mov ax, 4c00h ;The end of the program, return to the system
int 21h
MAIN ENDP
;TO DO: Add other procedures(PROC) here (as your requirement)
;*********shu chu ji lu shu zi jie shu********
;**************************************
display proc near
mov dx, offset outit
mov ah, 09h
int 21h
mov dx, offset out1
mov ah, 09h
int 21h
mov bx, row
do1:
mov cx, 10000d
call dec_div
mov cx, 1000d
call dec_div
mov cx, 100d
call dec_div
mov cx, 10d
call dec_div
mov cx, 1d
call dec_div
cmp a, 0
jne next1
;**************shu chu zi jie shu***************
mov dx, offset string
mov ah, 09h
int 21h
mov dx, offset out2
mov ah, 09h
int 21h
mov bx, row
mov cl, 04h
shl bx, cl
mov a, 01h
jmp do1
next1:
ret
dec_div proc near
mov ax, bx
mov dx, 0
div cx
mov bx, dx
mov dl, al
add dl, 30h
mov ah, 02h
int 21h
ret
dec_div endp
display endp
;******************************************
search proc near
mov dx, offset string1
mov ah, 09h
int 21h
mov ah, 0ah
mov dx, offset aimpar
int 21h
;*************************gei hou mian de quan dou tian shang kong ge
mov al, 20h
sub ch, ch
mov cl, aimlen
mov di, offset aimrec
add di, cx
neg cx
add cx, 14
cld
rep stosb
call openh
cmp recg, 0
jnz out3
doit:
call readh
cmp recg, 0
jnz out3
cmp endcde, 0;dang endcde=1 de shi hou cai biao shi wen jian cao zuo dao le wen jian de jie wei
jne next2
mov si, offset buf
mov di, offset aimrec
mov cx, 16
repe cmpsb
cmp cx, 0
je findit
jmp doit
findit:
mov al, b
inc al
mov b, al
jmp doit
next2:
cmp b, 0
jne doit1
jmp doit2
doit1:
mov dx, offset string2
mov ah, 09h
int 21h
mov dl, b
add dl, 30h
mov ah, 02h
int 21h
ret
doit2:
mov dx, offset string4
mov ah, 09h
int 21h
mov c, 01h
ret
out3:
mov c, 01h
ret
search endp
;********************************************
openh proc near
mov ax, 3d00h
mov dx, offset pathname1
int 21h
jc error3
mov handle1, ax
ret
error3:
mov dx, offset openmsg
mov ah, 09h
int 21h
mov recg, 01h
ret
openh endp
;*********************************************
readh proc near
mov ah, 3fh
mov bx, handle1
mov cx, 16
mov dx, offset buf
int 21h
jc error4
cmp buf, 1ah;EOF marker
je c1
ret
error4:
mov dx, offset readmsg
mov ah, 09h
int 21h
mov recg, 01h
ret
c1:
mov endcde, 01h
ret
readh endp
;*************************************************
choose proc near
mov dx, offset string5
mov ah, 09h
int 21h
mov ah, 01h
int 21h
cmp al, 59h
jne e1
jmp e2
e1:
cmp al, 79h
jne e3
jmp e2
e3:
mov bi, 1
ret;bu xiang ti huan
e2:
mov dx, offset string3
mov ah, 09h
int 21h
mov ah, 0ah
mov dx, offset transpar
int 21h
mov al, 20h
sub ch, ch
mov cl, translen
mov di, offset transrec
add di, cx
neg cx
add cx, 14
cld
rep stosb
ret
choose endp
;***************************************************
display2 proc near
mov recg, 0
mov endcde, 0
mov ah, 3dh
mov al, 00
mov dx, handle2
int 21h
mov ah, 3fh
mov bx, handle2
mov cx, 16
mov dx, offset buf1
int 21h
mov dx, offset buf1
mov ah, 09h
int 21h
dec row1
cmp row1, 0
je h1
ret
h1:
mov endcde, 01h
ret
display2 endp
;*******************************************************
CSEG ENDS
;TO DO: Add other segments here (as your requirement)
END MAIN
;----------------------------*The End*--------------------------------
;Warning:This ASMEditor can not support Chinese now.
;Please do NOT use any Chinese-word! Or you will LOST you file!!
;This Model was created by Honeybee. You can modify it as you wish.
;If you write a Model, save it with this name "InitSamp.EAM" in this
;application's floder.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -