0% found this document useful (0 votes)
45 views

Chapter 3

The document discusses different addressing modes in 8086, including: 1. Data addressing modes classify how data is accessed for instructions, including registers, memory, and I/O ports. 2. Memory can be accessed using base registers (BX, BP), index registers (SI, DI), and displacements to form effective addresses. 3. Common data addressing modes are immediate, register, direct, register indirect, based, indexed, based indexed, string, direct I/O, and indirect I/O addressing. Each mode specifies the operands and how they are accessed for instructions.

Uploaded by

bojaa m
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

Chapter 3

The document discusses different addressing modes in 8086, including: 1. Data addressing modes classify how data is accessed for instructions, including registers, memory, and I/O ports. 2. Memory can be accessed using base registers (BX, BP), index registers (SI, DI), and displacements to form effective addresses. 3. Common data addressing modes are immediate, register, direct, register indirect, based, indexed, based indexed, string, direct I/O, and indirect I/O addressing. Each mode specifies the operands and how they are accessed for instructions.

Uploaded by

bojaa m
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 58

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.

• Addressing mode indicates a way of locating data or operands.


• The addressing mode describes the types of operands and the way
they are accessed for executing an instruction.

• 8086 provides different addressing modes for Data, Program and


Stack Memory.
• The addressing modes of any processor can be broadly classified as:
1. Data Addressing Modes
2. Program Memory Addressing Modes
3. Stack Memory 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

4. Register Indirect Addressing

5. Based (with displacement) Addressing

6. Indexed (with displacement) Addressing Group II : Addressing modes for


accessing memory data
7. Based Index Addressing

8. Based Indexed with displacement

9. String Addressing

10. Direct I/O port Addressing


Group III : Addressing modes for
11. Indirect I/O port Addressing accessing I/O ports

12. Implied Addressing Group V : Implied Addressing mode


8
1. IMMEDIATE ADDRESSING MODE
• In immediate addressing mode, an 8-bit or 16-bit
immediate data is directly specified as part of the
instruction.
• Destination operand can never be immediate data.
• Example 1:
MOV DL, 08H

• The 8-bit data (08H) given in the instruction is moved


to DL
(DL)  08H

• Example 2:
MOV AX, 0A9FH

• The 16-bit data (0A9FH) given in the instruction is


moved to AX register. AH AL
(AX)  0A9FH AX 0A 9F
 In this addressing mode, the segment register can’t be 9
2.REGISTER ADDRESSING MODE
• The instruction will specify the name of the
register which holds the data to be operated by
the instruction.
• the data is stored in a register and it is referred using
the particular register.
• both the operands are registers.
• Source & Destination Operands: Registers

• Example 1: 8 bit register as source of operand.

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.

• Combining these registers inside [ ] symbols, we can get


different memory locations ( Effective Address, EA)

• Supported Combinations (supported addressing modes):

[BX + SI] [BX + SI + d8]


[SI]
[BX + DI] [BX + DI + d8]
[BP + SI] [DI] [BP + SI + d8]
d16 (variable offset only)
[BP + DI] [BX] [BP + DI + d8]

[SI + d8] [BX + SI + d16] [SI + d16] By default DS segment


[DI + d8] [BX + DI + d16]  [DI + d16]
[BP + d8] [BP + SI + d16] [BP + d16] register is used for all modes
[BX + d8] [BP + DI + d16] [BX + d16] except those with BP register,
for these SS segment register
BX SI is used.
+ disp
BP DI
14
Memory Access: Valid Combinations
• You can form all valid combinations by
taking only one item from each column or
skipping the column by not taking anything
from it.
• BX and BP never go
together, SI and DI
also don’t go together.

[BX + SI] [SI] [BX + SI + d8]


[BX + DI] [DI] [BX + DI + d8]
[BP + SI] [BP + SI + d8]
d16 (variable offset only)
[BP + DI]
[BX]
[BP + DI + d8] • Displacement(disp)
can be inside or
outside of [] symbols.
[SI + d8] [BX + SI + d16] [SI + d16]
[DI + d8] [BX + DI + d16]  [DI + d16] • Valid Combinations
[BP + d8] [BP + SI + d16] [BP + d16]
[BX + d8] [BP + DI + d16] [BX + d16] represent Effective
Addresses
𝑂𝑓𝑓𝑠𝑒𝑡 𝐴𝑑𝑑𝑟𝑒𝑠𝑠≤ 𝐸𝑓𝑓𝑒𝑐𝑡𝑖𝑣𝑒 𝐴𝑑𝑑𝑟𝑒𝑠𝑠< 𝑃h𝑦𝑠𝑖𝑐𝑎𝑙𝑙 𝐴𝑑𝑑𝑟𝑒𝑠𝑠 15
3. DIRECT ADDRESSING MODE
• Here, the effective address is directly given in the instruction as
displacement. MOV AX, [DISP]
• a 16-bit memory address (offset) directly specified in the instruction as a part of it.
 Example: MOV BX, [1234H]
 Here if DS=2000H and offset (Effective Address) =1234H
Physical Address=DS*10H+Offset Address
  =2000H*10H+1234H
=21234H
 This instruction moves the contents of 21234H & 21235H
memory location into BL and BH register respectively.
• The square brackets around the 1234H denotes the contents of
the memory location. When executed, this instruction will copy
the contents of the memory locations; 1234 H & 1235H, in the data
segment into BX register.
• This addressing mode is called direct because the displacement of
the operand from the segment base is specified directly in the
instruction.
• MOV AL,[1234H] and MOV AL, DS:[1234H] are the same. How?
• You must include the segment register DS: in this example,
before the [offset] part of the instruction. You may use any
segment register, but in most cases, data are stored in the data
segment, so this example uses DS:[1234H]. 16
4. REGISTER INDIRECT ADDRESSING MODE
• In Register indirect addressing, name of the register which holds
the Effective Address (EA) will be specified in the instruction.
• the effective address is in SI, DI or BX.
• BX is the "base'' register; it is the only general-purpose register
which may be used for indirect addressing.
• Registers used to hold Effective Address of an operand are any of
the following registers: BX, SI, DI.
• The segment is Data segment by default.

• For example, the instruction MOV [BX], AX causes the contents of


AX to be stored in the memory location whose address is given in
BX.
Note : Register/ memory
enclosed in brackets refer
MOV AX, [BX]
to content of register/
• Example: Operations: memory

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).

• In case of 8-bit displacement, it is sign extended to 16-bit


before adding to the base value.
MOV CX, [SI + A2H] ; indexing addressing mode with displacement
• Example:
Operations:

FFA2H  A2H (Sign extended)

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.

• When BP holds the base value of EA, BP and SS is used.

MOV AX, [BX + 08H]; Based Addressing Mode with displacement

Operations:
• Example: 0008H  08H (Sign extended)
EA = (BX) + 0008H
BA = (DS) x 10 H
MA = BA + EA

(AX)  (MA) or,


19
(AL)  (MA)
(AH)  (MA + 1)
7.BASED & INDEX ADDRESSING MODES
• In Based Index Addressing, the effective address is
computed from the sum of a base register (BX or BP), an
index register (SI or DI).
the effective address is sum of base register and index register.

MOV DX, [BX + SI ] or MOV DX, [BX][SI]


• Example: Operations:

EA = (BX) + (SI)
BA = (DS) x 10 H
MA = BA + EA

(DX)  (MA) or,

(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)

MOV AX, [BX + SI + 06H]


AH  [BX + SI + 07H] : AL  [BX + SI + 06H]
• Example 2:

The effective address is the sum of index register, base


register and displacement.

21
9. Strings Addressing Mode
• Employed in string operations to operate on string data.

• In this the value of SI and DI are auto incremented and


decremented depending upon the value of directional flag.
MOVS B; MOVS W;
• Example: MOVS BYTE ; in another way [ES:DI]  [DS:SI]

Operations:

Calculation of source memory location:


EAD = (SI) BAD = (DS) x 10 H MAD = BAD + EAD

Calculation of destination memory location:


EAE = (DI) BAE = (ES) x 10 H MAE = BAE + EAE
Note : Effective address of
the Data Segment

(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….

String means series of data such as letter of words or


sentence to be stored in consecutive memory locations.
8086 microprocessor permits the one block of data to be
copied to another consecutive memory locations using
string instructions.

MOVS/MOVSB/MOVSW/MOVSD/MOVSQ — Move Data


from String to String
 Usage MOVS destination, source (This syntax usage is misleading;
movement of data still happens from DS:SI to ES:DI)
MOVSB
MOVSW

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

 String : Sequence of bytes or words


 is a series of the same type of data items in sequential memory locations
 8086 instruction set includes instruction for string movement, comparison, scan,
load and store are the 5 types of string instructions.

 REP instruction prefix : used to repeat execution of string instructions

 String instructions end with S or SB or SW. S represents string, SB string byte


and SW string word.

 Offset or effective address of the source operand is stored in SI register and that of
the destination operand is stored in DI register.

 Depending on the status of DF, SI and DI registers are automatically updated.

o DF = 0 SI and DI are incremented by 1 for byte and 2 for word.

o DF = 1 SI and DI are decremented by 1 for byte and 2 for word.


25
Addressing modes for accessing I/O ports (I/O
modes)
• Standard i/o devices uses port addressing
modes.
• For memory-mapped i/o, memory addressing
modes are used.
• There two types of port addressing modes.
1. Direct
2. Indirect

26

10. Direct I/O Port Addressing
These addressing modes are used to access data from standard I/O
mapped devices or ports.

• I/O addresses in 8086 can be either 8 bit or 16 bit.

• In direct port addressing mode, the port number is an 8 bit immediate


operand. This follows fixed access to ports numbered 0 to 255.
• In direct port addressing mode an 8-bit port address is directly specified in
the instruction.
• IN AL, [80H] ; AL gets data from I/O port address 80H.

• IN AX, [80H] ; AX gets 16-bit data from I/O port address 80H

• OUT [80H], AL ; I/O port 80H gets 8-bit data from AL

• OUT [80H], AX ; I/O port 80H gets 16-bit data from AX

• This is also called Fixed Port Addressing.


IN AL, [09H] copies 8 bit contents of port 09H
Examples:- Out [05H], AL
Operations:
PORTaddr = 09H
(AL)  (PORT)

Content of port with address 09H is moved to AL register


27
11. Indirect I/O Port Addressing
• In indirect port addressing mode, the instruction will
specify the name of the register which holds the port
address. In 8086, the 16-bit port address is stored in
the DX register.
OUT [DX], AX
• Example:
Operations:
PORTaddr = (DX)
(PORT)  (AX)

Content of AX is moved to port whose address is specified


by DX register.

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

 Sets the Carry Flag to one.

• Example 2: CLC

 This clears the carry flag to zero.

• 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.

 If the branch is within the segment, it is called as an Intra-


Segment Branch or a Near Branch.
o The destination location is within the current segment
 If the branch is in a different segment, it’s called as an
Inter-segment Branch or a Far Branch.
o The destination location is from a different segment (it can
be any memory location within the entire memory
locations)
 In both instructions the name of a memory address, called a
label is specified in the instruction instead of address.
 If you want a delay you call a function/ subroutine

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…

• Program Memory Addressing Modes

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

The basic syntax of JMP instruction: JMP label


JMP label to declare a label in your program, just type its name and
add ":" to the end, label can be any character combination but it
cannot start with a number,
37
Intra-Segment Indirect Addressing Mode
o Address where to transfer program control is
specified indirectly in the instruction through a
register or a memory location.
o The value in the IP is replaced with the new value.
o As it is intra-segment, only IP changes, CS doesn’t
change.
o Eg: JMP WORD PTR [BX] ; IP {DS:[BX], DS:[BX + 1]}

Prefixes used in order to tell the assembler/compiler about data type.

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………..

• Program Memory Addressing Modes


 Inter-Segment Indirect Addressing Mode
o The new branch location is specified indirectly in
the instruction through a register or a memory
location.
o Both IP and CS get new values, as this is an inter-
segment branch
o Eg: JMP DWORD PTR [BX]; IP = changes
; CS =changes

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…

 The Microprocessor stores the information,


much like stacking plates. If it is desired to
take out the first stacked plate, we will have
to remove all plates above the first plate in
the reverse order.
 This means that, the first information pushed
on to the stack is the last information popped
off from the stack.
o This type of operation is known as first in,
last out (FILO) or last in first out (LIFO)

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.

(a) Before execution (a) After execution of POP DX and POP BX


51
Addressing Modes in 8086……
• Types of Stack Memory Addressing Modes
 Register Addressing Mode
o In this addressing mode the operands are
specified in registers ( Only 16-bit registers)
o Eg: PUSH BX ; Transfers BH at location pointed by SP-1
; and BL at Locations pointed by SP-2 in
; the stack segment.
;then, SP SP-2
 Register Indirect Addressing Mode
o In this addressing mode the addresses of the
operand is specified in the registers
o Eg: PUSH [BX] ; This instruction will transfer a word
from ; location pointed by BX and BX+1 in
Data Segment ; to SP -1 and SP – 2 in Stack
Segment respectively. 52
Addressing Modes in 8086……..
• Stack Memory Addressing Modes
 Flag Addressing Mode
o Here the contents of Flag Register are transferred
to and from the Stack.
o Eg: PUSHF ; This instruction will transfer higher byte
; of Flag Register to SP-1 and lower byte to
; SP-2 in the Stack Segment
 Segment Register Addressing Mode
o Here the Segment Registers (except CS) are
transferred to and from the Stack.
o Eg: PUSH DS ; This instruction will transfer higher byte
; of DS Register to SP-1 and lower byte to
; SP-2 in the Stack Segment

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.

• If the procedure is a far procedure (in different segment) then the


instruction pointer will be replaced with a word at the top of the
stack.

56
57
Thanks…………….

58

You might also like