title: MASM code for finding prime numbers not working
body: <p>I have the following code for finding prime numbers:</p>
  
  <pre><code>   isPrime PROC; checks if a number is prime by dividing out values less than it until it finds one that has a remainder of 0
           ;or the test value reaches the number
  
  retest:
  inc testNum
  mov eax, testPrime
  cmp eax, testNum
  je  prime
  mov edx, 0
  mov eax, testPrime
  mov ebx, testNum
  div ebx
  cmp edx, ZERO
  jg retest
  mov eax, 1
  mov testNum, eax
  inc testPrime
  prime:
  ret
  isPrime ENDP
  </code></pre>
  
  <p>The way it should be working is that testPrime is the number being tested.  It then checks testNum, which starts at 2 (1 at the beginning but is immediately incremented) and divides testPrime by testNum.  If the remainder is zero, it divides out, and testPrime is not a prime number.  testPrime is incremented, testNum is reset and the whole thing starts again.  If testPrime and testNum are equal, then it is a prime, and the procedure exits (which causes another part of the program to print it, and call the procedure again after incrememnting testPrime).</p>
  
  <p>What is happening is that it is printing every single integer from 2 to however many primes are requested.  I've done some debugging, and it seems that edx is getting a weirdly large number somehow, but I have no clue how.</p>