News:

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

Constants

Started by donkey, December 24, 2004, 06:36:50 AM

Previous topic - Next topic

donkey

Lately I have been noting alot of the following in new assembly coders source and thought I would point out why it shouldn't be done...

.CONST
IDD_DLG equ 1000
.DATA
etc....


The assembler, any one, will substitute an equate for the value directly in your source code, and does not need a section created for it. However with some assemblers, by specifying the .CONST section, you are directing the assembler to create a 512 byte (with normal alignment) section and in the case above filling it with 0. This is because the equ is not actually put there, it has no buffer size defined so no memory is allocated to it. The CONST section is ofcourse READONLY and so you should never need to put in any numeric value unless it exceeds a DWORD in size or you must address it indirectly via it's address. As a general rule it is used only for string or QWORD constants as they cannot be inserted directly in your code by the compiler or require an actual address. So in short the lesson is not to create a .CONST section unless you need it. Some assemblers will not create a section if it's empty and some will but it's easier, safer and better programming practice not to create it if you are not using it.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable