News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

MASM32 constant compilation.

Started by AssemblyChallenge, January 22, 2015, 03:59:06 AM

Previous topic - Next topic

AssemblyChallenge

Hi all.

Last year I found a very curious situation while working a small project. As you all know, I use -and love  :icon_cool:- EasyCode, and my first thought, of course, was to blame it for the problem but maybe not.

Let's say you declare one or more constants:

.const

MyConst1 = 1234h
MyConst2 = 4567h
.
.
etc.

The compiling goes fine and shows no error but back then my project crashed when executed. With the help of Ollydbg I found that my constant(s) became into a bunch of DBs. The reason? Using "=" instead of "Equ". Once I replaced the "="s everything came back to normal and I learned my lesson.  :lol:

I was wondering if this behavior is normal in MASM32's compiler and the "=" is not allowed for constant declaration.

Regards.

rrr314159

Hi AssemblyChallenge,

You should use EQU for constants. According to p.17 of the Masm 6.1 Programmer's Guide, once you define a constant with Equ it can't be changed later: "attempting to redefine it generates an error". If you use =, however, it can be redefined during the assembly process. Still, even with =, "a constant value is assigned during assembly for each use, and that value does not change at run time". Thus no storage location is assigned (no "bunch of DB's"). So they both define "constants", but Equ is "more constant".

I haven't checked specifically, but I'd be amazed if ML (or ML64, or JWasm) assigns a storage location for a symbol defined with =. Presumably EasyCode is doing that, mistakenly.

BTW you refer to "MASM32's compiler" .. just to clear a potential misunderstanding, MASM32 is not an assembler (or compiler), but a collection of tools and files to enhance the use of an assembler. You're probably using Microsoft's ML.exe, as you can see in your MASM32/bin directory. You could use other assemblers, such as JWasm; that's independent of MASM32. It's easy to get confused; I used MASM32 for months b4 I got this distinction.

If I'm wrong about any of this, sorry ... Ask an expert if you want to know for sure!
I am NaN ;)

AssemblyChallenge

Thank you.

You are right, it is not the whole MASM32 but the compiler (in this case). I assumed not to be EasyCode's fault because it just invokes the source code with some parameters. I was using "=" to declare Constants instead of "Equ" because of the book I was reading and assumed to be the same thing.  :biggrin:

Regards.

rsala

Hi AssemblyChallenge,

Thanks for using Easy Code.

The IDE just sends the sources to the compiler (ml.exe), so the the problem (or error if any) is caused by the compiler. There is nothing I can do about that.

Regards.
EC coder

AssemblyChallenge

That's my point. EasyCode just invokes ML. My real question is how "legal" the equal sign is when declaring constansts.

Regards, Master  8)

Quote from: rsala on January 22, 2015, 11:32:29 AM
Hi AssemblyChallenge,

Thanks for using Easy Code.

The IDE just sends the sources to the compiler (ml.exe), so the the problem (or error if any) is caused by the compiler. There is nothing I can do about that.

Regards.

dedndave

something is amiss, here
perhaps you can post a complete example

i have used both temporary "=" and permanent "EQU" constants for many years without problems
you must have re-assigned the value, somehow

rrr314159

Hello rsala,

I'm glad this problem, whatever it is, occurred, because it provoked me to take a look at EasyCode. It's a masterful job, and I learned a number of things from it. I finally know what's wrong with these .chm files - you have to unblock them! That one tip was worth the price of admission. My hat is off to you; EasyCode is far beyond my meager capabilities. However - even masters, you know, make mistakes. Napoleon marched on Moscow in the winter; Einstein rejected Quantum Mechanics; Fischer dropped a bishop against Spassky; Bruce Lee jumped off a tall building. In the computer world, Gary Kildall refused to sell CP/M to IBM for their new PC; Steve Jobs came out with Next; JWasm says the type of ymm0 is 8 (should be 32); and Bill Gates produced ML.exe, one of the buggiest programs ever. So if EasyCode is not perfect, you're in very good company!

Feeling foolish, I actually went and checked whether ML emitted a db statement for "=" constants. Of course, it doesn't. It may have done in this particular case; if so it's a brand new bug. So either ML did that; or EasyCode somehow modified the source to make that happen; or AssemblyChallenge misunderstood Olly's analysis (based on my experience with Olly, that's not impossible.)

Anyway, bottom line: if it's really constant, use EQU and you'll be a happy coder!
I am NaN ;)

dedndave

i don't agree - i use temporaries quite often, for example...

TmpFlags=WS_OVERLAPPEDWINDOW or WS_VISIBLE or WS_CLIPCHILDREN

        INVOKE  CreateWindowEx,edi,offset szClassName,offset szAppName,TmpFlags,
                CW_USEDEFAULT,SW_SHOWNORMAL,MAIN_WIDTH,MAIN_HEIGHT,edi,edi,ebx,edi


notice that i define it, then use it right away
i don't expect it to remain the same, because i may re-define it elsewhere

jj2007

Quote from: dedndave on January 23, 2015, 03:51:00 AM
something is amiss, here
perhaps you can post a complete example

i have used both temporary "=" and permanent "EQU" constants for many years without problems
you must have re-assigned the value, somehow

I can only echo that. MyFlag=0 is a very valid way to assign "constants", and I also use it all the time without any problems, in ML 6.15 to 10.0 and JWasm. The problem is elsewhere. Search your source code for reassignment. If your project is scattered over a dozen little includes and sources, you'll have to search them all. And don't forget that Masm32 itself *may* use constants - namespace pollution may occur, although Hutch uses EQU throughout, thus blocking the constants (which is a good thing for a library).

dedndave

in the original post, you gave us hypothetical names...

Quote from: AssemblyChallenge on January 22, 2015, 03:59:06 AM
Let's say you declare one or more constants:

.const

MyConst1 = 1234h
MyConst2 = 4567h
.
.
etc.

if you don't want to show us the complete source, at least tell us what names you actually had a problem with

AssemblyChallenge

Fortunately, I kept the message sent to Rsala back then. Also, couldn't replicate the problem; not in the original project nor a new one  :dazzled:

Please look at the attached images. I needed global variables and, following Rsala's kind advice, added a Module in my project and defined all of them there (Original code). The Constants you see were first defined with "=" and compiled successfully but the project crashed when executed. So, I set several NOPs, debugged the program with Olly and found the little mess (Bad compile). Then I replaced "=" by "Equ" in both constants, recompiled and voila, solved (Good compile). Even when several new versions of Easycode came out after that, I really really doubt about its fault and still blame the compiler.

ragdog

Analyse problem in Olly? try to delete the Udd´s

AssemblyChallenge

@rrr314159: A little bit off topic but, oh well  :biggrin:

Most part of Assembly tutorials and videos were created with Radasm and/or Winasm. Of course, I tried to learn and use those for some time but never got used to any of them; can't explain it but somehow I felt unconfortable, even when both are great and yes, took long readings (reviews) beforehand.

My love history with Easycode started a couple of years ago while browsing Woodmann's site and then I ended up here. Visited the site, downloaded it and never looked back  :lol:
Not only is simple and powerful; Ramon gave away tons of info, good examples, and explained very clearly some key concepts and tips about Windows programming that were driving me nuts and couldn't understand before. Plus, he is quick and gentile about the bugs found or my mistakes using his IDE; in a sentence: I was home.

Easycode, FTW!  :icon14: :icon14:  :icon_cool:

AssemblyChallenge

First I was astonished as always rebuild the whole project. This is important so Ollydbg debug the right exe (with no need to get rid off Udds). I'm pretty sure about it because of the million times a project must be debugged/tested. This means I recompiled several times before realizing the cause -surprising for me- and noting the constant names close to the weird DBs; that's how I found it (and comparing with other examples, all with Equs instead).  :t

Quote from: ragdog on January 24, 2015, 06:22:48 AM
Analyse problem in Olly? try to delete the Udd´s

jj2007

Quote from: AssemblyChallenge on January 24, 2015, 05:49:56 AMI set several NOPs, debugged the program with Olly and found the little mess (Bad compile).

The "little mess" might come from Olly not (yet) understanding your code. That happens frequently, you typically see a "mess" with db xyz statements. In that case, select a few lines before and after the interesting zone and press Ctrl A like "analyse". Olly then makes an extra effort, and your code will look much more meaningful.