title: How to end assembly correctly?
body: <p>I have a problem correctly terminating a 16bit DOS program written in Assembly.  Here's part of code:</p>
  
  <pre><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
  </code></pre>
  
  <p>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 <code>iretd</code> is performed.  Why does this happen?  How can do I terminate a 16bit DOS app correctly?</p>