Chapter 3
Chapter 3
ADDRESSING MODES
OF 8086
Haramaya University
COMPILED BY: Wogayehu A.
@2022/23
1
Addressing Modes in 8086
• The different ways that a processor can access data are referred to
as addressing modes.
2
Addressing Modes in 8086
3
Data Addressing Modes
• It is important for instructions to use registers that are the same size.
• Never mix an 8-bit register with a 16-bit register, or a l6-bit register
with a 32-bit register because this is not allowed by the
microprocessor and results in an error when assembled.
• a comma always separates the destination from the source in an
instruction.
• SHL DX, CL, are exceptions to this rule.
• None of the MOV instructions affect the flag bits.
• The flag bits are normally modified by arithmetic or logic
instructions.
• A segment-to-segment register MOV instruction is about the only
type of register MOV instruction not allowed.
• Note that the code segment register is not normally changed by a
MOV instruction because the address of the next instruction is found
by both IP/EIP and CS. If only CS were changed, the address of the
next instruction would be unpredictable. Therefore, changing the CS
register with a MOV instruction is not allowed. 4
Data Addressing Modes
• Anything given in square brackets will be an Offset Address also
called Effective Address.
• MOV instruction by default operates on the Data Segment; unless
specified otherwise.
• BX and BP are called Base Registers.
• BX holds Offset Address for Data Segment.
• BP holds Offset Address for Stack Segment.
• SI and DI are called Index Registers
• The Segment to be operated is decided by the Base Register and NOT
by the Index Register.
• memory-to-memory transfers are not allowed by any instruction
except for the MOVS instruction.
• Flag register remains unaffected by most data transfer instructions.
5
Data Addressing Modes
• MOV AX, BX instruction transfers the word contents of the source
register (BX) into the destination register (AX). The source never
changes, but the destination always changes.
• It is crucial to remember that a MOV instruction always copies the
source data into the destination.
• The source is to the right and the destination is to the left, next to the
opcode MOV.
• We naturally assume that things move from left to right, whereas
here they move from right to left.
6
Registers and Segments revisions……………………..
7
Various Data Addressing Modes
Group I : Addressing modes for
1. Immediate Addressing
accessing register and immediate data
2. Register Addressing
3. Direct Addressing
9. String Addressing
• Example 2:
MOV AX, 0A9FH
MOV CL, DH
• The content of 8-bit register DH is moved to
another 8-bit register CL: (CL) (DH)
• Example 2: 16 bit register as source of operand
MOV AX, BX 10
2.REGISTER ADDRESSING MODE
• Register addressing is the most common form of data
addressing and, once the register names are learned, is
the easiest to apply.
• It is important for instructions to use registers that are
the same size.
• Never mix an 8-bit register with a 16-bit register, an 8-
bit register with a 32-bit register, or a l6-bit register
with a 32-bit register because this is not allowed by the
microprocessor and results in an error when
assembled.
• The microprocessor contains the following 8-bit
registers names: AH, AL, BH, BL, CH, CL, DH, and DL.
• And the following 16-bit register names: AX, BX, CX,
DX, SP, BP, SI, and DI.
11
2.REGISTER ADDRESSING MODE
• In the 80386 and above, the extended 32-bit register
names are: EAX, EBX, ECX, EDX, ESP, EBP, EDI,ESI.
• In the 64-bit mode of the Pentium 4, the register
names are: RAX, RBX, RCX, RDX, RSP, RBP, RDI, RSI,
and R8 through R15.
• With register addressing, some MOV instructions and
the PUSH and POP instructions also use the 16-bit
segment register names (CS, ES, DS, SS, FS, and GS).
• Note that the source register’s contents do not change,
but the destination register’s contents do change. This
instruction moves (copies) a l234H from register CX
into register BX.
• This erases the old contents(76AFH) of register BX, but
the contents of CX remain unchanged.
• The contents of the destination register or destination
memory location change for all instructions except the
CMP and TEST instructions. 12
Examples
13
Memory Access
• To access memory we use the four registers: BX, SI, DI and BP.
EA = (BX)
BA = (DS) x 10 H where:
MA = BA + EA
DS = Data Segment
(AX) (MA) or, EA = Effective Address
BA = Base Address
(AL) (MA) MA = (Physical) Memory Address
17
(AH) (MA +1)
5.Indexed Addressing Mode
• SI or DI register is used to hold an index value for
memory data and a signed 8-bit or unsigned 16-bit
displacement will be specified in the instruction.
• The effective address is sum of index register and
displacement.
• Displacement is added to the index value in SI or DI
register to obtain the Effective Address (EA).
EA = (SI) + FFA2H
BA = (DS) x 10 H
MA = BA + EA
(CX) (MA) or,
(CL) (MA)
(CH) (MA + 1) 18
6. Based Addressing Mode
• In Based Addressing, BX or BP is used to hold the base
value for effective address and a signed 8-bit or unsigned
16-bit displacement will be specified in the instruction.
• In case of 8-bit displacement, it is sign extended to 16-bit
before adding to the base value.
• The effective address is the sum of base register and
displacement.
• When BX holds the base value of Effective Address ( EA ),
20-bit physical address is calculated from BX and DS.
Operations:
• Example: 0008H 08H (Sign extended)
EA = (BX) + 0008H
BA = (DS) x 10 H
MA = BA + EA
EA = (BX) + (SI)
BA = (DS) x 10 H
MA = BA + EA
(DL) (MA)
(DH) (MA + 1)
20
8.BASED & INDEX with Displacement ADDRESSING MODES
• In Based Index with displacement Addressing, the
effective address is computed from the sum of a base
register (BX or BP), an index register (SI or DI) and a
displacement. MOV DX, [BX + SI + 0AH]
• Example 1:
Operations:
000AH 0AH (Sign extended)
EA = (BX) + (SI) + 000AH
BA = (DS) x 10 H
MA = BA + EA
(DX) (MA) or,
(DL) (MA)
(DH) (MA + 1)
21
9. Strings Addressing Mode
• Employed in string operations to operate on string data.
Operations:
(MAE) (MAD)
Note : Effective address of
the Extra segment
If DF = 1, then (SI) (SI) – 1 and (DI) (DI) – 1
If DF = 0, then (SI) (SI) +1 and (DI) (DI) + 1
only a byte of data will be copied from the source to the destination.
22
9. Strings Addressing Mode….
23
9. Strings Addressing Mode….
The core compulsory rules for string instructions
1. The source block has to be present in the data segment
2. The destination block/string data has to be present in the
extra segment
3. The offset address of the source string has to be given by
source index
4. The offset address of the destination has to be given by
destination index
5. The count has to be given by CX register only
6. The direction has to be decided by flag register weather
automatically incremented or decremented.
24
STRING MANIPULATION INSTRUCTIONS
Offset or effective address of the source operand is stored in SI register and that of
the destination operand is stored in DI register.
26
•
10. Direct I/O Port Addressing
These addressing modes are used to access data from standard I/O
mapped devices or ports.
• IN AX, [80H] ; AX gets 16-bit data from I/O port address 80H
28
12. Implied Addressing Mode
• Instructions using this mode have no operands.
The instruction itself will specify the data to be
operated by the instruction.
• Example 1: STC
• Example 2: CLC
• Example 3: CLD,
This clears the Direction flag to zero.
STD--Sets the Direction Flag to one.
29
Exercise
30
2. Program Memory Addressing Modes
o Program Memory addressing mode is required for instructions that cause a
branch in the program.
o According to the flow of instruction execution, the instructions
may be categorized as
1. Sequential Control Flow Instructions
2. Control Transfer (BRANCH) Instructions
o Sequential control flow instructions are the instructions which
after execution, transfer control to the next instruction appearing
immediately after it (in the sequence) in the program.
For example the arithmetic, logic, data transfer and processor control
instructions are Sequential control flow instructions.
o The control transfer instructions on the other hand transfer
control to some predefined address or the address somehow
specified in the instruction, after their execution.
For example INT, CALL, RET, REP& JMP instructions fall under this category.
In a CALL we call a function or subroutine or procedure, execute it and you
come back or return to its exact next instruction not in the same instn.
In a JMP you go to a new location and you continue no return or no coming
31
back just continue..
Differences b/n JMP and CALL?
32
Addressing Modes in 8086…..
Program Memory addressing mode is required for
instructions that cause a branch in the program.
33
Addressing Modes in 8086…..
• For the control transfer instructions, the addressing modes depend
upon whether the destination location is within the same segment or
in a different one.
• It also depends upon the method of passing the destination address
to the processor.
• Basically, there are two addressing modes for the control transfer
instructions. Inter segment and intra segment addressing modes.
• Inter-Segment addressing modes. : Address to which the control to be transferred is in
a different segment
• Intra-Segment addressing modes. : Address to which the control to be transferred lies
in the same segment.
34
Addressing Modes in 8086…
35
Program Memory Addressing Modes 8086
Intra-Segment Direct Addressing Mode
o Address where to transfer program control is
specified directly in the instruction as an 8-bt (16-bit)
displacement.
o The effective address is thus calculated by adding
this displacement to the current value of IP.
o As it’s intra-segment, only IP changes, CS doesn’t
change.
o If the displacement is 8-bit it’s called as a short
branch.
o This addressing mode is also called as Relative
Addressing Mode.
36
Intra-Segment Direct Addressing Mode
38
Inter-Segment Direct Addressing Mode
o The new branch location is specified directly in the
instruction
o Both CS and IP get new values, as this is an inter-
segment branch.
39
Addressing Modes in 8086………..
40
Addressing Modes in 8086……..
3. Stack Memory Addressing Modes
The STACK is a portion of read/write memory set aside
by the user for the purpose of storing information
temporarily.
When the information is written on the stack, the
operation is called PUSH.
When the information is read from stack, the operation
is called POP.
Stack is an area of memory for keeping temporary
data.
Stack is used by CALL instruction to keep return address
for procedure, RET instruction gets this value from the
stack and returns to that offset.
41
Addressing Modes in 8086……….
• Stack Memory Addressing Modes
PUSH, POP Operations…
42
PUSH and POP operations
This STACK is implemented with the help of special memory
pointer register, called stack pointer.
During PUSH and POP operation, stack pointer register gives the
address of memory where the information is to be stored or to
be read.
The memory location currently pointed by stack pointer is called
top of stack.
o Stack Pointer always points to the top of stack.
• We can store data (PUSH) in it with out destroying
previously stored data. This is not true in the case of other
registers and memory locations.
• The stack may also be used for storing local variables of
subroutine and for the transfer of parameter addresses to
a subroutine.
43
44
45
46
Addressing Modes in 8086….
• Stack Memory Addressing Modes
Function of PUSH and POP operations…
o Temporarily stores the contents of 16-bit register
or memory location or program status word, and
retrieves when required.
o When the programmer realizes the shortage of the
registers, he stores the present contents of the
registers in the stack with the help of PUSH
instruction and then uses these registers for other
functions.
o After completion of other function, programmer
loads the previous contents of the register from
the stack with the help of POP Instruction. 47
Addressing Modes in 8086……
• Stack Memory Addressing Modes
PUSH Operation…
o The PUSH instruction decrements stack pointer by
two and copies a word from some source to the
location in the stack where the stack pointer points.
( here the source must be a word = 16-bit)
o The source of the word can be a general purpose
register, a segment register, or memory.
o The next slide shows the map of the stack before
and after execution of PUSH AX and PUSH CX
Instructions.
48
• Stack Memory Addressing Modes
PUSH Op….Whenever a word of data is pushed onto the stack
o The high-order 8 bits are placed in the location addressed by SP – 1.
o The low-order 8 bits are placed in the location addressed by SP – 2.
o The SP is then decremented by 2 so that the next word of data
is stored in the next available stack memory location.
Where SP is stack Pointer, and lets assume stack was empty.
49
Addressing Modes in 8086……
• Stack Memory Addressing Modes
POP Operation…
o The POP instruction copies a word from the stack
location pointed to by the stack pointer (SP) to the
destination.
o The destination can be a general purpose register,
a segment register, or memory.
o After the word is copied to the specified
destination, the stack pointer is automatically
incremented by 2. SP=SP+2
o The next slide shows the map of the stack before
and after execution of POP DX and POP BX
Instructions.
o In a stack, the top element is the element that is inserted at the last or most
50
recently inserted element which is Top of stack.
Addressing Modes in 8086……
• Stack Memory Addressing Modes
POP Operation…
o The byte @ SP is transferred to lower order byte position.
o Then, the byte @ SP+1 will be transferred to higher order
byte position. Then again SP will be incremented again.
53
Program Memory Addressing Modes 8086
• Call operation
• The call instruction is used to transfer execution to a subprogram
or procedure.
• There are two basic types of calls, Near and Far calls.
• A near call is a call to a procedure which is in the same segment as
the call instruction.
• When the 8086 executes a near call instruction it decrements the
stack pointer by two and copies the offset of the next instruction
after the call on the stack.
• it loads IP with offset of the first instructions of the procedure in
the same segment.
54
Program Memory Addressing Modes 8086
• Call operation
• A far call is a call to a procedure which is in a different segment
from that which contains the call instruction.
• When the 8086 executes a far call instruction it decrements the
stack pointer by two and copies the contents of the CS register to
the stack.
• It then decrements the stack pointer by two again and copies the
offset of the instruction after the call to the stack.
• Finally it loads CS with the segment base of the segment which
contains the procedure and IP with the offset of the first
instruction of the procedure in that segment.
55
Program Memory Addressing Modes 8086
• RET operation
• The RET instruction will return execution from a procedure to the
next instruction after the call instruction in the calling program.
• If the procedure is a near procedure (in the same segment) then
the return will be done by replacing the instruction pointer with a
word from the top of the stack.
56
57
Thanks…………….
58