So my program is supposed to take in user input (an integer between 10 and 200) and print out an array of random numbers and print out a sorted version of that array. However, t
If you look at your registers, you'll see that edx
is 0fA4h
, which is larger than it should be at the line it crashes on. ecx
is a negative number. This is a clue that your loop is executing after it should have stopped.
The problem is that the greater
branch will fall thru to the lesser
branch. This will decrement ecx
again, causing it to go negative and your loop will just keep running until you get the access violation.
The quick fix is to put an unconditional jmp
after the loop
instruction under the greater
label.
A better fix is to combine the tails of the loops into a simpler conditional:
cmp esi, [edi + (eax * 4)] ; compare array[j] and array[i]
jle lesser
mov eax, edx
lesser:
inc edx
loop secondLoop