i want to find a string in C:\text.txt. if i find it , i can modify it.
please help me~
data segment
tip db 'This program will search a string in C:\text.txt.If it exists,you can insert a new word in that position.$'
mes1 db 'please enter your string:$'
mes2 db 'not exist$'
mes3 db 'exist$'
mes4 db 'insert?(y/n)$'
mes5 db 'please enter a new word:$'
mes6 db 'ok!$'
posmes db 'H of the text.txt$' ;position message
errmes db 'error!$' ;error message
file db 'C:\text.txt',00
string db 10,?,10 dup(?)
text db 1024 dup(0)
word db 10,?,10 dup(?)
count db ?
handle dw ?
loc db ?
data ends
;**********************************************************************
code segment
assume cs:code,ds:data,es:data
main proc far
mov ax,data
mov ds,ax
mov es,ax
;******output tip
mov ah,9
mov dx,offset tip
int 21h
;******
mov dl,0ah
mov ah,02h
int 21h
;******output mes1
mov ah,9
mov dx,offset mes1
int 21h
;******input string
mov dx,offset string
mov ah,10
int 21h
;******open file
mov dx,offset file
mov al,010
mov ah,3dh
int 21h
jc error
mov handle,ax
;******read file
mov ah,3fh
mov bx,handle
mov cx,1024
lea dx,text
int 21h
jc error
;******
mov di,offset text+2
mov bx,di ;file buffer's add->bx
mov al,text+1 ;file's length->al
sub al,string+1 ;file'length-string'length
jl notexist
inc al
mov count,al ;the repeat time
;******search
next:
mov si,offset string+2 ;string's add->si
mov cl,string+1 ;string'length->cl
mov ch,0
cmp count,0
jl notexist
rep cmpsb
je exist
inc bx
mov di,bx
dec count
je notexist
jmp next
;******notexist
notexist:
;******output mes2
mov dl,0ah
mov ah,02h
int 21h
mov ah,9
mov dx,offset mes2
int 21h
jmp over
;******exist
exist:
sub bx,offset text+1 ;the location
mov loc,bx ;save to loc
;******output mes3
mov dl,0ah
mov ah,02h
int 21h
mov ah,9
mov dx,offset mes3
inc 21h
;******output posmes
call binihex ;call binihex
mov ah,9
mov dx,offset posmes
int 21h
;******output mes4
mov dl,0ah
mov ah,02h
int 21h
mov ah,9
mov dx,offset mes4
int 21h
;******decide insert or not
mov ah,01
int 21h
cmp al,79
jz insert
cmp al,59
jz insert
jmp over
;******insert
insert:
mov dl,0ah
mov ah,02h
int 21h
;******output mes5
mov ah,9
mov dx,offset mes5
int 21h
;******input new word
mov dx,offset word
mov ah,10
int 21h
;******move point
mov ah,42h
mov al,0
mov bx,handle
mov cx,0
mov dx,loc
int 21h
jc error
;******write new word
mov ah,40h
mov bx,handle
mov cx,word+1
mov dx,offset word
int 21h
jc error
;******close file
mov ah,3eh
mov bx,handle
int 21h
jmp over
;******error
error:
mov ah,9
mov dx,offset errmes
int 21h
;******over
over:
mov ah,4ch
int 21h
main endp
;******binihex
binihex proc near
mov ch,4
rotate:
mov ch,4
rol bx,cl
mov al,bl
and al,0fh
add al,30h
cmp al,3ah
jl printit
add al,7h
printit:
mov dl,al
mov ah,2
int 21h
dec ch
jnz rotate
ret
binihex endp
;******
code ends
end main