I\'m currently learning Intel x86 Assembly, and I\'ve run into a problem while trying to construct a simple loop, which loops 10 times. It\'s supposed to stop after the 10 l
If the "overwriting"-problem is solved and if we are begining with a counter of 10 for decreasing the counter each circuit and if we branch if the value of the counter is greater or equal than 0, then we become a looping of 11 times.
Alternativly we can also use the zeroflag to branch (if the zeroflag is not set):
dec cl
jnz _loop_start
The "dec" instruction already involve the flag register, so we do not need the "cmp"-instruction, if we want to check if a value was decreasing to zero.
Dirk
cx is the lower 16 bit portion of ecx. Your code suggest that you may think that your loop will run 10 times (you set cx to 10 before the loop). But then you overwrite the value with the address of msg with mov ecx, msg
. So you'll start to count down to 0 from the lower 16 bit of that number.
But the decrement doesn't even have an effect since during the next iteration you overwrite the ecx again with the msg's address. And the loop start again. It's an infinite loop.
Did you check the software in debugger? That can help a lot.