flat assembler
Message board for the users of flat assembler.

Index > Windows > Tricky Error [HELP ME PLEASE]

Author
Thread Post new topic Reply to topic
AsmER



Joined: 25 Mar 2006
Posts: 64
Location: England
AsmER 31 Mar 2006, 20:48
Hi everybody,
I always liked TASM and its IDEAL mode, so after it 'died', the only assembler with similar syntax is FASM. Infortunately I have very strange problem with it. I want create window (without any controls/menus) but after I run my program I getting beautiful window (developed by Microsoft) which ask me if I could send report (Access violation after executing CreateWindowEx first time). Source looks correct (however in C++ it worked). What I can say is that when hMenu parameter is set to '0h' function cause access volation, when param is EAX(which contain '0h') function return NULL. Any suggestion?
;Program source is in attachement.


Description:
Download
Filename: Program.ASM
Filesize: 1.48 KB
Downloaded: 237 Time(s)


_________________
;\\ http://theasmer.spaces.live.com \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Post 31 Mar 2006, 20:48
View user's profile Send private message Reply with quote
decard



Joined: 11 Sep 2003
Posts: 1092
Location: Poland
decard 31 Mar 2006, 21:49
Problem with your program was rather uncommon. Try to replace 'RET' from line 57 with 'ret' (in lowercase). This will prevent from crashing.
But why it works now? Because 'ret' in proc macro is redefined (it becomes a macro too). Preprocessor is case-sensitive, so it replaces 'ret' properly, while it doesn't touch 'RET'. This, in your situation, leaves stack unballanced, therefore causing crash.
Alternaively, you can add line with "RET fix ret" in the beginning of your code, if you want to have every instruction written in uppercase.
Post 31 Mar 2006, 21:49
View user's profile Send private message Visit poster's website Reply with quote
RedGhost



Joined: 18 May 2005
Posts: 443
Location: BC, Canada
RedGhost 01 Apr 2006, 01:55
without macroinstructions 'ret #_of_bytes_passed' will balance the stack, you can use cdecl style convention and do add esp, # after the call aswell
Post 01 Apr 2006, 01:55
View user's profile Send private message AIM Address MSN Messenger Reply with quote
bogdanontanu



Joined: 07 Jan 2004
Posts: 403
Location: Sol. Earth. Europe. Romania. Bucuresti
bogdanontanu 01 Apr 2006, 02:36
LZASM has the same syntax as TASM in ideal mode
and i am also (very slowly) working to an TASM like assembler
Post 01 Apr 2006, 02:36
View user's profile Send private message Visit poster's website Reply with quote
decard



Joined: 11 Sep 2003
Posts: 1092
Location: Poland
decard 01 Apr 2006, 05:43
RedGhost wrote:
without macroinstructions 'ret #_of_bytes_passed' will balance the stack, you can use cdecl style convention and do add esp, # after the call aswell

Not in this case - it's a window procedure.
Post 01 Apr 2006, 05:43
View user's profile Send private message Visit poster's website Reply with quote
RobotBob



Joined: 18 Jun 2003
Posts: 12
Location: USA
RobotBob 01 Apr 2006, 10:23
If this:

Quote:

without macroinstructions


How does this matter?

Quote:

it's a window procedure.
Post 01 Apr 2006, 10:23
View user's profile Send private message Reply with quote
decard



Joined: 11 Sep 2003
Posts: 1092
Location: Poland
decard 01 Apr 2006, 12:01
RobotBob wrote:
How does this matter?

It matters because window procedure can't be cdecl.
Post 01 Apr 2006, 12:01
View user's profile Send private message Visit poster's website Reply with quote
RobotBob



Joined: 18 Jun 2003
Posts: 12
Location: USA
RobotBob 01 Apr 2006, 12:14
Quote:

without macroinstructions 'ret #_of_bytes_passed' will balance the stack, you can use cdecl style convention and do add esp, # after the call aswell


he is refering to the stack, and ret # in relation to it. IMHO.
the inference that he is talking about the windowproc is wrong, and his
reference to cdecl stays within that reference since he uses *aswell*.

just semantics.
Post 01 Apr 2006, 12:14
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
Madis731 02 Apr 2006, 11:23
Guys, with window procedures there is an exception in OS programs were your program is even *lower* than the kernel, because what happens here is that USER32.DLL calls your procedure and when ret happens - it goes back to user32. You can't do 'add esp,const' to adjust it because you have no control over it.

There have been many problems before about unbalancing stack before leaving window proc or changin ebx which seems to be a 'safe' register. Eventually it will crash.
Post 02 Apr 2006, 11:23
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
RobotBob



Joined: 18 Jun 2003
Posts: 12
Location: USA
RobotBob 02 Apr 2006, 12:11
"You can't do 'add esp,const' to adjust it because you have no control over it. "

ok here is my comment in tarzan english:
(comment about stack and ret, no about winproc, must save jane) Very Happy

I apologize for posting, I was only confused by the english syntax.
Post 02 Apr 2006, 12:11
View user's profile Send private message Reply with quote
AsmER



Joined: 25 Mar 2006
Posts: 64
Location: England
AsmER 02 Apr 2006, 14:59
WOW!

I didn't think that the problem can be the 'ret' instruction in that line (I fought that I made a mistake in line between: 10 - 27). I began think it is something wrong with Fasm or me. Anyway it is good to know that fasm overwrite ret instruction in macros (with macro Smile ). THANKS Exclamation

_________________
;\\ http://theasmer.spaces.live.com \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Post 02 Apr 2006, 14:59
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.