【发布时间】:2018-04-15 15:57:25
【问题描述】:
我正在尝试编写一个使用中断 21h 读写文本文件的代码。
这是我的代码:
IDEAL
MODEL small
STACK 100h
DATASEG
filename db 'testfile.txt',0
filehandle dw ?
Message db 'Hello world!'
ErrorMsg db 'Error', 10, 13,'$'
CODESEG
proc OpenFile
; Open file for reading and writing
mov ah, 3Dh
mov al, 2
mov dx, offset filename
int 21h
jc openerror
mov [filehandle], ax
ret
openerror:
mov dx, offset ErrorMsg
mov ah, 9h
int 21h
ret
endp OpenFile
proc WriteToFile
; Write message to file
mov ah,40h
mov bx, [filehandle]
mov cx,12
mov dx,offset Message
int 21h
ret
endp WriteToFile
proc CloseFile
push ax
push bx
; Close file
mov ah,3Eh
mov bx, [filehandle]
int 21h
pop bx
pop ax
ret
endp CloseFile
start:
mov ax, @data
mov ds, ax
; Process file
call OpenFile
call WriteToFile
call CloseFile
quit:
mov ax, 4c00h
int 21h
END start
为什么它不起作用??
【问题讨论】:
-
我不知道汇编,所以我不确定
IDEAL是否需要缩进,甚至我是否修复了格式。 -
您可能想在帮助中心阅读stackoverflow.com/help/how-to-ask
-
notepad++ 在这里绝对无关紧要,所以这对您来说很紧迫。而“不工作”并不是一条有用的信息
-
在什么情况下它不起作用?您期望的行为是什么?它会做什么?
-
“它不起作用”不是错误描述。告诉我们您预计会发生什么以及会发生什么。