如何正确结束组装?
我在正确终止用汇编语言编写的 16 位 DOS 程序时遇到问题。这是代码的一部分:
.386P
.model flat
stack_s segment stack 'stack'
db 256 dup(0)
stack_s ends
data segment use16
data ends
code segment 'code' use16
assume cs:code, ds:data
main proc
mov ax, data
mov ds, ax
iretd
main endp
code ends
end main
问题是,程序没有以正确的方式终止。 DOSBox 死机了。我试图了解使用调试器会发生什么,并且在执行 iretd 后,程序似乎最终陷入无限循环。为什么会发生这种情况?如何正确终止 16 位 DOS 应用程序?
I have a problem correctly terminating a 16bit DOS program written in Assembly. Here's part of code:
.386P
.model flat
stack_s segment stack 'stack'
db 256 dup(0)
stack_s ends
data segment use16
data ends
code segment 'code' use16
assume cs:code, ds:data
main proc
mov ax, data
mov ds, ax
iretd
main endp
code ends
end main
The problem is, that the program doesn't terminate in a correct way. DOSBox just freezes. I tried to understand what happens using debugger, and it seems the program just ends up in an infinite loop after iretd
is performed. Why does this happen? How can do I terminate a 16bit DOS app correctly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Brendan 的答案显示了如何退出,但它使错误级别未定义(它将是 AL 寄存器中的任何内容...)
如果您想以错误级别 0 退出:
如果您想以错误级别 1 退出:
Brendan's answer shows how to exit but it leaves the error level undefined (it will be whatever is in the AL register...)
If you want to exit with error level 0:
If you want to exit with error level 1:
结束DOS程序最正确的方法是使用“终止”DOS功能;接下来是足够的注释,以便人们明白这个函数不会返回。
例如:
The most correct way to end a DOS program is to use the "terminate" DOS function; followed by adequate comments so that people understand that this function won't return.
For example:
如果您想在没有任何特定错误代码的情况下退出,则可以这样做:
但如果您想返回特定错误代码,这是更好的方法:
If you want to exit without any particular error code this is the way to go:
But if you want to return a particular error code, this is a better way: