```Move and Exchange
Instructions
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.1
MOV immediate data instructions
for general registers.
Opcode
Instruction
Operation
B0
MOV AL,imm8
imm8-->AL
B1
MOV CL,imm8
imm8-->CL
B2
MOV DL,imm8
imm8-->DL
B3
MOV BL,imm8
imm8-->BL
B4
MOV AH,imm8
imm8-->AH
B5
MOV CH,imm8
imm8-->CH
B6
MOV DH,imm8
imm8-->DH
B7
MOV BH,imm8
imm8-->BH
B8
MOV AX,imm16
imm16-->AX
B9
MOV CX,imm16
imm16-->CX
BA
MOV DX,imm16
imm16-->DX
BB
MOV BX,imm16
imm16-->BX
imm8 = 8-bit data byte
imm16 = 16-bit immediate data (low byte,high byte)
Introduction to Computer Engineering by Richard E. Haskell
Some MOV Instructions
Machine
Code
88 PB
89 PB
8A PB
8B PB
Assembly Language
Instruction
MOV b r/m,reg
MOV w r/m,reg
MOV b reg,r/m
MOV b reg,r/m
Operation
move byte from reg to r/m
move word from reg to r/m
move byte from r/m to reg
move byte from r/m to reg
Introduction to Computer Engineering by Richard E. Haskell
8
Table A2.a
Opcode Map
mov bx,ax
9
A
B
C
D
E
F
0
OR b
r/m,reg
OR w
OR b
OR b
OR w
r/m,reg reg,r/m reg,r/m AL,imm
OR w
AX,imm
PUSH
CS
1
SBB b
SBB w
SBB b
SBB b
SBB w
r/m,reg r/m,reg reg,r/m reg,r/m AL,imm
SBB w
AX,imm
PUSH
DS
POP
DS
2
SUB w
SUB b
SUB b
SUB b
SUB w
r/m,reg r/m,reg reg,r/m reg,r/m AL,imm
SUB w
AX,imm
SEGMENT
CS
DAS
3
CMP b
CMP b
CMP w
CMP b
CMP w
r/m,reg r/m,reg reg,r/m reg,r/m AL,imm
CMP w
AX,imm
SEGMENT
DS
AAS
4
DEC
AX
DEC
CX
DEC
DX
DEC
BX
DEC
SP
DEC
BP
DEC
SI
DEC
DI
5
POP
AX
POP
CX
POP
DX
POP
BX
POP
SP
POP
BP
POP
SI
POP
DI
JS
JNS
JP/JPE
6
8B D8
7
8
9
JNP/JPO JL/JNGE
JNL/JGE JLE/JNG JNLE/JG
MOV b
MOV
LEA
MOV
MOV W
MOV b
MOV W
r/m,reg r/m,reg reg,r/m reg,r/m r/m,seg reg,r/m seg,r/m
CBW
CWD
CALL
inter
WAIT
PUSHF
POP
r/m
POPF
SAHF
LAHF
A
TEST b
AL,imm
TEST w
AL,imm
STOS b
STOS w
LODS b
LODS w
SCAS b
SCAS w
B
MOV
AX,imm
MOV
CX,imm
MOV
DX,imm
MOV
BX,imm
MOV
SP,imm
MOV
BP,imm
MOV
SI,imm
MOV
DI,imm
RET
inter+
RET
inter
INT
type
INT
INTO
IRET
ESC
3
ESC
4
ESC
5
ESC
6
OUT b
DX,AL
C
D
ESC
0
ESC
1
ESC
2
E
CALL
intra
JMP
intra
JMP
inter
JMP
short
IN b
AL,DX
IN w
AX,DX
F
CLC
CLI
STI
CLD
STD
STC
Introduction to Computer Engineering by Richard E. Haskell
*
ESC
7
OUT w
DX,AX
*
Postbyte
Table A.3
Table A.4
Postbyte mod,r/m Fields
Postbyte reg Field
mod = 11
r/m
000
001
010
011
100
101
110
111
byte
AL
CL
DL
BL
AH
CH
DH
BH
word
AX
CX
DX
BX
SP
BP
SI
DI
mod = 00
BX + SI
BX + DI
BP + SI
BP + DI
SI
DI
Direct
BX
1
1
mod
8B
mov bx,ax
mov w reg,r/m
mod = 01
BX + SI + disp8
BX + DI + disp8
BP + SI + disp8
BP + DI + disp8
SI + disp8
DI + disp8
BP + disp8
BX + disp8
0
1
reg
mod = 10
BX + SI + disp16
BX + DI + disp16
BP + SI + disp16
BP + DI + disp16
SI + disp16
DI + disp16
BP + disp16
BX + disp16
1
0
0
reg
000
001
010
011
100
101
110
111
0
byte (b)
AL
CL
DL
BL
AH
CH
DH
BH
word (w)
AX
CX
DX
BX
SP
BP
SI
DI
= D8
r/m
reg = bx = 011
mod = 11
r/m = ax = 0 0 0
Introduction to Computer Engineering by Richard E. Haskell
mov bx,ax
8B D8
8
Table A2.a
Opcode Map
mov bx,ax
9
A
B
C
D
E
F
0
OR b
r/m,reg
OR w
OR b
OR b
OR w
r/m,reg reg,r/m reg,r/m AL,imm
OR w
AX,imm
PUSH
CS
1
SBB b
SBB w
SBB b
SBB b
SBB w
r/m,reg r/m,reg reg,r/m reg,r/m AL,imm
SBB w
AX,imm
PUSH
DS
POP
DS
2
SUB w
SUB b
SUB b
SUB b
SUB w
r/m,reg r/m,reg reg,r/m reg,r/m AL,imm
SUB w
AX,imm
SEGMENT
CS
DAS
3
CMP b
CMP b
CMP w
CMP b
CMP w
r/m,reg r/m,reg reg,r/m reg,r/m AL,imm
CMP w
AX,imm
SEGMENT
DS
AAS
4
DEC
AX
DEC
CX
DEC
DX
DEC
BX
DEC
SP
DEC
BP
DEC
SI
DEC
DI
5
POP
AX
POP
CX
POP
DX
POP
BX
POP
SP
POP
BP
POP
SI
POP
DI
JS
JNS
JP/JPE
6
8B D8
7
8
mov bx,ax
89 C3
9
JNP/JPO JL/JNGE
JNL/JGE JLE/JNG JNLE/JG
MOV b
MOV
LEA
MOV
MOV W
MOV b
MOV W
r/m,reg r/m,reg reg,r/m reg,r/m r/m,seg reg,r/m seg,r/m
CBW
CWD
CALL
inter
WAIT
PUSHF
POP
r/m
POPF
SAHF
LAHF
A
TEST b
AL,imm
TEST w
AL,imm
STOS b
STOS w
LODS b
LODS w
SCAS b
SCAS w
B
MOV
AX,imm
MOV
CX,imm
MOV
DX,imm
MOV
BX,imm
MOV
SP,imm
MOV
BP,imm
MOV
SI,imm
MOV
DI,imm
RET
inter+
RET
inter
INT
type
INT
INTO
IRET
ESC
3
ESC
4
ESC
5
ESC
6
OUT b
DX,AL
C
D
ESC
0
ESC
1
ESC
2
E
CALL
intra
JMP
intra
JMP
inter
JMP
short
IN b
AL,DX
IN w
AX,DX
F
CLC
CLI
STI
CLD
STD
STC
Introduction to Computer Engineering by Richard E. Haskell
*
ESC
7
OUT w
DX,AX
*
Postbyte
Table A.3
Table A.4
Postbyte mod,r/m Fields
Postbyte reg Field
mod = 11
r/m
000
001
010
011
100
101
110
111
byte
AL
CL
DL
BL
AH
CH
DH
BH
word
AX
CX
DX
BX
SP
BP
SI
DI
mod = 00
BX + SI
BX + DI
BP + SI
BP + DI
SI
DI
Direct
BX
1
1
mod
mov bx,ax
89 mov w r/m, reg
mod = 01
BX + SI + disp8
BX + DI + disp8
BP + SI + disp8
BP + DI + disp8
SI + disp8
DI + disp8
BP + disp8
BX + disp8
0
0
reg
reg
000
001
010
011
100
101
110
111
mod = 10
BX + SI + disp16
BX + DI + disp16
BP + SI + disp16
BP + DI + disp16
SI + disp16
DI + disp16
BP + disp16
BX + disp16
0
0 1
1
byte (b)
AL
CL
DL
BL
AH
CH
DH
BH
word (w)
AX
CX
DX
BX
SP
BP
SI
DI
= C3
r/m
reg = ax = 000
mod = 11
r/m = bx = 0 11
Introduction to Computer Engineering by Richard E. Haskell
mov bx,ax
89 C3
Postbyte
Table A.3
Table A.4
Postbyte mod,r/m Fields
Postbyte reg Field
mod = 11
r/m
000
001
010
011
100
101
110
111
byte
AL
CL
DL
BL
AH
CH
DH
BH
word
AX
CX
DX
BX
SP
BP
SI
DI
mod = 00
BX + SI
BX + DI
BP + SI
BP + DI
SI
DI
Direct
BX
0
0
mod
mod = 01
BX + SI + disp8
BX + DI + disp8
BP + SI + disp8
BP + DI + disp8
SI + disp8
DI + disp8
BP + disp8
BX + disp8
0
1
mod = 10
BX + SI + disp16
BX + DI + disp16
BP + SI + disp16
BP + DI + disp16
SI + disp16
DI + disp16
BP + disp16
BX + disp16
1
1 0 0
reg
Move byte pointed to by si into BL
mov bl,[si]
8A mov b reg, r/m
reg
000
001
010
011
100
101
110
111
reg = bl = 011
mod = 00
r/m = si = 100
byte (b)
AL
CL
DL
BL
AH
CH
DH
BH
word (w)
AX
CX
DX
BX
SP
BP
SI
DI
= 1C
r/m
mov bl,[si]
8A 1C
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
Code
9X
86 PB
87 PB
Assembly Language
Instruction
XCHG reg16
XCHG b r/m,reg
XCHG w r/m,reg
X
000
001
010
011
reg16
AX
CX
DX
BX
Operation
Exchange AX and reg16
Exchange r/m and reg bytes
Exchange r/m and reg words
X
100
101
110
111
reg16
SP
BP
SI
DI
Introduction to Computer Engineering by Richard E. Haskell
0
Table A2.a
Opcode Map
1
2
3
4
6
7
AX,imm
PUSH
ES
POP
ES
r/m,reg r/m,reg reg,r/m reg,r/m AL,imm
AX,imm
PUSH
SS
POP
SS
2
AND b
AND w
AND b
AND w
r/m,reg r/m,reg reg,r/m reg,r/m
AND b
AL,imm
AND w
AX,imm
SEGMENT
ES
DAA
3
XOR b
XOR w
XOR b
XOR w
r/m,reg r/m,reg reg,r/m reg,r/m
XOR b
AL,imm
XOR w
AX,imm
SEGMENT
SS
AAA
0
r/m,reg r/m,reg reg,r/m reg,r/m AL,imm
1
4
INC
AX
INC
CX
INC
DX
INC
BX
5
PUSH
AX
PUSH
CX
PUSH
DX
PUSH
BX
5
INC
SP
INC
BP
INC
SI
INC
DI
PUSH
SP
PUSH
BP
PUSH
SI
PUSH
DI
6
7
JO
JNO
8
*
*
JB/JNAE JNB/JAE
JC
JNC
*
*
JE/JZ
JNE/JNZ JBE/JNA JNBE/JA
TEST b TEST w
XCHG b XCHG w
r/m,reg r/m,reg r/m,reg r/m,reg
NOP
XCHG
CX,AX
XCHG
DX,AX
XCHG
BX,AX
XCHG
SP,AX
XCHG
BP,AX
XCHG
SI,AX
XCHG
DI,AX
A
MOV b
AL,mem
MOV w
AX,mem
MOV b
mem,AL
MOV w
mem,AX
MOVS b
MOVS w
CMPS b
CMPS w
B
MOV
AL,imm
MOV
CL,imm
MOV
DL,imm
MOV
BL,imm
MOV
AH,imm
MOV
CH,imm
MOV
DH,imm
RET
intra+
RET
intra
LES
LDS
MOV b
MOV w
reg.r/m reg.r/m r/m,imm r/m,imm
*
*
*
LOOPZ/
LOOPE
LOOP
JCXZ
9
C
D
*
E
LOOPNZ/
LOOPNE
F
LOCK
REP/REPNE REPE/
REPNZ
REPZ
AAM
MOV
BH,imm
XLAT
OUT b
OUT w
IN b
IN w
AL,port AX,port port,AL port,AX
HLT
CMC
*
Introduction to Computer Engineering by Richard E. Haskell
*
Postbyte
Table A.3
Table A.4
Postbyte mod,r/m Fields
Postbyte reg Field
mod = 11
r/m
000
001
010
011
100
101
110
111
byte
AL
CL
DL
BL
AH
CH
DH
BH
word
AX
CX
DX
BX
SP
BP
SI
DI
mod = 00
BX + SI
BX + DI
BP + SI
BP + DI
SI
DI
Direct
BX
1
1
mod
86
xchg bh,al
xchg b r/m,reg
mod = 01
BX + SI + disp8
BX + DI + disp8
BP + SI + disp8
BP + DI + disp8
SI + disp8
DI + disp8
BP + disp8
BX + disp8
0
0
mod = 10
BX + SI + disp16
BX + DI + disp16
BP + SI + disp16
BP + DI + disp16
SI + disp16
DI + disp16
BP + disp16
BX + disp16
0
1
reg
1
reg
000
001
010
011
100
101
110
111
1
byte (b)
AL
CL
DL
BL
AH
CH
DH
BH
word (w)
AX
CX
DX
BX
SP
BP
SI
DI
= C7
r/m
reg = al = 000
mod = 11
r/m = bh = 111
Introduction to Computer Engineering by Richard E. Haskell
xchg bh,al
86 C7
```