8086 Architecture - Addressing Modes
8086 Architecture - Addressing Modes
The 8086 is a 16-bit microprocessor. The term 16 bit implies that its arithmetic logic unit, its
internal registers, and most of its instructions are intended to work with 16-bit binary data.
The 8086 has a 16-bit data bus, so it can read data from or write data to memory and ports
either 16 bits or 8 bits at a time. The 8086 has a 20-bit address bus, so it can address any one
of 220, or 1,048,576 memory locations.
Bus Interface Unit (BIU): It handles all transfers of data and addresses on the buses for the
execution unit.
The QUEUE:
When EU is decoding or executing an instruction, bus will be free at that time. BIU pre-
fetches up to 6-instructions bytes to be executed and places them in QUEUE. This
improves the overall speed because in each time of execution of new instruction, instead
1
Compiled by: Er. Yuyutshu Banjara
of sending address of next instruction to be executed to the system memory and waiting
from the memory to send back the instruction byte, EU just picks up the fetched
instruction byte from the QUEUE.
The BIU stores these pre-fetched bytes in a first-in-first-out (FIFO) register set called a
queue. Fetching the next instruction while the current instruction executes is called
pipelining.
Segment Registers:
The BIU contains a dedicated address, which is used to produce the 20-bit address. The bus
control logic of the BIU generates all the bus control signals, such as the READ and WRITE
signals, for memory and I/O. The BIU also has four 16 bit segments registers namely:
Code segment (CS): holds the upper 16-bits of the starting addresses of the segment
from which BIU is currently fetching instruction code bytes.
Stack segment (SS): store addresses and data while subprogram executes
Extra segment (ES): store upper 16-bits of starting addresses of two memory
segments that are used for data.
Data segment(DS): store upper 16-bits of starting addresses of two memory
segments that are used for data.
All program instructions located in memory are pointed using 16 bits of segment
register CS and 16 bits offset contained in the 16-bit instruction pointer (IP). The BIU
computes the 20-bit physical address internally using the logical address that is the
contents of CS and IP. 16 bit contents of CS will be shifted 4 bits to the left and then
adding the 16 bit contents of IP. Thus, all instructions of the program are relative
contents of IP. Simply stated, CS contains the base or start of the current code segment,
and IP contains the distance or offset from this address to the next instruction byte to
be fetched. Graphically,
Fig: Diagram showing addition of IP to CS to produce the physical address of code byte Stack
Segment Register (SS) and Stack Pointer (SP)
2
Compiled by: Er. Yuyutshu Banjara
A stack is a section of memory to store addresses and data while a subprogram is in
progress. The stack segment registers points to the current stack. The 20-bit physical
stack address is calculated from the SS and SP. The programmer can also use Base
Pointer (BP) instead of SP for addressing. In this case, the 20-bit physical address is
calculated using SS and BP.
Flag Register:
It is a 16-bit register. 9-bit are used as different flags, remaining bits unused
Out of 9-flags, six are conditional (status) flags and three are control flags
Conditional flags:
These are set or reset by the EU on the basis of the results of some arithmetic or logic
operation. 8086 instructions check these flags to determine which of two alternative
actions should be done in executing the instructions.
OF (Overflow flag): is set if there is an arithmetic overflow, i.e. the size of the
result exceeds the capacity of the destination location.
SF (Sign flag): is set if the MSB of the result is 1
ZF (Zero flag): is set if the result is zero
AF (Auxiliary carry flag): is set if there is carry from lower nibble to upper nibble
or from lower byte to upper byte
PF (Parity flag): is set if the result has even parity
CF (Carry flag): is set if there is carry from addition or borrow from subtraction
Control flags:
They are set using certain instructions. They are used to control certain operations of
the processor.
3
Compiled by: Er. Yuyutshu Banjara
TF (Trap flag): for single stepping through the program
IF (Interrupt flag): to allow or prohibit the interruption of a program
DF (Direction flag): Used with string instructions
BH-BL pair BX register (to store the 16-bit data as well as the base address of the
memory location)
CH-CL pair CX register (to store 16-bit data and can be used as counter register for
some instructions like loop)
DH-DL pair DX register (to store 16-bit data and also used to hold the result of 16-
bit data multiplication and division operation)
Pointer Registers:
The two pointer registers, SP and BP are used to access data in the stack segment. The
SP is used as offset from current Stack Segment during execution of instruction that
involve stack. SP is automatically updated. BP contains offset address and is utilized in
based addressing mode. Overall, these are used to hold the offset address of the stack
address.
Index Registers:
EU also contains a 16-bit source index (SI) register and 16-bit destination index (DI)
register. These registers can be used for temporary storage of data similarly as the
general purpose registers. However, they are specially to hold the 16-bit offset of the
data word. SI and DI are used to hold the offset address of the data segment and extra
segment memory respectively.
4
Compiled by: Er. Yuyutshu Banjara
Addressing modes of 8086
The different ways in which a source operand is denoted in an instruction is known as
addressing modes. The different addressing modes in 8086 programming are:
MOV AX, [BX] ; copies the word-sized data from data segment offset
address indexed by BX into AX
Suppose the register BX contains 4123H , then the contents 4123H are moved
to AX
5
Compiled by: Er. Yuyutshu Banjara
6) Indexed Addressing mode:
In this addressing mode, the operands offset address is found by adding the contents
of SI or DI register and 8-bit/16-bit displacements.
Example:
MOV BX, [SI+04], ADD AL, [DI+16]
6
Compiled by: Er. Yuyutshu Banjara
Physical address calculation in 8086
20-bit physical address (actual address) of memory is generated by adding the segment address
and offset address (displacement value)
Let us consider:
CS= 1234 H
IP = 0022 H
Then,
Physical address = (Segment address x 10) + Offset address
= (1234 H x 10) + 0022 H
= 12340 H + 0022 H
= 12362 H
Note: Segment address is left shifted 4 times (4 bits) instead of multiplying by 10.
7
Compiled by: Er. Yuyutshu Banjara