flat assembler
Message board for the users of flat assembler.

Index > Main > Infinite loop

Author
Thread Post new topic Reply to topic
Ren



Joined: 09 Jun 2007
Posts: 11
Ren
Asm Newbie
Why is this an infinite loop?

code:

format PE CONSOLE
entry start
include 'c:\cc\crenshawbasic\testb\fasmw167\include\win32ax.inc'

section '.data' data readable
msg db 'HELLO'

section '.code' code readable executable
pushad
start:
mov ecx,0
loop1:
cinvoke printf,msg
add ecx,1
cmp ecx,10
jnz loop1
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'

Thanks!
Post 28 Jun 2007, 10:48
View user's profile Send private message Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
try pushing and poping ecx before and after the printf accordingly.
Post 28 Jun 2007, 11:36
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17720
Location: In your JS exploiting you and your system
revolution
Try using ebx, esi, ebp or edi instead of ecx. The 4 registers I mentioned there are preserved by the printf function whereas all the other registers (eax, ecx and edx) should be assumed to be clobbered.
Post 28 Jun 2007, 12:22
View user's profile Send private message Visit poster's website Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
I'd also like to note that your string isn't terminated (you seem to be using 10, but printf uses 0). That means it'll start printing the code of your Exe. Also, since each letter isn't null terminated, if you don't print out your code, the output would look a bit like this...

Quote:
HELLOELLOLLOLOO
Post 28 Jun 2007, 12:42
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
Ren



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

I did use ebx and that is OK.
But does it mean that I need to use ebx or push and pop ecx for all
the crtdll functions?
Are there other dll's who give problems with ebx or others that You
know of?

And Yes I got the HELLOHELLO.....
but no problem as I posted only because of the endless loop problem.

But never the less,

Thanks
Ren
Post 28 Jun 2007, 15:58
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
Quote:

But does it mean that I need to use ebx or push and pop ecx for all
the crtdll functions?

For every API function you call actually, it is the way stdcall and cdecl calling convention works. Only EBP, EBX, ESI and EDI are preserved. On stdcall ESP returns with the value prior to the first argument push and cdecl returns ESP with the same value it had before executing the CALL instruction.
Post 28 Jun 2007, 16:14
View user's profile Send private message Reply with quote
Ren



Joined: 09 Jun 2007
Posts: 11
Ren
Thanks, that's what I needed!

Ran
Post 29 Jun 2007, 04:28
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. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.