我正在尝试读取文本文件并在程序集中打印内容。读取文件并打印出内容。但是,“读取文件”将打印在文件内容之后的下一行。我想知道为什么在代码工作正常的情况下打印错误。
.model tiny
.data
filename db "file.txt", 0
bufferSize = 512
filehandle dw ?
buffer db ' $'
message1 db 'Cannot open file $'
message2 db 'Cannot read file $'
message3 db 'Cannot close file $'
.code
org 100h
start:
call open
call read
call close
call Exit
open:
mov ah,3DH
mov al,0
mov dx, offset filename
int 21h
jc openErr
mov filehandle, ax
ret
read:
mov ah, 3Fh
mov bx, filehandle
mov cx,bufferSize
mov dx, offset buffer
int 21h
cmp ax,0
jc readErr
;changes are here
;displays content of file
call clear
mov ah, 9
mov dx, offset buffer
int 21h
ret
;changes stop here
close:
mov ah, 3Eh
mov bx, filehandle
int 21h
jc closeErr
ret
Exit:
mov ax, 4C00h
int 21h
openErr:
call newline
lea DX,message1 ;set up pointer to error message
mov AH,9 ;display string function
int 21H ;DOS call
stc ;set error flag
ret
readErr:
call newline
lea DX,message2 ;set up pointer to error message
mov AH,9 ;display string function
int 21H ;DOS call
stc ;set error flag
ret
closeErr:
call newline
lea DX,message3 ;set up pointer to error message
mov AH,9 ;display string function
int 21H ;DOS call
stc ;set error flag
ret
newline: ;prints a newline
mov ah, 2
mov dl, 0DH
int 21h
mov dl, 0AH
int 21h
ret
clear: ;clears the screen
mov ax,003h
int 10h
ret
end start