INTRODUCTION

as the base, the logical address can be made up of many different types of values: it can be just the immediate data value contained in the instruction, or, it can be the sum of an immediate data value, plus a base register, plus an index register.

F or the sum of the addition to be 20-bits wide, the segment register value is automati- cally shifted left by four binary bits before it is added to the 16-bit logical address. The

result is always 20-bits ofphysical address.

Note that since logical addresses are always 16-bits wide, you can address up to 64K bytes in a given segment without changing the value ofthe segment base register. In systems that do not have more than 64K bytes of program plus 64K bytes of stack, plus 64K bytes in each of two different data areas, it is possible to set the segment registers at the beginning of the pro- gram and then forget them. In a system where the total amount of memory is 64K bytes or less, it is possible to set all segment registers equal and have fully overlapping segments.

On the other hand, segment registers are very useful when you have a large programming task and you want isolation between your program code and the data area or isolation between module data and the stack informa- tion, etc. Segmentation also makes it easy to build relocatable and/ or reentrant programs.

RELOCATABLE AND REENTRANT

PROGRAMS

In many cases, the task of relocating an 8088 program (relocation means having the ability to run the same program in several different areas of memory without changing the pro- gram itself) simply requires moving the program code and then adjusting of the code segment register to point to the base of the new code area. Since programs can be writ- ten for the 8088 where branches or jumps in program flow may occur using new locations

relative only to the instruction pointer, the program does not care what value is kept in the code segment register. Figure 1-13 shows how an entire process, consisting of code, stack and data areas, can be relocated.

Likewise in a reentrant program, a single program uses mUltiple data areas. Before the reentrant code is entered the second time, the data segment register value is changed so that a different data area is made available to the program.

ADDRESSING MODES

Now, let's continue our discussion of address- ing modes, providing more detail about how addresses are formed.

The 8088 has 24 different addressing modes to generate logical addresses. Figure 1-14 shows the different logical address combina- tions, from the simplest immediate data mode to the register addressing mode, where a selected register contains the data being used by the instruction. In the direct address- ing mode, the instruction itself contains the address of the data. In the register indirect mode, the instruction points to a register con- taining the memory address of the desired data. There are both indexed and based addressing modes where the contents of an index or based register is added to an imme- diate data value contained in the instruction to form the memory address.

Exactly how the 8088 selects an addressing mode for a given instruction is encoded within the bits of the instruction code. This is discussed in more detail in Chapter 2.

If we examine the most complex and power- ful of the addressing modes, which includes base register, index register, and displace- ment in the logical address,it can be seen that some fairly complex data structures can be easily addressed in a single instruction by the 8088.

1-7

Page 18
Image 18
Intel 210200-002 manual Result is always 20-bits ofphysical address