why does the following code compile perfectly?
Data Segment
Var1 Dw (any 4 digit hex value)
Var2 Dw Var1
Data Ends
what does the line "Var2 Dw Var1" even mean? I thought that only an immediate value can go after the type defining .
why does the following code compile perfectly?
Data Segment
Var1 Dw (any 4 digit hex value)
Var2 Dw Var1
Data Ends
what does the line "Var2 Dw Var1" even mean? I thought that only an immediate value can go after the type defining .
When you declare a variable like this:
VARX DW VARY
then you're basically saying:
VAR DW (offset of VARY into the segment VARY is in)
In your specific example, Var1
is the first variable in the data segment, so the declaration of Var2
is equivalent to:
Var2 DW 0x0000
If, later on, you add more variables before Var1
, in effect moving Var1
further into the segment, the value of Var2
will adjust correspondingly.
The typical usage of this is to get the start of array-like constructs by getting the address (offset in this context) of the start of the array.