The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: lingjie on May 05, 2007, 03:30:33 PM

Title: newbie, please help - loop
Post by: lingjie on May 05, 2007, 03:30:33 PM
1.

can somebody please tell me why this results in a infinite loop:

.386
.model flat,stdcall       ; FLAT memory model & STDCALL calling
option casemap:none       ; set code to case sensitive

include \masm32\include\masm32rt.inc


.stack  4096                  ; reserve 4096-byte stack
.data                         ; reserve storage for data


.code                              ; start of main program code
start:

mov ecx,96
s:
    inc ecx
    inc ecx
    cmp ecx, 9
    je e
    print " ",97,13,10
    jmp s
e:

invoke ExitProcess, 0      ; return 0;
PUBLIC start
end start                          ; end of source code



thanks in advance
Title: Re: newbie, please help - loop
Post by: lingjie on May 05, 2007, 03:34:38 PM
mis-type:

cmp ecx, 9
shoudl be
cmp ecx, 99

still infinite loop.
Title: Re: newbie, please help - loop
Post by: korte on May 05, 2007, 03:47:57 PM
Using higl level loop



      mov ecx,96
     .REPEAT
         statements
     .UNTILCXZ
Title: Re: newbie, please help - loop
Post by: lingjie on May 05, 2007, 04:05:09 PM
mov ecx,96
.REPEAT
    inc ecx
    inc ecx
    cmp ecx, 99
    mov ecx, 0
    print " ",97,10,13
.UNTILCXZ

still infinite loop, anything I did wrong???
Title: Re: newbie, please help - loop
Post by: SideSwipe on May 05, 2007, 04:21:52 PM
Hello:

If you start at ecx = 96

inc ecx : now is 97
inc ecx : now is 98
cmp to 99 : nope so loop again

inc ecx : now is 99
inc ecx : now is 100
cmp to 99 : nope so loop again

over and over

Take out one of the inc ecx statements. Also, if you set ecx to zero every time through the loop, you will get infinite loop syndrome.

Regards,

SS
Title: Re: newbie, please help - loop
Post by: lingjie on May 05, 2007, 04:27:13 PM
thanks...i took out one of the inc...


mov ecx,96
.REPEAT
    inc ecx
    cmp ecx, 99
    mov ecx, 0
    print " ",97,10,13
.UNTILCXZ


this still gives me infinite loope
Title: Re: newbie, please help - loop
Post by: SideSwipe on May 05, 2007, 04:29:36 PM
Take out mov ecx,0

SS
Title: Re: newbie, please help - loop
Post by: lingjie on May 05, 2007, 04:33:28 PM
mov ecx,96
.REPEAT
    inc ecx
    cmp ecx, 99
    print " ",97,10,13
.UNTILCXZ


still gives infinite loop...thanks
Title: Re: newbie, please help - loop
Post by: SideSwipe on May 05, 2007, 04:38:06 PM
Hello:

Well thats a real noodle baker then. I am not familiar with the Print macro. Is it trashing the ecx register? Try and step through your code with a debugger, you will see what is going on. I use Ollydbg for debugging purposes.

Regards,

SS
Title: Re: newbie, please help - loop
Post by: drizz on May 05, 2007, 04:42:59 PM
ecx is a scratch register that needs to be preserved when calling subroutines. (macro print calls StdOut which calls WriteFile).
mov ecx,96
.REPEAT
   inc ecx
   push ecx
   print " ",97,10,13
   pop ecx
.UNTIL  ecx == 99
Title: Re: newbie, please help - loop
Post by: lingjie on May 05, 2007, 04:48:30 PM
THANKS A lot, that worked..... :bg