What does `Var2 DW Var1` mean in TurboShell/TurboAsm?

452 views Asked by At

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 .

1

There are 1 answers

0
Lasse V. Karlsen On

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 Var2is 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.