News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Question on an assembly directive

Started by Dubhe, December 20, 2005, 08:32:50 PM

Previous topic - Next topic

Dubhe

Hi, All!

I am just now moving from DOS 16 bit MASM to Windows programming via MASM32. So far, so good.

Since I get distracted easily, I am using Pirogov's book, "The Assembly Programming Master Book" as a tutorial. In most of his example code, he uses the following assembler directive at the start of his code segments:

_DATA SEGMENT DWORD PUBLIC USE32 'DATA'

and the following directive at the start of his code segments:

_TEXT SEGMENT DWORD PUBLIC USE32 'CODE'

When I attempt to Assemble and Link this, I always get the following error:

"error A2015: segment attributes cannot change : alignment"

When I remove the keywords DWORD and USE32 from both statements, the program assembles, links, and runs fine.

There is a .MODEL FLAT directive earlier in the code. I think this means that 32 bit segments will be used by default, so are DWORD and USE32 redundent? Why are they there?


hutch--

Dubhe,

You rarely ever need to specify the segment directives any longer. If you use the format in most of the MASM32 examples you have very reliable operation.


      .486                 ; can be up to .686p
      .model flat, stdcall      ; 32 bit memory model
      option casemap :none      ; case sensitive

Write initialised data with,
.DATA

Write uninitialised data as,
.DATA?

and write the runtime code as,

.CODE


This gives you all of the appropriate sections reliably and you can change them through the code to put the data in more convenient locations.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

MichaelW

Dubhe,

The problem is with the DWORD alignment. You could fix the problem by changing the alignment to PARA, or by just not specifying an alignment. The USE32 is not causing a problem, but if your code starts with something like this:

.486                       ; create 32 bit code
.model flat, stdcall       ; 32 bit memory model
option casemap :none       ; case sensitive

With a .386 or higher processor directive preceding the model directive, USE32 is the default, so the USE32 in the SEGMENT directive is redundant.

Or you could fix the problem, with less effort, by just use the simplified segment directives as Hutch demonstrated.

Prior to testing this I would have guessed DWORD alignment, and I'm somewhat surprised that MASM is using PARA alignment, but clearly it works.

eschew obfuscation

GregL

Quote... I am using Pirogov's book, "The Assembly Programming Master Book" as a tutorial.

I read that book. He likes to be an "assembler purist", in other words, old style. He doesn't like the simplified segment directives or high level directives. He uses both MASM and TASM. In the first part of the book the programs are specific to MASM or TASM. Later in the book he writes programs that can be assembled with both assemblers with no modifications. It's an interesting idea, and it works, but I think it limits what can be done with each assembler alone.

I don't remember having problems assembling his code. Of course, you will have problems if you try to assemble a TASM specific program with MASM, or vice versa.

It's a pretty good book, I enjoyed reading it, but I don't really agree with the way he does things.


Dubhe