35
Instruction System - Instruction System - Transfer Instruction Transfer Instruction 计计计计计 计计 计计计计计 计计 Tel Tel 13882153765 13882153765 Email Email [email protected] [email protected] OICQ: 1340915 OICQ: 1340915

Instruction System - Transfer Instruction

  • Upload
    amelie

  • View
    53

  • Download
    0

Embed Size (px)

DESCRIPTION

Instruction System - Transfer Instruction. 计算机学院 李征 Tel : 13882153765 Email : [email protected] OICQ: 1340915. Transfer Instruction. All transfer instructions only move data from one cell to another. ALU is not used in these instructions. - PowerPoint PPT Presentation

Citation preview

Page 1: Instruction System - Transfer Instruction

Instruction System -Instruction System -Transfer InstructionTransfer Instruction

计算机学院 李征计算机学院 李征TelTel :: 1388215376513882153765

EmailEmail :: [email protected]@cs.scu.edu.cnOICQ: 1340915OICQ: 1340915

Page 2: Instruction System - Transfer Instruction

Transfer InstructionTransfer Instruction

All transfer instructions only move data All transfer instructions only move data from one cell to another.from one cell to another.

ALU is not used in these instructions.ALU is not used in these instructions.

So, So, transfer instruction does not affect transfer instruction does not affect flags unless FR is its destinationflags unless FR is its destination..

Page 3: Instruction System - Transfer Instruction

Transfer InstructionTransfer Instruction

(1) MOV(1) MOV(2) XCHG(2) XCHG(3) LAHF(3) LAHF(4) SAHF(4) SAHF(5) PUSH (PUSHF)(5) PUSH (PUSHF)(6) POP (POPF)(6) POP (POPF)(7) LEA(7) LEA(8) LDS (LES)(8) LDS (LES)

Page 4: Instruction System - Transfer Instruction

(1) MOV (Move)(1) MOV (Move)

Example:Example:

mov al, 06hmov al, 06h

mov 0100h[bx], almov 0100h[bx], al

mov ds, axmov ds, ax

Page 5: Instruction System - Transfer Instruction

(1) MOV (Move)(1) MOV (Move)

Error Usage:Error Usage:

mov [bx], [0102h]mov [bx], [0102h]

mov 0020h[si], 03hmov 0020h[si], 03h

mov ds, 1000hmov ds, 1000h

mov ds, esmov ds, es

Page 6: Instruction System - Transfer Instruction

(2) XCHG (Exchange)(2) XCHG (Exchange)

Example: exchange the data in var1 and Example: exchange the data in var1 and var2 cell.var2 cell.

mov al, var1mov al, var1

xchg al, var2xchg al, var2

mov var1, almov var1, al

Page 7: Instruction System - Transfer Instruction

(2) XCHG (Exchange)(2) XCHG (Exchange)

Error Usage:Error Usage:

XCHG AL, 03HXCHG AL, 03H

XCHG VAR1, VAR2XCHG VAR1, VAR2

Page 8: Instruction System - Transfer Instruction

(3) LAHF (Load AH from FR)(3) LAHF (Load AH from FR)

LAHFLAHF

No operation data, but two implied No operation data, but two implied address used.address used.

AH <=AH <= (( FRFR )) 7-07-0

Usage: protect FR temporallyUsage: protect FR temporally

Page 9: Instruction System - Transfer Instruction

(3) LAHF (Load AH from FR)(3) LAHF (Load AH from FR)

OOFF

DDFF

IIFF

TTFF

SSFF

ZZFF

AAFF

PPFF

CCFF

AHAH

FRFR

Page 10: Instruction System - Transfer Instruction

(4) SAHF (Store AH into FR)(4) SAHF (Store AH into FR)

SAHFSAHF

No operation data, but two implied No operation data, but two implied address used.address used.

FR7-0 <= (AH)FR7-0 <= (AH)

Usage: Restore previous FRUsage: Restore previous FR

Page 11: Instruction System - Transfer Instruction

(4) SAHF (Store AH into FR)(4) SAHF (Store AH into FR)

OOFF

DDFF

IIFF

TTFF

SSFF

ZZFF

AAFF

PPFF

CCFF

AHAH

FRFR

Page 12: Instruction System - Transfer Instruction

Example for LAHF and SAHFExample for LAHF and SAHF

CMP BYTE PTR [BX], 02HCMP BYTE PTR [BX], 02H

LAHF ; Protect FRLAHF ; Protect FR

INC BXINC BX

SAHF ; Restore FRSAHF ; Restore FR

JA L1 ; FR is from CMP, not INCJA L1 ; FR is from CMP, not INC

JMP L2JMP L2

…… ……

Page 13: Instruction System - Transfer Instruction

(5) PUSH (PUSHF)(5) PUSH (PUSHF)

PUSH SRCPUSH SRC

SP <=SP <= (( SPSP )) -2-2

(SP) <= (SRC)(SP) <= (SRC)

PUSHF : Send FR to stack topPUSHF : Send FR to stack top

Page 14: Instruction System - Transfer Instruction

源地址源地址 新栈顶新栈顶

旧栈顶旧栈顶 SPSP

Page 15: Instruction System - Transfer Instruction

(6) POP (POPF)(6) POP (POPF)

POP DESTPOP DEST

DEST <= DEST <= (( SPSP ))SP <= SP <= (( SPSP )) +2+2

POPF: Restore FR from stack top.POPF: Restore FR from stack top.

Page 16: Instruction System - Transfer Instruction

目的地址目的地址 旧栈顶旧栈顶

新栈顶新栈顶 SPSP

Page 17: Instruction System - Transfer Instruction

Example for Stack OperationExample for Stack Operation

……STACK1 SEGMENT STACK1 SEGMENT    STACKSTACK

DBDB 40H40H DUPDUP (( 00 ) ;堆栈空间为) ;堆栈空间为 3232 个字个字STACK1STACK1 ENDS ENDS……PUSH AXPUSH AX ;假定(;假定( AXAX )) =0E43DH=0E43DHPUSH DSPUSH DS ;假定(;假定( DSDS )) =3638H=3638HPUSH DATAWPUSH DATAW ;假定(;假定( DATAWDATAW )) =0D245H=0D245HPUSHFPUSHF ;假定(;假定( FRFR )) =0C243H=0C243HPOPFPOPFPOP DATAWPOP DATAWPOP DSPOP DSPOPPOP    AXAX……

Page 18: Instruction System - Transfer Instruction
Page 19: Instruction System - Transfer Instruction
Page 20: Instruction System - Transfer Instruction
Page 21: Instruction System - Transfer Instruction
Page 22: Instruction System - Transfer Instruction
Page 23: Instruction System - Transfer Instruction
Page 24: Instruction System - Transfer Instruction
Page 25: Instruction System - Transfer Instruction
Page 26: Instruction System - Transfer Instruction
Page 27: Instruction System - Transfer Instruction

Note for all stack operationNote for all stack operation

Important:Important:

The pop order is inverse to the push order.The pop order is inverse to the push order.

Page 28: Instruction System - Transfer Instruction

(7) LEA (Load Effective (7) LEA (Load Effective Address)Address)

LEA DESTLEA DEST ,, SRCSRC

DEST <= EA of SRCDEST <= EA of SRC

SRC can only be memory cell. Why?SRC can only be memory cell. Why?

DEST can only be 16-bit register. Why?DEST can only be 16-bit register. Why?

Page 29: Instruction System - Transfer Instruction

16位目16位目的地址的地址 EAEA

Page 30: Instruction System - Transfer Instruction

(7) LEA (Load Effective (7) LEA (Load Effective Address)Address)

Example:Example:

MOV BXMOV BX ,, 0024H0024HLEA BXLEA BX ,, [BX][BX]

Data stored inData stored in (( DSDS ):): 0024H is 0056H.0024H is 0056H.

So, after instruction execution, (BX)=?So, after instruction execution, (BX)=?

Page 31: Instruction System - Transfer Instruction

(7) LEA (Load Effective (7) LEA (Load Effective Address)Address)

Example:Example:

LEA SILEA SI ,, DSDS :: [0056H][0056H]

Data stored inData stored in (( DSDS ):): 0056H0056H is is 0048H.0048H.

So, after execution, (SI)=?So, after execution, (SI)=?

Page 32: Instruction System - Transfer Instruction

(8) LDS (LES)(8) LDS (LES)

LDS DESTLDS DEST , , SRCSRCLES DESTLES DEST , , SRCSRC

LDSLDS :: DEST <=DEST <= (( SRCSRC )) DS <=DS <= (( SRC+2SRC+2 ))

LESLES :: DEST <=DEST <= (( SRCSRC )) ES <=ES <= (( SRC+2SRC+2 ))

Page 33: Instruction System - Transfer Instruction

16位通16位通用寄存器用寄存器

DS或DS或ESES

源地址源地址

Page 34: Instruction System - Transfer Instruction

(8) LDS (LES)(8) LDS (LES)

Example:Example:MOV BXMOV BX ,, 0024H0024HLDS BXLDS BX ,, [BX][BX]MOV AXMOV AX ,, [BX][BX]

(( DSDS )) =02F8H=02F8H(( 02F8H02F8H :: 0024H0024H )) = 0056H= 0056H(( 02F8H02F8H :: 0026H0026H )) = 06A4H= 06A4H(( 02F8H02F8H :: 0056H0056H )) = 00B2H= 00B2H(( 06A4H06A4H :: 0056H0056H )) = 0008H= 0008H

After execution, After execution, (( DSDS )) == ?(?( BXBX )) == ? (? ( AXAX )) == ??

Page 35: Instruction System - Transfer Instruction

Difference between LEA and LDSDifference between LEA and LDS

LEA calculate the EA of SRC.LEA calculate the EA of SRC.

LDS explain the SRC as the EA and LDS explain the SRC as the EA and segment base value.segment base value.