The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: redskull on May 15, 2006, 06:49:36 PM

Title: forward referencing constants
Post by: redskull on May 15, 2006, 06:49:36 PM
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
Title: Re: forward referencing constants
Post by: Ossa on May 15, 2006, 07:10:50 PM
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
Title: Re: forward referencing constants
Post by: redskull on May 15, 2006, 07:21:37 PM
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