instruction system - transfer instruction

Post on 21-Jan-2016

53 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

Instruction System - Transfer Instruction. 计算机学院 李征 Tel : 13882153765 Email : lizheng@cs.scu.edu.cn 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

TRANSCRIPT

Instruction System -Instruction System -Transfer InstructionTransfer Instruction

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

EmailEmail :: lizheng@cs.scu.edu.cnlizheng@cs.scu.edu.cnOICQ: 1340915OICQ: 1340915

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..

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)

(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

(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

(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

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

Error Usage:Error Usage:

XCHG AL, 03HXCHG AL, 03H

XCHG VAR1, VAR2XCHG VAR1, VAR2

(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

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

OOFF

DDFF

IIFF

TTFF

SSFF

ZZFF

AAFF

PPFF

CCFF

AHAH

FRFR

(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

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

OOFF

DDFF

IIFF

TTFF

SSFF

ZZFF

AAFF

PPFF

CCFF

AHAH

FRFR

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

…… ……

(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

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

旧栈顶旧栈顶 SPSP

(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.

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

新栈顶新栈顶 SPSP

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……

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.

(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?

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

(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)=?

(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)=?

(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 ))

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

DS或DS或ESES

源地址源地址

(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 )) == ??

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.

top related