Addressing Modes of 8086
1. What is meant by addressing mode?
Ans. An instruction consists of an opcode and an operand. The operand may reside in the accumulator, or in a general purpose register or in a memory location.
The manner in which an operand is specified (or referred to) in an instruction is called addressing mode.
2. Name the different addressing modes of 8086.
Ans. The following are the different addressing modes of 8086:
z Register operand addressing.
z Immediate operand addressing.
z Memory operand addressing.
3. Mention the different memory addressing modes. Ans. The different memory addressing modes are:
z Direct Addressing
z Register Indirect Addressing
z Based Addressing
z Indexed Addressing
z Based Indexed Addressing and
z Based Indexed with displacement.
4. How the physical address is generated for the different memory addressing modes?
Ans. Physical address (for the operand) is the address from which either a read or write operation is initiated. The following shows the manner of generation of physical address.
Physical address |
= |
Segment base : Effective address |
= |
Segment base : Base + Index + Displacement |
i.e., effective address, for its generation, can have as many as three elements: Base, Index and Displacement. Thus the effective address is generated from the following:
Effective address = Base + Index + Displacement
The segment registers can be CS, SS, DS or ES. Base can be BX or PB. Index can be SI or DI and the Displacement can either be 8-bit or 16-bit.
It should be noted that not all the three elements viz., base, index or displacement are always used for effective address calculations.
5. Give examples each of (a) Register Addressing mode (b) Immediate Addressing mode.
Ans. (a) Register Addressing Mode.
In this mode, either an 8-bit or a 16-bit general purpose register contains the operand. Some examples are:
MOV AX, BX
MOV CX, DX
ADD AL, DH
ADD DX, CX
The content of BX register is moved to AX register in the first example, while in the third example, content of DH is added to the content of AL. Here, source and destination of data are CPU registers.
(b) Immediate Addressing Mode.
In this mode, the operand is contained in the instruction itself, i.e., the operand forms a part of the instruction itself. The operand can be either 8-bit or 16-bit in length. Some examples are:
MOV AL, 83 H
ADD AX, 1284 H
In the first example, 83 H is moved to AL register while in the second example, 1284 H is added to the contents of AX register. Here, source of data is within the instruction.
6. Discuss the Direct Addressing Mode.
Ans. In a way it is similar to ‘Immediate Addressing Mode’. In Immediate Addressing Mode, data follows the instruction opcode, while in this case an effective address follows the same. Thus in this case:
PA = Segment base : Direct address.
By default, the segment base register is DS. Thus,
PA = DS : EA
But if a segment override prefix (SEG) is used in the instruction, then any one of the four segment registers can be referenced. Hence, in general,
As an example, MOV CX, [ALPHA]
It means, “move the contents of the memory location, which is labelled as ALPHA in the current data segment, into register CX”.
Thus, if DS = 0300 H, and value assigned to ALPHA is 3216 H, then
PA = 03000 H + 3216 H
= 06216 H
Thus, data contained in address locations 06217 H and 06216 H will be stored in CH and CL registers respectively.
MOV [0404 H], CX would move the contents of CL to offset address 0404 H (relative to data segment register DS) and CH to 0405 H. Here, memory address is supplied within the instruction.
7. Discuss Register Indirect Addressing Mode.
Ans. In a way, this mode of addressing is similar to direct addressing mode in the sense that content of DS is combined with the effective address to get the physical address.
But the difference lies in the manner in which the offset is specified. In direct addressing mode EA is constant while in this mode EA is a variable.
EA can reside in either base register (BX or BP) or index register (SI or DI). The
default segment register is DS, but again by using a segment override prefix (SEG), any of the four segment registers can be referenced. Thus, PA can be computed as:
An instruction of this mode of addressing is:
MOV CX, [SI]
Execution of this instruction entails moving the content of the memory location having its offset value in SI from the beginning of the current data segment to the CX register.
If DS = 0300 H and SI = 3216 H, then PA becomes
PA = 03000 H + 3216 H = 06216 H.
Thus data contained in 06217 H and 06216 H will be placed in CH and CL registers respectively. Here, memory address is supplied in an index or pointer register.
8. Discuss Based Addressing Mode.
Ans. The physical address in this case is generated as follows:
PA = Segment base: Base + Displacement
i.e., the physical address is generated by adding either an 8-bit or 16-bit displacement to the contents of either base register BX or base pointer register BP and the current value in DS or SS respectively.
Fig. 13.1 shows the utility of using either BX/BP and displacement. The figure shows a data structure starting from ‘Element 0’ to ‘Element n’. Inserting a zero value for displacement would ensure accessing ‘Element 0’ of the structure. For accessing different elements within the same data structure, all that is to be done is to change the value of displacement.
Whereas, to access the same element is another data structure the value of the base register has to be changed, keeping the value of displacement same as before.
An example of this mode of addressing is MOV [BX] + ALPHA, AH
Here, ALPHA denotes displacement (which can be 8 or 16-bits) and BX the base register. Together, they give EA of the destination operand.
If DS = 3000 H, BX = 1234 H and displacement (16-bit) = 0012 H, Then, PA = 03000 H + 1234 H + 0012 H = 04246 H
Thus the content of AH (source operand) is placed in the physical address 04246 H (destination operand memory location).
In this mode also, the default register i.e., DS can be changed by a segment override
prefix (SEG). Also for accessing data from the stack segment of the memory, BP is to be used instead of BX.
Here, the memory address is the sum of BX or BP base registers plus an 8 or 16-bit displacement specified in the instruction.
9. Discuss Indexed Addressing Mode.
Ans. In a way, this mode of addressing is similar to the based addressing mode but the jobs carried out by base register and displacement in the based addressing mode are done by displacement and index register respectively in indexed addressing mode and shown in Fig. 13.2.
The physical address in this case is generated as follows: PA = Segment Base : Index + Displacement
An example of this mode of addressing is:
MOV [SI] + ALPHA, AH
where, ALPHA represents displacement.
Assuming, DS = 3000 H, SI = 1234 H and ALPHA (displacement) = 0012 H.
Thus, PA = 03000 H + 1234 H + 0012 H = 04246 H.
Thus, the data value residing in source operand AH will be moved to the physical
address location 04246 H. Here, memory address is the sum of the index register plus
an 8 or 16-bit displacement specified in the instruction.
10. Discuss Based Indexed Addressing mode.
Ans. It is a combination of based and indexed addressing modes. The physical address is generated in this case in the following manner:
PA = Segment Base : Base + Index
Here, BX and BP registers are used for data and stack segments respectively. An example of this mode of addressing is as follows:
MOV AL, [BX] [SI]
If DS = 3000 H, BX = 1000 H and SI = 1234 H, then
PA = 03000 H + 1000 H + 1234 H = 05234 H
On executing this instruction, the value stored in memory location 05234 H will be
stored in AL.
Here, memory address is the sum of an index register and a base register.
11. Discuss Based Indexed with displacement Addressing Mode.
Ans. It is a combination of based addressing mode and indexed addressing mode along with an 8 or 16-bit displacement. The physical address is generated in the following manner:
PA = Segment base : Base + Index + Displacement
This addressing mode is used to access a two dimensional (m × n) array, as shown in Fig. 13.3. The displacement, having a fixed value, locates the starting position of the array in the memory while the base register specifies one coordinate (say m) and index register the other coordinate (say n). Any position in the array can be located simply by changing the values in the base and index registers.
An example of this mode of addressing is as follows:
Thus the offset or effective address can be calculated from the contents of base and index registers and the fixed displacement as represented by ALPHA.
Assuming: DS = 3000 H, BX = 1000 H, SI = 1234 H and ALPHA (displacement) = 0012 H. Thus, PA = 03000 H + 1000 H + 1234 H + 0012 H = 05246 H.
On executing this instruction, the value stored in memory location 05246 H (source operand) will be stored in AL. Here, memory address is the sum of an index register, a base register and an 8 or 16-bit displacement within the instruction.