The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: MoonBeam777 on May 26, 2006, 08:50:10 PM

Title: Program Assembles and Links yet crashes
Post by: MoonBeam777 on May 26, 2006, 08:50:10 PM
I am reading "The Assembly Programming Master Book", and example 2.2 Assembles, links, and crashes.  :(

This is the asm file --> http://www.geocities.com/little5washu777/Masm32/Example_2.2.Asm
Title: Re: Program Assembles and Links yet crashes
Post by: Ossa on May 26, 2006, 09:00:26 PM
Well... just had a little look at that - I'll attempt to debug it, but, do yourself a favor and take a look at Iczelions tutorials - the format that your code is written in is a bit erm... over the top... you can make use of many of the features of MASM32 that are not being used in your code (e.g. _TEXT SEGMENT etc is prdefined as .code and all of the windows structres are predefined in the windows.inc file that comes with MASM32)

Iczelions tutorials come with MASM32, but you can get them on the web here: http://win32assembly.online.fr/tutorials.html

Ossa
Title: Re: Program Assembles and Links yet crashes
Post by: MoonBeam777 on May 26, 2006, 09:11:34 PM
Over the top seems common in Programming books!
Title: Re: Program Assembles and Links yet crashes
Post by: Ossa on May 26, 2006, 09:18:08 PM
OK,

first mistake (this does not fix it, but is a very major bug - stops the crash, but now crashes somewhere else): line 96, you have
MOV   [WC.CLSCEXTRA], OFFSET WNDPROC
it should be
MOV   [WC.CLWNDPROC], OFFSET WNDPROC
This means that windows has junk for the pointer to WNDPROC... so it jumps to a random address.

Ossa
Title: Re: Program Assembles and Links yet crashes
Post by: Ossa on May 26, 2006, 09:23:23 PM
OK, got it going now... second mistake is on line 185, you have
JMP   WMDESTROY
it should be
JMP   DEFWNDPROC
You always destroy the window otherwise... even before it is created.

Hope that helps... and you might want to treat yourself to some whitespace every now and then... solid lines of code are hard to read.

Ossa
Title: Re: Program Assembles and Links yet crashes
Post by: MoonBeam777 on May 26, 2006, 09:32:31 PM
You are right, I typed that line in wrong.

I am checking to see if I made any other mistakes like that.
Title: Re: Program Assembles and Links yet crashes
Post by: GregL on May 26, 2006, 09:50:51 PM
MoonBeam777,

I have that book too. Ossa is right, the author's style is a bit odd. His goal is writing code that will assemble with both MASM and TASM. In my opinion it really limits what you can do. I say pick an assembler and use all the available features it provides. The book was worth reading though.

Title: Re: Program Assembles and Links yet crashes
Post by: Ossa on May 26, 2006, 10:22:06 PM
Thought I'd just show the difference between the code you posted and something using the full MASM32 bag of tricks...

http://web.mit.edu/rcassels/www/example.asm

I added some comments to describe some of the differences (and really pointless things done in the example - like the .386P thing, why not use .386  ?).

Ossa
Title: Re: Program Assembles and Links yet crashes
Post by: MoonBeam777 on May 26, 2006, 10:40:25 PM
Thanks for the help, the whole thing was me typeing those lines in incorrectly.
Title: Re: Program Assembles and Links yet crashes
Post by: Ossa on May 26, 2006, 10:42:47 PM
Quote from: MoonBeam777 on May 26, 2006, 10:40:25 PM
Thanks for the help, the whole thing was me typeing those lines in incorrectly.

No problem

Ossa