title: Why is the zero flag not set after the first iteration of the cmp instruction here? x86
body: <p>I am currently learning x86 assembly language using NASM from the following website: <a href="https://www.asmtutor.com/" rel="nofollow noreferrer">https://www.asmtutor.com/</a> and I am presently on <a href="https://asmtutor.com/#lesson11" rel="nofollow noreferrer">Lesson 11</a> if you require the full code of this example.</p>
  <p>Using the <code>divideLoop:</code> subroutine below how does the <code>cmp</code> instruction not set the zero flag (ZF) after just the first iteration? Doesn't <code>idiv</code> set <code>eax</code> to the quotient part and <code>edx</code> to the remainder?</p>
  <pre><code>;EAX is set as 1 before the first iteration.
  
  divideLoop: 
      inc     ecx
      mov     edx, 0
      mov     esi, 10
      idiv    esi
      add     edx, 48
      push    edx
      cmp     eax, 0
      jnz     divideLoop
  
  </code></pre>
  <p>I was under the impression that after <code>idiv    esi</code> that <code>eax</code> would be set to 0 and <code>edx</code> would be set to 1 since 1 / 10 = 0R1 and therefore <code>cmp    eax, 0</code> would equal zero and thus set the zero flag.</p>
  <p>Maybe I'm misunderstanding how <code>idiv</code> works with the quotient part or how <code>cmp</code> sets the zero flag?</p>