ARCHITECTURE AND INSTRUCTIONS

Observe that the code at the head of the MY_CODE segment will, at program.execu- tion, initialize the various segment registers to point to the appropriate segments, and the code will initialize .the stack pointer to point to the end of the stack segment.

The ASSUME statement makes the assem- bler aware of segment register values when the code is executed.

To illustrate the purpose of the ASSUME statement, let's consider code (within SEG- MENT MY_CODE) that moves the contents of byte X to byte ALPHA. To do this, we need an instruction that moves the contents of X into a register, say BL, and an instruction that moves the contents of the register into ALPHA. How about:

MOV

BL,X

;from X to BL

MOV

ALPHA,BL

;from BL to ALPHA

During execution of such MOV instructions, the 8088 processor would normally use the DS register to find the starting address of the

OLD_DATA

SEGMENT

 

OLD_BYTE

DB

?

OLDJ)ATA

ENDS

 

segment where the specified item (X or ALPHA) is located. This will work fine when accessing X - the first instruction - because DS will indeed contain the starting address of segment MY_DATA where X is located.

But, this will not work when accessing ALPHA - the second instruction ~ because the starting address of segment MY_EXTRA, where ALPHA is located, will not be con- tained in DS.

The ASSUME statement has made the assembler aware that the first instruction will execute properly. The assembler is also aware (thanks to the ASSUME statement) that the starting address of MY_EXTRA, although not in DS, will be in one of the other segment registers - namely ES. The assembler, there- fore, generates a segment-overriding prefix for the second instruction so that it too, will execute properly.

It's not always possible to know what will be in the segment registers when a particular instruction will be executed. Consider:

NEW_DATA

SEGMENT

 

 

NEW_BYTE

DB

?

 

NEW_DATA

ENDS

 

 

MORE-CODE

SEGMENT

 

 

 

ASSUME

CS:MORE_CODE

 

 

MOV

AX,OU1-DATA

;put OLD-DATA into

 

MOV

DS,AX

;.. .oS and

 

MOV

ES,AX

;... ES

 

ASSUME

DS:OLD_DATA,ES:OLD_DATA

 

CYCLE:

INC

OLD_BYTE

;what'sin DS now?

 

MOV

AX,NEW_DATA

;put NEW_DATA

 

MOV

DS,AX

;...into DS

 

JMP

CYCLE

 

MORE_CODE

ENDS

 

 

2-34

Page 69
Image 69
Intel 210200-002 manual Bl,X