Assembly 我不知道';我不明白为什么我的程序是';行不通
我试图写一个代码,读写中断21h文本文件 这是我的密码:Assembly 我不知道';我不明白为什么我的程序是';行不通,assembly,dos,x86-16,tasm,Assembly,Dos,X86 16,Tasm,我试图写一个代码,读写中断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 m
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
为什么它不工作
请注意,当DOS报告错误时,仅仅显示一条消息,然后使用ret
您需要放弃该程序,因为后续操作无论如何都不会成功
DOS功能40h(写入文件)和3Eh(关闭文件)还可以通过CF报告可能的错误。请确保以类似的方式捕获该文件。我不知道汇编,因此我不确定是否需要缩进
IDEAL
,或者甚至不确定我是否修复了格式。您可能需要阅读帮助中心记事本++与此完全无关,因此这一事实对您来说非常紧迫。“不工作”不是一条有用的信息,它以什么方式不工作?您期望的行为是什么?它会做什么?“它不工作”不是错误描述。告诉我们你期望发生什么,以及会发生什么。
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 <--- This is an extra problem!
endp OpenFile
proc CreateFile
mov dx, offset filename
xor cx, cx
mov ah, 3Ch
int 21h
jc CreateError
mov [filehandle], ax
ret
CreateError:
mov dx, offset ErrorMsg
mov ah, 9h
int 21h
jmp Quit <--- Solution to the extra problem!
endp CreateFile