News:

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

forward referencing constants

Started by redskull, May 15, 2006, 06:49:36 PM

Previous topic - Next topic

redskull

If my understanding is correct, then the assembler just plugs is constants as immediete values before it creates the code; if that's the case, how come you can't forward reference them?

this won't work, but it will if you swap it around (.const before .data) it will

.data
ARRAY DWORD MAX_ARRAY DUP (0)
.const
MAX_ARRAY equ 5


It seems stupid, like it should be able to work.  I'm sure there's a good reason why it doesn't, hopefully someone can enlighten me
Strange women, lying in ponds, distributing swords, is no basis for a system of government

Ossa

You seem to have a misunderstanding between equates and constants. Equates are "plugged in at assemble time" and are defined, as you have, with the EQU directive. Constants are values that are constant - they don't change, but are kept in the .const section and are not "plugged in" until run time. So the following is valid:

MAX_ARRAY equ 5
.data
ARRAY DWORD MAX_ARRAY DUP (0)


Having got that out of the way, your question can now be answered: MASM is a single pass assembler - that is, it starts at the beginning of the file and goes through it once, so that by the end it has finished the assembly process. As a result, it can't "plug in" equates that it doesn't yet know about.

Ossa
Website (very old): ossa.the-wot.co.uk

redskull

Quote from: Ossa on May 15, 2006, 07:10:50 PMMASM is a single pass assembler...

Quote from: Ossa on May 15, 2006, 07:10:50 PMConstants are values that are constant - they don't change, but are kept in the .const section and are not "plugged in" until run time

You learn something new everyday. Thanks! :U
Strange women, lying in ponds, distributing swords, is no basis for a system of government