Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 50

Chapter 3

Addressing
Modes
prepared by
Dr: Mohamed EL-Bouridy Dr : Reda EL-Sheshtawy
mohamed.elbouridy@aiet.edu.eg RedaSheshto66@gmail.com
Chapter
Register Addressing
Overview
Immediate Addressing
Direct Data Addressing
Register Indirect Addressing
Base-Plus-lndex Addressing
Register Relative Addressing
Base Relative-Plus-lndex Addressing
Program memory Addressing Modes
Memory Organization
Introduction
 Efficient software development for the microprocessor
requires a complete familiarity with the addressing
modes employed by each instruction
 The MOV (move data) instruction is used to describe the
data-addressing modes.
 The MOV instruction transfers bytes or word of data
between registers and memory in 8086 ….80286, words
or doublewords in 80386 and above.

 In describing the program memory-addressing modes,


the CALL, and JMP instruction show how to modify the
flow of the program
Introduction
 The data addressing modes include (register addressing
mode, immediate addressing mode, direct addressing
mode, register indirect addressing mode, base-plus-
index addressing mode, register relative addressing
mode, and , base relative -plus-index addressing mode)
in 8086 ….80286 microprocessor. The 80386 and above
include a scaled-index mode of addressing memory
data.

 The program memory-addressing modes includes


(program relative memory-addressing, program direct
memory-addressing, program indirect memory-
addressing).
The MOV instruction

MOV AX , BX

Destination Source
Data-Addressing Modes
Transfers a copy of a byte or word from
Register
the source register or memory location
addressing
to the destination register or memory
mode
location.

MOV AX, BX

Register Register
BX AX
Source Destination
Register Addressing
• Register addressing is the most common form of data
addressing and, once the register names are learned,
it is the easiest to apply.

• Examples of the register-addressed instructions.


Assembly Language Size Operation
MOV AL, BL 8-bits Copies BL into AL
MOV CH, CL 8-bits Copies CL into CH
MOV AX, CX 16-bits Copies CX into AX
MOV SP, BP 16-bits Copies BP into SP
MOV BX, ES 16-bits Copies ES into BX
MOV ECX, EBX 32-bits Copies EBX into ECX
MOV ESP, EDX 32-bits Copies EDX into ESP
MOV ES, DS — Not allowed (segment-to-segment)
MOV BL, DX — Not allowed (mixed sizes)
Register Addressing Example
MOV BX, CX

The effect of executing the MOV BX, CX instruction


at the point just before the BX register changes. Note
that only the rightmost 16 bits of register EBX change.
Data-Addressing Modes
Transfers the source-immediate byte or
Immediate
word of data into the destination register
addressing
or memory location.

MOV CH, 3AH

Data Register
3AH CH
Source Destination
Immediate Addressing
• The term immediate implies that the data immediately
follow the hexadecimal code in the memory. Also note
that immediate data are constant data, while the data
transferred from a register are variable data.

• Examples of the immediate-addressed instructions.


Assembly Language Size Operation
MOV BL, 44 8-bits Copies a 44 decimal (2CH) into BL
MOV AX, 44H 16-bits Copies a 0044H into AX
MOV CH, 100 8-bits Copies a 100 decimal (64H) into CH
MOV AL, 'A' 8-bits Copies an ASCII A into AL
MOV AX, 'AB' 16-bits Copies an ASCII BA into AX
MOV CL, 11001110B 8-bits Copies a 11001110 binary into CL
MOV EBX, 12340000H 32-bits Copies a 12340000H into EBX
MOV ESI, 12 32-bits Copies a 12 decimal into ESI
MOV EAX, 100B 32-bits Copies a 100 binary into EAX
Immediate Addressing Example:

MOV EAX, 13456H

The operation of the MOV EAX,13456H instruction. This


instruction copies the immediate data (00013456H) into
EAX.
Data-Addressing Modes
Moves a byte or word between a memory
Direct location and a register. The instruction set
addressing does not support a memory-to-memory
transfer, except for the MOVS instruction.

MOV [1234H], AX

Memory
Register DS×10H+DISP
1000×10H+1234H address
AX
11234H

Source Destination
Direct Data Addressing
• Direct addressing with a MOV instruction transfers
data between a memory location, located within the
data segment, and the AL (8-bit), AX (16-bit), or EAX
(32-bit) register.
• Examples of the Direct addressed instructions.
Assembly Language Size Operation

MOV CH, DOG 8-bits Copies the byte contents of data segment
memory location DOG into CH
MOV CH, [1000H] 8-bits Copies the byte contents of data segment
offset address 1000HintoCH
MOV ES, DATA6 16-bits Copies the word contents of data
segment memory location DATA6 into ES
MOV DATA7, BP 16-bits Copies BP into data segment memory
location DATA7
MOV NUMBER, SP 16-bits Copies SP into data segment memory
location NUMBER
MOVDATA1, EAX 32-bits Copies EAX into data segment memory
location DATA1
MOV EDI, SUM1 32-bits Copies the doubleword contents of data
segment memory location SUM1 into EDI
Direct Addressing Example :
MOV AL, [1234H]

The operation of the MOV AL,[1234H] when DS = 1000H.


Data-Addressing Modes
Transfers a byte or word between a
Register
register and a memory location addressed
indirect
by an index or base register. The index and
addressing
base registers are BP, BX, DI, and SI.

MOV [BX], CL

Memory
Register DS×10H+BX
1000×10H+0300H address
CL
10300H

Source Destination
Register Indirect Addressing
• Register indirect addressing allows data to be addressed at any
memory location through an offset address held in any of the following
registers: BP, BX, DI, and SI.

• Examples of the Register indirect addressed instructions.


Assembly
Size Operation
Language
MOV CX, [BX] 16-bits Copies the word contents of the data segment
memory location address by BX into CX
MOV [BP], DL 8-bits Copies DL into the stack segment memory
location addressed by BP
MOV [DI], BH 8-bits Copies BH into the data segment memory
location addressed by Dl
MOV [DI], [BX] — Memory-to-memory moves are not allowed
except with string instructions
MOV AL, [EDX] 8-bits Copies the byte contents of the data segment
memory location addressed by EDX into AL
MOV ECX, [EBX] 32-bits Copies the doubleword contents of the data
segment memory location addressed by EBX
into ECX
Register indirect Addressing Example :
MOV AX, [BX]

The operation of the MOV AX,[BX] instruction


when BX = 1000H and DS = 0100H. Note that
this instruction is shown after the contents of
memory are transferred to AX.
Data-Addressing Modes
Transfers a byte or word between a
Base-plus-
register and the memory location
index
addressed by a base register (BP or BX)
addressing
plus an index register (DI or SI).

MOV [BX+SI], BP

Memory
Register DS×10H+BX+SI
1000×10H+0300H+0200 address
BP
H 10500H

Source Destination
Base-Plus-lndex Addressing
• Base-plus-index addressing is similar to indirect
addressing because it indirectly addresses memory data.
• In the 8086 through the 80286, this type of addressing
uses one base register (BP or BX), and one index register
(DI or SI) to indirectly address memory.

• Examples of the Base-Plus-Index addressed instructions.


Assembly Language Size Operation
MOV CX,[BX+DI] 16-bits Copies the word contents of the data
segment memory location address by BX
plus Dl into CX
MOV CH,[BP+SI] 8-bits Copies the byte contents of the stack
segment memory location addressed by BP
plus SI into CH
MOV [BX+SI],SP 16-bits Copies SP into the data segment memory
location addresses by BX plus SI
MOV [BP+ DI],AH 8-bits Copies AH into the stack segment memory
location addressed by BP plus Dl
Base-Plus-lndex Addressing Example :
MOV DX, [BX + DI]

An example showing how the base-plus-index


addressing mode functions for the MOV DX,[BX+DI]
instruction. Notice that memory address 02010H is
accessed because DS = 0100H, BX = 1000H,
and DI = 0010H.
Data-Addressing Modes
Register Moves a byte or word between a register
relative and the memory location addressed by an
addressing index or base register plus a displacement.

MOV CL,[BX+04H]

Memory
DS×10H+BX+4H Register
address 1000×10H+0300H+04H CL
10304H

Source Destination
Register Relative Addressing
• Register relative addressing is similar to base-plus-
index addressing and displacement addressing. In
register relative addressing, the data in a segment of
memory are addressed by adding the displacement
to the contents of a base or an index register (BP,
BX, Dl, or SI).
• Examples of the register Relative addressed instructions.
Assembly Language Size Operation
MOV AX, [DI+100H] 16-bits Copies the word contents of the data segment
memory location addressed by Dl plus 100H
into AX
MOV ARRAY[SI], BL 8-bits Copies BL into the data segment memory
location addressed by ARRAY plus SI
MOV LIST[SI+2], CL 8-bits Copies CL into the data segment memory
location addressed by sum of LIST, SI, and 2
MOV DI,SET_IT[BX] 16-bits Copies the word contents of the data segment
memory location addressed by the sum of
SET_IT and BX into Dl
MOV ARRAY[EBX],EAX 32-bits Moves EAX into the data segment memory
location addressed by the sum of ARRAY and
EBX
Register Relative Addressing
MOV AX, [BX + 1000H]

The operation of the MOV AX,[BX+1000H] instruction,


when BX = 0100H and DS = 0200H.
Data-Addressing Modes
Base Transfers a byte or word between a
relative- register and the memory location
plus- index addressed by a base and an index register
addressing plus a displacement.

MOV ARRAY[BX+SI],DX

Memory
Register DS×10H+ARRAY+BX+SI
address
DX 1000×10H+1000H+0300H+0200H
11500H

Source Destination
Base Relative-Plus-lndex Addressing

Assembly Language Size Operation

MOV DH, [BX+DI+20H] 8-bits Copies the byte contents of the data
segment memory location
addressed by the sum of BX, Dl,
and 20H into DH.

MOV AX, FILE[BX+DI] 16-bits Copies the word contents of the data
segment memory location
addressed by the sum of FILE, BX,
and Dl into AX.

MOV LIST[BP+DI], CL 8-bits Copies CL into the stack segment


memory location addressed by the
sum of LIST, BP, and Dl
Base Relative-Plus-lndex Addressing
MOV AX, [BX+SI+100H]

• An example of base relative-plus-index addressing using


a MOV AX, [BX+SI+100H] instruction.
• Note: DS = 1000H.
Data-Addressing Modes
Is available only in the 80386 through the
Scaled- Pentium 4 microprocessor. The second
index register of a pair of registers is modified by
addressing the scale factor of 2X, 4X, or 8X to
generate the operand memory address.

MOV [EBX+2×ESI],AX

Memory
Register DS×10H+EBX+2×ESI
address
AX 1000×10H+00000300H+2×00000200H
10700H

Source Destination
Program memory-
Addressing Modes
Program memory-Addressing Modes
Direct Used with JMP, and CALL instructions in
program low level language , Also used with GOTO,
memory and GOSUP instructions in high level
addressing language.
JMP [10000H]
Go directly to a memory location
CS×10H+IP
1000H×10H+0000H

This JMP instruction loads CS with 1000H and IP with


0000H to jump to memory location 10000H for the next
instruction.
Program memory-Addressing Modes
Relative
program The term relative means “ relative to the
memory instruction pointer(IP)”
addressing

JMP [2]

2 Adds to the instruction pointer


IP + 2
The new IP address =10000 + 2 =10002
Relative program memory addressing
JMP [2]
IP + 2
The new IP address =10002 + 2 =10004
Program memory-Addressing Modes
The microprocessor allows several forms
Indirect of indirect program memory addressing
program for JMP, and CALL. It can use any 16-bit
memory register (AX,BX,CX,DX,SP,DI, or SI) , any
addressing relative register ([BP],[BX],[DI], or [SI],
and any relative register with displacment.

JMP AX

JMP to CS × 10 H +AX +IP


Indirect program memory addressing
Stack memory addressing modes
Stack memory addressing modes

As shown in figure
Stack memory addressing modes
Stack memory addressing modes
Stack memory addressing modes
Memory Organization
BHE 16-bit
FFFE FFFF

EN
8-bit A8
A0 EN
A15 Address
A7 Even byte Odd byte
Address Lower byte Higher byte
8086 P D0 D7 D8 D 15
Data Bus

Any date stored in the memory: stored in two parts


Lower byte stored in the even byte of memory
Higher byte stored in the odd byte of memory
Example :
AX = AB07 H
BX = 249A H

Lower byte Higher byte

AX 07 AB

BX 9A 24

Even Odd
Example : The initial values of 8086 P registers
are shown, the memory is
AX = AB07 BX = 249A CX = 9A20
DX = 0200 IP = 00A0 CS = 0100
SS = B000 SP = 0108 DS = 8000

(A) By appropriate MOV instruction, AX register is


stored at memory location 0800H, and BX in
0806H. Show the memory content ?
(B) Show the stake memory contents after the
following sequence of instructions ?
(1) PUSH CX
(2) PUSH BX
(3) POP DX
Solution : (A)
The memory location of AX=DSx10H+offset
=80000H+ 0800H=80800H
The memory location of BX=DSx10H+offset
=80000H+ 0806=80806H
EVEN ODD
80808 80809
80806 9A 80807 24
80804 80805
80802 80803
80800 07 80801 AB

Lower Higher
Solution : (B)
The memory location in stake memory =SSx10H+SP
=B0000H+ 0108H=B0108H
(1) PUSH CX
(2) PUSH BX EVEN ODD

B0108 B0109
PUSH CX B0106 20 B0107 9A
PUSH BX B0104 9A B0105 24
B0102 B0103
B0100 B0101
Lower Higher
(3) POP DX

EVEN ODD

B0108 B0109
B0106 20 B0107 9A
POP DX B0104 9A B0105 24
B0102 B0103
B0100 B0101
Lower Higher

POP DX : Then DX = 249A, and SP at B0106


Design of Memory Bank
The available memory is1Kx 8bit, it means that,
the capacity is 1K, and the width is 8-bit

Example : The available memory is1Kx 8bit.


Design a bank of memory 4Kx16 ?

Solution :
The number of IC’s required=

= = 8 IC’s
Memory Bank 4Kx16-bit
Decoder
2x4
Demultiplex
A0 A0
A15 A15
Y0 CS CS
A10
Y1
Y2
A11
A0
Y3
A15
CS A0
A15
CS
1K (memory capacity) = 1024 = 210
4K (memory capacity) = 4096 = 212
Then the decoder is (2x4)
Memory Bank 4Kx8-bit
Decoder
2x4
Demultiplex
A0 A0
A7 A7
Y0 CS CS
A10
Y1
Y2
A11
A0
Y3
A7
CS A0
A7
CS
1K (memory capacity) = 1024 = 210
4K (memory capacity) = 4096 = 212
Then the decoder is (2x4)
Example : Design a memory bank of 1024x16,
where the available memory is 128x 8bit?

Solution :
The number of IC’s required=

= = 16 IC’s

128 (memory capacity) = 27


1024 (memory capacity) = 210
Then the decoder is (3x8)
Decoder
Memory Bank 1024x16-bit
3x8
Demultiplex A0
A15 CS A0
Y0
A15 CS
Y1
A7 A0
A15 CS A0
Y2
A15 CS
A8
Y3
A0
A15 CS A0
A15 CS
A9
Y4 A0
Y5 A15 CS A0
A15 CS
The
End

You might also like