flat assembler
Message board for the users of flat assembler.

Index > Windows > Why doesn't my jump work?

Author
Thread Post new topic Reply to topic
2



Joined: 26 Sep 2006
Posts: 92
2
I want it to print 'what ' to a file 4 times.

Code:
include 'win32ax.inc'

IO:



invoke CreateFile,f,GENERIC_WRITE,0,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0
mov [h],eax

xor ecx,ecx

p0:

invoke WriteFile,[h],b,6,r,0

inc ecx

cmp ecx,4
jb p0 ;this should jump back to p0: but it isn't!

invoke CloseHandle,[h]
invoke MessageBox,HWND_DESKTOP,"I want the string written four times!","problem",MB_OK
invoke ExitProcess,0
.end IO;
f db '10binary.txt',0
b db 'What',13,10
h rd 1
r rd 1 
    


It only does it once. I thought I did it right.

_________________
There are 10 kinds of people in the world.
Those who know binary and those who haven't met me.
Post 21 Nov 2006, 10:09
View user's profile Send private message Reply with quote
arafel



Joined: 29 Aug 2006
Posts: 131
Location: Jerusalem, Israel
arafel
Windows API functions don't preserve registers other than ebx, esi, edi, and ebp. Therefore your ecx gets corrupted during the WriteFile call.

push ecx
invoke WriteFile, ...
pop ecx
Post 21 Nov 2006, 10:43
View user's profile Send private message Reply with quote
2



Joined: 26 Sep 2006
Posts: 92
2
THANK YOU! I WILL write this down!
That's definitely what must be causing the problem.
Post 21 Nov 2006, 22:44
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
it's simpler to remember that winAPI trashes ECX and EDX Smile
Post 21 Nov 2006, 23:13
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
And EAX even if the function does not return any value. Modifies EFLAGS too (except some bits like DF).
Post 21 Nov 2006, 23:32
View user's profile Send private message Reply with quote
2



Joined: 26 Sep 2006
Posts: 92
2
Yeah<i wrote down that eax,ecx,and edx get messed with by Windows.
It's sad.
Post 22 Nov 2006, 02:52
View user's profile Send private message Reply with quote
RedGhost



Joined: 18 May 2005
Posts: 443
Location: BC, Canada
RedGhost
2 wrote:
Yeah<i wrote down that eax,ecx,and edx get messed with by Windows.
It's sad.


You can't expect every api to preserve every register. cdecl and other formats aren't even so liberal in saving registers, and fastcall uses registers as arguments.

You can do

Code:
pushad
;....
popad
    


If you must save all GPR.

_________________
redghost.ca
Post 22 Nov 2006, 03:42
View user's profile Send private message AIM Address MSN Messenger 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.