Upload
melvin-gordon
View
24
Download
1
Embed Size (px)
DESCRIPTION
Move and Exchange Instructions. Module M16.1 Section 10.2. MOV Move Instruction. Can move immediate data to a register or memory (but not a segment register). Can move data from a register to a register. Can move data from a register to memory. Can move data from memory to a register. - PowerPoint PPT Presentation
Citation preview
Introduction to Computer Engineering by Richard E. Haskell
Move and ExchangeInstructions
Module M16.1
Section 10.2
Introduction to Computer Engineering by Richard E. Haskell
MOV Move Instruction
• Can move immediate data to a register or memory (but not a segment register).
• Can move data from a register to a register.
• Can move data from a register to memory.
• Can move data from memory to a register.
• Can NOT use MOV instruction to move data directly from one memory location to another. But can use MOVS instruction.
Introduction to Computer Engineering by Richard E. Haskell
Table 10.1MOV immediate data instructions
for general registers.Opcode Instruction Operation
B0 MOV AL,imm8 imm8-->ALB1 MOV CL,imm8 imm8-->CLB2 MOV DL,imm8 imm8-->DLB3 MOV BL,imm8 imm8-->BLB4 MOV AH,imm8 imm8-->AHB5 MOV CH,imm8 imm8-->CHB6 MOV DH,imm8 imm8-->DHB7 MOV BH,imm8 imm8-->BHB8 MOV AX,imm16 imm16-->AXB9 MOV CX,imm16 imm16-->CXBA MOV DX,imm16 imm16-->DXBB MOV BX,imm16 imm16-->BX
imm8 = 8-bit data byteimm16 = 16-bit immediate data (low byte,high byte)
Introduction to Computer Engineering by Richard E. Haskell
Some MOV Instructions
Machine Assembly LanguageCode Instruction Operation 88 PB MOV b r/m,reg move byte from reg to r/m89 PB MOV w r/m,reg move word from reg to r/m8A PB MOV b reg,r/m move byte from r/m to reg8B PB MOV b reg,r/m move byte from r/m to reg
Introduction to Computer Engineering by Richard E. Haskell
Table A2.aOpcode Map
OR b AL,imm
OR w AX,imm
SBB b AL,imm
SBB w AX,imm
SUB b AL,imm
SUB w AX,imm
CMP b AL,imm
CMP w AX,imm
8 9 A B C D E F
0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F
MOV AX,imm
MOV CX,imm
MOV DX,imm
MOV BX,imm
MOV SP,imm
MOV BP,imm
MOV SI,imm
MOV DI,imm
TEST b AL,imm
TEST w AL,imm
OR br/m,reg
r/m,reg
r/m,reg
r/m,reg
r/m,reg
r/m,reg
r/m,reg
r/m,reg
OR w OR b OR wreg,r/m
reg,r/m
reg,r/m
reg,r/m
reg,r/m
reg,r/m
reg,r/m
reg,r/m
SBB b SBB w SBB b SBB w
SUB b SUB w SUB b SUB w
CMP b CMP w CMP b CMP w
PUSH CS
PUSH DS
POP DS
SEGMENT CS
SEGMENT DS
DAS
AAS
DEC AX
DEC CX
DEC DX
DEC BX
DEC SP
DEC BP
DEC SI
DEC DI
POP AX
POP CX
POP DX
POP BX
POP SP
POP BP
POP SI
POP DI
JS JNS JP/JPE JNP/JPO JL/JNGE JNL/JGE JLE/JNG JNLE/JG
MOV b r/m,reg
MOV W r/m,reg
MOV b reg,r/m
MOV W reg,r/m
MOV r/m,seg
LEA reg,r/m
MOV seg,r/m
LAHFSAHFPOPFPUSHF WAITCALL inter
CBW CWD
STOS b STOS w LODS b LODS w SCAS b SCAS w
RET inter+
RET inter
INT type
INT INTO IRET
ESC 0
ESC 1
ESC 2
ESC 3
ESC 4
ESC 5
ESC 6
ESC 7
CALL intra
JMP intra
JMP inter
JMP short
IN b AL,DX
IN w AX,DX
OUT b DX,AL
OUT w DX,AX
CLC STC CLI STI CLD STD * *
POP r/m
mov bx,ax
8B D8
Introduction to Computer Engineering by Richard E. Haskell
Table A.3Postbyte mod,r/m Fields
mod = 11
r/m byte word mod = 00 mod = 01 mod = 10000 AL AX BX + SI BX + SI + disp8 BX + SI + disp16001 CL CX BX + DI BX + DI + disp8 BX + DI + disp16010 DL DX BP + SI BP + SI + disp8 BP + SI + disp16011 BL BX BP + DI BP + DI + disp8 BP + DI + disp16100 AH SP SI SI + disp8 SI + disp16101 CH BP DI DI + disp8 DI + disp16110 DH SI Direct BP + disp8 BP + disp16111 BH DI BX BX + disp8 BX + disp16
Table A.4
Postbyte reg Field reg byte (b) word (w)000 AL AX001 CL CX010 DL DX011 BL BX100 AH SP101 CH BP110 DH SI111 BH DI
Postbyte
mod reg r/m
mov bx,ax8B mov w reg,r/m
reg = bx = 011
0 1 1
mod = 11r/m = ax = 0 0 0
1 1 0 0 0 = D8
mov bx,ax8B D8
Introduction to Computer Engineering by Richard E. Haskell
Table A2.aOpcode Map
OR b AL,imm
OR w AX,imm
SBB b AL,imm
SBB w AX,imm
SUB b AL,imm
SUB w AX,imm
CMP b AL,imm
CMP w AX,imm
8 9 A B C D E F
0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F
MOV AX,imm
MOV CX,imm
MOV DX,imm
MOV BX,imm
MOV SP,imm
MOV BP,imm
MOV SI,imm
MOV DI,imm
TEST b AL,imm
TEST w AL,imm
OR br/m,reg
r/m,reg
r/m,reg
r/m,reg
r/m,reg
r/m,reg
r/m,reg
r/m,reg
OR w OR b OR wreg,r/m
reg,r/m
reg,r/m
reg,r/m
reg,r/m
reg,r/m
reg,r/m
reg,r/m
SBB b SBB w SBB b SBB w
SUB b SUB w SUB b SUB w
CMP b CMP w CMP b CMP w
PUSH CS
PUSH DS
POP DS
SEGMENT CS
SEGMENT DS
DAS
AAS
DEC AX
DEC CX
DEC DX
DEC BX
DEC SP
DEC BP
DEC SI
DEC DI
POP AX
POP CX
POP DX
POP BX
POP SP
POP BP
POP SI
POP DI
JS JNS JP/JPE JNP/JPO JL/JNGE JNL/JGE JLE/JNG JNLE/JG
MOV b r/m,reg
MOV W r/m,reg
MOV b reg,r/m
MOV W reg,r/m
MOV r/m,seg
LEA reg,r/m
MOV seg,r/m
LAHFSAHFPOPFPUSHF WAITCALL inter
CBW CWD
STOS b STOS w LODS b LODS w SCAS b SCAS w
RET inter+
RET inter
INT type
INT INTO IRET
ESC 0
ESC 1
ESC 2
ESC 3
ESC 4
ESC 5
ESC 6
ESC 7
CALL intra
JMP intra
JMP inter
JMP short
IN b AL,DX
IN w AX,DX
OUT b DX,AL
OUT w DX,AX
CLC STC CLI STI CLD STD * *
POP r/m
mov bx,ax
8B D8
mov bx,ax
89 C3
Introduction to Computer Engineering by Richard E. Haskell
Table A.3Postbyte mod,r/m Fields
mod = 11
r/m byte word mod = 00 mod = 01 mod = 10000 AL AX BX + SI BX + SI + disp8 BX + SI + disp16001 CL CX BX + DI BX + DI + disp8 BX + DI + disp16010 DL DX BP + SI BP + SI + disp8 BP + SI + disp16011 BL BX BP + DI BP + DI + disp8 BP + DI + disp16100 AH SP SI SI + disp8 SI + disp16101 CH BP DI DI + disp8 DI + disp16110 DH SI Direct BP + disp8 BP + disp16111 BH DI BX BX + disp8 BX + disp16
Table A.4
Postbyte reg Field reg byte (b) word (w)000 AL AX001 CL CX010 DL DX011 BL BX100 AH SP101 CH BP110 DH SI111 BH DI
Postbyte
mod reg r/m
mov bx,ax89 mov w r/m, reg
reg = ax = 000
0 0 0
mod = 11r/m = bx = 0 11
1 1 0 1 1 = C3
mov bx,ax89 C3
Introduction to Computer Engineering by Richard E. Haskell
Table A.3Postbyte mod,r/m Fields
mod = 11
r/m byte word mod = 00 mod = 01 mod = 10000 AL AX BX + SI BX + SI + disp8 BX + SI + disp16001 CL CX BX + DI BX + DI + disp8 BX + DI + disp16010 DL DX BP + SI BP + SI + disp8 BP + SI + disp16011 BL BX BP + DI BP + DI + disp8 BP + DI + disp16100 AH SP SI SI + disp8 SI + disp16101 CH BP DI DI + disp8 DI + disp16110 DH SI Direct BP + disp8 BP + disp16111 BH DI BX BX + disp8 BX + disp16
Table A.4
Postbyte reg Field reg byte (b) word (w)000 AL AX001 CL CX010 DL DX011 BL BX100 AH SP101 CH BP110 DH SI111 BH DI
Postbyte
mod reg r/m
mov bl,[si]8A mov b reg, r/m
reg = bl = 011
0 1 1
mod = 00r/m = si = 100
0 0 1 0 0 = 1C
mov bl,[si]8A 1C
Move byte pointed to by si into BL
Introduction to Computer Engineering by Richard E. Haskell
XCHG Exchange Instruction
• Can exchange AX with a 16-bit register.
• Can exchange an 8-bit register with another 8-bit register or an 8-bit byte in memory.
• Can exchange a 16-bit register with another 16-bit register or a 16-bit word in memory.
Introduction to Computer Engineering by Richard E. Haskell
XCHG Instruction
Machine Assembly LanguageCode Instruction Operation
9X XCHG reg16 Exchange AX and reg1686 PB XCHG b r/m,reg Exchange r/m and reg bytes87 PB XCHG w r/m,reg Exchange r/m and reg words
X reg16 X reg16 000 AX 100 SP 001 CX 101 BP 010 DX 110 SI 011 BX 111 DI
Introduction to Computer Engineering by Richard E. Haskell
ADD b AL,imm
ADD w AX,imm
ADC b AL,imm
ADC w AX,imm
AND b AL,imm
AND w AX,imm
XOR b AL,imm
XOR w AX,imm
0 1 2 3 4 5 6 7
0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F
* * * *
MOV AL,imm
MOV CL,imm
MOV DL,imm
MOV BL,imm
MOV AH,imm
MOV CH,imm
MOV DH,imm
MOV BH,imm
MOV b r/m,imm
MOV w r/m,imm
* *
ADD b r/m,reg
ADD w ADD b ADD w
r/m,reg
r/m,reg
r/m,reg
r/m,reg
r/m,reg
r/m,reg
r/m,reg
reg,r/m
reg,r/m
reg,r/m
reg,r/m
reg,r/m
reg,r/m
reg,r/m
reg,r/m
ADC b ADC w ADC b ADC w
AND b AND w AND b AND w
XOR b XOR w XOR b XOR w
INC INC INC INC INC INC INC INC AX CX DX BX SP BP SI DI
PUSH PUSH PUSH PUSH PUSH PUSH PUSH PUSHAX CX DX BX SP BP SI DI
JO JNO JB/JNAE JC
JNB/JAE JNC
JE/JZ JNE/JNZ JBE/JNA JNBE/JA
TEST b TEST w XCHG b XCHG wr/m,reg r/m,reg r/m,reg r/m,reg
NOP XCHG XCHG XCHG XCHG XCHG XCHG XCHGCX,AX DX,AX BX,AX SP,AX BP,AX SI,AX DI,AX
MOV b AL,mem
MOV w AX,mem
MOV b mem,AL
MOV w mem,AX
MOVS b MOVS w CMPS b CMPS w
RET intra+
RET intra
LES LDS reg.r/m reg.r/m
* * * * AAM AAD XLAT
LOOPNZ/ LOOPNE
LOOPZ/ LOOPE
LOOP JCXZ IN b AL,port
OUT b port,AL
IN w AX,port
OUT w port,AX
LOCK REP/REPNE REPNZ
REPE/ REPZ
HLT CMC
PUSH ES
POP ES
PUSH SS
POP SS
SEGMENT ES
SEGMENT SS
DAA
AAA
Table A2.aOpcode Map
Introduction to Computer Engineering by Richard E. Haskell
Table A.3Postbyte mod,r/m Fields
mod = 11
r/m byte word mod = 00 mod = 01 mod = 10000 AL AX BX + SI BX + SI + disp8 BX + SI + disp16001 CL CX BX + DI BX + DI + disp8 BX + DI + disp16010 DL DX BP + SI BP + SI + disp8 BP + SI + disp16011 BL BX BP + DI BP + DI + disp8 BP + DI + disp16100 AH SP SI SI + disp8 SI + disp16101 CH BP DI DI + disp8 DI + disp16110 DH SI Direct BP + disp8 BP + disp16111 BH DI BX BX + disp8 BX + disp16
Table A.4
Postbyte reg Field reg byte (b) word (w)000 AL AX001 CL CX010 DL DX011 BL BX100 AH SP101 CH BP110 DH SI111 BH DI
Postbyte
mod reg r/m
xchg bh,al86 xchg b r/m,reg
reg = al = 000
0 0 0
mod = 11r/m = bh = 111
1 1 1 1 1 = C7
xchg bh,al86 C7