Comp 332 Lecture Slide Chapter 03 (Addressing Mode)
Comp 332 Lecture Slide Chapter 03 (Addressing Mode)
A D D R E S S IN G MODE
1
Contents
Types of addressing:
1. Register Addressing
2. Immediate Addressing
3. Direct Addressing
4. Register Indirect Addressing
5. Based Addressing
6. Indexed addressing
7. Based Index Addressing
8. String addressing
9. I/O Direct & Indirect Addressing
10. Relative addressing
11. Implied Addressing
2
Types of addressing mode
1. Register Addressing
• The ins truction w ill s p ecify the na m e of the register which
holds the data to be operated by the instruction.
Exam ple:
MOV CL, D H
Th e con tent of 8-b it r e g is ter D H is m ov ed to another 8-bit register CL
(CL) <-- (D H)
3
2. Immediate Addressing
• In immediate a ddr es s i n g mode, a n 8-bit or 16-bit data is
specified a s part of the instruction
Exa m p le:
M O V DL, 0 8 H
T he 8-bit d a t a (0 8 H ) g i v e n in the instruction i s
m o v e d to D L
(D L) 08 H
M O V AX, 0 A 9 F H
(AX) 0A9F H
4
2 0 A d d r e s s buses ⟶ 8086 can address up
t o 2 = 1 M b y t e s of m e m o r y
20
However, t he l a r g e s t re g i s t e r is o n l y 1 6 b i t s
P h y s ic a l A d d r e s s will h a v e t o b e calculated P h y s i c a l
A d d r e s s : Ac t u a l a d d r e s s of a b y t e in memory. i.e.
t he v a l u e which g o e s o u t o n t o t he a d d r e s s b u s .
8 9 A B : F 0 1 2 ⟶ 8 9 A B ⟶ 8 9 A B 0 ( Pa ra g ra p h to b y t e ⟶ 8 9 A B x 1 0 = 8 9 A B 0 )
F012 ⟶ 0F012 (Offset i s a l r e a d y in b y t e unit)
+ -------
98AC2 (The a b s o l u t e
address)
5
General Rules for Segment: Offset Values
CS:Ip
DS:BX,SI
SS:SP,BP
ES:BX,DI,SI
6
Problems on physical address calculation in 8086 Microprocessor
1. The value of Code Segment (CS) Register is 4042H and the value of
different offsets is as follows:
BX: 2025H , IP: 0580H , DI: 4247H
Calculate the effective address of the memory location pointed by the CS
register.
Effective address= Base address of CS register X 10 H + Address of IP
= 4042H X 10H + 0580H
= (40420 + 0580)H
= 41000H/409A0h
2. Calculate the effective address for the following register:
SS: 3860H, SP: 1735H, BP: 4826H
Exam ple:
M O V BX, [1354H]
M O V BL, [0400H]
• The square brackets around the 1354 H denotes
the contents of the m e m ory location. W h e n executed, this
instruction will copy the contents of the m em ory location into
B X register.
• This a d d re s s i n g m od e is called direct because the
displacement of the operand from the s e g m e n t b a s e is
specified directly in the instruction.
8
4. Register Indirect Addressing
• In R e g is ter ind irect a d d re s s ing , n a m e of the register which h olds the
effective a d d r e s s (EA) will be specified in the instruction.
Exa m p le:
Note : Register/ memory
M O V CX, [BX]
enclosed in brackets refer to
O p era tion s : content of register/ memory
EA = (BX)
B A = ( D S ) x 16 1 0
M A = BA + EA
(CX) ( M A ) or,
(C L) (M A )
(CH) ( M A + 1 )
9
5. Based Addressing
• In B a s e d Addressing, B X or B P is u s ed to hold the b a s e value
for effective a ddr es s a n d a s i gn ed 8- bit or unsigned 16-bit
displacement will be specified in the instruction.
1
9
6. Indexed Addressing
• 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.
• Displacement is a d d e d to the index value
in S I or D I register to obtain the EA.
• In case of 8-bit displacement, it is s i g n
extended to 16-bit before a d d i n g to the
b a s e value.
Exa m p le:
M O V CX, [SI + 0A2H]
Operations:
FFA2 H A2 H ( S ig n extended)
EA = (SI) + FFA2 H
BA = (DS)x 16 1 0
M A = BA + EA
(CX) (MA) or,
(CL) ( M A)
(CH ) ( M A+ 1)
11
7. Based Index Addressing
• In B a s e d Index Addressing, the effective a d d re s s is computed
from the s u m of a b a s e register ( B x o r B P ) , a n i n d e x r e g i s t e r
(S I or D I) a nd a d i s p l a c e m e n t .
Exam ple:
M O V DX, [BX + SI + 0AH]
Operations:
000A H 0A H (S ig n extended)
EA = (BX) + (SI) + 000A H
B A = ( D S ) x 16 1 0
M A = B A + EA
(D X ) (M A ) or,
(D L) (M A )
(D H ) (M A + 1)
12
8. String Addressing
• Em p loyed in s tring op erations to op erate on string data.
• The effective a d d re s s (EA) of source d ata is stored in S I register
a n d the EA of destination is stored in D I register.
• S e g m e n t register for calculating b a s e a d d re s s of source data is
D S a n d that of the destination d ata is E S
Example: M O V S BYTE
Operations:
Calculation of source memory location:
EA = (SI) B A = (DS) x 16 1 0 M A = B A + EA
13
9. I/O Direct & Indirect Addressing
• These a ddr es s i n g m o d e s are u s ed to access data from
standard I/O m a p p e d dev ices or ports.
• In d irect p ort a d d ress ing m od e, a n 8-b it p ort a ddres s is
directly specified in the instruction.
Example: I N AL, [09H]
Operations: PORT a d d r
= 09 H
(A L) (P O RT)
• Content of port with address 09 H is moved to AL register
• 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 D X
register.
Example: O UT [DX], A X
Operations: PORT a d d r = ( D X )
(P O RT) (A X )
14
10.Relative Addressing
• In this addressing mode, the effective address of a
program instruction is specified relative to Instruction
Pointer (IP) by an 8-bit signed displacement.
Example: JZ 0 A H
O p era tions :
000A H 0A H (sign extend)
If ZF = 1, then
EA = (IP) + 000A H
B A = ( C S ) x 16 1 0
M A = B A + EA
• If Z F = 1, then the pr o g ra m control jumps to
new a ddr es s calculated above.
• If Z F = 0, then next ins truction of the
pro gra m is executed.
11.Implied Addressing
16
END?
17