A Segment-Register-Association establishes an assembly-time association between a Segment-Register and an expression that resolves to a GroupName or SegmentName. It allows the programmer to describe for the assembler what values are held in the segment registers at program run-time.
When the user program executes, all instructions that access memory do so through a particular segment register. To generate the correct encoding for an instruction that accesses a memory location, the assembler must know which segment register will be used in the effective memory address. In general, accessing a memory location from within a user program is done by referencing a named variable defined within a particular named segment.
Before accessing a named program variable (in a named memory segment), it is the programmer's responsibility to insure that the desired segment register actually references the correct physical segment at program run-time. Unless the ASSUME directive is used to describe this association, the assembler has no way of knowing which segment register (if any) is addressing a named segment when a reference to a named variable contained therein is encountered. In this situation, the programmer is forced to use the Segment Override (: Operator) in every instruction to "reach" the desired variable and cause the assembler to generate the proper instruction encoding. The association established by the ASSUME directive allows the assembler to take over the task of verifying memory references and generating the appropriate instructions.
If you temporarily use a segment register to contain a value other than the segment or group identified in the ASSUME association, then you should reflect the change with a new ASSUME statement, or cancel the association with an ASSUME xS:NOTHING construct.
When the contents of a segment register are used for addressability, the register value should never contradict the association established for that register.
When the .MODEL directive is utilized and the program is designed to follow the conventions that it establishes, the ASSUME directive is no longer needed in most cases.
Example
Data SEGMENT Stuff WORD 0 Data ENDS Code SEGMENT ASSUME NOTHING ; Cancel all register assumptions mov ax,Data ; Load general-purpose register with segment frame, mov DS,ax ; then establish addressablity through DS mov ES,ax ; and ES. The assembler doesn't "know" this yet mov Stuff, 1 ; Error, can't reach Stuff ASSUME ES:Data ; Associate ES register with Data segment add Stuff, bx ; Now we can reach Stuff, but the assembler needs ; to generate an ES override instruction byte ASSUME DS:SEG Stuff ; Expression to extract the segment value of Stuff ; This has the same effect as ASSUME DS:Data ; Now both DS and ES are associated with Data add Stuff, cx ; This time, the instruction doesn't need an ; override byte because DS is the default ; register for normal accesses to memory ASSUME DS:NOTHING ; Cancel the association between DS and Data add Stuff, dx ; Once again, the ES override is generated add DS:Stuff, dx ; Must use "force" if we want the default encoding Code ends endWarning:
If an ASSUME CS:Expression is placed before the code segment it is referencing, the assembler will ignore the ASSUME. The ASSUME CS:Expression statement must follow the SEGMENT definition statement of the code segment it is referencing.
The ASSUME statement for the CS register should be placed immediately following the code SEGMENT statement, before any labels are defined in that code segment.