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?
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:
pleaseKillMeNow:
mov ah,0x4C ;DOS "terminate" function
int 0x21