You are decreasing ecx
twice. The dec
instruction will decrease it, and the loop
instrucction also decreases it.
Either use
dec ecx
jne L1
or use
loop L1
The reason why it doesn't exit is the following
dec ecx -> ecx = 8
loop l1 -> ecx = 7
dec ecx -> ecx = 6
loop l1 -> ecx = 5
dec ecx -> ecx = 4
loop l1 -> ecx = 3
dec ecx -> ecx = 2
loop l1 -> ecx = 1
And here comes the catch!
dec ecx -> ecx = 0 no condition
loop l1 -> ecx = 0xffffffff Loop will not break because it breaks on 0
dec ecx -> ecx = 0xfffffffe
loop l1 -> ecx = 0xfffffffd
...
... and so on. You get the idea. If you had used a debugger, you would have seen this after only a few iterations.
Actually ecx
will reach 0 in this roundtrip, but it takes LONG time. :)