[英]how can i clear string [dos asm]
when i'm reading and getting file's data and than trying to read and get another text file's data, it's writing the new data on the used string for example, string contains "oh yeah!", after getting another file's data "heyyeah!".当我正在读取和获取文件的数据而不是尝试读取和获取另一个文本文件的数据时,它会在使用的字符串上写入新数据,例如,字符串包含“哦耶!”,在获取另一个文件的数据“嘿耶!”之后. (obviously the second file i was reading contained the word hey in it).
(显然,我正在阅读的第二个文件中包含“嘿”这个词)。 i want to clear the string from the data it got from the 1st file when reading the second file/after displaying the data of the 1st file.
我想在读取第二个文件时/在显示第一个文件的数据后从第一个文件中获取的数据中清除字符串。
Full code:完整代码:
IDEAL
MODEL small
STACK 100h
DATASEG
szMsg1 db "Hi! What do you want to do?",10,13,10,13,"/h-help(see all the commands)",10,13,"/e-Exit",10,13,10,13,"$"
szHelloWorld db 10,13,"Hello World!",10,13,"$"
ErrorMsg db 10,13,"Illegal Command,Try again!",10,13,"$"
filenameStr db 13,0,13 dup("$")
help db 10,13,"HELP LIST:",10,13,"-----------",10,13,"Commands are:",10,13," /e-Exit",10,13," /h-help",10,13," /1-Says: 'Hello World!'",10,13,"$"
filename db ?,0
filehandle dw 0
ErrorOpenMsg db 'Error',10,13,'$'
FileNameLength db "file name consists of 8 letters max! (dont forget to add '.txt' at the end of the name: 'example.txt')",10,13,"/r/ ","$"
fileString db 255 dup (0)
space db " ","$"
CommandMsg db 10,13,"Enter your command:",10,13,"Command: ","$",10,13
filereaderline db "file's text:","$"
CODESEG
proc OpenFile
;Open file
mov ah,3Dh
xor al,al
lea dx,[filenameStr+2]
int 21h
jc openerror
mov [filehandle],ax
ret
openerror:
mov dx,offset ErrorOpenMsg
mov ah,9h
int 21h
ret
endp OpenFile
proc ReadFile
mov ah,3fh
mov bx,[filehandle]
mov cx,255
lea dx,[fileString]
int 21h
ret
endp ReadFile
proc DeleteFile
mov ah,41h
lea dx,[filenameStr+2]
int 21h
endp DeleteFile
proc DisplayFileString
mov ah,09h
lea dx,[fileString]
int 21h
endp DisplayFileString
proc KeyStroke
xor ax,ax
int 16h
endp KeyStroke
proc WriteToFile
mov ah,40h
mov bx,[filehandle]
mov cx,255
lea dx,[fileString]
int 21h
ret
endp WriteToFile
proc CloseFile
mov ah,3Eh
mov bx,[filehandle]
int 21h
ret
endp CloseFile
start:
mov ax, @data
mov ds, ax
mov dx,offset szMsg1
mov ah,9h
int 21h
jmp GetCommandLetter
_Error:
mov dx,offset ErrorMsg
mov ah,9h
int 21h
GetCommandLetter:
mov dx,offset CommandMsg
mov ah,9h
int 21h
mov ah, 1h
int 21h
mov bl,al
mov ah, 1h
int 21h
mov bh,al
compare:
cmp bl,'/'
jne _Error
cmp bh,'h'
je _help
cmp bl,'/'
jne _Error
cmp bh,'H'
je _help
cmp bl,'/'
jne _Error
cmp bh,'1'
je PrintLine
cmp bl,'/'
jne _Error
cmp bh,'e'
je _exit
cmp bl,'/'
jne _Error
cmp bh,'E'
je exit
mov dx,offset space
mov ah,9h
int 21h
mov dx,offset FileNameLength
mov ah,9h
int 21h
cmp bl,'/'
jne _Error
cmp bh,'r'
je GetFileName
cmp bl,'/'
jne _Error
cmp bh,'R'
je GetFileName
jmp _Error
_exit:
jmp exit
_help:
mov dx,offset help
mov ah,9h
int 21h
jmp GetCommandLetter
GetFileName:
mov dx,offset space
mov ah,9h
int 21h
mov dx,offset filenameStr
mov bx,dx
mov [byte ptr bx],13 ;8+1+3+1
mov ah,0Ah
int 21h
mov dx,offset filenameStr + 2
mov ah,9h
int 21h
mov [byte ptr filenameStr+2+8],0
call OpenFile
call ReadFile
mov dx,offset filereaderline
mov ah,9h
int 21h
call DisplayFileString
call CloseFile
jmp GetCommandLetter
PrintLine:
mov dx, offset szHelloWorld
mov ah, 9h
int 21h
jmp GetCommandLetter
exit:
mov ax, 4c00h
int 21h
END start
If your program runs fine for the "bova.txt" then you'll get a similar result for the second file "help.txt" if you just clean the buffer at the label fileString.如果您的程序对“bova.txt”运行良好,那么您将在第二个文件“help.txt”中得到类似的结果,如果您只清理标签 fileString 处的缓冲区。
call OpenFile
xor bx,bx
WipeClean:
mov [byte ptr fileString + bx], 0
inc bx
cmp bx, 255
jb WipeClean
call ReadFile
mov dx, offset filereaderline
mov ah, 09h
int 21h
call DisplayFileString
call CloseFile
jmp GetCommandLetter
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.