如何解决为什么我的代码收到“文件意外结束”?
该代码有一个意外的文件结尾错误,我似乎无法理解这是怎么回事,您能帮我解决这个问题吗?
;'--------------------------------
.MODEL small
.STACK
.DATA
LengthOfStr EQU 38
Handle DW ? ; to store file handle
FileName DB "C:\EXP6_FOLDER\test.txt",0 ; file to be opened
OpenError DB "An error has occured(opening)!$"
ReadError DB "An error has occured(reading)!$"
Buffer DB 100 dup (?) ; buffer to store data
.CODE
main proc far
mov ax,@data ; set up ds to be equal to the
mov ds,ax ; data segment
mov dx,OFFSET FileName ; put address of filename in dx
mov al,2 ; access mode - read and write
mov ah,3Dh ; function 3Dh -open a file
int 21h ; call DOS service
mov Handle,ax ; save file handle for later
jc ErrorOpening ; jump if carry flag set - error!
mov dx,offset Buffer ; address of buffer in dx
mov bx,Handle ; handle in bx
mov cx,100 ; amount of bytes to be read
mov ah,3Fh ; function 3Fh - read from file
int 21h ; call dos service
jc ErrorReading ; jump if carry flag set - error!
mov bx,Handle ; put file handle in bx
mov ah,3Eh ; function 3Eh - close a file
int 21h ; call DOS service
mov cx,LengthOfStr ; length of string
mov si,OFFSET Buffer ; DS:SI - address of string
xor bh,bh ; video page - 0
mov ah,0Eh ; function 0Eh - write character
NextChar:
lodsb ; AL = next character in string
int 10h ; call BIOS service
loop NextChar
mov ax,4C00h ; terminate program
int 21h
ErrorOpening:
mov dx,offset OpenError ; display an error
mov ah,09h ; using function 09h
int 21h ; call DOS service
mov ax,4C01h ; end program with an errorlevel =1
int 21h
ErrorReading:
mov dx,offset ReadError ; display an error
mov ah,4C02h ; end program with an errorlevel =2
int 21h
main endp
end main
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。