An immediate operand is a constant value that is specified at assembly time. It can be a constant or the result of a constant expression. Immediate values are usually encoded into the internal representation of the instruction at assembly time. These are typical examples:
mov cx, 20 ; Load constant to register
add var, 1Fh ; Add hex constant to variable
sub bx, 25 * 80 ; Subtract constant expression
Address constants are a special case of immediate operand and consist of an offset or segment value. The OFFSET operator specifies the offset of a memory location, as shown below:
mov bx, OFFSET var ; Load offset address
For information on differences between MASM 5.1 behavior and MASM 6.0 behavior related to OFFSET, see Appendix A.
Summary: An OFFSET expression is resolved at link time.
Since segments in different modules may be combined into a single segment, the true base of the segment is not known. Thus, the offset cannot be resolved until link time and var is a relocatable immediate.
The SEG operator specifies the segment of a memory location:
mov ax, SEG farvar ; Load segment address
mov es, ax
Summary: A SEG expression is resolved at load time.
The actual value of a particular segment is never known until the program is loaded into memory. Constant segments are encoded into the header of the executable file at link time. Executable files in the DOS .COM format (tiny model) cannot contain relocatable segment expressions.
When you use the SEG operator with a variable that is not external, MASM 6.0 returns the address of the frame (the segment, group, or segment register) if one has been explicitly set. Otherwise, it returns the group if one has been specified. In the absence of a defined group, SEG returns the segment where the variable is defined.
For external variables that are not defined in a segment, the linker fills in the segment portion of the address, which may be a segment or group.
This behavior can be changed with the /Zm command-line option or with the OPTION OFFSET:SEGMENT statement (see Appendix A, “Differences between MASM 6.0 and 5.1”). Section 1.3.2 introduces the OPTION directive.