Document

Chapter Four–80x86 Instruction Set
Principles of Microcomputers
Chapter four
80x86 Instruction Set(2)
8086 Addressing Modes
2017年7月29日
1
Chapter Four–80x86 Instruction Set
Principles of Microcomputers
What is the Addressing Mode ?
add dest, source
add ax,bx
; dest +source→dest
; ax +bx→ax
The addressing mode means where and how
the CPU gets the operands when the
instruction is executed.
2017年7月29日
2
Chapter Four–80x86 Instruction Set
Principles of Microcomputers
Three types of 8086
addressing modes
• Immediate Addressing Mode
---CPU gets the operand from the instruction
• Register Addressing Mode
---CPU gets the operand from one of the internal registers
• Memory Addressing Mode
---CPU gets the operand from the memory location(s)
2017年7月29日
3
Principles of Microcomputers
Chapter Four–80x86 Instruction Set
1. Immediate Addressing Mode
Exp:
MOV AL, 80H
Machine code:B080H
MOV AX, 1234H
Machine code:B83412H
Instruction Queue
AL
80H
Instruction Queue
B0H
80H
2017年7月29日
AH
12
MACHINE
CODE
AL
34
B8
34H
34
MACHINE
CODE
12H
12
4
Chapter Four–80x86 Instruction Set
Principles of Microcomputers
2. Register Addressing
Mode
Exp:MOV AX, CX
Memory
AX
CX
2017年7月29日
89
C1
Machine code
5
Chapter Four–80x86 Instruction Set
Principles of Microcomputers
3. Memory Addressing Mode
•
Specify an offset address (effective address) using expressions of the form (different parts of
expression are optional):
– [ Base Register + Index Register+ Displacement]
•
•
•
•
1) Base Register---BX, BP
2) Index Register---SI, DI
3) Displacement ---constant value
Example: 1) add ax,[20h]
3) add ax,[bx+20h]
5) add ax, [bx+si+20h]
2017年7月29日
2) add ax,[bx]
4) add ax, [bx+si]
6
Chapter Four–80x86 Instruction Set
Principles of Microcomputers
3. Memory Addressing Mode
⑴ Direct Addressing Mode
Exp: MOV AL, [1064H]
Machine code:A06410H
• The offset address of the operand is provided in the
instruction directly;
• The physical address can be calculated using the
content of DS and the offset :
PA = (DS)*10H+Offset
2017年7月29日
7
Chapter Four–80x86 Instruction Set
Principles of Microcomputers
⑴ Direct Addressing Mode
Example:
MOV AL, [1064h]
Machine code: A06410H
;Assume (DS)=2000H
A0
(DS)*10H=20000H
+
1064H
21064H
AL
45
64
10
20000H
…
21064H
2017年7月29日
Code
Segment
Data
Segment
45
8
Chapter Four–80x86 Instruction Set
Principles of Microcomputers
3. Memory Addressing
Mode
⑵ Register Indirect Addressing Mode
• The address of memory location is in a register
(SI,DI,or BX only)
• The physical address is calculated using the content of DS
and the register(SI,DI,BX)
PA = (DS)*10H+(SI)/(DI)/(BX)
2017年7月29日
9
Principles of Microcomputers
Chapter Four–80x86 Instruction Set
⑵ Register Indirect Addressing Mode
ASSUME: (DS)=3000H, (SI)=2000H, (BX)=1000H
MOV AX, [SI]
(DS)*10H=30000H
+ (SI)= 2000H
MOV [BX], AL
M
(DS)*10h= 30000H
+ (BX)= 1000H
50
32000H
2017年7月29日
AL
50
40
64H
31000H
…
30000H
…
40
30000H
…
AX
31000H
…
32000H
M
64H
10
Principles of Microcomputers
Chapter Four–80x86 Instruction Set
⑶ Register Relative Addressing
(BX)
(BP)
EA= (DI) +
(SI)
Displacement
For physical address calculation:
DS is used for BX,DI,SI;
SS is used for BP
PA=(DS)*10H+(BX)/(DI)/(SI)+Disp
OR
PA=(SS)*10H+(BP)+Disp
2017年7月29日
11
Chapter Four–80x86 Instruction Set
Principles of Microcomputers
⑶ Register Relative Addressing
MOV CL, [BX+1064H] ;assume: (DS)=2000h, (bx)=1000h
;Machine Code: 8A8F6410
PA=(ds)*10h+(bx)+10
64h
(DS)*10h= 20000H
(BX)=
1000H
+
1064H
22064H
8A
Code
Segment
8F
64
10
20000H
…
CL
45
Data
Segment
21000H
…
22064H
2017年7月29日
45
12
Principles of Microcomputers
Chapter Four–80x86 Instruction Set
⑷ Based Indexed Addressing
(BX)
EA= (BP) +
(DI)
(SI)
• Base register(bx or bp) determines which
segment(data or stack) the operand is stored;
• if using BX, the operand is defaultly located
in Data segment,then:
PA=(DS)*10H+(BX)+(DI)/(SI)
• if using BP, the operand is defaultly located
in stack segment,then:
PA=(SS)*10H+(BP)+(DI)/(SI)
2017年7月29日
13
Principles of Microcomputers
Chapter Four–80x86 Instruction Set
⑷ Based Indexed Addressing
Example: MOV AH, [BP][SI];Assume(ss)=4000h,(bp)=2000h,(si)=1200h
PA=(ss)*10h+(bp)+(si)
…
M
(SS)*10H= 40000H
(BP)= 2000H
+ (SI)= 1200H
43200H
40000H
56H
…
AH
56H
2017年7月29日
43200H
14
Principles of Microcomputers
Chapter Four–80x86 Instruction Set
⑸ Based Indexed Relative Addressing
(BX)
EA= (BP) +
(DI)
(SI)
+
Displacement
if using BX, the operand is defaultly located in
Data segment,then:
PA=(DS)*10H+(BX)+(DI)/(SI)+disp
if using BP, the operand is defaultly located in
stack segment,then:
PA=(SS)*10H+(BP)+(DI)/(SI)+disp
2017年7月29日
15
Chapter Four–80x86 Instruction Set
Principles of Microcomputers
⑸ Based Indexed Relative Addressing
MOV [BX+DI+1234H], AH
88
;assume (ds)=4000h,(bx)=0200h,(di)=0010h
;machine code:88A13412h
(DS)*10H=40000H
(BX)= 0200H
(DI)= 0010H
1234H
+
41444H
Code
segment
A1
34
12
40000H
…
Data
segment
AH
…
45
41444H
2017年7月29日
45
16
Principles of Microcomputers
Chapter Four–80x86 Instruction Set
Summary on the 8086 memory addressing modes
operand
1. Direct Addressing
offset address
(effective address)
[disp]
2. Register
[BX]/[SI] /[DI]
Indirect Addressing
3. Register
[SI/DI/BX/BP+disp]
Relative Addressing
4. Based Indexed
Addressing
5. Based Indexed
Relative Addressing
2017年7月29日
[BX+SI/DI]
[BP+SI/DI]
[BX+SI/DI+disp]
[BP+SI/DI+disp]
Default
Segment Register
disp
Overridden
Segment Register
DS
CS ES SS
DS
CS ES SS
(SI)/(DI)/(BX)/(BP)+disp DS
CS ES SS
Content of the R
(BX)+disp
(BP)+disp
(BX)+(SI)/(DI)+disp
(BP)+(SI)/(DI)+disp
DS
SS
CS ES SS
CS ES DS
DS
SS
CS ES SS
CS ES DS
17
Chapter Four–80x86 Instruction Set
Principles of Microcomputers
Examples:
Assume: (BX)=6000H, (BP)=4000H, (SI)=2000H,
(DS)=3000H, (ES)=3500H, (SS)=5000H
Instruction
physical
addressing
mode
1. MOV AX, [0520H]
Direct Addressing
logical
address
address
3000:0520
30520H
3000:6000
36000H
Register Relative Addressing
3000:3000
33000H
4. MOV AX, [BP+6060H] Register Relative Addressing
5000:A060
5A060H
5. MOV AX, ES: [BX+SI+0050H] Based Indexed Relative
Addressing
3500:8050
3D050H
2. MOV AX, [BX]
Register Indirect Addressing
3. MOV AX, [SI+1000H]
2017年7月29日
18