为什么我的代码收到“文件意外结束”?

问题描述

代码一个意外的文件结尾错误,我似乎无法理解这是怎么回事,您能帮我解决这个问题吗?

;'--------------------------------

.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 (将#修改为@)