0% found this document useful (0 votes)
100 views36 pages

CH-03 8086-Addressing Modes

ch 3

Uploaded by

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

CH-03 8086-Addressing Modes

ch 3

Uploaded by

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

Microcomputers and Interfacing

(ECEg-4161)

Intel 8086 Addressing Modes

Lecture 03

Beyene Jember UoG iOT Department of ECE


Contents

 Addressing modes: Definition and classification


 Data addressing modes
 Program memory addressing modes.
 Stack memory addressing modes

2
Addressing Modes: Definition and classification
 Microprocessor executes the instructions stored in memory (RAM).

 Each of the instruction contains operations and operands.

• Operation(Opcode) specifies the type of action to be performed (ADD, SUB, MOV, INC,
LOAD, STORE…).

• Operands are the data on which the operation is to be performed.

 An opcode is a short of “operation code”

 In machine language it is a binary or hexadecimal value such as B7 loaded into the


instruction register.

 In assembly language mnemonic form an opcode is a command such as MOV or ADD.


3
Addressing Modes: Definition and classification…
 Addressing Modes

 An addressing mode means the method by which an operand can be


specified in a register or a memory location.

 Addressing mode is the way of accessing operands(data).

 Addressing mode provide different ways for access an address to given data
to a processor.

 Operands may be contained in registers, within the instruction opcode, in


memory, or in I/O ports. 4
Classification of Addressing Modes
 Data Addressing Modes
 This mode is related to data transfer operation, that is, data is transferred either from the
memory to internal registers of 8086 processors or from one register to another register.
• Example: MOV AX, DX

 Program Memory addressing Modes


 This mode involves program memory addresses during various operations.
• Example: JMP AX, in this instruction, the code execution control jumps to the current code
segment location addressed by the contents of AX register.
 Stack memory addressing Modes
 This mode involves stack registry operations.
• Example: PUSH AX, this instruction copies the contents of AX register to the stack. 5
Addressing Modes: classification

6
Data addressing modes

 Immediate addressing
 Immediate addressing transfers the source, an immediate byte or word data, into the
destination register.
 Operand itself is provided in the instruction rather than its address
 Immediate data means constant data, whereas data transferred from a register or memory
location are variable data.
 Example:
MOV BL, 44 ; Copies 44 decimal (2CH) into BL
MOV AX, 44H ; Copies 0044H into AX
MOV AL, ‘A’ ; Copies ASCII A into AL
7
Data addressing modes…
 Register addressing
 Register addressing transfers a copy of a byte or word from the source register to
destination register.

 8-bit register names with register addressing: AH, AL, BH, BL, CH, CL, DH, DL.

 16-bit register names: AX, BX, CX, DX, SP, BP, SI ,DI, IP, CS, SS, DS and ES.

 Never mix an 8-bit register with 16-bit, it is not allowed in microprocessor.


 Code segment register (CS) is never used as destination!
 Segment to segment MOV instruction is not allowed!
• Example: MOV AL, BL ; Copies 8-bit content of BL into AL
MOV AX, CX ; Copies 16-bit content of CX into AX
MOV EX, DS ; Not allowed (segment to segment)
MOV BL, DX ; Not allowed (mixed size)
MOV CS, AX ; Not allowed (Code segment register may not be destination register) 8
Data addressing modes…
Accessing Data in Memory
• The EU has direct access to all registers and data for register and immediate operands. But it
cannot directly access the memory operands.

• The EU must use the BIU segment registers to access memory operands. It sends an offset
value to the BIU, and the BIU generates a 20-bit physical address.

 Direct data addressing


• Direct addressing moves a byte or word between a data segment memory location and
register.

• The instruction set does not support a memory to memory transfer except with the
MOVS instruction. 9
Data addressing modes…
 Direct data addressing…
 There are two basic form of direct data addressing:
 Direct addressing:
 Direct addressing with a MOV instruction transfers data between a memory location,
located within the data segment, and the AL (8-bit) or, AX (16-bit).
 A MOV instruction using this type of addressing is usually a three byte long instruction.
 Example: MOV AL, DS:[1234H]
 Displacement addressing:
 Direct addressing with a MOV instruction transfers data between a memory location,
located within the data segment, and registers other than AL or AX.

 It is almost identical to direct addressing except that the instruction is four byte wide
10
instead of three. Example: MOV CL, DS:[1234H]
Data addressing modes…
 Register Indirect addressing
 Register addressing transfers a byte or word between a register and memory location
addressed by an index or base register.

 The index and base registers are BP, BX, DI and SI. These registers hold the offset address
of the memory location.

 The data segment is used by default with register indirect addressing or any other
addressing modes that uses BX, DI or, SI to address memory.

 If BP register addresses memory, the stack segment is used by default.

 The [ ] symbol denote indirect addressing in assembly language.

11
Data addressing modes…
 Register Indirect addressing…
 Example:
MOV CX, [BX] ; Copies the contents of the data segment memory location addressed by
BX into CX.
MOV [BP], DL ; Copies DL into stack segment memory location addressed by
DI.
MOV [DI], [BX] ; Memory to memory transfers are not allowed except with string
inst.

12
Data addressing modes…
Register Indirect addressing..

13
Data addressing modes…
 Base Plus Index addressing
 Base-plus-index addressing transfer a byte or word between a register and a memory
location addressed by a base register (BP or BX) plus an index register (DI or SI).
 The base register often holds the beginning location of a memory array, whereas the index
register holds the relative position of an element in the array.
 When BP addresses memory, stack segment is selected by default and when BX addresses
memory data segment is selected by default.

14
Data addressing modes…
 Base-Plus-Index addressing…
 MOV CX, [BX+DI] ; Copies the word content of the data segment memory location addressed by BX plus DI
into CX.
 MOV [BP+DI], AH ; Copies AH into stack segment memory location addressed by BP plus DI

15
Data addressing modes…
 Register Relative addressing
• Register relative addressing moves a byte or word between a register and the memory
location addressed by an index or base register (BP, BX, DI or SI) plus a displacement.
• Remember that BX, DI or SI addresses data segment and BP addresses the stack segment.

• Example: MOV AX, [DI+100H] ; Copies the word content of the data segment memory location addressed
by DI plus 100H into AX.
MOV ARRAY[SI], BL ; Copies BL into the data segment memory location addressed by ARRAY plus SI
16
Data addressing modes…
 Register Relative addressing…

17
Data addressing modes…
 Base Relative plus Index addressing
 Base relative plus index addressing transfers a byte or word between a register and a
memory location addressed by a base and an index register plus displacement.
 It is similar to base plus index addressing, but it adds a displacement beside using a base
register and an index register.
 This type of addressing mode often addresses a two-dimensional array of memory data.

 Example: MOV DH, [BX+DI+20H] ; Copies the byte content of data segment memory
location addressed by the sum of BX, DI and 20H into DH.
MOV LIST[BP+DI], CL ; Copies CL into the stack segment memory location addressed by
18
the sum of LIST, BP, SI
Data addressing modes…
 Base Relative plus Index addressing

19
Data addressing modes…
 Addressing Modes for Accessing I/O Ports (I/O Modes)
 Standard I/O devices uses port addressing modes.
1. Direct Port Mode
• Here, the port number is an 8-bit immediate operand. This allows fixed access to ports
numbered 0 to 255.
Example OUT 05H, AL ; sends the contents of AL to 8-bit port 05H
IN AX, 80H ; copies 16-bit contents of port 80H
2. Indirect Port Mode
• Here the port number is taken from DX allowing 64K 8-bit ports or 32k 16-bit ports.
Example IN AL, DX ; if [DX]=7890H, then it copies 8-bit contents of port 7890H into AL
IN AX, DX ; copies the 16-bit contents of ports 7890H into AX. 20
Program Memory Addressing
 Program memory addressing modes, used with the JMP and CALL instructions, consist of three
distinct forms:
1. Direct Program Memory Addressing
2. Relative Program Memory Addressing
3. Indirect Program Memory Addressing

 Direct program memory addressing


 In this addressing mode addresses where to transfer program control is specified within the
instruction along with the opcode.

21
The 5-byte machine language version of a JMP 2000 instruction
Program Memory Addressing…
 Direct program memory addressing…
 The direct intersegment JMP instruction and the four bytes required to store the address
20000H.
 This JMP instruction loads CS with 2000H and IP with 0000H to jump to memory location
20000H for the next instruction.
 An intersegment jump is a jump where destination location is from a different Segment; it can
be any memory location within the entire memory locations. Therefore, intersection jump is
also known as far jump.

 Like JMP instruction, CALL instruction also uses direct program addressing with intersegment
or far CALL instruction. Usually in both instructions (JMP or CALL) the name of a memory
address, called a label is specified in the instruction instead of address. 22
Program Memory Addressing
Relative program memory addressing
 The term relative means “relative to the instruction pointer (IP)”.
 For example, if a JMP instruction skips the next 5 bytes of memory, the address in relation to
the instruction pointer is a 5 that adds to the instruction pointer. This generates the address of
the next program instruction.

23
Program Memory Addressing
Relative program memory addressing
 In JMP instruction, opcode takes one byte and displacement may take one or two byte.
 When displacement is one byte (8-bit), it is called short jump and when displacement is two
byte ( 16--bit), it is called near jump.
 In both (short and near) cases only content of IP register are modified; contents of CS register
are not modified. Such jumps are called intersegment jumps because jumps are within the
current code segment.

24
Program Memory Addressing
Relative program memory addressing
 The relative JMP and CALL instructions can have either an 8·bit or a l6·bit
signed displacement that allows a forward memory reference or a reverse memory
reference.
 In this addressing mode, it is possible to use any 16-bit register(AX, BX, CX,
DX, SP, BP, DI or Si); any relative registers ([BP], [BX], [DI], or [SI]); and any
relative register with displacement to specify the JMP address.

25
Program Memory Addressing

Indirect program memory addressing…


Instruction Operation
JMP [BX] Jumps to memory location addressed by BX with in current code segment
IP <= BX

JMP NEAR PTR [ BX] Jumps to memory location addressed by the contents of the data segment memory
location addressed by BX with in current code segment
IP <= ([BX + 1], [BX]
High byte Low byte
JMP NEAR PTR [ DI+2] Jumps to memory location addressed by the contents of the data segment memory
location addressed by DI plus 2 with in current code segment
IP <= ([DI + 3], [DI + 2]
High byte Low byte

Jumps to memory location addressed by the contents of the data segment memory
JMP ARRAY [BX] location addressed by ARRAY plus BX with in current code segment
IP <= ([ARRAY + BX + 1], [ARRAY + BX]
High byte Low byte
26
Stack Memory Addressing Modes
 Stack
 The stack is a portion of read/write memory set aside by the user for the purpose
of storing information temporarily and return addresses for procedures.
 The stack memory is a LIFO (last-in, first-out) memory which mean that the first
information pushed on to the stack is the last in formation popped of from the
stack.
 This stack is implemented with the help of special memory pointer register called
stack pointer(SP).
 During PUSH/POP operation, SP give the address of memory where the
27
information is to be stored.
Stack Memory Addressing Modes
Stack…
 The stack pointer’s contents are automatically manipulated to point to stack top
and the memory location currently pointed by stack pointer is called top of stack.
 Data are placed onto the stack with a PUSH instruction and removed with a POP
instruction.
 The CALL instruction also uses the stack to hold the return address for procedures
and a RET (return) instruction to remove the return address from the stack.

28
Stack Memory Addressing Modes
Stack Structure of 8086
 The stack pointer (SP) register contains the 16-bit offset from the start of the
segment to the top of stack.
 For stack operation, physical address is produced by adding the contents of SP
register to the segment base address in SS. To do this the contents of the SS
register is shifted 4-bits left and the contents of SP is added to the shifted result.
 Example: If the contents of SP is 9F20H and SS is 4000H then the physical
address is calculated as: SS = 4000H after shifting four bits left SS =
40000H
29
Stack Memory Addressing Modes
 Stack Structure of 8086
 SS = 4000H after shifting four bits left SS = 40000H
 SP=9F20H

30
Stack Memory Addressing Modes
PUSH and POP Operations
 Temporarily stores the contents of 16-bit register or memory location or program
status word, and retrieves when required.
 When the programmer realizes the shortage of the registers, he/she stores the
present content of the registers in the stack with the help of PUSH instruction and
then use the register for other functions.
 After completion of other function programmer loads the previous contents of the
register from the stack with the help of POP instruction.

31
Stack Memory Addressing Modes
PUSH and POP Operations…
PUSH Operation
 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) that can be a general purpose register, a segment
register or memory.

POP Operation
 The POP instruction copies a word from the stack location pointed by the stack pointer to the
destination. The destination can be a GPR, a segment register or a memory location.
 After the word is copied to the specified destination, the stack pointer is automatically
incremented by two.
32
Stack Memory Addressing Modes
 POSH Operation
PUSH AX
PUSH CX

33
Before execution After execution
Stack Memory Addressing Modes
 POP Operation
POP BX
POP DX

34
Before execution After execution
Stack Memory Addressing Modes
 CALL Instruction
 The CALL instruction is used to transfer execution to a sub program or procedure.
 There are two basic type of CALL, near and far.
 Near CALL
 Is a call to a procedure which is in the same code 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 task. It load IP with
the offset of the first instruction of the procedure in the same segment.
 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 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 35
Stack Memory Addressing Modes

 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 near (in the same code segment as the CALL instruction), then the return
will be done by replacing the instruction pointer with a word from the top of the Stack.
 If the procedure is far
 The instruction pointer will be replaced by the word at the top of the stack and the stack pointer will then
be incremented by two.
 The code segment register is then replaced with a word from the new top of the stack.
 After the code segment word is popped off the stack, the stack pointer is again incremented by two.
These words/word are the offset of the next instruction after the CALL. So 8086 will fetch the next
instruction after the CALL. 36

You might also like