title: Why is 'cmp' not necessary when using jumps on a loop?
body: <p>I fill <code>ecx</code> with the amount of times I want to loop, <code>dec</code>rease <code>ecx</code> and <code>jump if not zero</code> to <code>back:</code>. </p>
  
  <p>Now the question is, why isn't:</p>
  
  <p><code>cmp ecx, 0</code>
  necessary before <code>jnz back</code>.
  How does <code>jnz</code> knows automatically which register to compare when doing the jump? (which is <code>ecx</code> in this case).</p>
  
  <pre><code>int _tmain(int argc, _TCHAR* argv[])
  {
      int a = 0;
  
      __asm 
      {
          mov eax, 0
          mov ecx, 4
  back:
          inc eax
          sub ecx, 1
          jnz back
          mov a, eax
      }
  
      cout &lt;&lt; a &lt;&lt; endl; //outputs '4' properly
  
      return 0;
  }
  </code></pre>