title: What to do in interrupt handler for divide by zero?
body: <p>What should an operating system interrupt handler do for interrupts related to coding mistakes?</p>
  
  <p>For example, I tried to divide by 0 for testing my interrupt and my interrupt handler got called. However, because the div instruction was not successfully executed, EIP is not updated to the next instruction after it and after returning from the interrupt handler with <code>iret</code>, it goes back to the erroneous <code>div</code> instruction again.</p>
  
  <pre><code>  mov ax, 3
    mov dl, 0
    div dl    ; go back here again and again
  </code></pre>
  
  <p>What is the correct way to handle this interrupt? A few ways I thought of:</p>
  
  <ul>
  <li><p>Change <code>dl</code> to something else other than 0. However, I'm not sure if <code>dl</code> can keep if something happens, and interrupt routine is supposed to restore registers after exit, and I don't think silently correct an error by providing wrong computation is good.</p></li>
  <li><p>Retrieve the next instruction after <code>div</code>. However, I haven't thought of any simple and reliable way to get the next instruction.</p></li>
  <li><p>Modify the top of the stack that is currently containing the return address to the address of some other code. So, we do not go back to <code>div</code> instruction anymore.</p></li>
  </ul>