Chapter Four–80x86 Instruction Set Principles of Microcomputers 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 1 Chapter four 80x86 Instruction Set ( 2 ) 8086 Addressing Modes
Chapter Four–80x86 Instruction Set Principles of Microcomputers 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 2 What is the Addressing Mode ? add dest, source ; dest +source→dest add ax,bx ; ax +bx→ax The addressing mode means where and how the CPU gets the operands when the instruction is executed.
Chapter Four–80x86 Instruction Set Principles of Microcomputers 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 3 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)
Chapter Four–80x86 Instruction Set Principles of Microcomputers 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 4 Exp : MOV AL, 80H Machine code:B080H AL B0H 80H Instruction Queue MACHINE CODE B8 12H Instruction Queue AL MACHINE CODE AH 34H H Immediate Addressing Mode MOV AX, 1234H Machine code:B83412H
Chapter Four–80x86 Instruction Set Principles of Microcomputers 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 5 Exp : MOV AX, CX 89 C1 Memory AX CX Machine code 2. Register Addressing Mode
Chapter Four–80x86 Instruction Set Principles of Microcomputers 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 6 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] 2) add ax,[bx] 3) add ax,[bx+20h] 4) add ax, [bx+si] 5) add ax, [bx+si+20h] 3. Memory Addressing Mode
Chapter Four–80x86 Instruction Set Principles of Microcomputers 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 7 ⑴ 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 3. Memory Addressing Mode
Chapter Four–80x86 Instruction Set Principles of Microcomputers 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 8 ⑴ Direct Addressing Mode Example: MOV AL, [1064h] ;Assume (DS)=2000H Machine code: A06410H 21064H ( DS)*10H=20000H 20000H 21064H AL A … Code Segment Data Segment H
Chapter Four–80x86 Instruction Set Principles of Microcomputers 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 9 ⑵ 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) 3. Memory Addressing Mode
Chapter Four–80x86 Instruction Set Principles of Microcomputers 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 … … M AX ⑵ Register Indirect Addressing Mode ASSUME: (DS)=3000H, (SI)=2000H, (BX)=1000H 30000H (DS)*10H=30000H (SI)= 2000H H … … 64H M AL 30000H (DS)*10h= 30000H (BX)= 1000H H 64H MOV [BX], AL MOV AX, [SI]
Chapter Four–80x86 Instruction Set Principles of Microcomputers 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 11 ⑶ Register Relative Addressing EA= (BX) (BP) (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
Chapter Four–80x86 Instruction Set Principles of Microcomputers 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 12 ⑶ Register Relative Addressing MOV CL, [BX+1064H] ;assume: (DS)=2000h, (bx)=1000h ;Machine Code: 8A8F H 8F … Code Segment Data Segment 8A … CL H (BX)= 1000H (DS)*10h= 20000H 20000H H PA=(ds)*10h+(bx)+10 64h
Chapter Four–80x86 Instruction Set Principles of Microcomputers 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 13 ⑷ Based Indexed Addressing EA= (BX) (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)
Chapter Four–80x86 Instruction Set Principles of Microcomputers 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 14 ⑷ Based Indexed Addressing Example: MOV AH, [BP][SI]; Assume(ss)=4000h,(bp)=2000h,(si)=1200h 56H … … M AH 40000H (SS)*10H= 40000H (BP)= 2000H H (SI)= 1200H 56H PA=(ss)*10h+(bp)+(si)
Chapter Four–80x86 Instruction Set Principles of Microcomputers 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 15 ⑸ Based Indexed Relative Addressing EA= (BX) (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
Chapter Four–80x86 Instruction Set Principles of Microcomputers 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 16 ⑸ Based Indexed Relative Addressing MOV [BX+DI+1234H], AH ;assume (ds)=4000h,(bx)=0200h,(di)=0010h ;machine code:88A13412h A … Code segment Data segment 88 … 45 AH 40000H (DS)*10H=40000H (BX)= 0200H + (DI)= 0010H 1234H H
Chapter Four–80x86 Instruction Set Principles of Microcomputers 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 17 Summary on the 8086 memory addressing modes operand offset address Default Overridden ( effective address ) Segment Register Segment Register 3. Register [SI/DI/BX/BP+disp] (SI)/(DI)/(BX)/(BP)+disp DS CS ES SS Relative Addressing 2. Register [BX]/[SI] /[DI] Content of the R DS CS ES SS Indirect Addressing 1. Direct Addressing [disp] disp DS CS ES SS 4. Based Indexed [BX+SI/DI] (BX)+disp DS CS ES SS Addressing [BP+SI/DI] (BP)+disp SS CS ES DS 5. Based Indexed [BX+SI/DI+disp] (BX)+(SI)/(DI)+disp DS CS ES SS Relative Addressing [BP+SI/DI+disp] (BP)+(SI)/(DI)+disp SS CS ES DS
Chapter Four–80x86 Instruction Set Principles of Microcomputers 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 2015年5月17日 18 Examples: Assume: (BX)=6000H, (BP)=4000H, (SI)=2000H, (DS)=3000H, (ES)=3500H, (SS)=5000H 3000 : H Direct Addressing 2. MOV AX, [BX] 1. MOV AX, [0520H] 5. MOV AX, ES: [BX+SI+0050H] 4. MOV AX, [BP+6060H] Register Indirect Addressing 3000 : H Register Relative Addressing 3. MOV AX, [SI+1000H] 3000 : H 5000 : A060 5A060H 3500 : D050H Based Indexed Relative Addressing Instruction addressing logical physical mode address address mode address address