Multiple segments can be defined in the assembly language source program. Each segment must have a corresponding relationship with a segment register. The statement format for establishing such a ing is as follows:
Assume segment register name: segment name [, segment register name: segment name,…]
Where: The segment register is CS, DS, es, SS, FS, and GS, and the segment name is the segment name when the segment Definition Statement description.
In an assume statement, you can establish the relationship between multiple sets of segment registers and segments. Each correspondence must be separated by a comma. For example,
Assume Cs: code1, DS: data1
The preceding statement illustrates that CS corresponds to code1 in the code segment and DS corresponds to data1 in the data segment.
In the assume statement, you can also use the keyword "nothing" to indicate that a segment register does not correspond to any segment. The following statement shows that the segment register es does not correspond to a specific segment.
Assume ES: Nothing
In general, the first statement of the code segment is to use the assume statement to describe the correspondence between the segment register and the segment. In other parts of the code segment, you can use another assume statement to change the corresponding relationship described in the previous assume statement. In this way, the command in the code segment uses the correspondence established by the recent assume statement to determine the relevant information in the command.
In Example 6.1, the Assembly Language Section and its section describe the role of the statement. |
|
Data1 |
Segment |
; Define the data segment data1 |
Word1 |
DW 5678 H |
Byte1 |
DB "abcdefg" |
Data1 |
Ends |
Data2 |
Segment |
; Define the data segment data2 |
Word2 |
DW 1234 H |
Word3 |
DW 9876 H |
Data2 |
Ends |
Data3 |
Segment |
Define the data segment data3 |
Byte2 |
DB? |
Data3 |
Ends |
Code1 |
Segment |
Code segment code1 |
Assume |
CS: code1, DS: data1, ES: data2 |
; (1) |
MoV |
Ax, data1 |
; (2) |
MoV |
DS, ax |
; (3) |
MoV |
Ax, data2 |
; (4) |
MoV |
Es, ax |
; (5) |
... |
MoV |
Ax, word1 |
; The word variable word1 in the access segment data1 |
MoV |
Word2, ax |
; The word variable word2 in the access segment data2 |
... |
Assume |
DS: data3, ES: Nothing |
; (6) |
MoV |
Ax, data3 |
MoV |
DS, ax |
MoV |
BL, byte2 |
; Byte2, The Byte variable in the access segment data3 |
... |
MoV |
Ax, 4c00h |
; (7) |
Int |
21 h |
; (8) |
Code1 |
Ends |
Statements (1) and (6) Explain the correspondence between segments and registers, respectively. The statement (6) re-describes the correspondence specified by the statement (1.
Two groups of statements (2), (3), (4), and (5) are used to assign initial values to the DS and ES segments. The assume statement only serves as an illustration and does not assign values to the segment register. Therefore, you must assign values to the segment register. This method is also used in other subsequent source programs to assign values to Data Segment registers.
Statements (7) and (8) Call the 4ch function to interrupt the 21h to end the execution of the program. The return code of the program is determined by the register Al. The command to end the execution of this program is a statement that must be written by all the main modules.
Note: The code segment register cannot be assigned to it by the programmer in the source program. Its value is automatically assigned when the operating system loads it into the system.