News:

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

newbie, please help - loop

Started by lingjie, May 05, 2007, 03:30:33 PM

Previous topic - Next topic

lingjie

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

lingjie

mis-type:

cmp ecx, 9
shoudl be
cmp ecx, 99

still infinite loop.

korte

Using higl level loop



      mov ecx,96
     .REPEAT
         statements
     .UNTILCXZ

lingjie

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???

SideSwipe

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
"Crashing through life !"

lingjie

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

SideSwipe

"Crashing through life !"

lingjie

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


still gives infinite loop...thanks

SideSwipe

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
"Crashing through life !"

drizz

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
The truth cannot be learned ... it can only be recognized.

lingjie

THANKS A lot, that worked..... :bg