<<< Immediate Operands | Index | More about LEA Instruction >>> |
An address constant is a special type of immediate operand that consists of an offset or segment value.
The OFFSET operator returns the offset of a memory location relative to the beginning of the segment to which the location belongs:
mov bx, OFFSET var ; Load offset address
Since data in different modules may belong to a single segment, the assembler cannot know for each module the true offsets within a segment.
Thus, the offset for var, although an immediate value, is not determined until link time.
Instruction
lea eax, [LocalVar] ; Load effective address of LocalVar into eax lea eax, LocalVar ; This does exactly the same thing
generally equates to
mov eax, OFFSET LocalVar
but is 1 CPU cycle slower, so mov with OFFSET is preferred in cases other than local variables.
Also, if you need the program to be really small, and LEA already used 100 times, you can make the program 100 bytes smaller simply by using MOV x, OFFSET y instead.
Effective address is the physical address of the data in memory.
The OFFSET operator returns the offset of a data label. The offset represents the distance, in bytes, of the label from the beginning of the data segment. In Protected mode, an offset is always 32 bits long. In Real-address mode, offsets are only 16 bits.
<<< Immediate Operands | Index | More about LEA Instruction >>> |