Intel 8086 : 8086 Addressine Modes , Register and Immediate Modes , Memory Addressing Modes , Port Addressing and Relative Addressing Mode

8086 Addressine Modes

The 8086 provides various addressing modes to access instruction operands. Operands may be contained in registers, within the instruction op-code, in memory, or in I/0 ports. The 8086 has 12 addressing modes, which can be classified into five groups:

1. Register and immediate modes (two modes)

2. Memory addressing modes (six modes) 3.. Port addressing mode (two modes)

4. Relative addressing mode (one mode)

5. Implied addressing mode (one mode)

Note that in the following, symbol ( ) is used to indicate the contents of an 8086 register or a memory location.

9.4.1 Register and Immediate Modes

Register mode. The addressing modes are illustrated utilizing 8086 instructions with directives of a typical assembler. In register mode, source operands, destination operands, or both may be contained in registers. For example, MOV AX, BX moves the 16-bit contents ofBX into AX. On the other hand, MOV AH, BL moves the 8-bit contents ofBL into AH.

Immediate mode. In immediate mode, 8- or 16 bit data can be specified as part of the instruction. For example, MOV ex, 5062H moves the 16-bit data 506216 into register CX.

9.4.2 Memory Addressing Modes

The EU has direct access to all registers and data for register and immediate modes. However, the EU cannot directly access the memory operands. It must use the BIU to access memory operands. For example, when the EU needs a memory operand, it sends an offset value to the BIU. As mentioned before, this offset is added to the contents of a segment register after shifting it four times to the left, generating a 20-bit physical address. For example, suppose that the contents of a segment register is 2052 16 and the offset is 002016• Now, in order to generate the 20-bit physical address, the EU passes this offset to the BIU. The BIU then shifts the segment register four times to the left, obtains 20520 16 and then adds the 0020 16 offset to provide the 20-bit physical address 20540 16• Note that the 8086 must use a segment register whenever it accesses the memory.

Also, every memory addressing mode has a standard default segment register. However, a segment override instruction can be placed before most of the memory operand instructions whose default segment register is to be overridden. For example, INC BYTE PTR [START] will increment the 8-bit contents of a memory location in DS with offset START by 1. However, segment DS can be overridden byES as follows: INC ES: BYTE PTR [START ] . Segments cannot be overridden for stack reference instructions (such as PUSH and POP). The destination segment of a string segment, which must beES (if a prefix is used with a string instruction, only the source segment DS can be overridden) cannot be overridden. The code segment (eS) register used in program memory addressing cannot be overridden. The EU calculates an offset from the instruction for a memory operand. This offset is called the operand’s effective address, or EA. It is a 16-bit number that represents the operand’s distance in bytes from the start of the segment in which it resides.

The various memory addressing modes will now be described.

1. Memory Direct Addressing. In this mode, the effective address is taken directly from the displacement field of the instruction. No registers are involved. For example, MOV BX, [START], or MOV BX, OFFSET START moves the contents of the 20-bit address computed from DS and START to BX. Some assemblers use square brackets around START to indicate that the contents of the memory location(s) are at a displacement START from the segment DS. If square brackets are not used, then the programmer may define START as a 16-bit offset by using the assembler directive,

OFFSET.

2. Register Indirect Addressing. The effective address of a memory operand may be taken directly from one of the base or index registers (BX, BP, SI, DI). For example, consider MOV ex, [ BX l . If (DS) = 200016, (BX) = 0004 16, and (20004 16) = 022416, then, after MOV CX, [ BX], the contents of ex are 0224 16• Note that the segment register used in MOV ex, [ BX] can be overridden, such as MOV ex, ES: [ BX] . Now, the MOV instruction will use ES instead ofDS. If(ES) = 100016 and (10004 16) = 0002 16, then, after MOV ex,ES: [BX],the register CX will contain 0002 16• Note that in the above, symbol ( ) is used to indicate the contents of an 8086 register or a memory location.

3. Based Addressing. In this mode, the effective address is the sum of a displacement value (signed 8-bit or unsigned 16-bit) and the contents of register BX or BP. For example, MOV AX, 4 [BX]moves the contents ofthe 20-bit address computed from a segment register and BX + 4 into AX. The segment register is DS or SS. The content ofBX is unchanged. The displacement (4 in this case) can be unsigned 16-bit or signed 8-bit. This means that if the displacement is 8-bit, then the 8086 sign extends this to 16-bit. Segment register SS is used when the stack is accessed; otherwise, this mode uses segment register DS. When memory is accessed, the 20-bit physical address is computed from BX and DS. On the other hand, when the stack is accessed, the 20-bit physical address is computed from BP and SS. Note that BP may be considered as the user stack pointer while SP is the system stack pointer. This is because SP is used by some 8086 instructions (such as CALL subroutine) automatically. The based addressing mode with BP is a very convenient way to access stack data. BP can be used as a stack pointer in SS to access local variables. Consider the following instruction sequence (arbitrarily chosen to illustrate the use ofBP for stack):

image

4. Indexed Addressing. In this mode, the effective address is calculated from the sum of a displacement value and the contents of register SI or DI. For example, MOV AX, VALUE [SI] moves the contents of the 20-bit address computed from VALUE, SI and the segment register into AX. The segment register is DS. The content of SI is unchanged. The displacement (VALUE in this case) can be unsigned 16-bit or signed 8-bit. The indexed mode can be used to access a table.

5. Based Indexed Addressing. In this mode, the effective address is computed from the

sum of a base register (BX or BP), an index register (SI or DI), and a displacement. For example, MOV AX, 4 [BX][SI] moves the contents of the 20-bit address computed from the segment register and (BX) + (SI) + 4 into AX. The segment register is DS. The displacement can be unsigned 16-bit or signed 8-bit. This mode can be used to access two-dimensional arrays such as matrices.

6. String Addressing. This mode uses index registers. SI is assumed to point to the first byte or word of the source string, and DI is assumed to point to the first byte or word of the destination when a string instruction is executed. The SI or DI is automatically incremented or decremented to point to the next byte or word depending on DF. The default segment register for source is DS, and it may be overridden; the segment register used for the destination must be ES, and can not be overridden. An example is MOVS WORD. If (DF) = 0, (DS) = 3000 16, (SI) = 002016, (ES) 500016,(DI) = 0040 16,(30020) = 3016, (30021) = 0516,(50040) = 0616,and (50041) = 2016,then, after this MOVS, (50040) = 3016,(50041) = 0516, (SI) = 002216, and (DI) = 0042 16

9.4.3 Port Addressing

Two I/0 port addressing modes can be used: direct port and indirect port. In either case, 8- or 16-bit I/0 transfers must take place via AL or AX respectively .In direct port mode, the port number is an 8-bit immediate operand to access 256 ports. For example. IN AL, 0 2 moves the contents of port 02 to AL. In indirect port mode, the port number is taken from DX, allowing 64K bytes or 32K words of ports. For example, suppose (DX) = 0020, (port 0020) = 02 16, and (port 0021) = 0316• then, after IN AX, DX, register AX contains 0302 16• On the other hand, after IN AL, DX, register AL contains 02 16

9.4.4 Relative Addressing Mode

Instructions using this mode specify the operand as a signed 8-bit displacement relative to IP. An example is JNC sTART. This instruction means that if carry= 0, then IP is loaded with the current IP contents plus the 8-bit signed value of START; otherwise, the next instruction is executed.

An advantage of relative mode is that the destination address is specified relative to the address of the instruction after the conditional Jump instruction. Since the 8086 conditional Jump instructions do not contain an absolute address, the program can be placed anywhere in memory which can still be executed properly by the 8086. A program which can be placed anywhere in memory, and can still run correctly is called a "relocatable" program. It is a good practice to write relocatable programs.

9.4.5 Implied Addressing Mode

Instructions using this mode have no operands. An example is CLC, which clears the carry flag to zero.

Leave a comment

Your email address will not be published. Required fields are marked *