flat assembler
Message board for the users of flat assembler.

Index > Main > newbie endless loop

Author
Thread Post new topic Reply to topic
Ren



Joined: 09 Jun 2007
Posts: 11
Ren
Hello,
Trying to make a loop in a loop, pushing and popping as it should gives
me an endless loop ?

Thanks!
code:
format PE CONSOLE
entry start
include 'c:\cc\win32ax.inc'
section '.data' data readable
szNumcr db '%d',13,10,0
szNum db '%d',0,0,0

section '.data' data readable writeable
X DW ?
Y DW ?

section '.code' code readable executable
pushad
start:
LEA ESI, [X]
MOV DWORD[ESI], 0
L0:
ADD DWORD[ESI], 2
cinvoke printf, szNumcr, ESI
PUSH ESI ;pushing
LEA ESI, [Y]
MOV DWORD[ESI], 20 ;this gives me and endless loop ??
;L1:
;ADD DWORD[ESI], 2
;PUSH ESI
cinvoke printf, szNumcr, EBX
;POP ESI
;CMP DWORD[ESI], 30
;JNZ L1
POP ESI ;popping
cinvoke printf, szNumcr, ESI
CMP DWORD[ESI], 10
JNZ L0
invoke ExitProcess,0
popad
section '.idata' import data readable writeable
library kernel32,'kernel32.dll',crtdll,'crtdll.dll'
import kernel32,ExitProcess,'ExitProcess'
import crtdll,printf,'printf'
Post 30 Jun 2007, 19:40
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
After changing "DW" with "dd" or "DD" the infinite loop disappears. The "MOV DWORD[ESI], 20" was writing a half in Y variable and the other half in non assigned memory. The problem later was that when you compared against X variable you was actually comparing against a merge of X and Y and for that reason you never reach 10 because that "MOV DWORD[ESI], 20" keeps the value too high.

Either use "word [ESI]" or change the variables to the dword type using "dd" (the latter is prefered).
Post 30 Jun 2007, 20:38
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
When posting code next time, please use the "code tags":

Code:
    cli           ; Yeah Laughing
    pop cs
@@: cpuid
    ud2
    
Post 30 Jun 2007, 20:57
View user's profile Send private message Reply with quote
Ren



Joined: 09 Jun 2007
Posts: 11
Ren
Thanks Loco,

I think I have a lot to learn!

And NTOSKRNL_VXE, I will do that

Thanks,
Ren
Post 01 Jul 2007, 05:13
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.