Many of the assembler instructions assume a default segment. For example, JMP assumes the segment associated with the CS register, PUSH and POP assume the segment associated with the SS register, and MOV instructions assume the segment associated with the DS register.
Summary: The assembler must know the location of segment addresses.
When the assembler needs to reference an address, it must know what segment contains the address. It finds this by using the default segment or group addresses assigned with the ASSUME directive. The syntax is
ASSUME segregister:seglocation[[,segregister:seglocation]]
ASSUMEdataregister:qualifiedtype[[,dataregister:qualifiedtype]]
ASSUMEregister:ERROR[[,register:ERROR]]
ASSUME[[register:]]NOTHING[[,register:NOTHING]]
The seglocation must be the name of the segment or group that is to be associated with segregister. Subsequent instructions that assume a default register for referencing labels or variables automatically assume that if the default segment is segregister, the label or variable is in the seglocation. Beginning with MASM 6.0, the assembler automatically sets CS to have the address of the current code segment. Therefore, you do not need to include
ASSUME CS : MY_CODE
at the beginning of your program if you want the current segment associated with CS.
NOTE :
Using the ASSUME directive to tell the assembler which segment to associate with a segment register is not the same as telling the processor. The ASSUME directive affects only assembly-time assumptions. You may need to use instructions to change run-time assumptions. Initializing segment registers at run time is discussed in Section 3.1.1.1, “Informing the Assembler about Segment Values.”
The ASSUME directive can define a segment for each of the segment registers. The segregister can be CS, DS, ES, or SS (and FS and GS on the 80386/486). The seglocation must be one of the following:
The name of a segment defined in the source file with the SEGMENT directive
The name of a group defined in the source file with the GROUP directive
The keyword NOTHING, ERROR, or FLAT
A SEG expression (see Section 3.2.2, “Immediate Operands”)
A string equate (text macro) that evaluates to a segment or group name (but not a string equate that evaluates to a SEG expression)
It is legal to combine assumes to FLAT with assumes to specific segments. Combinations might be necessary in operating-system code that handles both 16- and 32-bit segments.
The keyword NOTHING cancels the current segment assumptions. For example, the statement ASSUME NOTHING cancels all register assumptions made by previous ASSUME statements.
Summary: The ASSUME directive can be used anywhere in your program.
Usually, a single ASSUME statement defines all four segment registers at the start of the source file. However, you can use the ASSUME directive at any point to change segment assumptions.
Using the ASSUME directive to change segment assumptions is often equivalent to changing assumptions with the segment-override operator (:) (see Section 3.2.3, “Direct Memory Operands”). The segment-override operator is more convenient for one-time overrides, whereas the ASSUME directive may be more convenient if previous assumptions must be overridden for a sequence of instructions.
You can also prevent the use of a register with
ASSUME SegRegister : ERROR
The assembler does an ASSUME CS:ERROR when you use simplified directives to create data segments, effectively preventing instructions or code labels from appearing in a data segment.
See Section 3.3.2 for information on other applications of ASSUME.