title: nasm assembly for loop
body: <p>I'm trying to build for loop, but it gives me infinite loop:</p>
  
  <pre><code>SECTION .data
  
  i: dd 0
  message: db "The number is %d",10,0
  SECTION .text
  
  extern printf
  global main
  
  main:
      push ebp
      mov ebp, esp
  
      mov eax, DWORD [i]
      mov ecx, DWORD 10
  
      L1:
          add eax, DWORD 1
          push eax
          push message
          call printf
          add esp, 8
          loop L1
      mov esp, ebp
      pop ebp
  </code></pre>
  
  <p>nasm gives me the output as <code>The number is 18</code> infinitely. But if I put <code>printf</code> at the end of the code. It gives me the correct output</p>
  
  <pre><code>L1:
      add eax, DWORD 1
      loop L1
  
  push eax
  push message
  call printf
  add esp, 8
  
  mov esp, ebp
  pop ebp
  </code></pre>
  
  <p>Anyone knows where I did wrong? </p>