title: NASM pass by reference
body: <p>I encountered a problem while coding in NASM (I am a beginner in this language). I am using pass by reference. The code should terminate when the value in [ebp-2](serve as counter) is equal to the value in [ebp+4](number from user). I am expecting 'checked' to be printed 5 times but the output is either an infinite loop or 'checked' printed n times.</p>
  
  <p>This is a part of my code where the problem is happening:</p>
  
  <pre><code>find_prime:
          mov ebp, esp
          sub esp, 2
  
          mov ecx, [ebp+4]      ;ecx contains address of ebp+4    
          mov word [ebp-2], 1   ;[ebp-2] as counter
  
          while1_begin:
              mov bx, [ebp-2]
              cmp bx, [ecx]     ;check if bx &lt; [ecx]  
              je terminate      ;if bx = [ecx] terminate
  
              mov eax, 4
              mov ebx, 1
              mov ecx, pri      ;pri contains 'checked'
              mov edx, priLen
                  int 80h
  
              inc word [ebp-2]
              jmp while1_begin
  
          while1_end:
              jmp terminate
  
          add esp, 2
          ret 4
  </code></pre>