The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: kemicza on July 15, 2008, 02:06:07 PM

Title: The difference when using .while
Post by: kemicza on July 15, 2008, 02:06:07 PM
Ok I don't understand the difference here. I'll explain with an example.

mov ABC,4
mov Randx,0
mov eax,ABC
.while Randx < eax
                                                ;DO CODE

inc Randx
.endw


and this:

mov Randx,0
.while Randx < 4
                       ;DO CODE

       inc Randx
.endw


Both codes compile perfectly, but the first one seems to block the programm.
Why is this? And how can I make the first one work?

Thanks in advance.
Title: Re: The difference when using .while
Post by: Jimg on July 15, 2008, 03:43:34 PM
If you are including windows.inc,  ABC is a structure and cannot be used as a variable name.
Title: Re: The difference when using .while
Post by: kemicza on July 15, 2008, 04:30:43 PM
i was using ABC as an example.. Let it be sjdhfqkhfsjfdhskh... Now can somebody anwser ?
Title: Re: The difference when using .while
Post by: Jimg on July 15, 2008, 04:54:22 PM
I tested it with masm 6.14 and 6.15 with no problem.

Do you have additional code within the loop?  any api and most procs will trash eax.
Title: Re: The difference when using .while
Post by: Tedd on July 15, 2008, 04:58:38 PM
What you've actually posted will work fine, the problem comes when you actually put something useful instead of ";DO CODE" -- if that code modifies 'eax' in any way, then you're no longer comparing against the value '4', but whatever the new value of eax is.
So, to make the first one work, you could push/pop to reserve the value of eax:

mov ABC,4
mov Randx,0
mov eax,ABC
.while Randx < eax
    push eax
    ;DO CODE
    pop eax
inc Randx
.endw
Title: Re: The difference when using .while
Post by: kemicza on July 15, 2008, 06:47:12 PM
Tedd thank you, it works perfectly now :) !