News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

The difference when using .while

Started by kemicza, July 15, 2008, 02:06:07 PM

Previous topic - Next topic

kemicza

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.

Jimg

If you are including windows.inc,  ABC is a structure and cannot be used as a variable name.

kemicza

i was using ABC as an example.. Let it be sjdhfqkhfsjfdhskh... Now can somebody anwser ?

Jimg

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.

Tedd

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
No snowflake in an avalanche feels responsible.

kemicza

Tedd thank you, it works perfectly now :) !