I am having a problem with a loop,

I have a variable:

variable WORD 5

and i am trying to assign this variable to the CX register, like this...

mov cx, variable
Loop LTest

So i am wanting the loop called LTest to loop 5 times, however this doesnt seem to work, it loops more times than it should, does anyone have an idea why?

If i replace variable and just put a decimal number... example:

mov cx, 5
Loop LTest

This works fine, it just never works when i try putting a variable to move into the cx register.

Can anyone help me please?


Thanks, Programmer_to_be :)
Posted on 2003-12-31 21:13:36 by Programmer_to_be
MOVZX ECX,variable ; (assuming variable is a word)

at a guess, i'd say the high bits of ecx are set to something
and loop will work from ecx in a 32 bit environment not cx (correct me if im wrong plz)
so that might explain your wierd loop issue
Posted on 2003-12-31 21:34:09 by evlncrn8
Another possible source to the problem could be API calls inside the loop, without preserving ECX first.
For example:

movzx ecx,variable
push ecx ;Preserve ECX (changed by the API call)
invoke WriteFile,stdout,offset text,sizeof text-1,offset byteswritten,NULL
pop ecx ;Restore ECX
loop LTest
Posted on 2004-01-01 12:11:02 by QvasiModo