AMD64 Architecture Programmer's Manual Volume 3 General-Purpose and System Instructions
AMD64 Architecture Programmer's Manual Volume 3 General-Purpose and System Instructions
AMD64 Architecture
Programmer’s Manual
Volume 3:
General-Purpose and
System Instructions
Trademarks
AMD, the AMD arrow logo, AMD Athlon, and AMD Opteron, and combinations thereof, and 3DNow! are trademarks,
and AMD-K6 is a registered trademark of Advanced Micro Devices, Inc.
MMX is a trademark and Pentium is a registered trademark of Intel Corporation.
Windows NT is a registered trademark of Microsoft Corporation.
Other product names used in this publication are for identification purposes only and may be trademarks of their
respective companies.
24594—Rev. 3.14—September 2007 AMD64 Technology
Contents
Revision History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
About This Book. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
Audience . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
Organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvi
Related Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxvi
1 Instruction Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1
1.1 Instruction Byte Order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Instruction Prefixes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Summary of Legacy Prefixes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Operand-Size Override Prefix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Address-Size Override Prefix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Segment-Override Prefixes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Lock Prefix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Repeat Prefixes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
REX Prefixes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.3 Opcode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
1.4 ModRM and SIB Bytes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
1.5 Displacement Bytes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
1.6 Immediate Bytes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
1.7 RIP-Relative Addressing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Encoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
REX Prefix and RIP-Relative Addressing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Address-Size Prefix and RIP-Relative Addressing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
2 Instruction Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .21
2.1 Instruction Subsets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2.2 Reference-Page Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
2.3 Summary of Registers and Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
General-Purpose Instructions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
System Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
128-Bit Media Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
64-Bit Media Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
x87 Floating-Point Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
2.4 Summary of Exceptions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
2.5 Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Mnemonic Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Opcode Syntax. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Pseudocode Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Contents i
AMD64 Technology 24594—Rev. 3.14—September 2007
ii Contents
24594—Rev. 3.14—September 2007 AMD64 Technology
INC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
INS
INSB
INSW
INSD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
INT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
INTO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
Jcc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
JCXZ
JECXZ
JRCXZ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
JMP (Near). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
JMP (Far) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
LAHF. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
LDS
LES
LFS
LGS
LSS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
LEA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
LEAVE. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
LFENCE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
LODS
LODSB
LODSW
LODSD
LODSQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
LOOP
LOOPE
LOOPNE
LOOPNZ
LOOPZ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
LZCNT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
MFENCE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
MOV . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
MOVD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
MOVMSKPD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
MOVMSKPS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
MOVNTI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
MOVS
MOVSB
MOVSW
MOVSD
MOVSQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
MOVSX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
MOVSXD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
MOVZX. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
Contents iii
AMD64 Technology 24594—Rev. 3.14—September 2007
MUL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
NEG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
NOP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
NOT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
OR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
OUT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
OUTS
OUTSB
OUTSW
OUTSD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
PAUSE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
POP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
POPA
POPAD. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
POPCNT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
POPF
POPFD
POPFQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
PREFETCH
PREFETCHW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
PREFETCHlevel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
PUSH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
PUSHA
PUSHAD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
PUSHF
PUSHFD
PUSHFQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
RCL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
RCR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
RET (Near) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
RET (Far). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
ROL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
ROR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
SAHF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
SAL
SHL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
SAR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
SBB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
SCAS
SCASB
SCASW
SCASD
SCASQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
SETcc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
SFENCE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
SHL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
SHLD. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
iv Contents
24594—Rev. 3.14—September 2007 AMD64 Technology
SHR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
SHRD. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
STC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
STD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
STOS
STOSB
STOSW
STOSD
STOSQ. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
SUB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
TEST . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
XADD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
XCHG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
XLAT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247
XLATB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247
XOR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
4 System Instruction Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .251
ARPL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
CLGI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
CLI. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
CLTS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
HLT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258
INT 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259
INVD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
INVLPG. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
INVLPGA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264
IRET
IRETD
IRETQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
LAR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
LGDT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
LIDT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
LLDT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277
LMSW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
LSL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280
LTR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282
MONITOR. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284
MOV (CRn) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286
MOV(DRn) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288
MWAIT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
RDMSR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292
RDPMC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293
RDTSC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294
RDTSCP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295
RSM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297
SGDT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299
SIDT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300
Contents v
AMD64 Technology 24594—Rev. 3.14—September 2007
SKINIT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301
SLDT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
SMSW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304
STI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305
STGI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307
STR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308
SWAPGS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309
SYSCALL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311
SYSENTER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315
SYSEXIT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317
SYSRET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319
UD2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323
VERR. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324
VERW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326
VMLOAD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327
VMMCALL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329
VMRUN. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 330
VMSAVE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335
WBINVD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337
WRMSR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338
Appendix A Opcode and Operand Encodings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .339
A.1 Opcode-Syntax Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339
A.2 Opcode Encodings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340
One-Byte Opcodes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340
Two-Byte Opcodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343
rFLAGS Condition Codes for Two-Byte Opcodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348
ModRM Extensions to One-Byte and Two-Byte Opcodes . . . . . . . . . . . . . . . . . . . . . . . . . . 348
ModRM Extensions to Opcodes 0F 01 and 0F AE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351
3DNow!™ Opcodes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351
x87 Encodings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354
rFLAGS Condition Codes for x87 Opcodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 363
A.3 Operand Encodings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 363
ModRM Operand References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 363
SIB Operand References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369
Appendix B General-Purpose Instructions in 64-Bit Mode . . . . . . . . . . . . . . . . . . . . . . . .373
B.1 General Rules for 64-Bit Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 373
B.2 Operation and Operand Size in 64-Bit Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 374
B.3 Invalid and Reassigned Instructions in 64-Bit Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399
B.4 Instructions with 64-Bit Default Operand Size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 400
B.5 Single-Byte INC and DEC Instructions in 64-Bit Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401
B.6 NOP in 64-Bit Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401
B.7 Segment Override Prefixes in 64-Bit Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402
Appendix C Differences Between Long Mode and Legacy Mode. . . . . . . . . . . . . . . . . . . .403
vi Contents
24594—Rev. 3.14—September 2007 AMD64 Technology
Contents vii
AMD64 Technology 24594—Rev. 3.14—September 2007
viii Contents
24594—Rev. 3.14—September 2007 AMD64 Technology
Figures
Figure 1-1. Instruction Byte-Order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Figure 1-2. Little-Endian Byte-Order of Instruction Stored in Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Figure 1-3. Encoding Examples of REX-Prefix R, X, and B Bits. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Figure 1-4. ModRM-Byte Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Figure 1-5. SIB-Byte Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Figure 2-1. Format of Instruction-Detail Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Figure 2-2. General Registers in Legacy and Compatibility Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Figure 2-3. General Registers in 64-Bit Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Figure 2-4. Segment Registers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Figure 2-5. General-Purpose Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Figure 2-6. System Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Figure 2-7. System Data Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Figure 2-8. 128-Bit Media Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Figure 2-9. 128-Bit Media Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Figure 2-10. 64-Bit Media Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Figure 2-11. 64-Bit Media Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Figure 2-12. x87 Registers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Figure 2-13. x87 Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Figure 2-14. Syntax for Typical Two-Operand Instruction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Figure 3-1. MOVD Instruction Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
Figure A-1. ModRM-Byte Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348
Figure A-2. ModRM-Byte Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 364
Figure A-3. SIB Byte Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 370
Figure D-1. Instruction Subsets vs. CPUID Feature Sets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 406
Figures ix
AMD64 Technology 24594—Rev. 3.14—September 2007
x Figures
24594—Rev. 3.14—September 2007 AMD64 Technology
Tables
Table 1-1. Legacy Instruction Prefixes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Table 1-2. Operand-Size Overrides . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Table 1-3. Address-Size Overrides. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Table 1-4. Pointer and Count Registers and the Address-Size Prefix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Table 1-5. Segment-Override Prefixes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Table 1-6. REP Prefix Opcodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Table 1-7. REPE and REPZ Prefix Opcodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Table 1-8. REPNE and REPNZ Prefix Opcodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Table 1-9. REX Instruction Prefixes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Table 1-10. Instructions Not Requiring REX Size Prefix in 64-Bit Mode . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Table 1-11. REX Prefix-Byte Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Table 1-12. Special REX Encodings for Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Table 1-13. Encoding for RIP-Relative Addressing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Table 2-1. Interrupt-Vector Source and Cause. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Table 2-2. +rb, +rw, +rd, and +rq Register Value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Table 3-1. Instruction Support Indicated by CPUID Feature Bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Table 3-2. Processor Vendor Return Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
Table 3-3. Locality References for the Prefetch Instructions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
Table A-1. One-Byte Opcodes, Low Nibble 0–7h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341
Table A-2. One-Byte Opcodes, Low Nibble 8–Fh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342
Table A-3. Second Byte of Two-Byte Opcodes, Low Nibble 0–7h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343
Table A-4. Second Byte of Two-Byte Opcodes, Low Nibble 8–Fh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345
Table A-5. rFLAGS Condition Codes for CMOVcc, Jcc, and SETcc . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348
Table A-6. One-Byte and Two-Byte Opcode ModRM Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349
Table A-7. Opcode 0F 01 and 0F AE ModRM Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351
Table A-8. Immediate Byte for 3DNow!™ Opcodes, Low Nibble 0–7h . . . . . . . . . . . . . . . . . . . . . . . . . . 352
Table A-9. Immediate Byte for 3DNow!™ Opcodes, Low Nibble 8–Fh . . . . . . . . . . . . . . . . . . . . . . . . . . 353
Table A-10. x87 Opcodes and ModRM Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355
Table A-11. rFLAGS Condition Codes for FCMOVcc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 363
Table A-12. ModRM Register References, 16-Bit Addressing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 364
Table A-13. ModRM Memory References, 16-Bit Addressing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
Table A-14. ModRM Register References, 32-Bit and 64-Bit Addressing . . . . . . . . . . . . . . . . . . . . . . . . . 367
Table A-15. ModRM Memory References, 32-Bit and 64-Bit Addressing . . . . . . . . . . . . . . . . . . . . . . . . . 368
Table A-16. SIB base Field References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 370
Tables xi
AMD64 Technology 24594—Rev. 3.14—September 2007
xii Tables
24594—Rev. 3.14—September 2007 AMD64 Technology
Revision History
Preface
Audience
This volume (Volume 3) is intended for all programmers writing application or system software for a
processor that implements the AMD64 architecture. Descriptions of general-purpose instructions
assume an understanding of the application-level programming topics described in Volume 1.
Descriptions of system instructions assume an understanding of the system-level programming topics
described in Volume 2.
Organization
Volumes 3, 4, and 5 describe the AMD64 architecture’s instruction set in detail. Together, they cover
each instruction’s mnemonic syntax, opcodes, functions, affected flags, and possible exceptions.
The AMD64 instruction set is divided into five subsets:
• General-purpose instructions
• System instructions
• 128-bit media instructions
• 64-bit media instructions
• x87 floating-point instructions
Several instructions belong to—and are described identically in—multiple instruction subsets.
This volume describes the general-purpose and system instructions. The index at the end cross-
references topics within this volume. For other topics relating to the AMD64 architecture, and for
Preface xv
AMD64 Technology 24594—Rev. 3.14—September 2007
information on instructions in other subsets, see the tables of contents and indexes of the other
volumes.
Definitions
Many of the following definitions assume an in-depth knowledge of the legacy x86 architecture. See
“Related Documents” on page xxvi for descriptions of the legacy x86 architecture.
xvi Preface
24594—Rev. 3.14—September 2007 AMD64 Technology
64-bit mode
A submode of long mode. In 64-bit mode, the default address size is 64 bits and new features, such
as register extensions, are supported for system and application software.
#GP(0)
Notation indicating a general-protection exception (#GP) with error code of 0.
absolute
Said of a displacement that references the base of a code segment rather than an instruction pointer.
Contrast with relative.
biased exponent
The sum of a floating-point value’s exponent and a constant bias for a particular floating-point data
type. The bias makes the range of the biased exponent always positive, which allows reciprocation
without overflow.
byte
Eight bits.
clear
To write a bit value of 0. Compare set.
compatibility mode
A submode of long mode. In compatibility mode, the default address size is 32 bits, and legacy 16-
bit and 32-bit applications run without modification.
commit
To irreversibly write, in program order, an instruction’s result to software-visible storage, such as a
register (including flags), the data cache, an internal write buffer, or memory.
CPL
Current privilege level.
CR0–CR4
A register range, from register CR0 through CR4, inclusive, with the low-order register first.
CR0.PE = 1
Notation indicating that the PE bit of the CR0 register has a value of 1.
direct
Referencing a memory location whose address is included in the instruction’s syntax as an
immediate operand. The address may be an absolute or relative address. Compare indirect.
dirty data
Data held in the processor’s caches or internal buffers that is more recent than the copy held in
main memory.
Preface xvii
AMD64 Technology 24594—Rev. 3.14—September 2007
displacement
A signed value that is added to the base of a segment (absolute addressing) or an instruction pointer
(relative addressing). Same as offset.
doubleword
Two words, or four bytes, or 32 bits.
double quadword
Eight words, or 16 bytes, or 128 bits. Also called octword.
DS:rSI
The contents of a memory location whose segment address is in the DS register and whose offset
relative to that segment is in the rSI register.
EFER.LME = 0
Notation indicating that the LME bit of the EFER register has a value of 0.
effective address size
The address size for the current instruction after accounting for the default address size and any
address-size override prefix.
effective operand size
The operand size for the current instruction after accounting for the default operand size and any
operand-size override prefix.
element
See vector.
exception
An abnormal condition that occurs as the result of executing an instruction. The processor’s
response to an exception depends on the type of the exception. For all exceptions except 128-bit
media SIMD floating-point exceptions and x87 floating-point exceptions, control is transferred to
the handler (or service routine) for that exception, as defined by the exception’s vector. For
floating-point exceptions defined by the IEEE 754 standard, there are both masked and unmasked
responses. When unmasked, the exception handler is called, and when masked, a default response
is provided instead of calling the handler.
FF /0
Notation indicating that FF is the first byte of an opcode, and a subopcode in the ModR/M byte has
a value of 0.
flush
An often ambiguous term meaning (1) writeback, if modified, and invalidate, as in “flush the cache
line,” or (2) invalidate, as in “flush the pipeline,” or (3) change a value, as in “flush to zero.”
xviii Preface
24594—Rev. 3.14—September 2007 AMD64 Technology
GDT
Global descriptor table.
IDT
Interrupt descriptor table.
IGN
Ignore. Field is ignored.
indirect
Referencing a memory location whose address is in a register or other memory location. The
address may be an absolute or relative address. Compare direct.
IRB
The virtual-8086 mode interrupt-redirection bitmap.
IST
The long-mode interrupt-stack table.
IVT
The real-address mode interrupt-vector table.
LDT
Local descriptor table.
legacy x86
The legacy x86 architecture. See “Related Documents” on page xxvi for descriptions of the legacy
x86 architecture.
legacy mode
An operating mode of the AMD64 architecture in which existing 16-bit and 32-bit applications and
operating systems run without modification. A processor implementation of the AMD64
architecture can run in either long mode or legacy mode. Legacy mode has three submodes, real
mode, protected mode, and virtual-8086 mode.
long mode
An operating mode unique to the AMD64 architecture. A processor implementation of the
AMD64 architecture can run in either long mode or legacy mode. Long mode has two submodes,
64-bit mode and compatibility mode.
lsb
Least-significant bit.
LSB
Least-significant byte.
Preface xix
AMD64 Technology 24594—Rev. 3.14—September 2007
main memory
Physical memory, such as RAM and ROM (but not cache memory) that is installed in a particular
computer system.
mask
(1) A control bit that prevents the occurrence of a floating-point exception from invoking an
exception-handling routine. (2) A field of bits used for a control purpose.
MBZ
Must be zero. If software attempts to set an MBZ bit to 1, a general-protection exception (#GP)
occurs.
memory
Unless otherwise specified, main memory.
ModRM
A byte following an instruction opcode that specifies address calculation based on mode (Mod),
register (R), and memory (M) variables.
moffset
A 16, 32, or 64-bit offset that specifies a memory operand directly, without using a ModRM or SIB
byte.
msb
Most-significant bit.
MSB
Most-significant byte.
multimedia instructions
A combination of 128-bit media instructions and 64-bit media instructions.
octword
Same as double quadword.
offset
Same as displacement.
overflow
The condition in which a floating-point number is larger in magnitude than the largest, finite,
positive or negative number that can be represented in the data-type format being used.
packed
See vector.
xx Preface
24594—Rev. 3.14—September 2007 AMD64 Technology
PAE
Physical-address extensions.
physical memory
Actual memory, consisting of main memory and cache.
probe
A check for an address in a processor’s caches or internal buffers. External probes originate
outside the processor, and internal probes originate within the processor.
protected mode
A submode of legacy mode.
quadword
Four words, or eight bytes, or 64 bits.
RAZ
Read as zero (0), regardless of what is written.
real-address mode
See real mode.
real mode
A short name for real-address mode, a submode of legacy mode.
relative
Referencing with a displacement (also called offset) from an instruction pointer rather than the
base of a code segment. Contrast with absolute.
reserved
Fields marked as reserved may be used at some future time.
To preserve compatibility with future processors, reserved fields require special handling when
read or written by software.
Reserved fields may be further qualified as MBZ, RAZ, SBZ or IGN (see definitions).
Software must not depend on the state of a reserved field, nor upon the ability of such fields to
return to a previously written state.
If a reserved field is not marked with one of the above qualifiers, software must not change the state
of that field; it must reload that field with the same values returned from a prior read.
REX
An instruction prefix that specifies a 64-bit operand size and provides access to additional
registers.
RIP-relative addressing
Addressing relative to the 64-bit RIP instruction pointer.
Preface xxi
AMD64 Technology 24594—Rev. 3.14—September 2007
set
To write a bit value of 1. Compare clear.
SIB
A byte following an instruction opcode that specifies address calculation based on scale (S), index
(I), and base (B).
SIMD
Single instruction, multiple data. See vector.
SSE
Streaming SIMD extensions instruction set. See 128-bit media instructions and 64-bit media
instructions.
SSE2
Extensions to the SSE instruction set. See 128-bit media instructions and 64-bit media
instructions.
SSE3
Further extensions to the SSE instruction set. See 128-bit media instructions.
sticky bit
A bit that is set or cleared by hardware and that remains in that state until explicitly changed by
software.
TOP
The x87 top-of-stack pointer.
TPR
Task-priority register (CR8).
TSS
Task-state segment.
underflow
The condition in which a floating-point number is smaller in magnitude than the smallest nonzero,
positive or negative number that can be represented in the data-type format being used.
vector
(1) A set of integer or floating-point values, called elements, that are packed into a single operand.
Most of the 128-bit and 64-bit media instructions use vectors as operands. Vectors are also called
packed or SIMD (single-instruction multiple-data) operands.
(2) An index into an interrupt descriptor table (IDT), used to access exception handlers. Compare
exception.
xxii Preface
24594—Rev. 3.14—September 2007 AMD64 Technology
virtual-8086 mode
A submode of legacy mode.
word
Two bytes, or 16 bits.
x86
See legacy x86.
Registers
In the following list of registers, the names are used to refer either to a given register or to the contents
of that register:
AH–DH
The high 8-bit AH, BH, CH, and DH registers. Compare AL–DL.
AL–DL
The low 8-bit AL, BL, CL, and DL registers. Compare AH–DH.
AL–r15B
The low 8-bit AL, BL, CL, DL, SIL, DIL, BPL, SPL, and R8B–R15B registers, available in 64-bit
mode.
BP
Base pointer register.
CRn
Control register number n.
CS
Code segment register.
eAX–eSP
The 16-bit AX, BX, CX, DX, DI, SI, BP, and SP registers or the 32-bit EAX, EBX, ECX, EDX,
EDI, ESI, EBP, and ESP registers. Compare rAX–rSP.
EFER
Extended features enable register.
eFLAGS
16-bit or 32-bit flags register. Compare rFLAGS.
EFLAGS
32-bit (extended) flags register.
Preface xxiii
AMD64 Technology 24594—Rev. 3.14—September 2007
eIP
16-bit or 32-bit instruction-pointer register. Compare rIP.
EIP
32-bit (extended) instruction-pointer register.
FLAGS
16-bit flags register.
GDTR
Global descriptor table register.
GPRs
General-purpose registers. For the 16-bit data size, these are AX, BX, CX, DX, DI, SI, BP, and SP.
For the 32-bit data size, these are EAX, EBX, ECX, EDX, EDI, ESI, EBP, and ESP. For the 64-bit
data size, these include RAX, RBX, RCX, RDX, RDI, RSI, RBP, RSP, and R8–R15.
IDTR
Interrupt descriptor table register.
IP
16-bit instruction-pointer register.
LDTR
Local descriptor table register.
MSR
Model-specific register.
r8–r15
The 8-bit R8B–R15B registers, or the 16-bit R8W–R15W registers, or the 32-bit R8D–R15D
registers, or the 64-bit R8–R15 registers.
rAX–rSP
The 16-bit AX, BX, CX, DX, DI, SI, BP, and SP registers, or the 32-bit EAX, EBX, ECX, EDX,
EDI, ESI, EBP, and ESP registers, or the 64-bit RAX, RBX, RCX, RDX, RDI, RSI, RBP, and RSP
registers. Replace the placeholder r with nothing for 16-bit size, “E” for 32-bit size, or “R” for 64-
bit size.
RAX
64-bit version of the EAX register.
RBP
64-bit version of the EBP register.
xxiv Preface
24594—Rev. 3.14—September 2007 AMD64 Technology
RBX
64-bit version of the EBX register.
RCX
64-bit version of the ECX register.
RDI
64-bit version of the EDI register.
RDX
64-bit version of the EDX register.
rFLAGS
16-bit, 32-bit, or 64-bit flags register. Compare RFLAGS.
RFLAGS
64-bit flags register. Compare rFLAGS.
rIP
16-bit, 32-bit, or 64-bit instruction-pointer register. Compare RIP.
RIP
64-bit instruction-pointer register.
RSI
64-bit version of the ESI register.
RSP
64-bit version of the ESP register.
SP
Stack pointer register.
SS
Stack segment register.
TPR
Task priority register, a new register introduced in the AMD64 architecture to speed interrupt
management.
TR
Task register.
Preface xxv
AMD64 Technology 24594—Rev. 3.14—September 2007
Endian Order
The x86 and AMD64 architectures address memory using little-endian byte-ordering. Multibyte
values are stored with their least-significant byte at the lowest byte address, and they are illustrated
with their least significant byte at the right side. Strings are illustrated in reverse order, because the
addresses of their bytes increase from right to left.
Related Documents
• Peter Abel, IBM PC Assembly Language and Programming, Prentice-Hall, Englewood Cliffs, NJ,
1995.
• Rakesh Agarwal, 80x86 Architecture & Programming: Volume II, Prentice-Hall, Englewood
Cliffs, NJ, 1991.
• AMD, AMD-K6™ MMX™ Enhanced Processor Multimedia Technology, Sunnyvale, CA, 2000.
• AMD, 3DNow!™ Technology Manual, Sunnyvale, CA, 2000.
• AMD, AMD Extensions to the 3DNow!™ and MMX™ Instruction Sets, Sunnyvale, CA, 2000.
• Don Anderson and Tom Shanley, Pentium Processor System Architecture, Addison-Wesley, New
York, 1995.
• Nabajyoti Barkakati and Randall Hyde, Microsoft Macro Assembler Bible, Sams, Carmel, Indiana,
1992.
• Barry B. Brey, 8086/8088, 80286, 80386, and 80486 Assembly Language Programming,
Macmillan Publishing Co., New York, 1994.
• Barry B. Brey, Programming the 80286, 80386, 80486, and Pentium Based Personal Computer,
Prentice-Hall, Englewood Cliffs, NJ, 1995.
• Ralf Brown and Jim Kyle, PC Interrupts, Addison-Wesley, New York, 1994.
• Penn Brumm and Don Brumm, 80386/80486 Assembly Language Programming, Windcrest
McGraw-Hill, 1993.
• Geoff Chappell, DOS Internals, Addison-Wesley, New York, 1994.
• Chips and Technologies, Inc. Super386 DX Programmer’s Reference Manual, Chips and
Technologies, Inc., San Jose, 1992.
• John Crawford and Patrick Gelsinger, Programming the 80386, Sybex, San Francisco, 1987.
• Cyrix Corporation, 5x86 Processor BIOS Writer's Guide, Cyrix Corporation, Richardson, TX,
1995.
• Cyrix Corporation, M1 Processor Data Book, Cyrix Corporation, Richardson, TX, 1996.
• Cyrix Corporation, MX Processor MMX Extension Opcode Table, Cyrix Corporation, Richardson,
TX, 1996.
• Cyrix Corporation, MX Processor Data Book, Cyrix Corporation, Richardson, TX, 1997.
• Ray Duncan, Extending DOS: A Programmer's Guide to Protected-Mode DOS, Addison Wesley,
NY, 1991.
xxvi Preface
24594—Rev. 3.14—September 2007 AMD64 Technology
• William B. Giles, Assembly Language Programming for the Intel 80xxx Family, Macmillan, New
York, 1991.
• Frank van Gilluwe, The Undocumented PC, Addison-Wesley, New York, 1994.
• John L. Hennessy and David A. Patterson, Computer Architecture, Morgan Kaufmann Publishers,
San Mateo, CA, 1996.
• Thom Hogan, The Programmer’s PC Sourcebook, Microsoft Press, Redmond, WA, 1991.
• Hal Katircioglu, Inside the 486, Pentium, and Pentium Pro, Peer-to-Peer Communications, Menlo
Park, CA, 1997.
• IBM Corporation, 486SLC Microprocessor Data Sheet, IBM Corporation, Essex Junction, VT,
1993.
• IBM Corporation, 486SLC2 Microprocessor Data Sheet, IBM Corporation, Essex Junction, VT,
1993.
• IBM Corporation, 80486DX2 Processor Floating Point Instructions, IBM Corporation, Essex
Junction, VT, 1995.
• IBM Corporation, 80486DX2 Processor BIOS Writer's Guide, IBM Corporation, Essex Junction,
VT, 1995.
• IBM Corporation, Blue Lightning 486DX2 Data Book, IBM Corporation, Essex Junction, VT,
1994.
• Institute of Electrical and Electronics Engineers, IEEE Standard for Binary Floating-Point
Arithmetic, ANSI/IEEE Std 754-1985.
• Institute of Electrical and Electronics Engineers, IEEE Standard for Radix-Independent Floating-
Point Arithmetic, ANSI/IEEE Std 854-1987.
• Muhammad Ali Mazidi and Janice Gillispie Mazidi, 80X86 IBM PC and Compatible Computers,
Prentice-Hall, Englewood Cliffs, NJ, 1997.
• Hans-Peter Messmer, The Indispensable Pentium Book, Addison-Wesley, New York, 1995.
• Karen Miller, An Assembly Language Introduction to Computer Architecture: Using the Intel
Pentium, Oxford University Press, New York, 1999.
• Stephen Morse, Eric Isaacson, and Douglas Albert, The 80386/387 Architecture, John Wiley &
Sons, New York, 1987.
• NexGen Inc., Nx586 Processor Data Book, NexGen Inc., Milpitas, CA, 1993.
• NexGen Inc., Nx686 Processor Data Book, NexGen Inc., Milpitas, CA, 1994.
• Bipin Patwardhan, Introduction to the Streaming SIMD Extensions in the Pentium III,
www.x86.org/articles/sse_pt1/ simd1.htm, June, 2000.
• Peter Norton, Peter Aitken, and Richard Wilton, PC Programmer’s Bible, Microsoft Press,
Redmond, WA, 1993.
• PharLap 386|ASM Reference Manual, Pharlap, Cambridge MA, 1993.
• PharLap TNT DOS-Extender Reference Manual, Pharlap, Cambridge MA, 1995.
Preface xxvii
AMD64 Technology 24594—Rev. 3.14—September 2007
• Sen-Cuo Ro and Sheau-Chuen Her, i386/i486 Advanced Programming, Van Nostrand Reinhold,
New York, 1993.
• Jeffrey P. Royer, Introduction to Protected Mode Programming, course materials for an onsite
class, 1992.
• Tom Shanley, Protected Mode System Architecture, Addison Wesley, NY, 1996.
• SGS-Thomson Corporation, 80486DX Processor SMM Programming Manual, SGS-Thomson
Corporation, 1995.
• Walter A. Triebel, The 80386DX Microprocessor, Prentice-Hall, Englewood Cliffs, NJ, 1992.
• John Wharton, The Complete x86, MicroDesign Resources, Sebastopol, California, 1994.
• Web sites and newsgroups:
- www.amd.com
- news.comp.arch
- news.comp.lang.asm.x86
- news.intel.microprocessors
- news.microsoft
xxviii Preface
24594—Rev. 3.14—September 2007 AMD64 Technology
1 Instruction Formats
The format of an instruction encodes its operation, as well as the locations of the instruction’s initial
operands and the result of the operation. This section describes the general format and parameters used
by all instructions. For information on the specific format(s) for each instruction, see:
• Chapter 3, “General-Purpose Instruction Reference.”
• Chapter 4, “System Instruction Reference.”
• “128-Bit Media Instruction Reference” in Volume 4.
• “64-Bit Media Instruction Reference” in Volume 5.
• “x87 Floating-Point Instruction Reference” in Volume 5.
Instructions are stored in memory in little-endian order. The least-significant byte of an instruction is
stored at its lowest memory address, as shown in Figure 1-2 on page 2.
Instruction Formats 1
AMD64 Technology 24594—Rev. 3.14—September 2007
7 0
Most-significant Immediate
(highest) address *
Immediate *
Immediate *
Immediate *
Displacement *
Displacement *
Displacement *
Displacement *
SIB *
≤ 15 Bytes
ModRM *
Opcode *
Opcode (all two-byte opcodes have 0Fh as their first byte)
REX Prefix + (available only in 64-bit mode)
Legacy Prefix +
Legacy Prefix +
Legacy Prefix +
Least-significant * optional, depending on the instruction
(lowest) address Legacy Prefix + + optional, with most instructions
513-304.eps
The basic operation of an instruction is specified by an opcode. The opcode is one or two bytes long, as
described in “Opcode” on page 17. An opcode can be preceded by any number of legacy prefixes.
These prefixes can be classified as belonging to any of the five groups of prefixes described in
“Instruction Prefixes” on page 3. The legacy prefixes modify an instruction’s default address size,
operand size, or segment, or they invoke a special function such as modification of the opcode, atomic
bus-locking, or repetition. The REX prefix can be used in 64-bit mode to access the register extensions
illustrated in “Application-Programming Register Set” in Volume 1. If a REX prefix is used, it must
immediately precede the first opcode byte.
An instruction’s opcode consists of one or two bytes. In several 128-bit and 64-bit media instructions,
a legacy operand-size or repeat prefix byte is used in a special-purpose way to modify the opcode. The
opcode can be followed by a mode-register-memory (ModRM) byte, which further describes the
operation and/or operands. The opcode, or the opcode and ModRM byte, can also be followed by a
scale-index-base (SIB) byte, which describes the scale, index, and base forms of memory addressing.
The ModRM and SIB bytes are described in “ModRM and SIB Bytes” on page 17, but their legacy
functions can be modified by the REX prefix (“Instruction Prefixes” on page 3).
The 15-byte instruction-length limit can only be exceeded by using redundant prefixes. If the limit is
exceeded, a general-protection exception occurs.
2 Instruction Formats
24594—Rev. 3.14—September 2007 AMD64 Technology
Instruction Formats 3
AMD64 Technology 24594—Rev. 3.14—September 2007
Prefix
Prefix Group1 Mnemonic
Byte (Hex)
Description
4 Instruction Formats
24594—Rev. 3.14—September 2007 AMD64 Technology
be used with any general-purpose instruction that accesses non-fixed-size operands in memory or
general-purpose registers (GPRs), and it can also be used with the x87 FLDENV, FNSTENV,
FNSAVE, and FRSTOR instructions.
In 64-bit mode, the prefix allows mixing of 16-bit, 32-bit, and 64-bit data on an instruction-by-
instruction basis. In compatibility and legacy modes, the prefix allows mixing of 16-bit and 32-bit
operands on an instruction-by-instruction basis.
In 64-bit mode, most instructions default to a 32-bit operand size. For these instructions, a REX prefix
(page 13) can specify a 64-bit operand size, and a 66h prefix specifies a 16-bit operand size. The REX
prefix takes precedence over the 66h prefix. However, if an instruction defaults to a 64-bit operand
size, it does not need a REX prefix and it can only be overridden to a 16-bit operand size. It cannot be
overridden to a 32-bit operand size, because there is no 32-bit operand-size override prefix in 64-bit
mode. Two groups of instructions have a default 64-bit operand size in 64-bit mode:
• Near branches. For details, see “Near Branches in 64-Bit Mode” in Volume 1.
• All instructions, except far branches, that implicitly reference the RSP. For details, see “Stack
Operation” in Volume 1.
Instructions that Cannot Use the Operand-Size Prefix. The operand-size prefix should be used
only with general-purpose instructions and the x87 FLDENV, FNSTENV, FNSAVE, and FRSTOR
Instruction Formats 5
AMD64 Technology 24594—Rev. 3.14—September 2007
instructions, in which the prefix selects between 16-bit and 32-bit operand size. The prefix is ignored
by all other x87 instructions and by 64-bit media floating-point (3DNow!™) instructions.
When used with 64-bit media integer instructions, the 66h prefix acts in a special way to modify the
opcode. This modification typically causes an access to an XMM register or 128-bit memory operand
and thereby converts the 64-bit media instruction into its comparable 128-bit media instruction. The
result of using an F2h or F3h repeat prefix along with a 66h prefix in 128-bit or 64-bit media
instructions is unpredictable.
Operand-Size and REX Prefixes. The REX operand-size prefix takes precedence over the 66h
prefix. See “REX.W: Operand Width” on page 13 for details.
6 Instruction Formats
24594—Rev. 3.14—September 2007 AMD64 Technology
As Table 1-3 shows, the default address size is 64 bits in 64-bit mode. The size can be overridden to 32
bits, but 16-bit addresses are not supported in 64-bit mode. In compatibility and legacy modes, the
default address size is 16 bits or 32 bits, depending on the operating mode (see “Processor
Initialization and Long Mode Activation” in Volume 2 for details). In these modes, the address-size
prefix selects the non-default size, but the 64-bit address size is not available.
Certain instructions reference pointer registers or count registers implicitly, rather than explicitly. In
such instructions, the address-size prefix affects the size of such addressing and count registers, just as
it does when such registers are explicitly referenced. Table 1-4 lists all such instructions and the
registers referenced using the three possible address sizes.
Table 1-4. Pointer and Count Registers and the Address-Size Prefix
Pointer or Count Register
Instruction 16-Bit 32-Bit 64-Bit
Address Size Address Size Address Size
CMPS, CMPSB, CMPSW,
CMPSD, CMPSQ—Compare SI, DI, CX ESI, EDI, ECX RSI, RDI, RCX
Strings
INS, INSB, INSW, INSD—
DI, CX EDI, ECX RDI, RCX
Input String
JCXZ, JECXZ, JRCXZ—Jump
CX ECX RCX
on CX/ECX/RCX Zero
LODS, LODSB, LODSW,
LODSD, LODSQ—Load SI, CX ESI, ECX RSI, RCX
String
LOOP, LOOPE, LOOPNZ,
CX ECX RCX
LOOPNE, LOOPZ—Loop
MOVS, MOVSB, MOVSW,
MOVSD, MOVSQ—Move SI, DI, CX ESI, EDI, ECX RSI, RDI, RCX
String
OUTS, OUTSB, OUTSW,
SI, CX ESI, ECX RSI, RCX
OUTSD—Output String
REP, REPE, REPNE, REPNZ,
CX ECX RCX
REPZ—Repeat Prefixes
SCAS, SCASB, SCASW,
SCASD, SCASQ—Scan DI, CX EDI, ECX RDI, RCX
String
STOS, STOSB, STOSW,
STOSD, STOSQ—Store DI, CX EDI, ECX RDI, RCX
String
XLAT, XLATB—Table Look-up
BX EBX RBX
Translation
Instruction Formats 7
AMD64 Technology 24594—Rev. 3.14—September 2007
Segment Overrides in 64-Bit Mode. In 64-bit mode, the CS, DS, ES, and SS segment-override
prefixes have no effect. These four prefixes are not treated as segment-override prefixes for the
purposes of multiple-prefix rules. Instead, they are treated as null prefixes.
The FS and GS segment-override prefixes are treated as true segment-override prefixes in 64-bit mode.
Use of the FS or GS prefix causes their respective segment bases to be added to the effective address
calculation. See “FS and GS Registers in 64-Bit Mode” in Volume 2 for details.
8 Instruction Formats
24594—Rev. 3.14—September 2007 AMD64 Technology
bus signaling or packet messaging between the processor and a memory controller). The prefix is
intended to give the processor exclusive use of shared memory in a multiprocessor system.
The LOCK prefix can only be used with forms of the following instructions that write a memory
operand: ADC, ADD, AND, BTC, BTR, BTS, CMPXCHG, CMPXCHG8B, CMPXCHG16B, DEC,
INC, NEG, NOT, OR, SBB, SUB, XADD, XCHG, and XOR. An invalid-opcode exception occurs if
the LOCK prefix is used with any other instruction.
REP. The REP prefix repeats its associated string instruction the number of times specified in the
counter register (rCX). It terminates the repetition when the value in rCX reaches 0. The prefix can be
used with the INS, LODS, MOVS, OUTS, and STOS instructions. Table 1-6 shows the valid REP
prefix opcodes.
Instruction Formats 9
AMD64 Technology 24594—Rev. 3.14—September 2007
REPE and REPZ. REPE and REPZ are synonyms and have identical opcodes. These prefixes repeat
their associated string instruction the number of times specified in the counter register (rCX). The
repetition terminates when the value in rCX reaches 0 or when the zero flag (ZF) is cleared to 0. The
REPE and REPZ prefixes can be used with the CMPS, CMPSB, CMPSD, CMPSW, SCAS, SCASB,
SCASD, and SCASW instructions. Table 1-7 shows the valid REPE and REPZ prefix opcodes.
REPNE and REPNZ. REPNE and REPNZ are synonyms and have identical opcodes. These prefixes
repeat their associated string instruction the number of times specified in the counter register (rCX).
The repetition terminates when the value in rCX reaches 0 or when the zero flag (ZF) is set to 1. The
REPNE and REPNZ prefixes can be used with the CMPS, CMPSB, CMPSD, CMPSW, SCAS,
SCASB, SCASD, and SCASW instructions. Table 1-8 on page 11 shows the valid REPNE and
REPNZ prefix opcodes.
10 Instruction Formats
24594—Rev. 3.14—September 2007 AMD64 Technology
Instructions that Cannot Use Repeat Prefixes. In general, the repeat prefixes should only be used
in the string instructions listed in tables 1-6, 1-7, and 1-8, and in 128-bit or 64-bit media instructions.
When used in media instructions, the F2h and F3h prefixes act in a special way to modify the opcode
rather than cause a repeat operation. The result of using a 66h operand-size prefix along with an F2h or
F3h prefix in 128-bit or 64-bit media instructions is unpredictable.
Optimization of Repeats. Depending on the hardware implementation, the repeat prefixes can have a
setup overhead. If the repeated count is variable, the overhead can sometimes be avoided by substituting
a simple loop to move or store the data. Repeated string instructions can be expanded into equivalent
sequences of inline loads and stores or a sequence of stores can be used to emulate a REP STOS.
For repeated string moves, performance can be maximized by moving the largest possible operand
size. For example, use REP MOVSD rather than REP MOVSW and REP MOVSW rather than REP
MOVSB. Use REP STOSD rather than REP STOSW and REP STOSW rather than REP MOVSB.
Depending on the hardware implementation, string moves with the direction flag (DF) cleared to 0
(up) may be faster than string moves with DF set to 1 (down). DF = 1 is only needed for certain cases
of overlapping REP MOVS, such as when the source and the destination overlap.
Instruction Formats 11
AMD64 Technology 24594—Rev. 3.14—September 2007
• Use of the extended control and debug registers, as described in “64-Bit-Mode Extended Control
Registers” in Volume 2 and “64-Bit-Mode Extended Debug Registers” in Volume 2.
• Use of the uniform byte registers (AL–R15).
Table 1-9 shows the REX prefixes. The value of a REX prefix is in the range 40h through 4Fh,
depending on the particular combination of AMD64 register extensions desired.
A REX prefix is normally required with an instruction that accesses a 64-bit GPR or one of the
extended GPR or XMM registers. Only a few instructions have an operand size that defaults to (or is
fixed at) 64 bits in 64-bit mode, and thus do not need a REX prefix. These exceptions to the normal
rule are listed in Table 1-10.
Table 1-10. Instructions Not Requiring REX Size Prefix in 64-Bit Mode
CALL (Near) POP reg/mem
ENTER POP reg
Jcc POP FS
JrCXZ POP GS
JMP (Near) POPFQ
LEAVE PUSH imm8
LGDT PUSH imm32
LIDT PUSH reg/mem
LLDT PUSH reg
LOOP PUSH FS
LOOPcc PUSH GS
LTR PUSHFQ
MOV CR(n) RET (Near)
MOV DR(n)
An instruction can have only one REX prefix, although the prefix can express several extension
features. If a REX prefix is used, it must immediately precede the first opcode byte in the instruction
format. Any other placement of a REX prefix, or any use of a REX prefix in an instruction that does
12 Instruction Formats
24594—Rev. 3.14—September 2007 AMD64 Technology
not access an extended register, is ignored. The legacy instruction-size limit of 15 bytes still applies to
instructions that contain a REX prefix.
REX prefixes are a set of sixteen values that span one row of the main opcode map and occupy entries
40h through 4Fh. Table 1-11 and Figure 1-3 on page 15 show the prefix fields and their uses.
REX.W: Operand Width. Setting the REX.W bit to 1 specifies a 64-bit operand size. Like the
existing 66h operand-size prefix, the REX 64-bit operand-size override has no effect on byte
operations. For non-byte operations, the REX operand-size override takes precedence over the 66h
prefix. If a 66h prefix is used together with a REX prefix that has the REX.W bit set to 1, the 66h
prefix is ignored. However, if a 66h prefix is used together with a REX prefix that has the REX.W bit
cleared to 0, the 66h prefix is not ignored and the operand size becomes 16 bits.
REX.R: Register. The REX.R bit adds a 1-bit (high) extension to the ModRM reg field (page 17)
when that field encodes a GPR, XMM, control, or debug register. REX.R does not modify ModRM reg
when that field specifies other registers or opcodes. REX.R is ignored in such cases.
REX.X: Index. The REX.X bit adds a 1-bit (high) extension to the SIB index field (page 17).
REX.B: Base. The REX.B bit adds a 1-bit (high) extension to either the ModRM r/m field to specify
a GPR or XMM register, or to the SIB base field to specify a GPR. (See Table 2-2 on page 40 for more
about the REX.B bit.)
Encoding Examples. Figure 1-3 on page 15 shows four examples of how the R, X, and B bits of
REX prefixes are concatenated with fields from the ModRM byte, SIB byte, and opcode to specify
register and memory addressing. The R, X, and B bits are described in Table 1-11 on page 13.
Instruction Formats 13
AMD64 Technology 24594—Rev. 3.14—September 2007
Byte-Register Addressing. In the legacy architecture, the byte registers (AH, AL, BH, BL, CH, CL,
DH, and DL, shown in Figure 2-2 on page 24) are encoded in the ModRM reg or r/m field or in the
opcode reg field as registers 0 through 7. The REX prefix provides an additional byte-register
addressing capability that makes the least-significant byte of any GPR available for byte operations
(Figure 2-3 on page 25). This provides a uniform set of byte, word, doubleword, and quadword
registers better suited for register allocation by compilers.
Special Encodings for Registers. Readers who need to know the details of instruction encodings
should be aware that certain combinations of the ModRM and SIB fields have special meaning for
register encodings. For some of these combinations, the instruction fields expanded by the REX prefix
are not decoded (treated as don’t cares), thereby creating aliases of these encodings in the extended
registers. Table 1-12 on page 16 describes how each of these cases behaves.
Implications for INC and DEC Instructions. The REX prefix values are taken from the 16 single-
byte INC and DEC instructions, one for each of the eight GPRs. Therefore, these single-byte opcodes
for INC and DEC are not available in 64-bit mode, although they are available in legacy and
compatibility modes. The functionality of these INC and DEC instructions is still available in 64-bit
mode, however, using the ModRM forms of those instructions (opcodes FF /0 and FF /1).
14 Instruction Formats
24594—Rev. 3.14—September 2007 AMD64 Technology
4
4
Rrrr Bbbb
4
4
Rrrr Bbbb
4 4
4
Rrrr Xxxx Bbbb
Opcode Byte
REX Prefix op reg
4WRXB bbb REX.R is not used
REX.X is not used
4
Bbbb 513-302.eps
Instruction Formats 15
AMD64 Technology 24594—Rev. 3.14—September 2007
16 Instruction Formats
24594—Rev. 3.14—September 2007 AMD64 Technology
1.3 Opcode
Each instruction has a unique opcode, although assemblers can support multiple mnemonics for a
single instruction opcode. The opcode specifies the operation that the instruction performs and, in
certain cases, the kinds of operands it uses. An opcode consists of one or two bytes, but certain 128-bit
media instructions also use a prefix byte in a special way to modify the opcode. The 3-bit reg field of
the ModRM byte (“ModRM and SIB Bytes” on page 17) is also used in certain instructions either for
three additional opcode bits or for a register specification.
128-Bit and 64-Bit Media Instruction Opcodes. Many 128-bit and 64-bit media instructions
include a 66h, F2h, or F3h prefix byte in a special way to modify the opcode. These same byte values
can be used in certain general-purpose and x87 instructions to modify operand size (66h) or repeat the
operation (F2h, F3h). In 128-bit and 64-bit media instructions, however, such prefix bytes modify the
opcode. If a 128-bit or 64-bit media instruction uses one of these three prefixes, and also includes any
other prefix in the 66h, F2h, and F3h group, the result is unpredictable.
All opcodes for 64-bit media instructions begin with a 0Fh byte. In the case of 64-bit floating-point
(3DNow!) instructions, the 0Fh byte is followed by a second 0Fh opcode byte. A third opcode byte
occupies the same position at the end of a 3DNow! instruction as would an immediate byte. The value
of the immediate byte is shown as the third opcode byte-value in the syntax for each instruction in
“64-Bit Media Instruction Reference” in Volume 5. The format is:
0Fh 0Fh ModRM [SIB] [displacement] 3DNow!_third_opcode_byte
For details on opcode encoding, see Appendix A, “Opcode and Operand Encodings.”
Instruction Formats 17
AMD64 Technology 24594—Rev. 3.14—September 2007
Bits: 7 6 5 4 3 2 1 0
mod reg r/m ModRM
In some instructions, the ModRM byte is followed by an SIB byte, which defines memory addressing
for the complex-addressing modes described in “Effective Addresses” in Volume 1. The SIB byte has
three fields—scale, index, and base—that define the scale factor, index-register number, and base-
register number for 32-bit and 64-bit complex addressing modes. In 64-bit mode, the REX.B and
REX.X bits extend the encoding of the SIB byte’s base and index fields.
Figure 1-5 shows the format of an SIB byte.
Bits: 7 6 5 4 3 2 1 0
scale index base SIB
513-306.eps
REX.B bit of REX prefix can
extend this field to 4 bits
The encodings of ModRM and SIB bytes not only define memory-addressing modes, but they also
specify operand registers. The encodings do this by using 3-bit fields in the ModRM and SIB bytes,
depending on the format:
• ModRM: the reg and r/m fields of the ModRM byte. (Case 1 in Figure 1-3 on page 15 shows an
example of this).
• ModRM with SIB: the reg field of the ModRM byte and the base and index fields of the SIB byte.
(Case 3 in Figure 1-3 on page 15 shows an example of this).
18 Instruction Formats
24594—Rev. 3.14—September 2007 AMD64 Technology
• Instructions without ModRM: the reg field of the opcode. (Case 4 in Figure 1-3 on page 15 shows
an example of this).
In 64-bit mode, the bits needed to extend each field for accessing the additional registers are provided
by the REX prefixes, as shown in Figure 1-4 and Figure 1-5 on page 18.
For details on opcode encoding, see Appendix A, “Opcode and Operand Encodings.”
Instruction Formats 19
AMD64 Technology 24594—Rev. 3.14—September 2007
Without RIP-relative addressing, ModRM instructions address memory relative to zero. With RIP-
relative addressing, ModRM instructions can address memory relative to the 64-bit RIP using a signed
32-bit displacement. This provides an offset range of ±2 Gbytes from the RIP.
Programs usually have many references to data, especially global data, that are not register-based. To
load such a program, the loader typically selects a location for the program in memory and then adjusts
program references to global data based on the load location. RIP-relative addressing of data makes
this adjustment unnecessary.
1.7.1 Encoding
Table 1-13 shows the ModRM and SIB encodings for RIP-relative addressing. Redundant forms of 32-
bit displacement-only addressing exist in the current ModRM and SIB encodings. There is one
ModRM encoding with several SIB encodings. RIP-relative addressing is encoded using one of the
redundant forms. In 64-bit mode, the ModRM Disp32 (32-bit displacement) encoding is redefined to
be RIP + Disp32 rather than displacement-only.
20 Instruction Formats
24594—Rev. 3.14—September 2007 AMD64 Technology
2 Instruction Overview
Instruction Overview 21
AMD64 Technology 24594—Rev. 3.14—September 2007
22 Instruction Overview
24594—Rev. 3.14—September 2007 AMD64 Technology
In most modern assemblers, the AAM instruction adjusts to base-10 values. However,
by coding the instruction directly in binary, it can adjust to any base specified by the
immediate byte value (ib) suffixed onto the D4h opcode. For example, code D408h for
octal, D40Ah for decimal, and D40Ch for duodecimal (base 12).
rFLAGS Affected
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Divide by zero, #DE X X X 8-bit immediate value was 0.
Invalid opcode, #UD X This instruction was executed in 64-bit mode.
AAM 63
Instruction Overview 23
AMD64 Technology 24594—Rev. 3.14—September 2007
Registers. The size and number of general-purpose registers (GPRs) depends on the operating mode,
as do the size of the flags and instruction-pointer registers. Figure 2-2 shows the registers available in
legacy and compatibility modes.
0 AH (4) AL AX EAX
3 BH (7) BL BX EBX
1 CH (5) CL CX ECX
2 DH (6) DL DX EDX
6 SI SI ESI
7 DI DI EDI
5 BP BP EBP
4 SP SP ESP
31 16 15 0
IP IP EIP
31 0
513-311.eps
Figure 2-3 on page 25 shows the registers accessible in 64-bit mode. Compared with legacy mode,
registers become 64 bits wide, eight new data registers (R8–R15) are added and the low byte of all 16
GPRs is available for byte operations, and the four high-byte registers of legacy mode (AH, BH, CH,
and DH) are not available if the REX prefix is used. The high 32 bits of doubleword operands are zero-
extended to 64 bits, but the high bits of word and byte operands are not modified by operations in 64-
24 Instruction Overview
24594—Rev. 3.14—September 2007 AMD64 Technology
bit mode. The RFLAGS register is 64 bits wide, but the high 32 bits are reserved. They can be written
with anything but they read as zeros (RAZ).
0 RFLAGS 513-309.eps
RIP
63 32 31 0 * Not addressable when
a REX prefix is used.
** Only addressable when
a REX prefix is used.
For most instructions running in 64-bit mode, access to the extended GPRs requires a REX instruction
prefix (page 11).
Instruction Overview 25
AMD64 Technology 24594—Rev. 3.14—September 2007
Figure 2-4 shows the segment registers which, like the instruction pointer, are used by all instructions.
In legacy and compatibility modes, all segments are accessible. In 64-bit mode, which uses the flat
(non-segmented) memory model, only the CS, FS, and GS segments are recognized, whereas the
contents of the DS, ES, and SS segment registers are ignored (the base for each of these segments is
assumed to be zero, and neither their segment limit nor attributes are checked). For details, see
“Segmented Virtual Memory” in Volume 2.
CS CS
(Attributes only)
DS ignored
ES ignored
FS FS
(Base only)
GS GS
(Base only)
SS ignored
15 0 15 0
513-312.eps
Data Types. Figure 2-5 on page 27 shows the general-purpose data types. They are all scalar, integer
data types. The 64-bit (quadword) data types are only available in 64-bit mode, and for most
instructions they require a REX instruction prefix.
26 Instruction Overview
24594—Rev. 3.14—September 2007 AMD64 Technology
Signed Integer
127 0
s 16 bytes (64-bit mode only) Double
Quadword
s 8 bytes (64-bit mode only) Quadword
63 s 4 bytes Doubleword
31 s 2 bytes Word
15 s Byte
7 0
Unsigned Integer
127 0
Packed BCD
BCD Digit
7 3 Bit
513-326.eps
0
Registers. The system instructions use several specialized registers shown in Figure 2-6 on page 28.
System software uses these registers to, among other things, manage the processor’s operating
environment, define system resource characteristics, and monitor software execution. With the
exception of the RFLAGS register, system registers can be read and written only from privileged
software.
All system registers are 64 bits wide, except for the descriptor-table registers and the task register,
which include 64-bit base-address fields and other fields.
Instruction Overview 27
AMD64 Technology 24594—Rev. 3.14—September 2007
DR7 MCG_STAT
TR
513-260.eps
Data Structures. Figure 2-7 on page 29 shows the system data structures. These are created and
maintained by system software for use in protected mode. A processor running in protected mode uses
these data structures to manage memory and protection, and to store program-state information when
an interrupt or task switch occurs.
28 Instruction Overview
24594—Rev. 3.14—September 2007 AMD64 Technology
Descriptor Tables
Page-Translation Tables
513-261.eps
Registers. The 128-bit media instructions use the 128-bit XMM registers. The number of available
XMM data registers depends on the operating mode, as shown in Figure 2-8 on page 30. In legacy and
compatibility modes, the eight legacy XMM data registers (XMM0–XMM7) are available. In 64-bit
mode, eight additional XMM data registers (XMM8–XMM15) are available when a REX instruction
prefix is used.
The MXCSR register contains floating-point and other control and status flags used by the 128-bit
media instructions. Some 128-bit media instructions also use the GPR (Figure 2-2 and Figure 2-3) and
Instruction Overview 29
AMD64 Technology 24594—Rev. 3.14—September 2007
the MMX registers (Figure 2-10 on page 32) or set or clear flags in the rFLAGS register (see
Figure 2-2 and Figure 2-3).
xmm0
xmm1
xmm2
xmm3
xmm4
xmm5
xmm6
xmm7
xmm8
xmm9
xmm10
xmm11
xmm12
xmm13
xmm14
xmm15
Data Types. Figure 2-9 on page 31 shows the 128-bit media data types. They include floating-point
and integer vectors and floating-point scalars. The floating-point data types include IEEE-754 single
precision and double precision types.
30 Instruction Overview
24594—Rev. 3.14—September 2007 AMD64 Technology
quadword quadword
byte byte byte byte byte byte byte byte byte byte byte byte byte byte byte byte
127 119 111 103 95 87 79 71 63 55 47 39 31 23 15 7 0
ss exp significand
63 51 ss exp significand
31 22 0
Scalar Unsigned Integers
Instruction Overview 31
AMD64 Technology 24594—Rev. 3.14—September 2007
Registers. The 64-bit media instructions use the eight 64-bit MMX registers, as shown in
Figure 2-10. These registers are mapped onto the x87 floating-point registers, and 64-bit media
instructions write the x87 tag word in a way that prevents an x87 instruction from using MMX data.
Some 64-bit media instructions also use the GPR (Figure 2-2 and Figure 2-3) and the XMM registers
(Figure 2-8).
mmx0
mmx1
mmx2
mmx3
mmx4
mmx5
mmx6
mmx7
513-327.eps
Data Types. Figure 2-11 on page 33 shows the 64-bit media data types. They include floating-point
and integer vectors and integer scalars. The floating-point data type, used by 3DNow! instructions,
consists of a packed vector or two IEEE-754 32-bit single-precision data types. Unlike other kinds of
floating-point instructions, however, the 3DNow!™ instructions do not generate floating-point
exceptions. For this reason, there is no register for reporting or controlling the status of exceptions in
the 64-bit-media instruction subset.
32 Instruction Overview
24594—Rev. 3.14—September 2007 AMD64 Technology
doubleword doubleword
Signed Integers
s quadword
63 s doubleword
31 s word
15 s byte
7 0
Unsigned Integers
quadword
63 doubleword
31 word
15 byte
7
513-319.eps 0
Instruction Overview 33
AMD64 Technology 24594—Rev. 3.14—September 2007
Registers. The x87 floating-point instructions use the x87 registers shown in Figure 2-12. There are
eight 80-bit data registers, three 16-bit registers that hold the x87 control word, status word, and tag
word, and three registers (last instruction pointer, last opcode, last data pointer) that hold information
about the last x87 operation.
The physical data registers are named FPR0–FPR7, although x87 software references these registers as
a stack of registers, named ST(0)–ST(7). The x87 instructions store operands only in their own 80-bit
floating-point registers or in memory. They do not access the GPR or XMM registers.
fpr0
fpr1
fpr2
fpr3
fpr4
fpr5
fpr6
fpr7
Data Types. Figure 2-13 on page 35 shows all x87 data types. They include three floating-point
formats (80-bit double-extended precision, 64-bit double precision, and 32-bit single precision), three
signed-integer formats (quadword, doubleword, and word), and an 80-bit packed binary-coded
decimal (BCD) format.
34 Instruction Overview
24594—Rev. 3.14—September 2007 AMD64 Technology
Floating-Point
79 63 0
Double-Extended
s exp i significand Precision
79 s exp significand Double Precision
63 51 s exp significand Single Precision
31 22 0
Signed Integer
s 8 bytes Quadword
63 4 bytes
s Doubleword
31 s 2 bytes Word
15 0
ss Packed Decimal
79 71 0
513-317.eps
Instruction Overview 35
AMD64 Technology 24594—Rev. 3.14—September 2007
36 Instruction Overview
24594—Rev. 3.14—September 2007 AMD64 Technology
2.5 Notation
2.5.1 Mnemonic Syntax
Each instruction has a syntax that includes the mnemonic and any operands that the instruction can
take. Figure 2-14 shows an example of a syntax in which the instruction takes two operands. In most
instructions that take two operands, the first (left-most) operand is both a source operand (the first
source operand) and the destination operand. The second (right-most) operand serves only as a source,
not a destination.
Mnemonic
The following notation is used to denote the size and type of source and destination operands:
• cReg—Control register.
• dReg—Debug register.
• imm8—Byte (8-bit) immediate.
• imm16—Word (16-bit) immediate.
• imm16/32—Word (16-bit) or doubleword (32-bit) immediate.
• imm32—Doubleword (32-bit) immediate.
• imm32/64—Doubleword (32-bit) or quadword (64-bit) immediate.
• imm64—Quadword (64-bit) immediate.
• mem—An operand of unspecified size in memory.
• mem8—Byte (8-bit) operand in memory.
• mem16—Word (16-bit) operand in memory.
• mem16/32—Word (16-bit) or doubleword (32-bit) operand in memory.
• mem32—Doubleword (32-bit) operand in memory.
• mem32/48—Doubleword (32-bit) or 48-bit operand in memory.
• mem48—48-bit operand in memory.
Instruction Overview 37
AMD64 Technology 24594—Rev. 3.14—September 2007
38 Instruction Overview
24594—Rev. 3.14—September 2007 AMD64 Technology
Instruction Overview 39
AMD64 Technology 24594—Rev. 3.14—September 2007
• ib, iw, id, iq—Specifies an immediate-operand value. The opcode determines whether the value is
signed or unsigned. The value following the opcode, ModRM, or SIB byte is either one byte (ib),
two bytes (iw), or four bytes (id). Word and doubleword values start with the low-order byte.
• +rb, +rw, +rd, +rq—Specifies a register value that is added to the hexadecimal byte on the left,
forming a one-byte opcode. The result is an instruction that operates on the register specified by the
register code. Valid register-code values are shown in Table 2-2.
• m64—Specifies a quadword (64-bit) operand in memory.
• +i—Specifies an x87 floating-point stack operand, ST(i). The value is used only with x87 floating-
point instructions. It is added to the hexadecimal byte on the left, forming a one-byte opcode. Valid
values range from 0 to 7.
40 Instruction Overview
24594—Rev. 3.14—September 2007 AMD64 Technology
/////////////////////////////////////////////////////////////////////////////////
// Basic Definitions
/////////////////////////////////////////////////////////////////////////////////
REAL_MODE = (cr0.pe=0)
PROTECTED_MODE = ((cr0.pe=1) && (rflags.vm=0))
VIRTUAL_MODE = ((cr0.pe=1) && (rflags.vm=1))
LEGACY_MODE = (efer.lma=0)
LONG_MODE = (efer.lma=1)
64BIT_MODE = ((efer.lma=1) && (cs.L=1) && (cs.d=0))
COMPATIBILITY_MODE = (efer.lma=1) && (cs.L=0)
PAGING_ENABLED = (cr0.pg=1)
ALIGNMENT_CHECK_ENABLED = ((cr0.am=1) && (eflags.ac=1) && (cpl=3))
CPL = the current privilege level (0-3)
OPERAND_SIZE = 16, 32, or 64 (depending on current code and 66h/rex prefixes)
ADDRESS_SIZE = 16, 32, or 64 (depending on current code and 67h prefixes)
STACK_SIZE = 16, 32, or 64 (depending on current code and SS.attr.B)
Instruction Overview 41
AMD64 Technology 24594—Rev. 3.14—September 2007
V = 2 if OPERAND_SIZE=16
4 if OPERAND_SIZE=32
8 if OPERAND_SIZE=64
Z = 2 if OPERAND_SIZE=16
4 if OPERAND_SIZE=32
4 if OPERAND_SIZE=64
A = 2 if ADDRESS_SIZE=16
4 if ADDRESS_SIZE=32
8 if ADDRESS_SIZE=64
S = 2 if STACK_SIZE=16
4 if STACK_SIZE=32
8 if STACK_SIZE=64
/////////////////////////////////////////////////////////////////////////////////
// Bit Range Inside a Register
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
// Moving Data From One Register To Another
/////////////////////////////////////////////////////////////////////////////////
42 Instruction Overview
24594—Rev. 3.14—September 2007 AMD64 Technology
/////////////////////////////////////////////////////////////////////////////////
// Bitwise Operations
/////////////////////////////////////////////////////////////////////////////////
temp = a AND b
temp = a OR b
temp = a XOR b
temp = NOT a
temp = a SHL b
temp = a SHR b
/////////////////////////////////////////////////////////////////////////////////
// Logical Operations
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
// IF-THEN-ELSE
/////////////////////////////////////////////////////////////////////////////////
IF (FOO)
...
IF (FOO)
...
ELSIF (BAR)
...
ELSE
Instruction Overview 43
AMD64 Technology 24594—Rev. 3.14—September 2007
...
/////////////////////////////////////////////////////////////////////////////////
// Exceptions
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
// READ_MEM
// General memory read. This zero-extends the data to 64 bits and returns it.
/////////////////////////////////////////////////////////////////////////////////
usage:
temp = READ_MEM.x [seg:offset] // where x is one of {v, z, b, w, d, q}
// and denotes the size of the memory read
definition:
44 Instruction Overview
24594—Rev. 3.14—September 2007 AMD64 Technology
/////////////////////////////////////////////////////////////////////////////////
// WRITE_MEM // General memory write
/////////////////////////////////////////////////////////////////////////////////
usage:
WRITE_MEM.x [seg:offset] = temp.x // where <X> is one of these:
// {V, Z, B, W, D, Q} and denotes the
Instruction Overview 45
AMD64 Technology 24594—Rev. 3.14—September 2007
definition:
46 Instruction Overview
24594—Rev. 3.14—September 2007 AMD64 Technology
/////////////////////////////////////////////////////////////////////////////////
// PUSH // Write data to the stack
/////////////////////////////////////////////////////////////////////////////////
usage:
PUSH.x temp // where x is one of these: {v, z, b, w, d, q} and
// denotes the size of the push
definition:
/////////////////////////////////////////////////////////////////////////////////
// POP // Read data from the stack, zero-extend it to 64 bits
/////////////////////////////////////////////////////////////////////////////////
usage:
POP.x temp // where x is one of these: {v, z, b, w, d, q} and
// denotes the size of the pop
definition:
/////////////////////////////////////////////////////////////////////////////////
// READ_DESCRIPTOR // Read 8-byte descriptor from GDT/LDT, return the descriptor
/////////////////////////////////////////////////////////////////////////////////
usage:
temp_descriptor = READ_DESCRIPTOR (selector, chktype)
// chktype field is one of the following:
// cs_chk used for far call and far jump
// clg_chk used when reading CS for far call or far jump through call gate
// ss_chk used when reading SS
// iret_chk used when reading CS for IRET or RETF
// intcs_chk used when readin the CS for interrupts and exceptions
definition:
Instruction Overview 47
AMD64 Technology 24594—Rev. 3.14—September 2007
IF (temp_desc.attr.p=0)
EXCEPTION [#NP(selector)]
RETURN (temp_desc)
/////////////////////////////////////////////////////////////////////////////////
// READ_IDT // Read an 8-byte descriptor from the IDT, return the descriptor
/////////////////////////////////////////////////////////////////////////////////
usage:
temp_idt_desc = READ_IDT (vector)
// "vector" is the interrupt vector number
definition:
48 Instruction Overview
24594—Rev. 3.14—September 2007 AMD64 Technology
EXCEPTION [#GP(vector*8+2)]
IF (temp_desc.attr.p=0)
EXCEPTION [#NP(vector*8+2)]
// segment-not-present exception, with an error code that
// indicates this idt gate
RETURN (temp_desc)
/////////////////////////////////////////////////////////////////////////////////
// READ_INNER_LEVEL_STACK_POINTER
// Read a new stack pointer (rsp or ss:esp) from the tss
/////////////////////////////////////////////////////////////////////////////////
usage:
temp_SS_desc:temp_RSP = READ_INNER_LEVEL_STACK_POINTER (new_cpl, ist_index)
definition:
IF (LONG_MODE)
{
IF (ist_index>0)
// if IST is selected, read an ISTn stack pointer from the tss
temp_RSP = READ_MEM.q [tss:ist_index*8+28]
ELSE // (ist_index=0)
// otherwise read an RSPn stack pointer from the tss
temp_RSP = READ_MEM.q [tss:new_cpl*8+4]
return (temp_RSP:temp_SS_desc)
Instruction Overview 49
AMD64 Technology 24594—Rev. 3.14—September 2007
/////////////////////////////////////////////////////////////////////////////////
// READ_BIT_ARRAY // Read 1 bit from a bit array in memory
/////////////////////////////////////////////////////////////////////////////////
usage:
temp_value = READ_BIT_ARRAY ([mem], bit_number)
definition:
50 Instruction Overview
24594—Rev. 3.14—September 2007 AMD64 Technology
The general-purpose instructions can be used in legacy mode or 64-bit long mode. Compilation of
general-purpose programs for execution in 64-bit long mode offers three primary advantages: access to
the eight extended, 64-bit general-purpose registers (for a register set consisting of GPR0–GPR15),
access to the 64-bit virtual address space, and access to the RIP-relative addressing mode.
For further information about the general-purpose instructions and register resources, see:
Instruction Reference 51
AMD64 Technology 24594—Rev. 3.14—September 2007
52 Instruction Reference
24594—Rev. 3.14—September 2007 AMD64 Technology
Related Instructions
AAD, AAM, AAS
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
U U U M U M
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are
blank. Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Invalid opcode, #UD X This instruction was executed in 64-bit mode.
Related Instructions
AAA, AAM, AAS
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
U M M U M U
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank.
Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Invalid opcode, #UD X This instruction was executed in 64-bit mode.
In most modern assemblers, the AAM instruction adjusts to base-10 values. However, by coding the
instruction directly in binary, it can adjust to any base specified by the immediate byte value (ib)
suffixed onto the D4h opcode. For example, code D408h for octal, D40Ah for decimal, and D40Ch for
duodecimal (base 12).
Using this instruction in 64-bit mode generates an invalid-opcode exception.
Related Instructions
AAA, AAD, AAS
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
U M M U M U
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M. Unaffected flags are blank. Undefined
flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Divide by zero, #DE X X X 8-bit immediate value was 0.
Invalid opcode, #UD X This instruction was executed in 64-bit mode.
Related Instructions
AAA, AAD, AAM
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
U U U M U M
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are
blank. Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Invalid opcode, #UD X This instruction was executed in 64-bit mode.
Related Instructions
ADD, SBB, SUB
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
M M M M M M
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank.
Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
A memory address exceeded a data segment limit or was non-
X X X
canonical.
General protection,
#GP X The destination operand was in a non-writable segment.
X A null data segment was used to reference memory.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, X X An unaligned memory reference was performed while
#AC alignment checking was enabled.
Related Instructions
ADC, SBB, SUB
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
M M M M M M
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are
blank. Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
A memory address exceeded a data segment limit or was non-
X X X
canonical.
General protection,
#GP X The destination operand was in a non-writable segment.
X A null data segment was used to reference memory.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, X X An unaligned memory reference was performed while
#AC alignment checking was enabled.
X Y X AND Y
0 0 0
0 1 0
1 0 0
1 1 1
The forms of the AND instruction that write to memory support the LOCK prefix. For details about the
LOCK prefix, see “Lock Prefix” on page 8.
AND AX, imm16 25 iw AND the contents of AX with an immediate 16-bit value
and store the result in AX.
AND the contents of EAX with an immediate 32-bit
AND EAX, imm32 25 id
value and store the result in EAX.
AND the contents of RAX with a sign-extended
AND RAX, imm32 25 id immediate 32-bit value and store the result in RAX.
AND reg/mem8, imm8 80 /4 ib AND the contents of reg/mem8 with imm8.
AND reg/mem16, imm16 81 /4 iw AND the contents of reg/mem16 with imm16.
AND reg/mem32, imm32 81 /4 id AND the contents of reg/mem32 with imm32.
AND the contents of reg/mem64 with sign-extended
AND reg/mem64, imm32 81 /4 id
imm32.
Related Instructions
TEST, OR, NOT, NEG, XOR
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
0 M M U M 0
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are
blank. Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
A memory address exceeded a data segment limit or was non-
X X X
canonical.
General protection,
#GP X The destination operand was in a non-writable segment.
X A null data segment was used to reference memory.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference was performed while
X X
#AC alignment checking was enabled.
Related Instructions
INT, INT3, INTO
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Bound range, #BR X X X The bound range was exceeded.
X X X The source operand was a register.
Invalid opcode, #UD
X Instruction was executed in 64-bit mode.
Stack, #SS X X X A memory address exceeded the stack segment limit
General protection, X X X A memory address exceeded a data segment limit.
#GP X A null data segment was used to reference memory.
Virtual
Exception Real 8086 Protected Cause of Exception
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference was performed while
X X
#AC alignment checking was enabled.
Related Instructions
BSR
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
U U M U U U
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are
blank. Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
A memory address exceeded a data segment limit or was non-
General protection, X X X
canonical.
#GP
X A null data segment was used to reference memory.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference was performed while
X X
#AC alignment checking was enabled.
Related Instructions
BSF
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
U U M U U U
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are
blank. Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
A memory address exceeded the data segment limit or was
General protection, X X X
non-canonical.
#GP
X A null data segment was used to reference memory.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference was performed while
X X
#AC alignment checking was enabled.
Related Instructions
XCHG
rFLAGS Affected
None
Exceptions
None
BT Bit Test
Copies a bit, specified by a bit index in a register or 8-bit immediate value (second operand), from a bit
string (first operand), also called the bit base, to the carry flag (CF) of the rFLAGS register.
If the bit base operand is a register, the instruction uses the modulo 16, 32, or 64 (depending on the
operand size) of the bit index to select a bit in the register.
If the bit base operand is a memory location, bit 0 of the byte at the specified address is the bit base of
the bit string. If the bit index is in a register, the instruction selects a bit position relative to the bit base
in the range –263 to +263 – 1 if the operand size is 64, –231 to +231 – 1, if the operand size is 32, and
–215 to +215 – 1 if the operand size is 16. If the bit index is in an immediate value, the bit selected is
that value modulo 16, 32, or 64, depending on operand size.
When the instruction attempts to copy a bit from memory, it accesses 2, 4, or 8 bytes starting from the
specified memory address for 16-bit, 32-bit, or 64-bit operand sizes, respectively, using the following
formula:
Effective Address + (NumBytesi * (BitOffset DIV NumBitsi*8))
When using this bit addressing mechanism, avoid referencing areas of memory close to address space
holes, such as references to memory-mapped I/O registers. Instead, use a MOV instruction to load a
register from such an address and use a register form of the BT instruction to manipulate the data.
Related Instructions
BTC, BTR, BTS
68 BT Instruction Reference
24594—Rev. 3.14—September 2007 AMD64 Technology
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
U U U U U M
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are
blank. Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
A memory address exceeded a data segment limit or was non-
General protection, X X X
canonical.
#GP
X A null data segment was used to reference memory.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference was performed while
#AC X X alignment checking was enabled.
Instruction Reference BT 69
AMD64 Technology 24594—Rev. 3.14—September 2007
BTC reg/mem16, imm8 0F BA /7 ib Copy the value of the selected bit to the carry flag, then
complement the selected bit.
Copy the value of the selected bit to the carry flag, then
BTC reg/mem32, imm8 0F BA /7 ib complement the selected bit.
Copy the value of the selected bit to the carry flag, then
BTC reg/mem64, imm8 0F BA /7 ib
complement the selected bit.
Related Instructions
BT, BTR, BTS
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
U U U U U M
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are
blank. Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
A memory address exceeded a data segment limit or was non-
X X X
canonical.
General protection,
#GP X The destination operand was in a non-writable segment.
X A null data segment was used to reference memory.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, X X An unaligned memory reference was performed while
#AC alignment checking was enabled.
BTR reg/mem16, imm8 0F BA /6 ib Copy the value of the selected bit to the carry flag, then
clear the selected bit.
Copy the value of the selected bit to the carry flag, then
BTR reg/mem32, imm8 0F BA /6 ib clear the selected bit.
Copy the value of the selected bit to the carry flag, then
BTR reg/mem64, imm8 0F BA /6 ib
clear the selected bit.
Related Instructions
BT, BTC, BTS
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
U U U U U M
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are
blank. Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
A memory address exceeded a data segment limit or was non-
X X X
canonical.
General protection,
#GP X The destination operand was in a non-writable segment.
X A null data segment was used to reference memory.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, X X An unaligned memory reference was performed while
#AC alignment checking was enabled.
BTS reg/mem16, imm8 0F BA /5 ib Copy the value of the selected bit to the carry flag, then
set the selected bit.
Copy the value of the selected bit to the carry flag, then
BTS reg/mem32, imm8 0F BA /5 ib set the selected bit.
Copy the value of the selected bit to the carry flag, then
BTS reg/mem64, imm8 0F BA /5 ib
set the selected bit.
Related Instructions
BT, BTC, BTR
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
U U U U U M
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are
blank. Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
A memory address exceeded a data segment limit or was non-
X X X
canonical.
General protection,
#GP X The destination operand was in a non-writable segment.
X A null data segment was used to reference memory.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, X X An unaligned memory reference was performed while
#AC alignment checking was enabled.
For details about control-flow instructions, see “Control Transfers” in Volume 1, and “Control-
Transfer Privilege Checks” in Volume 2.
Related Instructions
CALL(Far), RET(Near), RET(Far)
rFLAGS Affected
None.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
A memory address exceeded a data segment limit or was non-
X X X
canonical.
General protection,
#GP X X X The target offset exceeded the code segment limit or was non-
canonical.
X A null data segment was used to reference memory.
Alignment Check, An unaligned memory reference was performed while
#AC X X alignment checking was enabled.
Page Fault, #PF X X A page fault resulted from the execution of the instruction.
CALL FAR pntr16:32 9A cp Far call direct, with the target specified by a far pointer
contained in the instruction. (Invalid in 64-bit mode.)
Far call indirect, with the target specified by a far pointer
CALL FAR mem16:16 FF /3
in memory.
Far call indirect, with the target specified by a far pointer
CALL FAR mem16:32 FF /3
in memory.
Action
// See “Pseudocode Definitions” on page 41.
CALLF_START:
IF (REAL_MODE)
CALLF_REAL_OR_VIRTUAL
ELSIF (PROTECTED_MODE)
CALLF_PROTECTED
ELSE // (VIRTUAL_MODE)
CALLF_REAL_OR_VIRTUAL
CALLF_REAL_OR_VIRTUAL:
PUSH.v old_CS
PUSH.v next_RIP
IF (temp_RIP>CS.limit)
EXCEPTION [#GP(0)]
CS.sel = temp_CS
CS.base = temp_CS SHL 4
RIP = temp_RIP
EXIT
CALLF_PROTECTED:
IF (temp_desc.attr.type = ’available_tss’)
TASK_SWITCH // Using temp_sel as the target TSS selector.
ELSIF (temp_desc.attr.type = ’taskgate’)
TASK_SWITCH // Using the TSS selector in the task gate
// as the target TSS.
ELSIF (temp_desc.attr.type = ’code’)
// If the selector refers to a code descriptor, then
// the offset we read is the target RIP.
{
temp_RIP = temp_offset
CS = temp_desc
PUSH.v old_CS
PUSH.v next_RIP
IF ((!64BIT_MODE) && (temp_RIP > CS.limit))
// temp_RIP can’t be non-canonical because
EXCEPTION [#GP(0)] // it’s a 16- or 32-bit offset, zero-extended
// to 64 bits.
RIP = temp_RIP
EXIT
}
ELSE // (temp_desc.attr.type = ’callgate’)
// If the selector refers to a call gate, then
// the target CS and RIP both come from the call gate.
{
IF (LONG_MODE)
// The size of the gate controls the size of the stack pushes.
V=8-byte
// Long mode only uses 64-bit call gates, force 8-byte opsize.
ELSIF (temp_desc.attr.type = ’callgate32’)
V=4-byte
// Legacy mode, using a 32-bit call-gate, force 4-byte opsize.
ELSE // (temp_desc.attr.type = ’callgate16’)
V=2-byte
temp_RIP = temp_desc.offset
IF (CS.attr.conforming=1)
temp_CPL = CPL
ELSE
temp_CPL = CS.attr.dpl
IF (CPL=temp_CPL)
{
PUSH.v old_CS
PUSH.v next_RIP
RIP = temp_RIP
EXIT
}
ELSE // (CPL != temp_CPL), Changing privilege level.
{
CPL = temp_CPL
temp_ist = 0 // Call-far doesn’t use ist pointers.
temp_SS_desc:temp_RSP = READ_INNER_LEVEL_STACK_POINTER (CPL, temp_ist)
RSP.q = temp_RSP
SS = temp_SS_desc
PUSH.v old_SS // #SS on this and following pushes use
// SS.sel as error code.
PUSH.v old_RSP
IF (LEGACY_MODE) // Legacy-mode call gates have
{ // a param_count field.
temp_PARAM_COUNT = temp_desc.attr.param_count
Related Instructions
CALL (Near), RET (Near), RET (Far)
rFLAGS Affected
None, unless a task switch occurs, in which case all flags are modified.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
X X X The far CALL indirect opcode (FF /3) had a register operand.
Invalid opcode, #UD
X The far CALL direct opcode (9A) was executed in 64-bit mode.
As part of a stack switch, the target stack segment selector or
X
rSP in the TSS was beyond the TSS limit.
As part of a stack switch, the target stack segment selector in
X the TSS was a null selector.
As part of a stack switch, the target stack selector’s TI bit was
X
set, but LDT selector was a null selector.
As part of a stack switch, the target stack segment selector in
Invalid TSS, #TS X the TSS was beyond the limit of the GDT or LDT descriptor
(selector) table.
As part of a stack switch, the target stack segment selector in
X the TSS contained a RPL that was not equal to its DPL.
As part of a stack switch, the target stack segment selector in
X the TSS contained a DPL that was not equal to the CPL of the
code segment selector.
As part of a stack switch, the target stack segment selector in
X
the TSS was not a writable segment.
Virtual
Exception Real 8086 Protected Cause of Exception
Segment not
The accessed code segment, call gate, task gate, or TSS was
present, #NP X
not present.
(selector)
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical, and no stack switch occurred.
After a stack switch, a memory access exceeded the stack
X
segment limit or was non-canonical.
Stack, #SS
(selector) As part of a stack switch, the SS register was loaded with a
X non-null segment selector and the segment was marked not
present.
Related Instructions
CWD, CDQ, CQO
rFLAGS Affected
None
Exceptions
None
Related Instructions
CBW, CWDE, CDQE
rFLAGS Affected
None
Exceptions
None
Related Instructions
STC, CMC
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank.
Undefined flags are U.
Exceptions
None
Related Instructions
CMPSx, INSx, LODSx, MOVSx, OUTSx, SCASx, STD, STOSx
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are
blank. Undefined flags are U.
Exceptions
None
Related Instructions
INVD, WBINVD
rFLAGS Affected
None
Exceptions
Virtual
Exception (vector) Real 8086 Protected Cause of Exception
The CLFLUSH instruction is not supported, as
Invalid opcode, #UD X X X indicated by EDX bit 19 of CPUID function
0000_0001h.
A memory address exceeded the stack segment limit
Stack, #SS X X X
or was non-canonical.
A memory address exceeded a data segment limit or
General protection, X X X was non-canonical.
#GP
X A null data segment was used to reference memory.
A page fault resulted from the execution of the
Page fault, #PF X X
instruction.
Related Instructions
CLC, STC
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank.
Undefined flags are U.
Exceptions
None
Related Instructions
MOV
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
The CMOVcc instruction is not supported, as indicated by
Invalid opcode, #UD X X X EDX bit 15 of CPUID function 0000_0001h or function
8000_0001h.
Stack, #SS X X X A memory address exceeded the stack segment limit or was
non-canonical.
A memory address exceeded a data segment limit or was non-
General protection, X X X
canonical.
#GP
X A null data segment was used to reference memory.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference was performed while
#AC X X alignment checking was enabled.
CMP Compare
Compares the contents of a register or memory location (first operand) with an immediate value or the
contents of a register or memory location (second operand), and sets or clears the status flags in the
rFLAGS register to reflect the results. To perform the comparison, the instruction subtracts the second
operand from the first operand and sets the status flags in the same manner as the SUB instruction, but
does not alter the first operand. If the second operand is an immediate value, the instruction sign-
extends the value to the length of the first operand.
Use the CMP instruction to set the condition codes for a subsequent conditional jump (Jcc),
conditional move (CMOVcc), or conditional SETcc instruction. Appendix E, “Instruction Effects on
RFLAGS,” shows how instructions affect the rFLAGS status flags.
.
CMP reg/mem8, imm8 80 /7 ib Compare an 8-bit immediate value with the contents of
an 8-bit register or memory operand.
Compare a 16-bit immediate value with the contents of
CMP reg/mem16, imm16 81 /7 iw
a 16-bit register or memory operand.
Compare a 32-bit immediate value with the contents of
CMP reg/mem32, imm32 81 /7 id
a 32-bit register or memory operand.
Compare a 32-bit signed immediate value with the
CMP reg/mem64, imm32 81 /7 id
contents of a 64-bit register or memory operand.
Compare an 8-bit signed immediate value with the
CMP reg/mem16, imm8 83 /7 ib
contents of a 16-bit register or memory operand.
CMP reg/mem32, imm8 83 /7 ib Compare an 8-bit signed immediate value with the
contents of a 32-bit register or memory operand.
Compare an 8-bit signed immediate value with the
CMP reg/mem64, imm8 83 /7 ib
contents of a 64-bit register or memory operand.
Compare the contents of an 8-bit register or memory
CMP reg/mem8, reg8 38 /r
operand with the contents of an 8-bit register.
CMP reg16, reg/mem16 3B /r Compare the contents of a 16-bit register with the
contents of a 16-bit register or memory operand.
Compare the contents of a 32-bit register with the
CMP reg32, reg/mem32 3B /r
contents of a 32-bit register or memory operand.
Compare the contents of a 64-bit register with the
CMP reg64, reg/mem64 3B /r
contents of a 64-bit register or memory operand.
Operands CF ZF
dest = source 0 1
Operands OF ZF
dest = source 0 1
Related Instructions
SUB, CMPSx, SCASx
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
M M M M M M
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are
blank. Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
A memory address exceeded a data segment limit or was non-
General protection, X X X
canonical.
#GP
X A null data segment was used to reference memory.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference was performed while
#AC X X alignment checking was enabled.
CMPSW A7 Compare the word at DS:rSI with the word at ES:rDI and
then increment or decrement rSI and rDI.
Compare the doubleword at DS:rSI with the doubleword
CMPSD A7
at ES:rDI and then increment or decrement rSI and rDI.
Compare the quadword at DS:rSI with the quadword at
CMPSQ A7
ES:rDI and then increment or decrement rSI and rDI.
Related Instructions
CMP, SCASx
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
M M M M M M
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank.
Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
A memory address exceeded a data segment limit or was non-
General protection, X X X
canonical.
#GP
X A null data segment was used to reference memory.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference was performed while
X X
#AC alignment checking was enabled.
Related Instructions
CMPXCHG8B, CMPXCHG16B
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
M M M M M M
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are
blank. Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
A memory address exceeded a data segment limit or was non-
X X X
canonical.
General protection,
#GP X The destination operand was in a non-writable segment.
X A null data segment was used to reference memory.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, X X An unaligned memory reference was performed while
#AC alignment checking was enabled.
Related Instructions
CMPXCHG
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are
blank. Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
The CMPXCHG8B instruction is not supported, as indicated
X X X by EDX bit 8 of CPUID function 0000_0001h or function
8000_0001h.
Invalid opcode, #UD
The CMPXCHG16B instruction is not supported, as indicated
X by ECX bit 13 of CPUID function 0000_0001h.
X X X The operand was a register.
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
A memory address exceeded a data segment limit or was non-
X X X canonical.
General protection, X The destination operand was in a non-writable segment.
#GP X A null data segment was used to reference memory.
The memory operand for CMPXCHG16B was not aligned on a
X
16-byte boundary.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference was performed while
X X
#AC alignment checking was enabled.
For more detailed on CPUID standard and extended functions, see the AMD CPUID Specification,
order# 25481.
Related Instructions
None
rFLAGS Affected
None
Exceptions
None
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
U M M M M M
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are
blank. Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Invalid opcode, #UD X This instruction was executed in 64-bit mode.
Related Instructions
DAA
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
U M M M M M
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank.
Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Invalid opcode, #UD X This instruction was executed in 64-bit mode.
DEC Decrement by 1
Subtracts 1 from the specified register or memory location. The CF flag is not affected.
The one-byte forms of this instruction (opcodes 48 through 4F) are used as REX prefixes in 64-bit
mode. See “REX Prefixes” on page 11.
The forms of the DEC instruction that write to memory support the LOCK prefix. For details about the
LOCK prefix, see “Lock Prefix” on page 8.
To perform a decrement operation that updates the CF flag, use a SUB instruction with an immediate
operand of 1.
Related Instructions
INC, SUB
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
M M M M M
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are
blank. Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X non-canonical.
A memory address exceeded the data segment limit or was
X X X
non-canonical.
General protection,
#GP X The destination operand was in a non-writable segment.
X A null data segment was used to reference memory.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference was performed while
X X
#AC alignment checking was enabled.
Double quadword/
RDX:RAX reg/mem64 RAX RDX 264 – 1
quadword
The instruction truncates non-integral results towards 0 and the remainder is always less than the
divisor. An overflow generates a #DE (divide error) exception, rather than setting the CF flag.
Division by zero generates a divide-by-zero exception.
Related Instructions
MUL
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
U U U U U U
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are
blank. Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
X X X The divisor operand was 0.
Divide by zero, #DE
X X X The quotient was too large for the designated register.
A memory address exceeded the stack segment limit or was
Stack, #SS X X X non-canonical.
The ENTER and LEAVE instructions provide support for block structured languages. The LEAVE
instruction releases the stack frame on returning from a procedure.
In 64-bit mode, the operand size of ENTER defaults to 64 bits, and there is no prefix available for
encoding a 32-bit operand size.
Action
// See “Pseudocode Definitions” on page 41.
ENTER_START:
PUSH.v old_RBP
RBP.v = temp_RBP
EXIT
Related Instructions
LEAVE
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack-segment limit or was
Stack, #SS X X X
non-canonical.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, X X An unaligned memory reference was performed while
#AC alignment checking was enabled.
Double quadword/
RDX:RAX reg/mem64 RAX RDX –2 63 to 263– 1
quadword
The instruction truncates non-integral results towards 0. The sign of the remainder is always the same
as the sign of the dividend, and the absolute value of the remainder is less than the absolute value of the
divisor. An overflow generates a #DE (divide error) exception, rather than setting the OF flag.
To avoid overflow problems, precede this instruction with a CBW, CWD, CDQ, or CQO instruction to
sign-extend the dividend.
Related Instructions
IMUL
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
U U U U U U
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are
blank. Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
X X X The divisor operand was 0.
Divide by zero, #DE
X X X The quotient was too large for the designated register.
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
A memory address exceeded a data segment limit or was non-
General protection, X X X canonical.
#GP
X A null data segment was used to reference memory.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference was performed while
X X
#AC alignment checking was enabled.
Related Instructions
IDIV
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
M U U U U M
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are
blank. Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
A memory address exceeded a data segment limit or was non-
General protection, X X X
canonical.
#GP
X A null data segment was used to reference memory.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference was performed while
X X
#AC alignment checking was enabled.
Related Instructions
INSx, OUT, OUTSx
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
One or more I/O permission bits were set in the TSS for the
X
General protection, accessed port.
#GP The CPL was greater than the IOPL and one or more I/O
X permission bits were set in the TSS for the accessed port.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
INC Increment by 1
Adds 1 to the specified register or memory location. The CF flag is not affected, even if the operand is
incremented to 0000.
The one-byte forms of this instruction (opcodes 40 through 47) are used as REX prefixes in 64-bit
mode. See “REX Prefixes” on page 11.
The forms of the INC instruction that write to memory support the LOCK prefix. For details about the
LOCK prefix, see “Lock Prefix” on page 8.
To perform an increment operation that updates the CF flag, use an ADD instruction with an
immediate operand of 1.
Related Instructions
ADD, DEC
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
M M M M M
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are
blank. Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
A memory address exceeded a data segment limit or was non-
X X X
canonical.
General protection,
#GP X The destination operand was in a non-writable segment.
X A null data segment was used to reference memory.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, X X An unaligned memory reference was performed while
#AC alignment checking was enabled.
Related Instructions
IN, OUT, OUTSx
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Action
// See “Pseudocode Definitions” on page 41.
INT_N_START:
IF (REAL_MODE)
INT_N_REAL
ELSIF (PROTECTED_MODE)
INT_N_PROTECTED
ELSE // (VIRTUAL_MODE)
INT_N_VIRTUAL
INT_N_REAL:
temp_int_n_vector = byte-sized interrupt vector specified in the instruction,
zero-extended to 64 bits
PUSH.w old_RFLAGS
PUSH.w old_CS
PUSH.w next_RIP
IF (temp_RIP>CS.limit)
EXCEPTION [#GP]
CS.sel = temp_CS
CS.base = temp_CS SHL 4
RFLAGS.AC,TF,IF,RF cleared
RIP = temp_RIP
EXIT
INT_N_PROTECTED:
IF (temp_idt_desc.attr.type = ’taskgate’)
TASK_SWITCH // using tss selector in the task gate as the target tss
temp_RIP = temp_idt_desc.offset
IF (LONG_MODE)
// In long mode, we need to read the 2nd half of a
// 16-byte interrupt-gate from the IDT, to get the
// upper 32 bits of the target RIP
{
temp_upper = READ_MEM.q [idt:temp_int_n_vector*16+8]
IF (CS.attr.conforming=1)
temp_CPL = CPL
ELSE
temp_CPL = CS.attr.dpl
PUSH.v old_RFLAGS
PUSH.v old_CS
PUSH.v next_RIP
RFLAGS.VM,NT,TF,RF cleared
RFLAGS.IF cleared if interrupt gate
RIP = temp_RIP
EXIT
}
ELSE // (CPL > temp_CPL), changing privilege level
{
CPL = temp_CPL
temp_SS_desc:temp_RSP = READ_INNER_LEVEL_STACK_POINTER
(CPL, temp_idt_desc.ist)
IF (LONG_MODE)
temp_RSP = temp_RSP AND 0xFFFFFFFFFFFFFFF0
// in long mode, interrupts/exceptions align rsp
// to a 16-byte boundary
RSP.q = temp_RSP
SS = temp_SS_desc
PUSH.v old_SS // #SS on the following pushes uses SS.sel as error code
PUSH.v old_RSP
PUSH.v old_RFLAGS
PUSH.v old_CS
PUSH.v next_RIP
RFLAGS.VM,NT,TF,RF cleared
RFLAGS.IF cleared if interrupt gate
RIP = temp_RIP
EXIT
}
INT_N_VIRTUAL:
IF (temp_VME_REDIRECTION_BIT=1)
{ // the virtual-mode int-n bitmap bit is set, so don’t
// redirect this interrupt
IF (RFLAGS.IOPL=3)
INT_N_VIRTUAL_TO_PROTECTED
ELSE
EXCEPTION [#GP(0)]
}
ELSE // redirect interrupt through virtual-mode idt
{
temp_RIP = READ_MEM.w [0:temp_int_n_vector*4]
// read target CS:RIP from the virtual-mode idt at
// linear address 0
temp_CS = READ_MEM.w [0:temp_int_n_vector*4+2]
IF (RFLAGS.IOPL < 3)
old_RFLAGS = old_RFLAGS with VIF bit shifted into IF bit, and IOPL = 3
PUSH.w old_RFLAGS
PUSH.w old_CS
PUSH.w next_RIP
CS.sel = temp_CS
CS.base = temp_CS SHL 4
RFLAGS.TF,RF cleared
RIP = temp_RIP // RFLAGS.IF cleared if IOPL = 3
// RFLAGS.VIF cleared if IOPL < 3
EXIT
}
INT_N_VIRTUAL_TO_PROTECTED:
IF ((temp_idt_desc.attr.type = ’intgate32’)
|| (temp_idt_desc.attr.type = ’trapgate32’))
// the size of the gate controls the size of the stack pushes
V=4-byte // legacy mode, using a 32-bit gate
ELSE // gate is intgate16 or trapgate16
V=2-byte // legacy mode, using a 16-bit gate
temp_RIP = temp_idt_desc.offset
CS = READ_DESCRIPTOR (temp_idt_desc.segment, intcs_chk)
CPL = 0
RSP.q = temp_RSP
SS = temp_SS_desc
PUSH.v old_GS // #SS on the following pushes use SS.sel as error code.
PUSH.v old_FS
PUSH.v old_DS
PUSH.v old_ES
PUSH.v old_SS
PUSH.v old_RSP
PUSH.v old_RFLAGS // Pushed with RF clear.
PUSH.v old_CS
PUSH.v next_RIP
RFLAGS.VM,NT,TF,RF cleared
RFLAGS.IF cleared if interrupt gate
RIP = temp_RIP
EXIT
Related Instructions
INT 3, INTO, BOUND
rFLAGS Affected
If a task switch occurs, all flags are modified. Otherwise settings are as follows:
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
M M M 0 M M 0
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are
blank. Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
As part of a stack switch, the target stack segment selector or
X X
rSP in the TSS was beyond the TSS limit.
As part of a stack switch, the target stack segment selector in
X X the TSS was a null selector.
As part of a stack switch, the target stack segment selector’s
X X
TI bit was set, but the LDT selector was a null selector.
As part of a stack switch, the target stack segment selector in
Invalid TSS, #TS X X the TSS was beyond the limit of the GDT or LDT descriptor
(selector) table.
As part of a stack switch, the target stack segment selector in
X X the TSS contained a RPL that was not equal to its DPL.
As part of a stack switch, the target stack segment selector in
X X the TSS contained a DPL that was not equal to the CPL of the
code segment selector.
As part of a stack switch, the target stack segment selector in
X X
the TSS was not a writable segment.
Segment not
present, #NP X X The accessed code segment, interrupt gate, trap gate, task
gate, or TSS was not present.
(selector)
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical, and no stack switch occurred.
After a stack switch, a memory address exceeded the stack
X X segment limit or was non-canonical.
Stack, #SS
(selector) As part of a stack switch, the SS register was loaded with a
X X non-null segment selector and the segment was marked not
present.
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded a data segment limit or was non-
X X X
canonical.
The target offset exceeded the code segment limit or was non-
X X X
General protection, canonical.
#GP X The IOPL was less than 3 and CR4.VME was 0.
IOPL was less than 3, CR4.VME was 1, and the
X corresponding bit in the VME interrupt redirection bitmap was
1.
X X X The interrupt vector was beyond the limit of IDT.
The descriptor in the IDT was not an interrupt, trap, or task
X X gate in legacy mode or not a 64-bit interrupt or trap gate in
long mode.
The DPL of the interrupt, trap, or task gate descriptor was less
X X
than the CPL.
The segment selector specified by the interrupt or trap gate
X X had its TI bit set, but the LDT selector was a null selector.
General protection,
#GP The segment descriptor specified by the interrupt or trap gate
(selector) X X
exceeded the descriptor table limit or was a null selector.
The segment descriptor specified by the interrupt or trap gate
X X was not a code segment in legacy mode, or not a 64-bit code
segment in long mode.
The DPL of the segment specified by the interrupt or trap gate
X
was greater than the CPL.
The DPL of the segment specified by the interrupt or trap gate
X pointed was not 0 or it was a conforming segment.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference was performed while
#AC X X alignment checking was enabled.
Action
IF (64BIT_MODE)
EXCEPTION[#UD]
IF (RFLAGS.OF = 1) // #OF is a trap, and pushes the rIP of the instruction
EXCEPTION [#OF] // following INTO.
EXIT
Related Instructions
INT, INT 3, BOUND
rFLAGS Affected
None.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Overflow, #OF X X X The INTO instruction was executed with 0F set to 1.
Invalid opcode, #UD X Instruction was executed in 64-bit mode.
where FarLabel is located in another code segment, use the opposite condition in a conditional short
jump before an unconditional far jump. Such a code sequence might look like:
cmp A,B ; compare operands
jne NextInstr ; continue program if not equal
jmp far FarLabel ; far jump if operands are equal
For details about control-flow instructions, see “Control Transfers” in Volume 1, and “Control-
Transfer Privilege Checks” in Volume 2.
Related Instructions
JMP (Near), JMP (Far), JrCXZ
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
General protection, The target offset exceeded the code segment limit or was non-
#GP X X X canonical.
Related Instructions
Jcc, JMP (Near), JMP (Far)
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
General protection, The target offset exceeded the code segment limit or was non-
X X X
#GP canonical
Related Instructions
JMP (Far), Jcc, JrCX
rFLAGS Affected
None.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X non-canonical.
A memory address exceeded a data segment limit or was non-
X X X
canonical.
General protection,
The target offset exceeded the code segment limit or was non-
#GP X X X
canonical.
X A null data segment was used to reference memory.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference was performed while
X X
#AC alignment checking was enabled.
JMP FAR mem16:32 FF /5 Far jump indirect, with the target specified by a far
pointer in memory.
Action
// Far jumps (JMPF)
// See “Pseudocode Definitions” on page 41.
JMPF_START:
IF (REAL_MODE)
JMPF_REAL_OR_VIRTUAL
ELSIF (PROTECTED_MODE)
JMPF_PROTECTED
ELSE // (VIRTUAL_MODE)
JMPF_REAL_OR_VIRTUAL
JMPF_REAL_OR_VIRTUAL:
IF (temp_RIP>CS.limit)
EXCEPTION [#GP(0)]
CS.sel = temp_CS
CS.base = temp_CS SHL 4
RIP = temp_RIP
EXIT
JMPF_PROTECTED:
IF (OPCODE = jmpf [mem]) // JMPF Indirect
{
temp_offset = READ_MEM.z [mem]
temp_sel = READ_MEM.w [mem+Z]
}
ELSE // (OPCODE = jmpf direct)
{
IF (64BIT_MODE)
EXCEPTION [#UD] // ’jmpf direct’ is illegal in 64-bit mode
IF (temp_desc.attr.type = ’available_tss’)
TASK_SWITCH // using temp_sel as the target tss selector
ELSIF (temp_desc.attr.type = ’taskgate’)
TASK_SWITCH // using the tss selector in the task gate as the
// target tss
ELSIF (temp_desc.attr.type = ’code’)
// if the selector refers to a code descriptor, then
// the offset we read is the target RIP
{
temp_RIP = temp_offset
CS = temp_desc
IF ((!64BIT_MODE) && (temp_RIP > CS.limit))
// temp_RIP can’t be non-canonical because
// it’s a 16- or 32-bit offset, zero-extended to 64 bits
{
EXCEPTION [#GP(0)]
}
RIP = temp_RIP
EXIT
}
ELSE
{
// (temp_desc.attr.type = ’callgate’)
// if the selector refers to a call gate, then
// the target CS and RIP both come from the call gate
temp_RIP = temp_desc.offset
IF (LONG_MODE)
{
// in long mode, we need to read the 2nd half of a 16-byte call-gate
// from the gdt/ldt to get the upper 32 bits of the target RIP
temp_upper = READ_MEM.q [temp_sel+8]
IF (temp_upper’s extended attribute bits != 0)
EXCEPTION [#GP(temp_sel)] // Make sure the extended
// attribute bits are all zero.
Related Instructions
JMP (Near), Jcc, JrCX
rFLAGS Affected
None, unless a task switch occurs, in which case all flags are modified.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
X X X The far JUMP indirect opcode (FF /5) had a register operand.
Invalid opcode, #UD The far JUMP direct opcode (EA) was executed in 64-bit
X
mode.
Segment not The accessed code segment, call gate, task gate, or TSS was
present, #NP X
not present.
(selector)
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
A memory address exceeded a data segment limit or was non-
X X X
canonical.
General protection, The target offset exceeded the code segment limit or was non-
#GP X X X
canonical.
X A null data segment was used to reference memory.
Virtual
Exception Real 8086 Protected Cause of Exception
X The target code segment selector was a null selector.
A code, call gate, task gate, or TSS descriptor exceeded the
X
descriptor table limit.
A segment selector’s TI bit was set, but the LDT selector was
X
a null selector.
The segment descriptor specified by the instruction was not a
code segment, task gate, call gate or available TSS in legacy
X
mode, or not a 64-bit code segment or a 64-bit call gate in long
mode.
The RPL of the non-conforming code segment selector
X specified by the instruction was greater than the CPL, or its
DPL was not equal to the CPL.
The DPL of the conforming code segment descriptor specified
X by the instruction was greater than the CPL.
General protection,
#GP
The DPL of the callgate, taskgate, or TSS descriptor specified
(selector) X by the instruction was less than the CPL or less than its own
RPL.
The segment selector specified by the call gate or task gate
X
was a null selector.
The segment descriptor specified by the call gate was not a
X code segment in legacy mode or not a 64-bit code segment in
long mode.
X The DPL of the segment descriptor specified the call gate was
greater than the CPL and it is a conforming segment.
The DPL of the segment descriptor specified by the callgate
X
was not equal to the CPL and it is a non-conforming segment.
X The 64-bit call gate’s extended attribute bits were not zero.
X The TSS descriptor was found in the LDT.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference was performed while
X X
#AC alignment checking was enabled.
Related Instructions
SAHF
rFLAGS Affected
None.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
This instruction is not supported in 64-bit mode, as indicated
Invalid opcode, #UD X
by ECX bit 0 returned by CPUID function 8000_0001h.
Related Instructions
None
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
X X X The source operand was a register.
Invalid opcode, #UD
X LDS or LES was executed in 64-bit mode.
Segment not
The DS, ES, FS, or GS register was loaded with a non-null
present, #NP X
segment selector and the segment was marked not present.
(selector)
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
Stack, #SS X The SS register was loaded with a non-null segment selector
(selector) and the segment was marked not present.
A memory address exceeded a data segment limit or was non-
General protection, X X X
canonical.
#GP
X A null data segment was used to reference memory.
A segment register was loaded, but the segment descriptor
X exceeded the descriptor table limit.
A segment register was loaded and the segment selector’s TI
X
bit was set, but the LDT selector was a null selector.
The SS register was loaded with a null segment selector in
X
non-64-bit mode or while CPL = 3.
General protection, The SS register was loaded and the segment selector RPL
X
#GP and the segment descriptor DPL were not equal to the CPL.
(selector)
X The SS register was loaded and the segment pointed to was
not a writable data segment.
The DS, ES, FS, or GS register was loaded and the segment
X pointed to was a data or non-conforming code segment, but
the RPL or CPL was greater than the DPL.
X The DS, ES, FS, or GS register was loaded and the segment
pointed to was not a data segment or readable code segment.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference was performed while
X X
#AC alignment checking was enabled.
However, LEA allows software to use any valid ModRM and SIB addressing mode for the source
operand. For example:
lea eax, [ebx+edi]
loads the sum of the EBX and EDI registers into the EAX register. This could not be accomplished by
a single MOV instruction.
The LEA instruction has a limited capability to perform multiplication of operands in general-purpose
registers using scaled-index addressing. For example:
lea eax, [ebx+ebx*8]
loads the value of the EBX register, multiplied by 9, into the EAX register. Possible values of
multipliers are 2, 4, 8, 3, 5, and 9.
The LEA instruction is widely used in string-processing and array-processing to initialize an index
register (rSI or rDI) before performing string instructions such as MOVSx. It is also used to initialize
the rBX register before performing the XLAT instruction in programs that perform character
translations. In data structures, the LEA instruction can calculate addresses of operands stored in
memory, and in particular, addresses of array or string elements.
Related Instructions
MOV
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Invalid opcode, #UD X X X The source operand was a register.
To return program control to the calling procedure, execute a RET instruction after the LEAVE
instruction.
In 64-bit mode, the LEAVE operand size defaults to 64 bits, and there is no prefix available for
encoding a 32-bit operand size.
Related Instructions
ENTER
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference was performed while
X X
#AC alignment checking was enabled.
Related Instructions
MFENCE, SFENCE
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
The LFENCE instruction is not supported as indicated by EDX
Invalid opcode, #UD X X X
bit 26 of CPUID function 0000_0001h.
Related Instructions
MOVSx, STOSx
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X non-canonical.
A memory address exceeded a data segment limit or was non-
General protection, X X X
canonical.
#GP
X A null data segment was used to reference memory.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference was performed while
#AC X X alignment checking was enabled.
LOOP Loop
LOOPE
LOOPNE
LOOPNZ
LOOPZ
Decrements the count register (rCX) by 1, then, if rCX is not 0 and the ZF flag meets the condition
specified by the mnemonic, it jumps to the target instruction specified by the signed 8-bit relative
offset. Otherwise, it continues with the next instruction after the LOOPcc instruction.
The size of the count register used (CX, ECX, or RCX) depends on the address-size attribute of the
LOOPcc instruction.
The LOOP instruction ignores the state of the ZF flag.
The LOOPE and LOOPZ instructions jump if rCX is not 0 and the ZF flag is set to 1. In other words,
the instruction exits the loop (falls through to the next instruction) if rCX becomes 0 or ZF = 0.
The LOOPNE and LOOPNZ instructions jump if rCX is not 0 and ZF flag is cleared to 0. In other
words, the instruction exits the loop if rCX becomes 0 or ZF = 1.
The LOOPcc instruction does not change the state of the ZF flag. Typically, the loop contains a
compare instruction to set or clear the ZF flag.
If the jump is taken, the signed displacement is added to the rIP (of the following instruction) and the
result is truncated to 16, 32, or 64 bits, depending on operand size.
In 64-bit mode, the operand size defaults to 64 bits without the need for a REX prefix, and the
processor sign-extends the 8-bit offset before adding it to the RIP.
LOOPE rel8off E1 cb Decrement rCX, then jump short if rCX is not 0 and ZF
is 1.
Decrement rCX, then Jump short if rCX is not 0 and ZF
LOOPNE rel8off E0 cb
is 0.
Decrement rCX, then Jump short if rCX is not 0 and ZF
LOOPNZ rel8off E0 cb
is 0.
Decrement rCX, then Jump short if rCX is not 0 and ZF
LOOPZ rel8off E1 cb
is 1.
Related Instructions
None
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
General protection, The target offset exceeded the code segment limit or was non-
X X X
#GP canonical.
Related Instructions
BSF, BSR, POPCNT
rFLAGS Affected
U U M U U M
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are
blank. Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or
Stack, #SS X X X
was non-canonical.
A memory address exceeded a data segment limit or was
X X X
General protection, #GP non-canonical.
X A null data segment was used to reference memory.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
An unaligned memory reference was performed while
Alignment check, #AC X X alignment checking was enabled.
Related Instructions
LFENCE, SFENCE
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
The MFENCE instruction is not supported as indicated by bit
Invalid opcode, #UD X X X
26 of CPUID function 0000_0001h.
MOV Move
Copies an immediate value or the value in a general-purpose register, segment register, or memory
location (second operand) to a general-purpose register, segment register, or memory location. The
source and destination must be the same size (byte, word, doubleword, or quadword) and cannot both
be memory locations.
In opcodes A0 through A3, the memory offsets (called moffsets) are address sized. In 64-bit mode,
memory offsets default to 64 bits. Opcodes A0–A3, in 64-bit mode, are the only cases that support a
64-bit offset value. (In all other cases, offsets and displacements are a maximum of 32 bits.) The B8
through BF (B8 +rq) opcodes, in 64-bit mode, are the only cases that support a 64-bit immediate value
(in all other cases, immediate values are a maximum of 32 bits).
When reading segment-registers with a 32-bit operand size, the processor zero-extends the 16-bit
selector results to 32 bits. When reading segment-registers with a 64-bit operand size, the processor
zero-extends the 16-bit selector to 64 bits. If the destination operand specifies a segment register (DS,
ES, FS, GS, or SS), the source operand must be a valid segment selector.
It is possible to move a null segment selector value (0000–0003h) into the DS, ES, FS, or GS register.
This action does not cause a general protection fault, but a subsequent reference to such a segment
does cause a #GP exception. For more information about segment selectors, see “Segment Selectors
and Registers” on page 67.
When the MOV instruction is used to load the SS register, the processor blocks external interrupts until
after the execution of the following instruction. This action allows the following instruction to be a
MOV instruction to load a stack pointer into the ESP register (MOV ESP,val) before an interrupt
occurs. However, the LSS instruction provides a more efficient method of loading SS and ESP.
Attempting to use the MOV instruction to load the CS register generates an invalid opcode exception
(#UD). Use the far JMP, CALL, or RET instructions to load the CS register.
To initialize a register to 0, rather than using a MOV instruction, it may be more efficient to use the
XOR instruction with identical destination and source operands.
MOV RAX, moffset64 A1 Move 64-bit data at a specified memory offset to the
RAX register.
Move the contents of the AL register to an 8-bit memory
MOV moffset8, AL A2
offset.
Move the contents of the AX register to a 16-bit memory
MOV moffset16, AX A3 offset.
Move the contents of the EAX register to a 32-bit
MOV moffset32, EAX A3
memory offset.
Move the contents of the RAX register to a 64-bit
MOV moffset64, RAX A3 memory offset.
MOV reg8, imm8 B0 +rb ib Move an 8-bit immediate value into an 8-bit register.
MOV reg16, imm16 B8 +rw iw Move a 16-bit immediate value into a 16-bit register.
MOV reg32, imm32 B8 +rd id Move an 32-bit immediate value into a 32-bit register.
MOV reg64, imm64 B8 +rq iq Move an 64-bit immediate value into a 64-bit register.
Move an 8-bit immediate value to an 8-bit register or
MOV reg/mem8, imm8 C6 /0 ib
memory operand.
Move a 16-bit immediate value to a 16-bit register or
MOV reg/mem16, imm16 C7 /0 iw
memory operand.
Move a 32-bit immediate value to a 32-bit register or
MOV reg/mem32, imm32 C7 /0 id
memory operand.
Related Instructions
MOV(CRn), MOV(DRn), MOVD, MOVSX, MOVZX, MOVSXD, MOVSx
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Invalid opcode, #UD X X X An attempt was made to load the CS register.
Segment not
The DS, ES, FS, or GS register was loaded with a non-null
present, #NP X
segment selector and the segment was marked not present.
(selector)
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
Stack, #SS The SS register was loaded with a non-null segment selector,
X
(selector) and the segment was marked not present.
The diagrams in Figure 3-1 on page 160 illustrate the operation of the MOVD instruction.
xmm reg/mem32
127 32 31 0 31 0
0
xmm reg/mem64
127 64 63 0 63 0
0
reg/mem32 xmm
All operations 31 0 127 32 31 0
are "copy"
reg/mem64 xmm
63 0 127 64 63 0
mmx reg/mem32
63 32 31 0 31 0
0
mmx reg/mem64
63 0 63 0
reg/mem64 mmx
63 0 63 0
Related Instructions
MOVDQA, MOVDQU, MOVDQ2Q, MOVQ, MOVQ2DQ
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Description
The MMX instructions are not supported, as indicated
X X X
by EDX bit 23 of CPUID function 0000_0001h.
The SSE2 instructions are not supported, as indicated
X X X
Invalid opcode, #UD by EDX bit 26 of CPUID function 0000_0001.
X X X The emulate bit (EM) of CR0 was set to 1.
Page fault, #PF X X A page fault resulted from the execution of the
instruction.
x87 floating-point
An x87 floating-point exception was pending and the
exception pending, X X X
instruction referenced an MMX register.
#MF
reg32 xmm
31 1 0 127 63 0
0
copy sign
copy sign
movmskpd.eps
Related Instructions
MOVMSKPS, PMOVMSKB
rFLAGS Affected
None
Exceptions
Virtual
Exception (vector) Real 8086 Protected Cause of Exception
The SSE2 instructions are not supported, as indicated
X X X by EDX bit 26 of CPUID function 0000_0001h.
Invalid opcode, #UD The operating-system FXSAVE/FXRSTOR support bit
X X X
(OSFXSR) of CR4 was cleared to 0.
X X X The emulate bit (EM) of CR0 was set to 1.
Device not available,
X X X The task-switch bit (TS) of CR0 was set to 1.
#NM
reg32 xmm
31 3 0 127 95 63 31 0
0
movmskps.eps
Related Instructions
MOVMSKPD, PMOVMSKB
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
The SSE2 instructions are not supported, as indicated
X X X by EDX bit 26 of CPUID function 1.
Invalid opcode, #UD The operating-system FXSAVE/FXRSTOR support bit
X X X
(OSFXSR) of CR4 was cleared to 0.
X X X The emulate bit (EM) of CR0 was set to 1.
Device not available,
X X X The task-switch bit (TS) of CR0 was set to 1.
#NM
Related Instructions
MOVNTDQ, MOVNTPD, MOVNTPS, MOVNTQ
rFLAGS Affected
None
Exceptions
Virtual
Exception (vector) Real 8086 Protected Cause of Exception
The SSE2 instructions are not supported, as indicated
Invalid opcode, #UD X X X
by EDX bit 26 of CPUID function 0000_0001h.
A memory address exceeded the stack segment limit
Stack, #SS X X X
or was non-canonical.
Virtual
Exception (vector) Real 8086 Protected Cause of Exception
A page fault resulted from the execution of the
Page fault, #PF X X
instruction.
MOVS mem64, mem64 A5 Move quadword at DS:rSI to ES:rDI, and then increment
or decrement rSI and rDI.
Move byte at DS:rSI to ES:rDI, and then increment or
MOVSB A4
decrement rSI and rDI.
Move word at DS:rSI to ES:rDI, and then increment or
MOVSW A5
decrement rSI and rDI.
Related Instructions
MOV, LODSx, STOSx
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X non-canonical.
Related Instructions
MOVSXD, MOVZX
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
A memory address exceeded a data segment limit or was non-
General protection, X X X canonical.
#GP
X A null data segment was used to reference memory.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference was performed while
X X
#AC alignment checking was enabled.
Related Instructions
MOVSX, MOVZX
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Stack, #SS X A memory address was non-canonical.
General protection,
#GP X A memory address was non-canonical.
Page fault, #PF X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference was performed while
X
#AC alignment checking was enabled.
Related Instructions
MOVSXD, MOVSX
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
A memory address exceeded a data segment limit or was non-
General protection, X X X canonical.
#GP
X A null data segment was used to reference memory.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference was performed while
X X
#AC alignment checking was enabled.
Related Instructions
DIV
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
M U U U U M
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank.
Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X non-canonical.
A memory address exceeded a data segment limit or was non-
General protection, X X X
canonical.
#GP
X A null data segment was used to reference memory.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference is performed while alignment
X X
#AC checking was enabled.
Related Instructions
AND, NOT, OR, XOR
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
M M M M M M
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank.
Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X non-canonical.
A memory address exceeded a data segment limit or was non-
X X X
canonical.
General protection,
#GP X The destination operand is in a non-writable segment.
X A null data segment was used to reference memory.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference was performed while
X X
#AC alignment checking was enabled.
NOP No Operation
Does nothing. This one-byte instruction increments the rIP to point to next instruction in the
instruction stream, but does not affect the machine state in any other way.
The NOP instruction is an alias for XCHG rAX,rAX.
Related Instructions
None
rFLAGS Affected
None
Exceptions
None
Related Instructions
AND, NEG, OR, XOR
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
A memory address exceeded a data segment limit or was non-
X X X
canonical.
General protection,
#GP X The destination operand was in a non-writable segment.
X A null data segment was used to reference memory.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference is performed while alignment
#AC X X checking was enabled.
OR Logical OR
Performs a logical OR on the bits in a register, memory location, or immediate value (second operand)
and a register or memory location (first operand) and stores the result in the first operand location. The
two operands cannot both be memory locations.
If both corresponding bits are 0, the corresponding bit of the result is 0; otherwise, the corresponding
result bit is 1.
The forms of the OR instruction that write to memory support the LOCK prefix. For details about the
LOCK prefix, see “Lock Prefix” on page 8.
X Y X OR Y
0 0 0
0 1 1
1 0 1
1 1 1
Related Instructions
AND, NEG, NOT, XOR
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
0 M M U M 0
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are
blank. Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
A memory address exceeded a data segment limit or was non-
X X X
canonical.
General protection,
#GP X The destination operand was in a non-writable segment.
X A null data segment was used to reference memory.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference was performed while
#AC X X alignment checking was enabled.
Related Instructions
IN, INSx, OUTSx
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
One or more I/O permission bits were set in the TSS for the
X
General protection, accessed port.
#GP The CPL was greater than the IOPL and one or more I/O
X
permission bits were set in the TSS for the accessed port.
Page fault (#PF) X X A page fault resulted from the execution of the instruction.
Related Instructions
IN, INSx, OUT
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X non-canonical.
A memory address exceeded a data segment limit or was non-
X X X
canonical.
X A null data segment was used to reference memory.
General protection,
#GP One or more I/O permission bits were set in the TSS for the
X
accessed port.
The CPL was greater than the IOPL and one or more I/O
X
permission bits were set in the TSS for the accessed port.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference is performed while alignment
#AC X X checking was enabled.
PAUSE Pause
Improves the performance of spin loops, by providing a hint to the processor that the current code is in
a spin loop. The processor may use this to optimize power consumption while in the spin loop.
Architecturally, this instruction behaves like a NOP instruction.
Processors that do not support PAUSE treat this opcode as a NOP instruction.
Related Instructions
None
rFLAGS Affected
None
Exceptions
None
POP reg32 58 +rd Pop the top of the stack into a 32-bit register.
(No prefix for encoding this in 64-bit mode.)
POP reg64 58 +rq Pop the top of the stack into a 64-bit register.
Pop the top of the stack into the DS register.
POP DS 1F (Invalid in 64-bit mode.)
Pop the top of the stack into the ES register.
POP ES 07
(Invalid in 64-bit mode.)
Related Instructions
PUSH
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Invalid opcode, #UD X POP DS, POP ES, or POP SS was executed in 64-bit mode.
Segment not The DS, ES, FS, or GS register was loaded with a non-null
present, #NP X
(selector) segment selector and the segment was marked not present.
Related Instructions
PUSHA, PUSHAD
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Invalid opcode
X This instruction was executed in 64-bit mode.
(#UD)
Stack, #SS X X X A memory address exceeded the stack segment limit.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference was performed while
X X
#AC alignment checking was enabled.
Related Instructions
BSF, BSR, LZCNT
rFLAGS Affected
0 0 M 0 0 0
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are
blank. Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
The POPCNT instruction is not supported, as indicated by
Invalid opcode, #UD X X X ECX bit 23 as returned by CPUID function 0000_0001h.
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
Action
// See “Pseudocode Definitions” on page 41.
POPF_START:
IF (REAL_MODE)
POPF_REAL
ELSIF (PROTECTED_MODE)
POPF_PROTECTED
ELSE // (VIRTUAL_MODE)
POPF_VIRTUAL
POPF_REAL:
POP.v temp_RFLAGS
RFLAGS.v = temp_RFLAGS // VIF,VIP,VM unchanged
// RF cleared
EXIT
POPF_PROTECTED:
POP.v temp_RFLAGS
RFLAGS.v = temp_RFLAGS // VIF,VIP,VM unchanged
// IOPL changed only if (CPL=0)
// IF changed only if (CPL<=old_RFLAGS.IOPL)
// RF cleared
EXIT
POPF_VIRTUAL:
IF (RFLAGS.IOPL=3)
{
POP.v temp_RFLAGS
RFLAGS.v = temp_RFLAGS // VIF,VIP,VM,IOPL unchanged
// RF cleared
EXIT
}
ELSIF ((CR4.VME=1) && (OPERAND_SIZE=16))
{
POP.w temp_RFLAGS
IF (((temp_RFLAGS.IF=1) && (RFLAGS.VIP=1)) || (temp_RFLAGS.TF=1))
EXCEPTION [#GP(0)]
// notify the virtual-mode-manager to deliver
// the task’s pending interrupts
RFLAGS.w = temp_RFLAGS // IF,IOPL unchanged
// RFLAGS.VIF=temp_RFLAGS.IF
// RF cleared
EXIT
}
ELSE // ((RFLAGS.IOPL<3) && ((CR4.VME=0) || (OPERAND_SIZE!=16)))
EXCEPTION [#GP(0)]
Related Instructions
PUSHF, PUSHFD, PUSHFQ
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
M M M 0 M M M M M M M M M M M
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank.
Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X non-canonical.
The I/O privilege level was less than 3 and one of the following
conditions was true:
• CR4.VME was 0.
General protection, • The effective operand size was 32-bit.
X
#GP
• Both the original EFLAGS.VIP and the new EFLAGS.IF bits
were set.
• The new EFLAGS.TF bit was set.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference was performed while
X X
#AC alignment checking was enabled.
Related Instructions
PREFETCHlevel
rFLAGS Affected
None
Exceptions
Virtual
Exception (vector) Real 8086 Protected Cause of Exception
The PREFETCH/W instructions are not supported, as
indicated when the following bits are all clear:
• PREFETCH/PREFETCHW are not supported, as
indicated by ECX bit 8 of CPUID function
8000_0001h
X X X
Invalid opcode, #UD • Long Mode is not supported, as indicated by EDX
bit 29 of CPUID function 8000_0001h
• The 3DNow!™ instructions are not supported, as
indicated by EDX bit 31 of CPUID function
8000_0001h.
X X X The operand was a register.
Related Instructions
PREFETCH, PREFETCHW
rFLAGS Affected
None
Exceptions
None
Related Instructions
POP
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
PUSH CS, PUSH DS, PUSH ES, or PUSH SS was executed
Invalid opcode, #UD X
in 64-bit mode.
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
Related Instructions
POPA, POPAD
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Invalid opcode, #UD X This instruction was executed in 64-bit mode.
Stack, #SS X X X A memory address exceeded the stack segment limit.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference was performed while
X X
#AC alignment checking was enabled.
Action
// See “Pseudocode Definitions” on page 41.
PUSHF_START:
IF (REAL_MODE)
PUSHF_REAL
ELSIF (PROTECTED_MODE)
PUSHF_PROTECTED
ELSE // (VIRTUAL_MODE)
PUSHF_VIRTUAL
PUSHF_REAL:
PUSH.v old_RFLAGS // Pushed with RF and VM cleared.
EXIT
PUSHF_PROTECTED:
PUSH.v old_RFLAGS // Pushed with RF cleared.
EXIT
PUSHF_VIRTUAL:
IF (RFLAGS.IOPL=3)
{
PUSH.v old_RFLAGS // Pushed with RF,VM cleared.
EXIT
}
Related Instructions
POPF, POPFD, POPFQ
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
General protection, The I/O privilege level was less than 3 and either VME was not
X
#GP enabled or the operand size was not 16-bit.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference was performed while
X X
#AC alignment checking was enabled.
RCL reg/mem32, 1 D1 /2 Rotate the 33 bits consisting of the carry flag and a 32-
bit register or memory location left 1 bit.
Rotate 33 bits consisting of the carry flag and a 32-bit
RCL reg/mem32, CL D3 /2 register or memory location left the number of bits
specified in the CL register.
Rotate the 33 bits consisting of the carry flag and a 32-
RCL reg/mem32, imm8 C1 /2 ib bit register or memory location left the number of bits
specified by an 8-bit immediate value.
Rotate the 65 bits consisting of the carry flag and a 64-
RCL reg/mem64, 1 D1 /2
bit register or memory location left 1 bit.
Related Instructions
RCR, ROL, ROR
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
M M
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are
blank. Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
A memory address exceeded a data segment limit or was non-
X X X
canonical.
General protection,
#GP X The destination operand was in a non-writable segment.
X A null data segment was used to reference memory.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference was performed while
X X
#AC alignment checking was enabled.
RCR reg/mem32,1 D1 /3 Rotate the 33 bits consisting of the carry flag and a 32-
bit register or memory location right 1 bit.
Rotate 33 bits consisting of the carry flag and a 32-bit
RCR reg/mem32,CL D3 /3 register or memory location right the number of bits
specified in the CL register.
Rotate the 33 bits consisting of the carry flag and a 32-
RCR reg/mem32, imm8 C1 /3 ib bit register or memory location right the number of bits
specified by an 8-bit immediate value.
Rotate the 65 bits consisting of the carry flag and a 64-
RCR reg/mem64,1 D1 /3
bit register or memory location right 1 bit.
Related Instructions
RCL, ROR, ROL
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
M M
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are
blank. Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
A memory address exceeded a data segment limit or was non-
X X X
canonical.
General protection,
#GP X The destination operand was in a non-writable segment.
X A null data segment was used to reference memory.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference was performed while
X X
#AC alignment checking was enabled.
Related Instructions
CALL (Near), CALL (Far), RET (Far)
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
General protection, The target offset exceeded the code segment limit or was non-
X X X
#GP canonical.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference was performed while
X X
#AC alignment checking was enabled.
RETF imm16 CA iw Far return to the calling procedure, then pop the
specified number of bytes from the stack.
Action
// Far returns (RETF)
// See “Pseudocode Definitions” on page 41.
RETF_START:
IF (REAL_MODE)
RETF_REAL_OR_VIRTUAL
ELSIF (PROTECTED_MODE)
RETF_PROTECTED
ELSE // (VIRTUAL_MODE)
RETF_REAL_OR_VIRTUAL
RETF_REAL_OR_VIRTUAL:
POP.v temp_RIP
POP.v temp_CS
CS.sel = temp_CS
CS.base = temp_CS SHL 4
RETF_PROTECTED:
POP.v temp_RIP
POP.v temp_CS
temp_CPL = temp_CS.rpl
IF (CPL=temp_CPL)
{
CS = READ_DESCRIPTOR (temp_CS, iret_chk)
RIP = temp_RIP
EXIT
}
ELSE // (CPL!=temp_CPL)
{
RSP.s = RSP + temp_IMM
POP.v temp_RSP
POP.v temp_SS
CPL = temp_CPL
IF (changing CPL)
{
FOR (seg = ES, DS, FS, GS)
IF ((seg.attr.dpl < CPL) && ((seg.attr.type = ’data’)
|| (seg.attr.type = ’non-conforming-code’)))
{
seg = NULL // can’t use lower dpl data segment at higher cpl
}
}
RIP = temp_RIP
EXIT
}
Related Instructions
CALL (Near), CALL (Far), RET (Near)
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Segment not
present, #NP X The return code segment was marked not present.
(selector)
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
Stack, #SS
X The return stack segment was marked not present.
(selector)
General protection, X X X The target offset exceeded the code segment limit or was non-
#GP canonical.
Virtual
Exception Real 8086 Protected Cause of Exception
X The return code selector was a null selector.
The return stack selector was a null selector and the return
X
mode was non-64-bit mode or CPL was 3.
The return code or stack descriptor exceeded the descriptor
X table limit.
The return code or stack selector’s TI bit was set but the LDT
X
selector was a null selector.
The segment descriptor for the return code was not a code
X
segment.
The RPL of the return code segment selector was less than
X
General protection, the CPL.
#GP
(selector) The return code segment was non-conforming and the
X segment selector’s DPL was not equal to the RPL of the code
segment’s segment selector.
The return code segment was conforming and the segment
X selector’s DPL was greater than the RPL of the code
segment’s segment selector.
The segment descriptor for the return stack was not a writable
X data segment.
The stack segment descriptor DPL was not equal to the RPL
X
of the return code segment selector.
The stack segment selector RPL was not equal to the RPL of
X the return code segment selector.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned-memory reference was performed while
#AC X X alignment checking was enabled.
ROL reg/mem16, imm8 C1 /0 ib Rotate a 16-bit register or memory operand left the
number of bits specified by an 8-bit immediate value.
ROL reg/mem32, 1 D1 /0 Rotate a 32-bit register or memory operand left 1 bit.
ROL reg/mem64, imm8 C1 /0 ib Rotate a 64-bit register or memory operand left the
number of bits specified by an 8-bit immediate value.
Related Instructions
RCL, RCR, ROR
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
M M
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are
blank. Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
A memory address exceeded a data segment limit or was non-
X X X
canonical.
General protection,
#GP X The destination operand was in a non-writable segment.
X A null data segment was used to reference memory.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, X X An unaligned memory reference was performed while
#AC alignment checking was enabled.
ROR reg/mem8, imm8 C0 /1 ib Rotate an 8-bit register or memory location right the
number of bits specified by an 8-bit immediate value.
ROR reg/mem16, 1 D1 /1 Rotate a 16-bit register or memory location right 1 bit.
Rotate a 16-bit register or memory location right the
ROR reg/mem16, CL D3 /1 number of bits specified in the CL register.
Rotate a 16-bit register or memory location right the
ROR reg/mem16, imm8 C1 /1 ib
number of bits specified by an 8-bit immediate value.
ROR reg/mem32, 1 D1 /1 Rotate a 32-bit register or memory location right 1 bit.
Rotate a 32-bit register or memory location right the
ROR reg/mem32, CL D3 /1
number of bits specified in the CL register.
Rotate a 32-bit register or memory location right the
ROR reg/mem32, imm8 C1 /1 ib
number of bits specified by an 8-bit immediate value.
ROR reg/mem64, 1 D1 /1 Rotate a 64-bit register or memory location right 1 bit.
Rotate a 64-bit register or memory operand right the
ROR reg/mem64, CL D3 /1
number of bits specified in the CL register.
ROR reg/mem64, imm8 C1 /1 ib Rotate a 64-bit register or memory operand right the
number of bits specified by an 8-bit immediate value.
Related Instructions
RCL, RCR, ROL
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
M M
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are
blank. Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
A memory address exceeded a data segment limit or was non-
X X X
canonical.
General protection,
#GP X The destination operand was in a non-writable segment.
X A null data segment was used to reference memory.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, X X An unaligned memory reference was performed while
#AC alignment checking was enabled.
Related Instructions
LAHF
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
M M M M M
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are
blank. Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
This instruction is not supported in 64-bit mode, as indicated
Invalid opcode, #UD X
by ECX bit 0 returned by CPUID function 8000_0001h.
SAL reg/mem8, imm8 C0 /4 ib Shift an 8-bit register or memory location left the number
of bits specified by an 8-bit immediate value.
SAL reg/mem16, 1 D1 /4 Shift a 16-bit register or memory location left 1 bit.
Shift a 16-bit register or memory location left the number
SAL reg/mem16, CL D3 /4
of bits specified in the CL register.
Shift a 16-bit register or memory location left the number
SAL reg/mem16, imm8 C1 /4 ib
of bits specified by an 8-bit immediate value.
SAL reg/mem32, 1 D1 /4 Shift a 32-bit register or memory location left 1 bit.
Shift a 32-bit register or memory location left the number
SAL reg/mem32, CL D3 /4
of bits specified in the CL register.
Shift a 32-bit register or memory location left the number
SAL reg/mem32, imm8 C1 /4 ib
of bits specified by an 8-bit immediate value.
SAL reg/mem64, 1 D1 /4 Shift a 64-bit register or memory location left 1 bit.
SAL reg/mem64, CL D3 /4 Shift a 64-bit register or memory location left the number
of bits specified in the CL register.
Shift a 64-bit register or memory location left the number
SAL reg/mem64, imm8 C1 /4 ib
of bits specified by an 8-bit immediate value.
SHL reg/mem8, CL D2 /4 Shift an 8-bit register or memory location left the number
of bits specified in the CL register.
Shift an 8-bit register or memory location left the number
SHL reg/mem8, imm8 C0 /4 ib
of bits specified by an 8-bit immediate value.
SHL reg/mem16, 1 D1 /4 Shift a 16-bit register or memory location left 1 bit.
Shift a 16-bit register or memory location left the number
SHL reg/mem16, CL D3 /4
of bits specified in the CL register.
SHL reg/mem16, imm8 C1 /4 ib Shift a 16-bit register or memory location left the number
of bits specified by an 8-bit immediate value.
SHL reg/mem32, 1 D1 /4 Shift a 32-bit register or memory location left 1 bit.
Shift a 32-bit register or memory location left the number
SHL reg/mem32, CL D3 /4 of bits specified in the CL register.
Shift a 32-bit register or memory location left the number
SHL reg/mem32, imm8 C1 /4 ib
of bits specified by an 8-bit immediate value.
SHL reg/mem64, 1 D1 /4 Shift a 64-bit register or memory location left 1 bit.
SHL reg/mem64, CL D3 /4 Shift a 64-bit register or memory location left the number
of bits specified in the CL register.
Shift a 64-bit register or memory location left the number
SHL reg/mem64, imm8 C1 /4 ib of bits specified by an 8-bit immediate value.
Related Instructions
SAR, SHR, SHLD, SHRD
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
M M M U M M
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are
blank. Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X non-canonical.
A memory address exceeded a data segment limit or was non-
X X X
canonical.
General protection,
#GP X The destination operand was in a non-writable segment.
X A null data segment was used to reference memory.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference was performed while
X X
#AC alignment checking was enabled.
Related Instructions
SAL, SHL, SHR, SHLD, SHRD
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
M M M U M M
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are
blank. Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
SBB reg/mem8, imm8 80 /3 ib Subtract an immediate 8-bit value from an 8-bit register
or memory location with borrow.
Subtract an immediate 16-bit value from a 16-bit register
SBB reg/mem16, imm16 81 /3 iw
or memory location with borrow.
Subtract an immediate 32-bit value from a 32-bit register
SBB reg/mem32, imm32 81 /3 id
or memory location with borrow.
Subtract a sign-extended immediate 32-bit value from a
SBB reg/mem64, imm32 81 /3 id
64-bit register or memory location with borrow.
Subtract a sign-extended 8-bit immediate value from a
SBB reg/mem16, imm8 83 /3 ib
16-bit register or memory location with borrow.
Subtract a sign-extended 8-bit immediate value from a
SBB reg/mem32, imm8 83 /3 ib
32-bit register or memory location with borrow.
Subtract a sign-extended 8-bit immediate value from a
SBB reg/mem64, imm8 83 /3 ib
64-bit register or memory location with borrow.
SBB reg/mem8, reg8 18 /r Subtract the contents of an 8-bit register from an 8-bit
register or memory location with borrow.
Subtract the contents of a 16-bit register from a 16-bit
SBB reg/mem16, reg16 19 /r
register or memory location with borrow.
SBB reg/mem64, reg64 19 /r Subtract the contents of a 64-bit register from a 64-bit
register or memory location with borrow.
Subtract the contents of an 8-bit register or memory
SBB reg8, reg/mem8 1A /r location from the contents of an 8-bit register with
borrow.
Subtract the contents of a 16-bit register or memory
SBB reg16, reg/mem16 1B /r location from the contents of a 16-bit register with
borrow.
Subtract the contents of a 32-bit register or memory
SBB reg32, reg/mem32 1B /r location from the contents of a 32-bit register with
borrow.
Subtract the contents of a 64-bit register or memory
SBB reg64, reg/mem64 1B /r location from the contents of a 64-bit register with
borrow.
Related Instructions
SUB, ADD, ADC
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
M M M M M M
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are
blank. Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
A memory address exceeded a data segment limit or was non-
X X X
canonical.
General protection,
#GP X The destination operand was in a non-writable segment.
X A null data segment was used to reference memory.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference was performed while
#AC X X alignment checking was enabled.
Related Instructions
CMP, CMPSx
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
M M M M M M
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are
blank. Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
X A null ES segment was used to reference memory.
General protection,
#GP X X X A memory address exceeded the ES segment limit or was
non-canonical.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference was performed while
X X
#AC alignment checking was enabled.
Related Instructions
None
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
A memory address exceeded a data segment limit or was non-
X X X
canonical.
General protection,
#GP X The destination operand was in a non-writable segment.
X A null data segment was used to reference memory.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Related Instructions
LFENCE, MFENCE
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
The SSE instructions are not supported, as indicated by EDX
Invalid Opcode, bit 25 of CPUID function 0000_0001h; and the AMD
X X X
#UD extensions to MMX are not supported, as indicated by EDX bit
22 of CPUID function 8000_0001h.
Related Instructions
SHRD, SAL, SAR, SHR, SHL
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
M M M U M M
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank.
Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
A memory address exceeded a data segment limit or was non-
X X X
canonical.
General protection,
#GP X The destination operand was in a non-writable segment.
X A null data segment was used to reference memory.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, X X An unaligned memory reference was performed while
#AC alignment checking was enabled.
SHR reg/mem8, imm8 C0 /5 ib Shift an 8-bit register or memory operand right the
number of bits specified by an 8-bit immediate value.
SHR reg/mem16, 1 D1 /5 Shift a 16-bit register or memory operand right 1 bit.
Shift a 16-bit register or memory operand right the
SHR reg/mem16, CL D3 /5
number of bits specified in the CL register.
Shift a 16-bit register or memory operand right the
SHR reg/mem16, imm8 C1 /5 ib
number of bits specified by an 8-bit immediate value.
SHR reg/mem32, 1 D1 /5 Shift a 32-bit register or memory operand right 1 bit.
Shift a 32-bit register or memory operand right the
SHR reg/mem32, CL D3 /5
number of bits specified in the CL register.
Shift a 32-bit register or memory operand right the
SHR reg/mem32, imm8 C1 /5 ib
number of bits specified by an 8-bit immediate value.
SHR reg/mem64, 1 D1 /5 Shift a 64-bit register or memory operand right 1 bit.
Related Instructions
SHL, SAL, SAR, SHLD, SHRD
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
M M M U M M
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are
blank. Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
A memory address exceeded a data segment limit or was non-
X X X
canonical.
General protection,
#GP X The destination operand was in a non-writable segment.
X A null data segment was used to reference memory.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, X X An unaligned memory reference was performed while
#AC alignment checking was enabled.
Related Instructions
SHLD, SHR, SHL, SAR, SAL
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
M M M U M M
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank.
Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
A memory address exceeded a data segment limit or was non-
X X X
canonical.
General protection,
#GP X The destination operand was in a non-writable segment.
X A null data segment was used to reference memory.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, X X An unaligned memory reference was performed while
#AC alignment checking was enabled.
Related Instructions
CLC, CMC
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank.
Undefined flags are U.
Exceptions
None
Related Instructions
CLD, INSx, LODSx, MOVSx, OUTSx, SCASx, STOSx, CMPSx
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are
blank. Undefined flags are U.
Exceptions
None
Related Instructions
LODSx, MOVSx
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the ES segment limit or was
X X X
non-canonical.
General protection,
#GP X The ES segment was a non-writable segment.
X A null ES segment was used to reference memory.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference was performed while
X X
#AC alignment checking was enabled.
SUB Subtract
Subtracts an immediate value or the value in a register or memory location (second operand) from a
register or a memory location (first operand) and stores the result in the first operand location. An
immediate value is sign-extended to the length of the first operand.
This instruction evaluates the result for both signed and unsigned data types and sets the OF and CF
flags to indicate a borrow in a signed or unsigned result, respectively. It sets the SF flag to indicate the
sign of a signed result.
The forms of the SUB instruction that write to memory support the LOCK prefix. For details about the
LOCK prefix, see “Lock Prefix” on page 8.
SUB reg/mem8, reg8 28 /r Subtract the contents of an 8-bit register from an 8-bit
destination register or memory location.
Subtract the contents of a 16-bit register from a 16-bit
SUB reg/mem16, reg16 29 /r
destination register or memory location.
SUB reg/mem32, reg32 Subtract the contents of a 32-bit register from a 32-bit
29 /r
destination register or memory location.
Subtract the contents of a 64-bit register from a 64-bit
SUB reg/mem64, reg64 29 /r destination register or memory location.
Related Instructions
ADC, ADD, SBB
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
M M M M M M
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank.
Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
TEST AL, imm8 A8 ib AND an immediate 8-bit value with the contents of the
AL register and set rFLAGS to reflect the result.
AND an immediate 16-bit value with the contents of the
TEST AX, imm16 A9 iw
AX register and set rFLAGS to reflect the result.
TEST EAX, imm32 A9 id AND an immediate 32-bit value with the contents of the
EAX register and set rFLAGS to reflect the result.
AND a sign-extended immediate 32-bit value with the
TEST RAX, imm32 A9 id contents of the RAX register and set rFLAGS to reflect
the result.
AND an immediate 8-bit value with the contents of an 8-
TEST reg/mem8, imm8 F6 /0 ib bit register or memory operand and set rFLAGS to
reflect the result.
AND an immediate 16-bit value with the contents of a
TEST reg/mem16, imm16 F7 /0 iw 16-bit register or memory operand and set rFLAGS to
reflect the result.
AND an immediate 32-bit value with the contents of a
TEST reg/mem32, imm32 F7 /0 id 32-bit register or memory operand and set rFLAGS to
reflect the result.
AND a sign-extended immediate32-bit value with the
TEST reg/mem64, imm32 F7 /0 id contents of a 64-bit register or memory operand and set
rFLAGS to reflect the result.
AND the contents of an 8-bit register with the contents
TEST reg/mem8, reg8 84 /r of an 8-bit register or memory operand and set rFLAGS
to reflect the result.
AND the contents of a 16-bit register with the contents
TEST reg/mem16, reg16 85 /r of a 16-bit register or memory operand and set rFLAGS
to reflect the result.
AND the contents of a 32-bit register with the contents
TEST reg/mem32, reg32 85 /r of a 32-bit register or memory operand and set rFLAGS
to reflect the result.
AND the contents of a 64-bit register with the contents
TEST reg/mem64, reg64 85 /r of a 64-bit register or memory operand and set rFLAGS
to reflect the result.
Related Instructions
AND, CMP
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
0 M M U M 0
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank.
Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
A memory address exceeded a data segment limit or was non-
X X X
canonical.
General protection,
#GP X The destination operand was in a non-writable segment.
X A null data segment was used to reference memory.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, X X An unaligned memory reference was performed while
#AC alignment checking was enabled.
Related Instructions
None
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
M M M M M M
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank.
Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X non-canonical.
A memory address exceeded a data segment limit or was non-
X X X
canonical.
General protection,
#GP X The destination operand was in a non-writable segment.
X A null data segment was used to reference memory.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference was performed while
X X
#AC alignment checking was enabled.
XCHG Exchange
Exchanges the contents of the two operands. The operands can be two general-purpose registers or a
register and a memory location. If either operand references memory, the processor locks
automatically, whether or not the LOCK prefix is used and independently of the value of IOPL. For
details about the LOCK prefix, see “Lock Prefix” on page 8.
The x86 architecture commonly uses the XCHG EAX, EAX instruction (opcode 90h) as a one-byte
NOP. In 64-bit mode, the processor treats opcode 90h as a true NOP only if it would exchange rAX
with itself. Without this special handling, the instruction would zero-extend the upper 32 bits of RAX,
and thus it would not be a true no-operation. Opcode 90h can still be used to exchange rAX and r8 if
the appropriate REX prefix is used.
This special handling does not apply to the two-byte ModRM form of the XCHG instruction.
XCHG reg32, EAX 90 +rd Exchange the contents of a 32-bit register with the
contents of the EAX register.
Exchange the contents of the RAX register with the
XCHG RAX, reg64 90 +rq
contents of a 64-bit register.
Exchange the contents of a 64-bit register with the
XCHG reg64, RAX 90 +rq
contents of the RAX register.
Exchange the contents of an 8-bit register with the
XCHG reg/mem8, reg8 86 /r
contents of an 8-bit register or memory operand.
Exchange the contents of an 8-bit register or memory
XCHG reg8, reg/mem8 86 /r
operand with the contents of an 8-bit register.
Exchange the contents of a 16-bit register with the
XCHG reg/mem16, reg16 87 /r
contents of a 16-bit register or memory operand.
Exchange the contents of a 16-bit register or memory
XCHG reg16, reg/mem16 87 /r
operand with the contents of a 16-bit register.
Exchange the contents of a 32-bit register with the
XCHG reg/mem32, reg32 87 /r
contents of a 32-bit register or memory operand.
Exchange the contents of a 32-bit register or memory
XCHG reg32, reg/mem32 87 /r
operand with the contents of a 32-bit register.
Exchange the contents of a 64-bit register with the
XCHG reg/mem64, reg64 87 /r
contents of a 64-bit register or memory operand.
Exchange the contents of a 64-bit register or memory
XCHG reg64, reg/mem64 87 /r
operand with the contents of a 64-bit register.
Related Instructions
BSWAP, XADD
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X non-canonical.
A memory address exceeded a data segment limit or was non-
X X X
canonical.
General protection, The source or destination operand was in a non-writable
#GP X
segment.
X A null data segment was used to reference memory.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference was performed while
X X
#AC alignment checking was enabled.
Related Instructions
None
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
X Y X XOR Y
0 0 0
0 1 1
1 0 1
1 1 0
Related Instructions
OR, AND, NOT, NEG
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
0 M M U M 0
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are
blank. Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X non-canonical.
A memory address exceeded a data segment limit or was non-
X X X
canonical.
General protection,
#GP X The destination operand was in a non-writable segment.
X A null data segment was used to reference memory.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference was performed while
X X
#AC alignment checking was enabled.
Related Instructions
LAR, LSL, VERR, VERW
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to one or cleared to zero is M (modified). Unaffected flags
are blank. Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
This instruction is only recognized in protected legacy and
Invalid opcode, #UD X X compatibility mode.
Stack, #SS X A memory address exceeded the stack segment limit.
X A memory address exceeded a data segment limit.
General protection, X The destination operand was in a non-writable segment.
#GP
X A null segment selector was used to reference memory.
Page fault, #PF X A page fault resulted from the execution of the instruction.
An unaligned memory reference was performed while
Alignment check, #AC X
alignment checking was enabled.
Related Instructions
STGI
rFLAGS Affected
None.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
The SVM instructions are not supported as indicated by ECX
X X X
bit 2 as returned by CPUID function 8000_0001h.
Invalid opcode, #UD
X Secure Virtual Machine was not enabled (EFER.SVME=0).
X X Instruction is only recognized in protected mode.
General protection,
X CPL was not zero.
#GP
Action
IF (CPL <= IOPL)
RFLAGS.IF = 0
ELSE
EXCEPTION[#GP(0)]
Related Instructions
STI
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
M M
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to one or cleared to zero is M (modified). Unaffected flags
are blank. Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
The CPL was greater than the IOPL and virtual mode
X
extensions are not enabled (CR4.VME = 0).
General protection,
#GP The CPL was greater than the IOPL and either the CPL was
X not 3 or protected mode virtual interrupts were not enabled
(CR4.PVI = 0).
Related Instructions
LMSW, MOV (CRn)
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
General protection,
X X CPL was not 0.
#GP
HLT Halt
Causes the microprocessor to halt instruction execution and enter the HALT state. Entering the HALT
state puts the processor in low-power mode. Execution resumes when an unmasked hardware interrupt
(INTR), non-maskable interrupt (NMI), system management interrupt (SMI), RESET, or INIT occurs.
If an INTR, NMI, or SMI is used to resume execution after a HLT instruction, the saved instruction
pointer points to the instruction following the HLT instruction.
Before executing a HLT instruction, hardware interrupts should be enabled. If rFLAGS.IF = 0, the
system will remain in a HALT state until an NMI, SMI, RESET, or INIT occurs.
If an SMI brings the processor out of the HALT state, the SMI handler can decide whether to return to
the HALT state or not. See Volume 2: System Programming, for information on SMIs.
Current privilege level must be 0 to execute this instruction.
Related Instructions
STI, CLI
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
General protection,
X X CPL was not 0.
#GP
For complete descriptions of the steps performed by INT instructions, see the following:
• Legacy-Mode Interrupts: “Legacy Protected-Mode Interrupt Control Transfers” in Volume 2.
• Long-Mode Interrupts: “Long-Mode Interrupt Control Transfers” in Volume 2.
Action
// Refer to INT instruction’s Action section for the details on INT_N_REAL,
// INT_N_PROTECTED, and INT_N_VIRTUAL_TO_PROTECTED.
INT3_START:
If (REAL_MODE)
INT_N_REAL //N = 3
ELSEIF (PROTECTED_MODE)
INT_N_PROTECTED //N = 3
ELSE // VIRTUAL_MODE
INT_N_VIRTUAL_TO_PROTECTED //N = 3
Related Instructions
INT, INTO, IRET
rFLAGS Affected
If a task switch occurs, all flags are modified; otherwise, setting are as follows:
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
M 0 0 M M 0
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to one or cleared to zero is M (modified). Unaffected flags
are blank. Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Breakpoint, #BP X X X INT 3 instruction was executed.
As part of a stack switch, the target stack segment selector or
X X
rSP in the TSS that was beyond the TSS limit.
As part of a stack switch, the target stack segment selector in
X X the TSS was beyond the limit of the GDT or LDT descriptor
table.
As part of a stack switch, the target stack segment selector in
X X
the TSS was a null selector.
Invalid TSS, #TS X X
As part of a stack switch, the target stack segment selector’s
(selector) TI bit was set, but the LDT selector was a null selector.
As part of a stack switch, the target stack segment selector in
X X
the TSS contained a RPL that was not equal to its DPL.
As part of a stack switch, the target stack segment selector in
X X the TSS contained a DPL that was not equal to the CPL of the
code segment selector.
As part of a stack switch, the target stack segment selector in
X X
the TSS was not a writable segment.
Segment not
The accessed code segment, interrupt gate, trap gate, task
present, #NP X X
gate, or TSS was not present.
(selector)
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
After a stack switch, a memory address exceeded the stack
X X segment limit or was non-canonical and a stack switch
Stack, #SS occurred.
(selector) As part of a stack switch, the SS register was loaded with a
X X non-null segment selector and the segment was marked not
present.
A memory address exceeded the data segment limit or was
X X X non-canonical.
General protection,
#GP The target offset exceeded the code segment limit or was non-
X X X
canonical.
Virtual
Exception Real 8086 Protected Cause of Exception
X X X The interrupt vector was beyond the limit of IDT.
The descriptor in the IDT was not an interrupt, trap, or task
X X gate in legacy mode or not a 64-bit interrupt or trap gate in
long mode.
The DPL of the interrupt, trap, or task gate descriptor was less
X X
than the CPL.
The segment selector specified by the interrupt or trap gate
X X
General protection, had its TI bit set, but the LDT selector was a null selector.
#GP The segment descriptor specified by the interrupt or trap gate
(selector) X X exceeded the descriptor table limit or was a null selector.
The segment descriptor specified by the interrupt or trap gate
X X was not a code segment in legacy mode, or not a 64-bit code
segment in long mode.
The DPL of the segment specified by the interrupt or trap gate
X
was greater than the CPL.
The DPL of the segment specified by the interrupt or trap gate
X
pointed was not 0 or it was a conforming segment.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference was performed while
X X
#AC alignment checking was enabled.
Related Instructions
WBINVD, CLFLUSH
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
General protection,
X X CPL was not 0.
#GP
Related Instructions
INVLPGA, MOV CRn (CR3 and CR4)
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
General protection, X X CPL was not 0.
#GP
Related Instructions
INVLPG.
rFLAGS Affected
None.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
The SVM instructions are not supported as indicated by ECX
X X X bit 2 as returned by CPUID function 8000_0001h.
Invalid opcode, #UD
X Secure Virtual Machine was not enabled (EFER.SVME=0).
X X Instruction is only recognized in protected mode.
General protection,
X CPL was not zero.
#GP
Action
IRET_START:
IF (REAL_MODE)
IRET_REAL
ELSIF (PROTECTED_MODE)
IRET_PROTECTED
ELSE // (VIRTUAL_MODE)
IRET_VIRTUAL
IRET_REAL:
POP.v temp_RIP
POP.v temp_CS
POP.v temp_RFLAGS
CS.sel = temp_CS
CS.base = temp_CS SHL 4
IRET_PROTECTED:
POP.v temp_RIP
POP.v temp_CS
POP.v temp_RFLAGS
temp_CPL = temp_CS.rpl
IF ((64BIT_MODE) || (temp_CPL!=CPL))
{
POP.v temp_RSP // in 64-bit mode, iret always pops ss:rsp
POP.v temp_SS
}
CPL = temp_CPL
IF (changing CPL)
{
FOR (seg = ES, DS, FS, GS)
IF ((seg.attr.dpl < CPL) && ((seg.attr.type = ’data’)
|| (seg.attr.type = ’non-conforming-code’)))
{
seg = NULL // can’t use lower dpl data segment at higher cpl
}
}
RFLAGS.v = temp_RFLAGS // VIF,VIP,IOPL only changed if (old_CPL=0)
// IF only changed if (old_CPL<=old_RFLAGS.IOPL)
// VM unchanged
// RF cleared
RIP = temp_RIP
EXIT
IRET_VIRTUAL:
POP.v temp_RIP
POP.v temp_CS
POP.v temp_RFLAGS
IF (RFLAGS.IOPL=3)
{
RFLAGS.v = temp_RFLAGS // VIF,VIP,VM,IOPL unchanged
// RF cleared
CS.sel = temp_CS
CS.base = temp_CS SHL 4
RIP = temp_RIP
EXIT
}
ELSIF ((OPERAND_SIZE=16)
&& !((temp_RFLAGS.IF=1) && (RFLAGS.VIP=1))
&& (temp_RFLAGS.TF=0))
{
RFLAGS.w = temp_RFLAGS // RFLAGS.VIF=temp_RFLAGS.IF
// IF,IOPL unchanged
// RF cleared
CS.sel = temp_CS
CS.base = temp_CS SHL 4
RIP = temp_RIP
EXIT
}
ELSE // ((RFLAGS.IOPL<3) && (CR4.VME=1) && ((OPERAND_SIZE=32) ||
// ((temp_RFLAGS.IF=1) && (RFLAGS.VIP=1)) || (temp_RFLAGS.TF=1)))
EXCEPTION [#GP(0)]
IRET_FROM_PROTECTED_TO_VIRTUAL:
POP.d temp_RSP
POP.d temp_SS
POP.d temp_ES
POP.d temp_DS
POP.d temp_FS
POP.d temp_GS
SS.sel = temp_SS
SS.base = temp_SS SHL 4
SS.limit= 0x0000FFFF
SS.attr = 16-bit dpl3 stack
DS.sel = temp_DS
DS.base = temp_DS SHL 4
DS.limit= 0x0000FFFF
DS.attr = 16-bit dpl3 data
ES.sel = temp_ES
ES.base = temp_ES SHL 4
ES.limit= 0x0000FFFF
ES.attr = 16-bit dpl3 data
FS.sel = temp_FS
FS.base = temp_FS SHL 4
FS.limit= 0x0000FFFF
FS.attr = 16-bit dpl3 data
GS.sel = temp_GS
GS.base = temp_GS SHL 4
GS.limit= 0x0000FFFF
GS.attr = 16-bit dpl3 data
RSP.d = temp_RSP
RFLAGS.d = temp_RFLAGS
CPL = 3
Related Instructions
INT, INTO, INT3
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
M M M M M M M M M M M M M M M M M
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to one or cleared to zero is M (modified). Unaffected flags
are blank. Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Segment not
present, #NP X The return code segment was marked not present.
(selector)
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
Stack, #SS The SS register was loaded with a non-null segment selector
X
(selector) and the segment was marked not present.
X X X The target offset exceeded the code segment limit or was non-
canonical.
IOPL was less than 3 and one of the following conditions was
true:
• CR4.VME was 0.
General protection,
#GP X • The effective operand size was 32-bit.
• Both the original EFLAGS.VIP and the new EFLAGS.IF
were set.
• The new EFLAGS.TF was set.
X IRETx was executed in long mode while EFLAGS.NT=1.
Virtual
Exception Real 8086 Protected Cause of Exception
X The return code selector was a null selector.
The return stack selector was a null selector and the return
X
mode was non-64-bit mode or CPL was 3.
The return code or stack descriptor exceeded the descriptor
X table limit.
The return code or stack selector’s TI bit was set but the LDT
X
selector was a null selector.
The segment descriptor for the return code was not a code
X
segment.
The RPL of the return code segment selector was less than
X
General protection, the CPL.
#GP
(selector) The return code segment was non-conforming and the
X segment selector’s DPL was not equal to the RPL of the code
segment’s segment selector.
The return code segment was conforming and the segment
X selector’s DPL was greater than the RPL of the code
segment’s segment selector.
The segment descriptor for the return stack was not a writable
X data segment.
The stack segment descriptor DPL was not equal to the RPL
X
of the return code segment selector.
The stack segment selector RPL was not equal to the RPL of
X the return code segment selector.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference was performed while
#AC X X alignment checking was enabled.
2 2 LDT
5 — Task gate
If the segment descriptor passes these checks, the attributes are loaded into the destination general-
purpose register. If it does not, then the zero flag is cleared and the destination register is not modified.
When the operand size is 16 bits, access rights include the DPL and Type fields located in bytes 4 and
5 of the descriptor table entry. Before loading the access rights into the destination operand, the low
order word is masked with FF00H.
When the operand size is 32 or 64 bits, access rights include the DPL and type as well as the descriptor
type (S field), segment present (P flag), available to system (AVL flag), default operation size (D/B
flag), and granularity flags located in bytes 4–7 of the descriptor. Before being loaded into the
destination operand, the doubleword is masked with 00FF_FF00H.
In 64-bit mode, for both 32-bit and 64-bit operand sizes, 32-bit register results are zero-extended to 64
bits.
This instruction can only be executed in protected mode.
Related Instructions
ARPL, LSL, VERR, VERW
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to one or zero is M (modified). Unaffected flags are blank.
Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Invalid opcode, #UD X X This instruction is only recognized in protected mode.
A memory address exceeded the stack segment limit or was
Stack, #SS X non-canonical.
Related Instructions
LIDT, LLDT, LTR, SGDT, SIDT, SLDT, STR
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Invalid opcode, #UD X X X The operand was a register.
A memory address exceeded the stack segment limit or was
Stack, #SS X X
non-canonical.
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the data segment limit or was
X X non-canonical.
General protection, X X CPL was not 0.
#GP
X The new GDT base address was non-canonical.
X A null data segment was used to reference memory.
Page fault, #PF X A page fault resulted from the execution of the instruction.
Related Instructions
LGDT, LLDT, LTR, SGDT, SIDT, SLDT, STR
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Invalid opcode, #UD X X X The operand was a register.
A memory address exceeded the stack segment limit or was
Stack, #SS X X
non-canonical.
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the data segment limit or was
X X non-canonical.
General protection, X X CPL was not 0.
#GP
X The new IDT base address was non-canonical.
X A null data segment was used to reference memory.
Page fault, #PF X A page fault resulted from the execution of the instruction.
Related Instructions
LGDT, LIDT, LTR, SGDT, SIDT, SLDT, STR
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Invalid opcode, #UD X X This instruction is only recognized in protected mode.
Segment not present,
X The LDT descriptor was marked not present.
#NP (selector)
A memory address exceeded the stack segment limit or was
Stack, #SS X
non-canonical.
Virtual
Exception Real 8086 Protected Cause of Exception
X The source selector did not point into the GDT.
X The descriptor was beyond the GDT limit.
General protection,
X The descriptor was not an LDT descriptor.
#GP
(selector) The descriptor's extended attribute bits were not zero in 64-
X bit mode.
X The new LDT base address was non-canonical.
Page fault, #PF X A page fault resulted from the execution of the instruction.
Related Instructions
MOV (CRn), SMSW
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X
non-canonical.
A memory address exceeded a data segment limit or was non-
X X
canonical.
General protection,
#GP X X CPL was not 0.
X A null data segment was used to reference memory.
Page fault, #PF X A page fault resulted from the execution of the instruction.
2 2 LDT
If the segment selector passes these checks and the segment limit is loaded into the destination general-
purpose register, the instruction sets the zero flag of the rFLAGS register to 1. If the selector does not
pass the checks, then LSL clears the zero flag to 0 and does not modify the destination.
The instruction calculates the segment limit to 32 bits, taking the 20-bit limit and the granularity bit
into account. When the operand size is 16 bits, it truncates the upper 16 bits of the 32-bit adjusted
segment limit and loads the lower 16-bits into the target register.
Related Instructions
ARPL, LAR, VERR, VERW
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are
blank. Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Invalid opcode, #UD X X This instruction is only recognized in protected mode.
A memory address exceeded the stack segment limit or was
Stack, #SS X
non-canonical.
A memory address exceeded a data segment limit or was non-
X canonical.
General protection,
#GP X A null data segment was used to reference memory.
The extended attribute bits of a system descriptor was not
X
zero in 64-bit mode.
Page fault, #PF X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference was performed while
X
#AC alignment checking was enabled.
Related Instructions
LGDT, LIDT, LLDT, STR, SGDT, SIDT, SLDT
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Invalid opcode, #UD X X This instruction is only recognized in protected mode.
Segment not present,
X The TSS descriptor was marked not present.
#NP (selector)
A memory address exceeded the stack segment limit or was
Stack, #SS X
non-canonical.
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded a data segment limit or was
X non-canonical.
General protection, X CPL was not 0.
#GP
X A null data segment was used to reference memory.
X The new TSS selector was a null selector.
X The source selector did not point into the GDT.
X The descriptor was beyond the GDT limit.
General protection, X The descriptor was not an available TSS descriptor.
#GP
(selector) The descriptor's extended attribute bits were not zero in 64-
X
bit mode.
X The new TSS base address was non-canonical.
Page fault, #PF X A page fault resulted from the execution of the instruction.
while (!matching_store_done){
MONITOR EAX, ECX, EDX
IF (!matching_store_done) {
MWAIT EAX, ECX
}
}
Related Instructions
MWAIT
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
The MONITOR/MWAIT instructions are not
X X X supported, as indicated by ECX bit 3 (Monitor) as
Invalid opcode, #UD returned by CPUID function 0000_0001h.
CPL was not zero and
X X MSR C001_0015[MonMwaitUserEn] = 0.
A memory address exceeded the stack segment limit
Stack, #SS X X X or was non-canonical.
A memory address exceeded a data segment limit or
X X X
was non-canonical.
General protection, #GP
X X X ECX was non-zero.
X A null data segment was used to reference memory.
A page fault resulted from the execution of the
Page Fault, #PF X X
instruction.
Related Instructions
CLTS, LMSW, SMSW
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
An illegal control register was referenced (CR1, CR5–CR7,
X X X CR9–CR15).
Invalid Instruction,
#UD The use of the LOCK prefix to read CR8 is not supported, as
X X X indicated by ECX bit 4 as returned by CPUID function
8000_0001h.
X X CPL was not 0.
X X An attempt was made to set CR0.PG = 1 and CR0.PE = 0.
X X An attempt was made to set CR0.CD = 0 and CR0.NW = 1.
Reserved bits were set in the page-directory pointers table
X X (used in the legacy extended physical addressing mode) and
the instruction modified CR0, CR3, or CR4.
General protection,
#GP An attempt was made to write 1 to any reserved bit in CR0,
X X
CR3, CR4 or CR8.
An attempt was made to set CR0.PG while long mode was
X X enabled (EFER.LME = 1), but paging address extensions
were disabled (CR4.PAE = 0).
An attempt was made to clear CR4.PAE while long mode was
X
active (EFER.LMA = 1).
Related Instructions
None
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A debug register was referenced while the general detect
Debug, #DB X X (GD) bit in DR7 was set.
DR4 or DR5 was referenced while the debug extensions
X X
Invalid opcode, #UD (DE) bit in CR4 was set.
X An illegal debug register (DR8–DR15) was referenced.
X X CPL was not 0.
General protection,
#GP A 1 was written to any of the upper 32 bits of DR6 or DR7 in
X
64-bit mode.
while (!matching_store_done ){
MONITOR EAX, ECX, EDX
IF ( !matching_store_done ) {
MWAIT EAX, ECX
}
}
Related Instructions
MONITOR
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
The MONITOR/MWAIT instructions are not supported,
X X X as indicated by ECX bit 3 (Monitor) as returned by
Invalid opcode, #UD CPUID function 0000_0001h.
CPL was not zero and
X X
MSRC001_0015[MonMwaitUserEn] = 0.
General protection,
X X X Unsupported extension bits were set in ECX
#GP
Related Instructions
WRMSR, RDTSC, RDPMC
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
The RDMSR instruction is not supported, as indicated by
Invalid opcode, #UD X X X EDX bit 5 returned by CPUID function 0000_0001h or function
8000_0001h.
X X CPL was not 0.
General protection,
#GP The value in ECX specifies a reserved or unimplemented
X X
MSR address.
Related Instructions
RDMSR, WRMSR
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
The value in ECX specified an unimplemented performance
General Protection, X X X
counter number.
#GP
X X CPL was not 0 and CR4.PCE = 0.
Related Instructions
RDTSCP, RDMSR, WRMSR
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
The RDTSC instruction is not supported, as indicated by
Invalid opcode, #UD X X X EDX bit 4 returned by CPUID function 0000_0001h or
function 8000_0001h.
General protection,
X X CPL was not 0 and CR4.TSD = 1.
#GP
Related Instructions
RDTSC
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
The RDTSCP instruction is not supported, as indicated by
Invalid opcode, #UD X X X EDX bit 27 returned by CPUID function 8000_0001h.
General protection,
X X CPL was not 0 and CR4.TSD = 1.
#GP
Related Instructions
None
rFLAGS Affected
All flags are restored from the state-save map (SSM).
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
M M M M M M M M M M M M M M M M M
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are
blank. Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Invalid opcode, #UD X X X The processor was not in System Management Mode (SMM).
Related Instructions
SIDT, SLDT, STR, LGDT, LIDT, LLDT, LTR
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Invalid opcode, #UD X X X The operand was a register.
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
A memory address exceeded a data segment limit or was non-
X X X
canonical.
General protection,
#GP X The destination operand was in a non-writable segment.
X A null data segment was used to reference memory.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, X X An unaligned memory reference was performed while
#AC alignment checking was enabled.
Related Instructions
SGDT, SLDT, STR, LGDT, LIDT, LLDT, LTR
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Invalid opcode, #UD X X X The operand was a register.
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
A memory address exceeded a data segment limit or was non-
X X X
canonical.
General protection,
#GP X The destination operand was in a non-writable segment.
X A null data segment was used to reference memory.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, X X An unaligned memory reference was performed while
#AC alignment checking was enabled.
Action
IF ((EFER.SVMEN == 0) && !(CPUID 8000_0001.ECX[SKINIT]) || (!PROTECTED_MODE))
CS.sel = 0x0008
CS.attr = 32-bit code, read/execute
CS.base = 0
CS.limit = 0xFFFFFFFF
SS.sel = 0x0010
SS.attr = 32-bit stack, read/write, expand up
SS.base = 0
SS.limit = 0xFFFFFFFF
EFER = 0
VM_CR.DPD = 1
VM_CR.R_INIT = 1
VM_CR.DIS_A20M = 1
GIF = 0
Related Instructions
None.
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank.
Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Secure Virtual Machine was not enabled (EFER.SVME=0)
and both of the following conditions were true:
• SVM-Lock is not available, as indicated by EDX bit 2
X returned by CPUID function 8000_000Ah.
Invalid opcode, #UD
• DEV is not available, as indicated by ECX bit 12 returned
by CPUID function 8000_0001h.
X X Instruction is only recognized in protected mode.
General protection,
X CPL was not zero.
#GP
Related Instructions
SIDT, SGDT, STR, LIDT, LGDT, LLDT, LTR
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Invalid opcode, #UD X X This instruction is only recognized in protected mode.
A memory address exceeded the stack segment limit or was
Stack, #SS X
non-canonical.
A memory address exceeded a data segment limit or was non-
X
canonical.
General protection,
#GP X The destination operand was in a non-writable segment.
X A null data segment was used to reference memory.
Page fault, #PF X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference was performed while
X
#AC alignment checking was enabled.
Related Instructions
LMSW, MOV(CRn)
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded the stack segment limit or was
Stack, #SS X X X
non-canonical.
A memory address exceeded a data segment limit or was non-
X X X
canonical.
General protection,
#GP X The destination operand was in a non-writable segment.
X A null data segment was used to reference memory.
Page fault, #PF X X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference was performed while
#AC X X alignment checking was enabled.
In the following sequence, INTR will be allowed to happen only after the NOP.
STI
NOP
CLI
If STI sets the VIF flag and VIP is already set, a #GP fault will be generated.
See “Virtual-8086 Mode Extensions” in Volume 2 for more information about IOPL-sensitive
instructions.
Action
IF (CPL <= IOPL)
RFLAGS.IF = 1
Related Instructions
CLI
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
M M
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. M (modified) is either set to one or cleared to zero. Unaffected flags
are blank. Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
The CPL was greater than the IOPL and virtual-mode
X
extensions were not enabled (CR4.VME = 0).
The CPL was greater than the IOPL and either the CPL was
General protection,
X not 3 or protected-mode virtual interrupts were not enabled
#GP (CR4.PVI = 0).
This instruction would set RFLAGS.VIF to 1 and
X X
RFLAGS.VIP was already 1.
Related Instructions
CLGI
rFLAGS Affected
None.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Secure Virtual Machine was not enabled (EFER.SVME=0)
and both of the following conditions were true:
• SVM-Lock is not available, as indicated by EDX bit 2
X returned by CPUID function 8000_000Ah.
Invalid opcode, #UD
• DEV is not available, as indicated by ECX bit 12 returned
by CPUID function 8000_0001h.
X X Instruction is only recognized in protected mode.
General protection, X CPL was not zero.
#GP
Related Instructions
LGDT, LIDT, LLDT, LTR, SIDT, SGDT, SLDT
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Invalid opcode, #UD X X This instruction is only recognized in protected mode.
A memory address exceeded the stack segment limit or was
Stack, #SS X
non-canonical.
A memory address exceeded a data segment limit or was
X
non-canonical.
General protection,
#GP X The destination operand was in a non-writable segment.
X A null data segment was used to reference memory.
Page fault, #PF X A page fault resulted from the execution of the instruction.
An unaligned memory reference was performed while
Alignment check, #AC X
alignment checking was enabled.
Examples
At a kernel entry point, the OS uses SwapGS to obtain a pointer to kernel data structures and
simultaneously save the user's GS base. Upon exit, it uses SwapGS to restore the user's GS base:
SystemCallEntryPoint:
SwapGS ; get kernel pointer, save user GSbase
mov gs:[SavedUserRSP], rsp ; save user's stack pointer
mov rsp, gs:[KernelStackPtr] ; set up kernel stack
push rax ; now save user GPRs on kernel stack
. ; perform system service
.
SwapGS ; restore user GS, save kernel pointer
Related Instructions
None
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
This instruction was executed in legacy or
Invalid opcode, #UD X X X
compatibility mode.
General protection, #GP X CPL was not 0.
Legacy x86 Mode. In legacy x86 mode, when SYSCALL is executed, the EIP of the instruction
following the SYSCALL is copied into the ECX register. Bits 31–0 of the SYSCALL/SYSRET target
address register (STAR) are copied into the EIP register. (The STAR register is model-specific register
C000_0081h.)
New selectors are loaded, without permission checking (see above), as follows:
• Bits 47–32 of the STAR register specify the selector that is copied into the CS register.
• Bits 47–32 of the STAR register + 8 specify the selector that is copied into the SS register.
• The CS_base and the SS_base are both forced to zero.
• The CS_limit and the SS_limit are both forced to 4 Gbyte.
• The CS segment attributes are set to execute/read 32-bit code with a CPL of zero.
• The SS segment attributes are set to read/write and expand-up with a 32-bit stack referenced by
ESP.
Long Mode. When long mode is activated, the behavior of the SYSCALL instruction depends on
whether the calling software is in 64-bit mode or compatibility mode. In 64-bit mode, SYSCALL
saves the RIP of the instruction following the SYSCALL into RCX and loads the new RIP from
LSTAR bits 63–0. (The LSTAR register is model-specific register C000_0082h.) In compatibility
mode, SYSCALL saves the RIP of the instruction following the SYSCALL into RCX and loads the
new RIP from CSTAR bits 63–0. (The CSTAR register is model-specific register C000_0083h.)
New selectors are loaded, without permission checking (see above), as follows:
• Bits 47–32 of the STAR register specify the selector that is copied into the CS register.
• Bits 47–32 of the STAR register + 8 specify the selector that is copied into the SS register.
• The CS_base and the SS_base are both forced to zero.
• The CS_limit and the SS_limit are both forced to 4 Gbyte.
• The CS segment attributes are set to execute/read 64-bit code with a CPL of zero.
• The SS segment attributes are set to read/write and expand-up with a 64-bit stack referenced by
RSP.
The WRMSR instruction loads the target RIP into the LSTAR and CSTAR registers. If an RIP written
by WRMSR is not in canonical form, a general-protection exception (#GP) occurs.
How SYSCALL and SYSRET handle rFLAGS, depends on the processor’s operating mode.
In legacy mode, SYSCALL treats EFLAGS as follows:
• EFLAGS.IF is cleared to 0.
• EFLAGS.RF is cleared to 0.
• EFLAGS.VM is cleared to 0.
In long mode, SYSCALL treats RFLAGS as follows:
• The current value of RFLAGS is saved in R11.
• RFLAGS is masked using the value stored in SYSCALL_FLAG_MASK.
• RFLAGS.RF is cleared to 0.
For further details on the SYSCALL and SYSRET instructions and their associated MSR registers
(STAR, LSTAR, CSTAR, and SYSCALL_FLAG_MASK), see “Fast System Call and Return” in
Volume 2.
Action
// See “Pseudocode Definitions” on page 41.
SYSCALL_START:
IF (LONG_MODE)
SYSCALL_LONG_MODE
ELSE // (LEGACY_MODE)
SYSCALL_LEGACY_MODE
SYSCALL_LONG_MODE:
RCX.q = next_RIP
R11.q = RFLAGS // with rf cleared
IF (64BIT_MODE)
temp_RIP.q = MSR_LSTAR
ELSE // (COMPATIBILITY_MODE)
temp_RIP.q = MSR_CSTAR
SS.sel = MSR_STAR.SYSCALL_CS + 8
SS.attr = 64-bit stack,dpl0
SS.base = 0x00000000
SS.limit = 0xFFFFFFFF
CPL = 0
RIP = temp_RIP
EXIT
SYSCALL_LEGACY_MODE:
RCX.d = next_RIP
temp_RIP.d = MSR_STAR.EIP
CS.base = 0x00000000
CS.limit = 0xFFFFFFFF
SS.sel = MSR_STAR.SYSCALL_CS + 8
SS.attr = 32-bit stack,dpl0
SS.base = 0x00000000
SS.limit = 0xFFFFFFFF
RFLAGS.VM,IF,RF=0
CPL = 0
RIP = temp_RIP
EXIT
Related Instructions
SYSRET, SYSENTER, SYSEXIT
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
M M M M 0 0 M M M M M M M M M M M
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to one or cleared to zero is M (modified). Unaffected flags
are blank. Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
The SYSCALL and SYSRET instructions are not
X X X supported, as indicated by EDX bit 11 returned by
CPUID function 8000_0001h.
Invalid opcode, #UD
The system call extension bit (SCE) of the extended
X X X feature enable register (EFER) is set to 0. (The
EFER register is MSR C000_0080h.)
Related Instructions
SYSCALL, SYSEXIT, SYSRET
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
0 0
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to one or zero is M (modified). Unaffected flags are blank.
Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
The SYSENTER and SYSEXIT instructions are not
X X X supported, as indicated by EDX bit 11 returned by
Invalid opcode, #UD CPUID function 0000_0001h.
X This instruction is not recognized in long mode.
X This instruction is not recognized in real mode.
General protection, #GP
X X MSR_SYSENTER_CS was a null selector.
Related Instructions
SYSCALL, SYSENTER, SYSRET
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to one or cleared to zero is M (modified). Unaffected flags
are blank.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
The SYSENTER and SYSEXIT instructions are not
X X X supported, as indicated by EDX bit 11 returned by
Invalid opcode, #UD CPUID function 0000_0001h.
X This instruction is not recognized in long mode.
This instruction is only recognized in protected
X X
mode.
General protection, #GP
X CPL was not 0.
X MSR_SYSENTER_CS was a null selector.
• The CS segment attributes are set to execute-read 32 bits or 64 bits (see below).
• The SS segment base, limit, and attributes are not modified.
When SYSCALLed system software is running in 64-bit mode, it has been entered from either 64-bit
mode or compatibility mode. The corresponding SYSRET needs to know the mode to which it must
return. Executing SYSRET in non-64-bit mode or with a 16- or 32-bit operand size returns to 32-bit
mode with a 32-bit stack pointer. Executing SYSRET in 64-bit mode with a 64-bit operand size returns
to 64-bit mode with a 64-bit stack pointer.
The instruction pointer is updated with the return address based on the operating mode in which
SYSRET is executed:
• If returning to 64-bit mode, SYSRET loads RIP with the value of RCX.
• If returning to 32-bit mode, SYSRET loads EIP with the value of ECX.
How SYSRET handles RFLAGS depends on the processor’s operating mode:
• If executed in 64-bit mode, SYSRET loads the lower-32 RFLAGS bits from R11[31:0] and clears
the upper 32 RFLAGS bits.
• If executed in legacy mode or compatibility mode, SYSRET sets EFLAGS.IF.
For further details on the SYSCALL and SYSRET instructions and their associated MSR registers
(STAR, LSTAR, and CSTAR), see “Fast System Call and Return” in Volume 2.
Action
// See “Pseudocode Definitions” on page 41.
SYSRET_START:
IF (64BIT_MODE)
SYSRET_64BIT_MODE
ELSE // (!64BIT_MODE)
SYSRET_NON_64BIT_MODE
SYSRET_64BIT_MODE:
temp_RIP.q = RCX
}
ELSE // Return to 32-bit compatibility mode.
{
CS.sel = MSR_STAR.SYSRET_CS OR 3
CS.base = 0x00000000
CS.limit = 0xFFFFFFFF
CS.attr = 32-bit code,dpl3
temp_RIP.d = RCX
}
RIP = temp_RIP
EXIT
SYSRET_NON_64BIT_MODE:
temp_RIP.d = RCX
RIP = temp_RIP
EXIT
Related Instructions
SYSCALL, SYSENTER, SYSEXIT
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
M M M M 0 M M M M M M M M M M M
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to one or cleared to zero is M (modified). Unaffected flags
are blank. Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
The SYSCALL and SYSRET instructions are not
X X X supported, as indicated by EDX bit 11 returned by
CPUID function 8000_0001h.
Invalid opcode, #UD
The system call extension bit (SCE) of the extended
X X X feature enable register (EFER) is set to 0. (The
EFER register is MSR C000_0080h.)
This instruction is only recognized in protected
X X
General protection, #GP mode.
X CPL was not 0.
Related Instructions
None
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Invalid opcode, #UD X X X This instruction is not recognized.
Related Instructions
ARPL, LAR, LSL, VERW
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to one or cleared to zero is M (modified). Unaffected flags
are blank. Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Invalid opcode, #UD X X This instruction is only recognized in protected mode.
A memory address exceeded the stack segment limit or is
Stack, #SS X
non-canonical.
A memory address exceeded a data segment limit or was non-
General protection, X
canonical.
#GP
X A null data segment was used to reference memory.
Virtual
Exception Real 8086 Protected Cause of Exception
Page fault, #PF X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference was performed while
X
#AC alignment checking was enabled.
Related Instructions
ARPL, LAR, LSL, VERR
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0
Note: Bits 31–22, 15, 5, 3, and 1 are reserved. A flag set to one or cleared to zero is M (modified). Unaffected flags
are blank. Undefined flags are U.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Invalid opcode, #UD X X This instruction is only recognized in protected mode.
A memory address exceeded the stack segment limit or was
Stack, #SS X
non-canonical.
A memory address exceeded a data segment limit or was non-
General protection, X canonical.
#GP
X A null data segment was used to access memory.
Page fault, #PF X A page fault resulted from the execution of the instruction.
Alignment check, An unaligned memory reference was performed while
X
#AC alignment checking was enabled.
Action
IF ((MSR_EFER.SVME = 0) || (!PROTECTED_MODE))
EXCEPTION [#UD] // This instruction can only be executed in protected
// mode with SVM enabled
Related Instructions
VMSAVE
rFLAGS Affected
None.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
The SVM instructions are not supported as indicated by ECX
X X X
bit 2 as returned by CPUID function 8000_0001h.
Invalid opcode, #UD
X Secure Virtual Machine was not enabled (EFER.SVME=0).
X X The instruction is only recognized in protected mode.
X CPL was not zero.
General protection, rAX referenced a physical address above the maximum
X
#GP supported physical address.
X The address in rAX was not aligned on a 4Kbyte boundary.
Related Instructions
None.
rFLAGS Affected
None.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
The SVM instructions are not supported as indicated by ECX
X X X
bit 2 as returned by CPUID function 8000_0001h.
Invalid opcode, #UD
X X X Secure Virtual Machine was not enabled (EFER.SVME=0).
X X X VMMCALL was not intercepted.
Action
IF ((MSR_EFER.SVME = 0) || (!PROTECTED_MODE))
EXCEPTION [#UD] // This instruction can only be executed in protected
// mode with SVM enabled
if (intercepted(VMRUN))
#VMEXIT (VMRUN)
remember VMCB address (delivered in rAX) for next #VMEXIT
save host state to physical memory indicated in the VM_HSAVE_PA MSR:
ES.sel
CS.sel
SS.sel
DS.sel
GDTR.{base,limit}
IDTR.{base,limit}
EFER
CR0
CR4
CR3
// host CR2 is not saved
RFLAGS
RIP
RSP
RAX
BR_TO
LASTEXCP_FROM
LASTEXCP_TO
Upon #VMEXIT, the processor performs the following actions in order to return to the host execution
context:
GIF = 0
save guest state to VMCB:
ES.{base,limit,attr,sel}
CS.{base,limit,attr,sel}
SS.{base,limit,attr,sel}
DS.{base,limit,attr,sel}
GDTR.{base,limit}
IDTR.{base,limit}
EFER
CR4
CR3
CR2
CR0
if (nested paging enabled)
gPAT
RFLAGS
RIP
RSP
RAX
DR7
DR6
CPL
INTERRUPT_SHADOW
save additional state and intercept information:
V_IRQ, V_TPR
EXITCODE
EXITINFO1
EXITINFO2
EXITINTINFO
clear EVENTINJ field in VMCB
clear v_intr_masking
clear tsc_offset
disable nested paging
clear ASID to zero
Related Instructions
VMLOAD, VMSAVE.
rFLAGS Affected
None.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
The SVM instructions are not supported as indicated by ECX
X X X
bit 2 as returned by CPUID function 8000_0001h.
Invalid opcode, #UD
X Secure Virtual Machine was not enabled (EFER.SVME=0).
X X The instruction is only recognized in protected mode.
X CPL was not zero.
General protection, rAX referenced a physical address above the maximum
#GP X supported physical address.
X The address in rAX was not aligned on a 4Kbyte boundary.
Action
IF ((MSR_EFER.SVME = 0) || (!PROTECTED_MODE))
EXCEPTION [#UD] // This instruction can only be executed in protected
// mode with SVM enabled
Related Instructions
VMLOAD
rFLAGS Affected
None.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
The SVM instructions are not supported as indicated by ECX
X X X
bit 2 as returned by CPUID function 8000_0001h.
Invalid opcode, #UD
X Secure Virtual Machine was not enabled (EFER.SVME=0).
X X The instruction is only recognized in protected mode.
X CPL was not zero.
General protection, rAX referenced a physical address above the maximum
X
#GP supported physical address.
X The address in rAX was not aligned on a 4Kbyte boundary.
Related Instructions
CLFLUSH, INVD
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
General protection, X X CPL was not 0.
#GP
Related Instructions
RDMSR
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
The WRMSR instruction is not supported, as indicated by
Invalid opcode, #UD X X X
EDX bit 5 returned by CPUID function 1 or 8000_0001h.
X X CPL was not 0.
The value in ECX specifies a reserved or unimplemented
X X
General protection, MSR address.
#GP X X Writing 1 to any bit that must be zero (MBZ) in the MSR.
Writing a non-canonical value to a MSR that can only be
X X
written with canonical values.
a Two 16-bit or 32-bit memory operands, depending on the effective operand size. Used in the
BOUND instruction.
b A byte, irrespective of the effective operand size.
d A doubleword (32 bits), irrespective of the effective operand size.
dq A double-quadword (128 bits), irrespective of the effective operand size.
p A 32-bit or 48-bit far pointer, depending on the effective operand size.
pd A 128-bit double-precision floating-point vector operand (packed double).
pi A 64-bit MMX operand (packed integer).
ps A 128-bit single-precision floating-point vector operand (packed single).
q A quadword, irrespective of the effective operand size.
s A 6-byte or 10-byte pseudo-descriptor.
sd A scalar double-precision floating-point operand (scalar double).
si A scalar doubleword (32-bit) integer operand (scalar integer).
ss A scalar single-precision floating-point operand (scalar single).
v A word, doubleword, or quadword, depending on the effective operand size.
w A word, irrespective of the effective operand size.
z A word if the effective operand size is 16 bits, or a doubleword if the effective operand size is 32
or 64 bits.
/n A ModRM-byte reg field or SIB-byte base field that contains a value (n) between zero (binary
000) and 7 (binary 111).
For definitions of the mnemonics used to name registers, see “Summary of Registers and Data Types”
on page 24.
Table A-3. Second Byte of Two-Byte Opcodes, Low Nibble 0–7h (continued)
Prefix Nibble1 0 1 2 3 4 5 6 7
PUNPCK- PUNPCK- PUN-
PACKSSWB PCMPGTB PCMPGTW PCMPGTD PACKUSWB
none LBW LWD PCKLDQ
Pq, Qd Pq, Qd Pq, Qd Pq, Qq Pq, Qq Pq, Qq Pq, Qq Pq, Qq
invalid invalid invalid invalid invalid invalid invalid invalid
F3
6
PUNPCK- PUNPCK- PUN-
PACKSSWB PCMPGTB PCMPGTW PCMPGTD PACKUSWB
LBW LWD PCKLDQ
66 Vdq, Wq Vdq, Wq Vdq, Wq Vdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdq
invalid invalid invalid invalid invalid invalid invalid invalid
F2
PSHUFW Group 122 Group 132 Group 142 PCMPEQB PCMPEQW PCMPEQD EMMS
none
Pq, Qq, Ib Pq, Qq Pq, Qq Pq, Qq
PSHUFHW invalid invalid invalid invalid invalid invalid invalid
F3
Vq, Wq, Ib
7
PSHUFD Group 122 Group 132 Group 142 PCMPEQB PCMPEQW PCMPEQD invalid
66
Vdq, Wdq, Ib Vdq, Wdq Vdq, Wdq Vdq, Wdq
PSHUFLW invalid invalid invalid invalid invalid invalid invalid
F2
Vq, Wq, Ib
JO JNO JB JNB JZ JNZ JBE JNBE
n/a 8
Jz Jz Jz Jz Jz Jz Jz Jz
SETO SETNO SETB SETNB SETZ SETNZ SETBE SETNBE
n/a 9
Eb Eb Eb Eb Eb Eb Eb Eb
PUSH POP CPUID BT SHLD invalid invalid
n/a A
FS FS Ev, Gv Ev, Gv, Ib Ev, Gv, CL
CMPXCHG LSS BTR LFS LGS MOVZX
n/a B
Eb, Gb Ev, Gv Gz, Mp Ev, Gv Gz, Mp Gz, Mp Gv, Eb Gv, Ew
XADD CMPPS MOVNTI PINSRW PEXTRW SHUFPS Group 92
none
Vps, Wps, Ib Md/q, Gd/q Pq, Ew, Ib Gd, PRq, Ib Vps, Wps, Ib
CMPSS invalid invalid invalid invalid
F3
Vss, Wss, Ib
C
Eb, Gb Ev, Gv CMPPD invalid PINSRW PEXTRW SHUFPD Mq
66
Vpd, Wpd, Ib Vdq, Ew, Ib Gd, VRdq, Ib Vpd, Wpd, Ib
CMPSD invalid invalid invalid invalid
F2
Vsd, Wsd, Ib
invalid PSRLW PSRLD PSRLQ PADDQ PMULLW invalid PMOVMSKB
none
Pq, Qq Pq, Qq Pq, Qq Pq, Qq Pq, Qq Gd, PRq
invalid invalid invalid invalid invalid invalid MOVQ2DQ invalid
F3
Vdq, PRq
D
ADDSUBPD PSRLW PSRLD PSRLQ PADDQ PMULLW MOVQ PMOVMSKB
66
Vpd, Wpd Vdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdq Wq, Vq Gd, VRdq
ADDSUBPS invalid invalid invalid invalid invalid MOVDQ2Q invalid
F2
Vps, Wps Pq, VRq
Note:
1. All two-byte opcodes begin with an 0Fh byte. Rows in the table show the high nibble of the second opcode bytes,
columns show the low nibble of this byte.
2. An opcode extension is specified in bits 5–3 of the ModRM byte. See “ModRM Extensions to One-Byte and Two-
Byte Opcodes” on page 348 for details.
3. Invalid in long mode.
Table A-3. Second Byte of Two-Byte Opcodes, Low Nibble 0–7h (continued)
Prefix Nibble1 0 1 2 3 4 5 6 7
PAVGB PSRAW PSRAD PAVGW PMULHUW PMULHW invalid MOVNTQ
none
Pq, Qq Pq, Qq Pq, Qq Pq, Qq Pq, Qq Pq, Qq Mq, Pq
invalid invalid invalid invalid invalid invalid CVTDQ2PD invalid
F3
Vpd, Wq
E CVTTPD2D
PAVGB PSRAW PSRAD PAVGW PMULHUW PMULHW MOVNTDQ
66 Q
Vdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdq Vq, Wpd Mdq, Vdq
invalid invalid invalid invalid invalid invalid CVTPD2DQ invalid
F2
Vq, Wpd
invalid PSLLW PSLLD PSLLQ PMULUDQ PMADDWD PSADBW MASKMOVQ
none
Pq, Qq Pq, Qq Pq, Qq Pq, Qq Pq, Qq Pq, Qq Pq, PRq
invalid invalid invalid invalid invalid invalid invalid invalid
F3
F MASK-
invalid PSLLW PSLLD PSLLQ PMULUDQ PMADDWD PSADBW
66 MOVDQU
Vdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, VRdq
LDDQU invalid invalid invalid invalid invalid invalid invalid
F2
Vpd,Mdq
Note:
1. All two-byte opcodes begin with an 0Fh byte. Rows in the table show the high nibble of the second opcode bytes,
columns show the low nibble of this byte.
2. An opcode extension is specified in bits 5–3 of the ModRM byte. See “ModRM Extensions to One-Byte and Two-
Byte Opcodes” on page 348 for details.
3. Invalid in long mode.
Table A-4. Second Byte of Two-Byte Opcodes, Low Nibble 8–Fh (continued)
Prefix Nibble1 8 9 A B C D E F
invalid invalid invalid invalid invalid invalid invalid invalid
n/a 3
CMOVS CMOVNS CMOVP CMOVNP CMOVL CMOVNL CMOVLE CMOVNLE
n/a 4
Gv, Ev Gv, Ev Gv, Ev Gv, Ev Gv, Ev Gv, Ev Gv, Ev Gv, Ev
ADDPS MULPS CVTPS2PD CVTDQ2PS SUBPS MINPS DIVPS MAXPS
none
Vps, Wps Vps, Wps Vpd, Wps Vps, Wdq Vps, Wps Vps, Wps Vps, Wps Vps, Wps
CVTTPS2D
ADDSS MULSS CVTSS2SD SUBSS MINSS DIVSS MAXSS
F3 Q
5 Vss, Wss Vss, Wss Vsd, Wss Vdq, Wps Vss, Wss Vss, Wss Vss, Wss Vss, Wss
ADDPD MULPD CVTPD2PS CVTPS2DQ SUBPD MINPD DIVPD MAXPD
66
Vpd, Wpd Vpd, Wpd Vps, Wpd Vdq, Wps Vpd, Wpd Vpd, Wpd Vpd, Wpd Vpd, Wpd
ADDSD MULSD CVTSD2SS invalid SUBSD MINSD DIVSD MAXSD
F2
Vsd, Wsd Vsd, Wsd Vss, Wsd Vsd, Wsd Vsd, Wsd Vsd, Wsd Vsd, Wsd
PUNPCK- PUNPCK- PUNPCK-
PACKSSDW invalid invalid MOVD MOVQ
none HBW HWD HDQ
Pq, Qd Pq, Qd Pq, Qd Pq, Qq Pq, Ed/q Pq, Qq
invalid invalid invalid invalid invalid invalid invalid MOVDQU
F3
Vdq, Wdq
6
PUNPCK- PUNPCK- PUNPCK- PUNPCK- PUNPCK-
PACKSSDW MOVD MOVDQA
66 HBW HWD HDQ LQDQ HQDQ
Vdq, Wq Vdq, Wq Vdq, Wq Vdq, Wdq Vdq, Wq Vdq, Wq Vdq, Ed/q Vdq, Wdq
invalid invalid invalid invalid invalid invalid invalid invalid
F2
invalid invalid invalid invalid invalid invalid MOVD MOVQ
none
Ed/q, Pd/q Qq, Pq
invalid invalid invalid invalid invalid invalid MOVQ MOVDQU
F3
Vq, Wq Wdq, Vdq
7
Group 172 EXTRQ invalid invalid HADDPD HSUBPD MOVD MOVDQA
66
Vdq, VRq Vpd,Wpd Vpd,Wpd Ed/q, Vd/q Wdq, Vdq
INSERTQ INSERTQ invalid invalid HADDPS HSUBPS invalid invalid
F2
Vdq,VRq,Ib,Ib Vdq, VRdq Vps,Wps Vps,Wps
JS JNS JP JNP JL JNL JLE JNLE
n/a 8
Jz Jz Jz Jz Jz Jz Jz Jz
SETS SETNS SETP SETNP SETL SETNL SETLE SETNLE
n/a 9
Eb Eb Eb Eb Eb Eb Eb Eb
PUSH POP RSM BTS SHRD Group 152 IMUL
n/a A
GS GS Ev, Gv Ev, Gv, Ib Ev, Gv, CL Gv, Ev
reserved Group 102 Group 82 BTC BSF BSR MOVSX
none
Ev, Ib Ev, Gv Gv, Ev Gv, Ev Gv, Eb Gv, Ew
POPCNT reserved reserved reserved reserved LZCNT reserved reserved
F3 B
Gv, Ev Gv, Ev
reserved reserved reserved reserved reserved reserved reserved reserved
F2
Note:
1. All two-byte opcodes begin with an 0Fh byte. Rows show high opcode nibble (hex), columns show low opcode nibble
in hex.
2. An opcode extension is specified in the ModRM reg field (bits 5–3). See “ModRM Extensions to One-Byte and Two-
Byte Opcodes” on page 348 for details.
3. This instruction takes a ModRM byte.
Table A-4. Second Byte of Two-Byte Opcodes, Low Nibble 8–Fh (continued)
Prefix Nibble1 8 9 A B C D E F
BSWAP
n/a C
rAX/r8 rCX/r9 rDX/r10 rBX/r11 rSP/r12 rBP/r13 rSI/r14 rDI/r15
PSUBUSB PSUBUSW PMINUB PAND PADDUSB PADDUSW PMAXUB PANDN
none
Pq, Qq Pq, Qq Pq, Qq Pq, Qq Pq, Qq Pq, Qq Pq, Qq Pq, Qq
invalid invalid invalid invalid invalid invalid invalid invalid
F3
D
PSUBUSB PSUBUSW PMINUB PAND PADDUSB PADDUSW PMAXUB PANDN
66
Vdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdq
invalid invalid invalid invalid invalid invalid invalid invalid
F2
PSUBSB PSUBSW PMINSW POR PADDSB PADDSW PMAXSW PXOR
none
Pq, Qq Pq, Qq Pq, Qq Pq, Qq Pq, Qq Pq, Qq Pq, Qq Pq, Qq
invalid invalid invalid invalid invalid invalid invalid invalid
F3
E
PSUBSB PSUBSW PMINSW POR PADDSB PADDSW PMAXSW PXOR
66
Vdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdq
invalid invalid invalid invalid invalid invalid invalid invalid
F2
PSUBB PSUBW PSUBD PSUBQ PADDB PADDW PADDD invalid
none
Pq, Qq Pq, Qq Pq, Qq Pq, Qq Pq, Qq Pq, Qq Pq, Qq
invalid invalid invalid invalid invalid invalid invalid invalid
F3
F
PSUBB PSUBW PSUBD PSUBQ PADDB PADDW PADDD invalid
66
Vdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdq
invalid invalid invalid invalid invalid invalid invalid invalid
F2
Note:
1. All two-byte opcodes begin with an 0Fh byte. Rows show high opcode nibble (hex), columns show low opcode nibble
in hex.
2. An opcode extension is specified in the ModRM reg field (bits 5–3). See “ModRM Extensions to One-Byte and Two-
Byte Opcodes” on page 348 for details.
3. This instruction takes a ModRM byte.
Table A-5. rFLAGS Condition Codes for CMOVcc, Jcc, and SETcc
Low Nibble of
Arithmetic
Second Opcode rFLAGS Value cc Mnemonic Condition(s)
Type
Byte (hex)
0 OF = 1 O Overflow
Signed
1 OF = 0 NO No Overflow
2 CF = 1 B, C, NAE Below, Carry, Not Above or Equal
3 CF = 0 NB, NC, AE Not Below, No Carry, Above or Equal
4 ZF = 1 Z, E Zero, Equal
Unsigned
5 ZF = 0 NZ, NE Not Zero, Not Equal
6 CF = 1 or ZF = 1 BE, NA Below or Equal, Not Above
7 CF = 0 and ZF = 0 NBE, A Not Below or Equal, Above
8 SF = 1 S Sign
Signed
9 SF = 0 NS Not Sign
A PF = 1 P, PE Parity, Parity Even
n/a
B PF = 0 NP, PO Not Parity, Parity Odd
C (SF xor OF) = 1 L, NGE Less than, Not Greater than or Equal to
D (SF xor OF) = 0 NL, GE Not Less than, Greater than or Equal to
(SF xor OF) = 1 Signed
E LE, NG Less than or Equal to, Not Greater than
or ZF = 1
(SF xor OF) = 0
F NLE, G Not Less than or Equal to, Greater than
and ZF = 0
Bits: 7 6 5 4 3 2 1 0
mod reg r/m ModRM
513-325.eps
In most cases, the reg field (bits 5–3) provides the additional bits with which to extend the encodings
of the first one or two opcode bytes. In the case of the x87 floating-point instructions, the entire
ModRM byte is used to extend the opcode encodings.
Table A-6 on page 349 shows how the ModRM reg field is used to extend the range of one-byte and
two-byte opcodes. The opcode ranges are organized into groups of opcode extensions. The group
number is shown in the left-most column of Table A-6. These groups are referenced in the opcodes
shown in Table A-1 on page 341 through Table A-4 on page 345. An entry of “n.a.” in the Prefix
column means that prefixes are not applicable to the opcodes in that row. Prefixes only apply to certain
128-bit media, 64-bit media, and a few other instructions introduced with the SSE or SSE2
technologies.
The /0 through /7 notation for the ModRM reg field (bits 5–3) means that the three-bit field contains a
value from zero (binary 000) to 7 (binary 111).
Table A-8 and Table A-9 on page 353 show the immediate byte following the opcode bytes for
3DNow! instructions. In these tables, rows show the high nibble of the immediate byte, and columns
show the low nibble of the immediate byte. Table A-8 shows the immediate bytes whose low nibble is
in the range 0–7h. Table A-9 shows the same for immediate bytes whose low nibble is in the range
8–Fh.
Byte values shown as reserved in these tables have implementation-specific functions, which can
include an invalid-opcode exception.
Table A-8. Immediate Byte for 3DNow!™ Opcodes, Low Nibble 0–7h
Nibble1 0 1 2 3 4 5 6 7
reserved reserved reserved reserved reserved reserved reserved reserved
0
reserved reserved reserved reserved reserved reserved reserved reserved
1
reserved reserved reserved reserved reserved reserved reserved reserved
2
reserved reserved reserved reserved reserved reserved reserved reserved
3
reserved reserved reserved reserved reserved reserved reserved reserved
4
reserved reserved reserved reserved reserved reserved reserved reserved
5
reserved reserved reserved reserved reserved reserved reserved reserved
6
reserved reserved reserved reserved reserved reserved reserved reserved
7
reserved reserved reserved reserved reserved reserved reserved reserved
8
PFCMPGE reserved reserved reserved PFMIN reserved PFRCP PFRSQRT
9
Pq, Qq Pq, Qq Pq, Qq Pq, Qq
PFCMPGT reserved reserved reserved PFMAX reserved PFRCPIT1 PFRSQIT1
A
Pq, Qq Pq, Qq Pq, Qq Pq, Qq
PFCMPEQ reserved reserved reserved PFMUL reserved PFRCPIT2 PMULHRW
B
Pq, Qq Pq, Qq Pq, Qq Pq, Qq
reserved reserved reserved reserved reserved reserved reserved reserved
C
reserved reserved reserved reserved reserved reserved reserved reserved
D
reserved reserved reserved reserved reserved reserved reserved reserved
E
reserved reserved reserved reserved reserved reserved reserved reserved
F
Note:
1. All 3DNow!™ opcodes consist of two 0Fh bytes. This table shows the immediate byte for 3DNow! opcodes. Rows
show the high nibble of the immediate byte. Columns show the low nibble of the immediate byte.
Table A-9. Immediate Byte for 3DNow!™ Opcodes, Low Nibble 8–Fh
Nibble1 8 9 A B C D E F
reserved reserved reserved reserved PI2FW PI2FD reserved reserved
0
Pq, Qq Pq, Qq
reserved reserved reserved reserved PF2IW PF2ID reserved reserved
1
Pq, Qq Pq, Qq
reserved reserved reserved reserved reserved reserved reserved reserved
2
reserved reserved reserved reserved reserved reserved reserved reserved
3
reserved reserved reserved reserved reserved reserved reserved reserved
4
reserved reserved reserved reserved reserved reserved reserved reserved
5
reserved reserved reserved reserved reserved reserved reserved reserved
6
reserved reserved reserved reserved reserved reserved reserved reserved
7
reserved reserved PFNACC reserved reserved reserved PFPNACC reserved
8
Pq, Qq Pq, Qq
reserved reserved PFSUB reserved reserved reserved PFADD reserved
9
Pq, Qq Pq, Qq
reserved reserved PFSUBR reserved reserved reserved PFACC reserved
A
Pq, Qq Pq, Qq
reserved reserved reserved PSWAPD reserved reserved reserved PAVGUSB
B
Pq, Qq Pq, Qq
reserved reserved reserved reserved reserved reserved reserved reserved
C
reserved reserved reserved reserved reserved reserved reserved reserved
D
reserved reserved reserved reserved reserved reserved reserved reserved
E
reserved reserved reserved reserved reserved reserved reserved reserved
F
Note:
1. All 3DNow!™ opcodes consist of two 0Fh bytes. This table shows the immediate byte for 3DNow! opcodes. Rows
show the high nibble of the immediate byte. Columns show the low nibble of the immediate byte.
00–BF
!11 FADD FMUL FCOM FCOMP FSUB FSUBR FDIV FDIVR
mem32real mem32real mem32real mem32real mem32real mem32real mem32real mem32real
C0 C8 D0 D8 E0 E8 F0 F8
FADD FMUL FCOM FCOMP FSUB FSUBR FDIV FDIVR
ST(0), ST(0),
ST(0), ST(0) ST(0), ST(0) ST(0), ST(0) ST(0), ST(0) ST(0), ST(0) ST(0), ST(0)
ST(0) ST(0)
C1 C9 D1 D9 E1 E9 F1 F9
FADD FMUL FCOM FCOMP FSUB FSUBR FDIV FDIVR
ST(0), ST(0),
ST(0), ST(1) ST(0), ST(1) ST(0), ST(1) ST(0), ST(1) ST(0), ST(1) ST(0), ST(1)
ST(1) ST(1)
C2 CA D2 DA E2 EA F2 FA
FADD FMUL FCOM FCOMP FSUB FSUBR FDIV FDIVR
ST(0), ST(0),
ST(0), ST(2) ST(0), ST(2) ST(0), ST(2) ST(0), ST(2) ST(0), ST(2) ST(0), ST(2)
ST(2) ST(2)
C3 CB D3 DB E3 EB F3 FB
FADD FMUL FCOM FCOMP FSUB FSUBR FDIV FDIVR
D8 ST(0), ST(0),
ST(0), ST(3) ST(0), ST(3) ST(0), ST(3) ST(0), ST(3) ST(0), ST(3) ST(0), ST(3)
ST(3) ST(3)
11
C4 CC D4 DC E4 EC F4 FC
FADD FMUL FCOM FCOMP FSUB FSUBR FDIV FDIVR
ST(0), ST(0),
ST(0), ST(4) ST(0), ST(4) ST(0), ST(4) ST(0), ST(4) ST(0), ST(4) ST(0), ST(4)
ST(4) ST(4)
C5 CD D5 DD E5 ED F5 FD
FADD FMUL FCOM FCOMP FSUB FSUBR FDIV FDIVR
ST(0), ST(0),
ST(0), ST(5) ST(0), ST(5) ST(0), ST(5) ST(0), ST(5) ST(0), ST(5) ST(0), ST(5)
ST(5) ST(5)
C6 CE D6 DE E6 EE F6 FE
FADD FMUL FCOM FCOMP FSUB FSUBR FDIV FDIVR
ST(0), ST(0),
ST(0), ST(6) ST(0), ST(6) ST(0), ST(6) ST(0), ST(6) ST(0), ST(6) ST(0), ST(6)
ST(6) ST(6)
C7 CF D7 DF E7 EF F7 FF
FADD FMUL FCOM FCOMP FSUB FSUBR FDIV FDIVR
ST(0), ST(0),
ST(0), ST(7) ST(0), ST(7) ST(0), ST(7) ST(0), ST(7) ST(0), ST(7) ST(0), ST(7)
ST(7) ST(7)
00–BF
!11 FILD FISTTP FIST FISTP invalid FLD invalid FSTP
mem32int mem32int mem32int mem32int mem80real mem80real
C0 C8 D0 D8 E0 E8 F0 F8
FCMOVNB FCMOVNE FCMOVNBE FCMOVNU reserved FUCOMI FCOMI invalid
ST(0), ST(0),
ST(0), ST(0) ST(0), ST(0) ST(0), ST(0) ST(0), ST(0)
ST(0) ST(0)
C1 C9 D1 D9 E1 E9 F1 F9
FCMOVNB FCMOVNE FCMOVNBE FCMOVNU reserved FUCOMI FCOMI invalid
ST(0), ST(0),
ST(0), ST(1) ST(0), ST(1) ST(0), ST(1) ST(0), ST(1)
ST(1) ST(1)
C2 CA D2 DA E2 EA F2 FA
FCMOVNB FCMOVNE FCMOVNBE FCMOVNU FNCLEX FUCOMI FCOMI invalid
ST(0), ST(0),
ST(0), ST(2) ST(0), ST(2) ST(0), ST(2) ST(0), ST(2)
ST(2) ST(2)
C3 CB D3 DB E3 EB F3 FB
FCMOVNB FCMOVNE FCMOVNBE FCMOVNU FNINIT FUCOMI FCOMI invalid
DB ST(0), ST(0),
ST(0), ST(3) ST(0), ST(3) ST(0), ST(3) ST(0), ST(3)
ST(3) ST(3)
11
C4 CC D4 DC E4 EC F4 FC
FCMOVNB FCMOVNE FCMOVNBE FCMOVNU reserved FUCOMI FCOMI invalid
ST(0), ST(0),
ST(0), ST(4) ST(0), ST(4) ST(0), ST(4) ST(0), ST(4)
ST(4) ST(4)
C5 CD D5 DD E5 ED F5 FD
FCMOVNB FCMOVNE FCMOVNBE FCMOVNU invalid FUCOMI FCOMI invalid
ST(0), ST(0),
ST(0), ST(5) ST(0), ST(5) ST(0), ST(5) ST(0), ST(5)
ST(5) ST(5)
C6 CE D6 DE E6 EE F6 FE
FCMOVNB FCMOVNE FCMOVNBE FCMOVNU invalid FUCOMI FCOMI invalid
ST(0), ST(0),
ST(0), ST(6) ST(0), ST(6) ST(0), ST(6) ST(0), ST(6)
ST(6) ST(6)
C7 CF D7 DF E7 EF F7 FF
FCMOVNB FCMOVNE FCMOVNBE FCMOVNU invalid FUCOMI FCOMI invalid
ST(0), ST(0),
ST(0), ST(7) ST(0), ST(7) ST(0), ST(7) ST(0), ST(7)
ST(7) ST(7)
Bits: 7 6 5 4 3 2 1 0
mod reg r/m ModRM
The two sections below describe the ModRM operand encodings, first for 16-bit references and then
for 32-bit and 64-bit references.
16-Bit Register and Memory References. Table A-12 shows the notation and encoding
conventions for register references using the ModRM reg field. This table is comparable to Table A-14
on page 367 but applies only when the address-size is 16-bit. Table A-13 on page 365 shows the
notation and encoding conventions for 16-bit memory references using the ModRM byte. This table is
comparable to Table A-15 on page 368.
[BX+DI] 01 09 11 19 21 29 31 39 001
[BP+SI] 02 0A 12 1A 22 2A 32 3A 010
[BP+DI] 03 0B 13 1B 23 2B 33 3B 011
00
[SI] 04 0C 14 1C 24 2C 34 3C 100
[DI] 05 0D 15 1D 25 2D 35 3D 101
[disp16] 06 0E 16 1E 26 2E 36 3E 110
[BX] 07 0F 17 1F 27 2F 37 3F 111
[BX+SI+disp8] 40 48 50 58 60 68 70 78 000
[BX+DI+disp8] 41 49 51 59 61 69 71 79 001
[BP+SI+disp8] 42 4A 52 5A 62 6A 72 7A 010
[BP+DI+disp8] 43 4B 53 5B 63 6B 73 7B 011
01
[SI+disp8] 44 4C 54 5C 64 6C 74 7C 100
[DI+disp8] 45 4D 55 5D 65 6D 75 7D 101
[BP+disp8] 46 4E 56 5E 66 6E 76 7E 110
[BX+disp8] 47 4F 57 5F 67 6F 77 7F 111
[BX+SI+disp16] 80 88 90 98 A0 A8 B0 B8 000
[BX+DI+disp16] 81 89 91 99 A1 A9 B1 B9 001
[BP+SI+disp16] 82 8A 92 9A A2 AA B2 BA 010
[BP+DI+disp16] 83 8B 93 9B A3 AB B3 BB 011
10
[SI+disp16] 84 8C 94 9C A4 AC B4 BC 100
[DI+disp16] 85 8D 95 9D A5 AD B5 BD 101
[BP+disp16] 86 8E 96 9E A6 AE B6 BE 110
[BX+disp16] 87 8F 97 9F A7 AF B7 BF 111
Note:
1. In these combinations, “disp8” and “disp16” indicate an 8-bit or 16-bit signed displacement.
2. See Table A-12 for complete specification of ModRM “reg” field.
CL/CX/ECX/MMX1/XMM1 C1 C9 D1 D9 E1 E9 F1 F9 001
DL/DX/EDX/MMX2/XMM2 C2 CA D2 DA E2 EA F2 FA 010
BL/BX/EBX/MMX3/XMM3 C3 CB D3 DB E3 EB F3 FB 011
11
AH/SP/ESP/MMX4/XMM4 C4 CC D4 DC E4 EC F4 FC 100
CH/BP/EBP/MMX5/XMM5 C5 CD D5 DD E5 ED F5 FD 101
DH/SI/ESI/MMX6/XMM6 C6 CE D6 DE E6 EE F6 FE 110
BH/DI/EDI/MMX7/XMM7 C7 CF D7 DF E7 EF F7 FF 111
Note:
1. In these combinations, “disp8” and “disp16” indicate an 8-bit or 16-bit signed displacement.
2. See Table A-12 for complete specification of ModRM “reg” field.
reg16 AX CX DX BX SP BP SI DI
[rIP+disp32] or
[rIP+disp32] or [disp32]2 05 0D 15 1D 25 2D 35 3D 101
[disp32]2
[rSI] [r14] 06 0E 16 1E 26 2E 36 3E 110
Table A-15. ModRM Memory References, 32-Bit and 64-Bit Addressing (continued)
ModRM ModRM reg Field3 ModRM
Effective Address1 mod r/m
Field /0 /1 /2 /3 /4 /5 /6 /7 Field
REX.B = 0 REX.B = 1 (binary) Complete ModRM Byte (hex) (binary)
AL/rAX/MMX0/XMM0 r8/MMX0/XMM8 C0 C8 D0 D8 E0 E8 F0 F8 000
r10/MMX2/XMM1
DL/rDX/MMX2/XMM2 C2 CA D2 DA E2 EA F2 FA 010
0
r11/MMX3/XMM1
BL/rBX/MMX3/XMM3 C3 CB D3 DB E3 EB F3 FB 011
1
AH/SPL/rSP/MMX4/XM r12/MMX4/XMM1 11 C4 CC D4 DC E4 EC F4 FC 100
M4 2
CH/BPL/rBP/MMX5/XM r13/MMX5/XMM1
C5 CD D5 DD E5 ED F5 FD 101
M5 3
DH/SIL/rSI/MMX6/XMM r14/MMX6/XMM1
C6 CE D6 DE E6 EE F6 FE 110
6 4
BH/DIL/rDI/MMX7/XMM r15/MMX7/XMM1
C7 CF D7 DF E7 EF F7 FF 111
7 5
Note:
1. In these combinations, “disp8” and “disp32” indicate an 8-bit or 32-bit signed displacement.
2. In 64-bit mode, the effective address is [rIP+disp32]. In all other modes, the effective address is [disp32]. If the
address-size prefix is used in 64-bit mode to override 64-bit addressing, the [RIP+disp32] effective address is trun-
cated after computation to 64 bits.
3. See Table A-14 for complete specification of ModRM “reg” field.
4. An SIB byte follows the ModRM byte to identify the memory operand.
Bits: 7 6 5 4 3 2 1 0
scale index base SIB
513-306.eps
REX.B bit of REX prefix can
extend this field to 4 bits
Table A-16 shows the encodings for the SIB byte’s base field, which specifies the base register for
addressing. Table A-17 on page 371 shows the encodings for the effective address referenced by a
complete SIB byte, including its scale and index fields. The /0 through /7 notation for the SIB base
field means that the three-bit field contains a value between zero (binary 000) and 7 (binary 111).
/0 /1 /2 /3 /4 /5 /6 /7
REX.X = 0 REX.X = 1 Complete SIB Byte (hex)
[rAX+base] [r8+base] 000 00 01 02 03 04 05 06 07
/0 /1 /2 /3 /4 /5 /6 /7
REX.X = 0 REX.X = 1 Complete SIB Byte (hex)
[rAX*8+base] [r8*8+base] 000 C0 C1 C2 C3 C4 C5 C6 C7
• Displacements and Offsets: The maximum size of an address displacement or offset is 32 bits,
except that 64-bit offsets can be used by specific MOV opcodes that read or write AL or rAX.
Displacements and offsets that are less than 64 bits are a maximum of 32 bits, and are sign-
extended to 64 bits during use.
• Undefined High 32 Bits After Mode Change: The processor does not preserve the upper 32 bits
of the 64-bit GPRs across switches from 64-bit mode to compatibility or legacy modes. In
compatibility or legacy mode, the upper 32 bits of the GPRs are undefined and not accessible to
software.
Note:
1. See “General Rules for 64-Bit Mode” on page 373, for opcodes that do not appear in this table.
2. The type of operation, excluding considerations of operand size or extension of results. See “General Rules for 64-
Bit Mode” on page 373 for definitions of “Promoted to 64 bits” and related topics.
3. If “Type of Operation” is 64 bits, a REX prefix is needed for 64-bit operand size, unless the instruction size defaults
to 64 bits. If the operand size is fixed, operand-size overrides are silently ignored.
4. Special actions in 64-bit mode, in addition to legacy-mode actions. Zero or sign extensions apply only to result oper-
ands, not source operands. Unless otherwise stated, 8-bit and 16-bit results leave the high 56 or 48 bits, respec-
tively, of 64-bit destination registers unchanged. Immediates and branch displacements are sign-extended to 64
bits.
5. Any pointer registers (rDI, rSI) or count registers (rCX) are address-sized and default to 64 bits. For 32-bit address
size, any pointer and count registers are zero-extended to 64 bits.
6. The default operand size can be overridden to 16 bits with 66h prefix, but there is no 32-bit operand-size override
in 64-bit mode.
0F A8 (PUSH GS)
0E (PUSH CS)
1E (PUSH DS)
INVALID IN 64-BIT MODE (invalid-opcode exception)
06 (PUSH ES)
16 (PUSH SS)
PUSHA, PUSHAD - Push All to GPR
Words or Doublewords INVALID IN 64-BIT MODE (invalid-opcode exception)
60
PUSHF, PUSHFD, PUSHFQ—Push PUSHFQ (new
rFLAGS Word, Doubleword, or mnemonic):
Promoted to
Quadword onto Stack
64 bits.
64 bits Cannot encode6 Pushes the 64-bit
RFLAGS
9C register.
RCL—Rotate Through Carry Left
D1 /2 Zero-extends 32-
Promoted to
32 bits bit register Uses 6-bit count.
D3 /2 64 bits.
results to 64 bits.
C1 /2
RCR—Rotate Through Carry Right
D1 /3 Zero-extends 32-
Promoted to
32 bits bit register Uses 6-bit count.
D3 /3 64 bits.
results to 64 bits.
C1 /3
RDMSR—Read Model-Specific Register RDX[31:0] contains MSR[63:32],
Same as RAX[31:0] contains MSR[31:0].
Not relevant.
0F 32 legacy mode. Zero-extends 32-bit register results
to 64 bits.
Note:
1. See “General Rules for 64-Bit Mode” on page 373, for opcodes that do not appear in this table.
2. The type of operation, excluding considerations of operand size or extension of results. See “General Rules for 64-
Bit Mode” on page 373 for definitions of “Promoted to 64 bits” and related topics.
3. If “Type of Operation” is 64 bits, a REX prefix is needed for 64-bit operand size, unless the instruction size defaults
to 64 bits. If the operand size is fixed, operand-size overrides are silently ignored.
4. Special actions in 64-bit mode, in addition to legacy-mode actions. Zero or sign extensions apply only to result oper-
ands, not source operands. Unless otherwise stated, 8-bit and 16-bit results leave the high 56 or 48 bits, respec-
tively, of 64-bit destination registers unchanged. Immediates and branch displacements are sign-extended to 64
bits.
5. Any pointer registers (rDI, rSI) or count registers (rCX) are address-sized and default to 64 bits. For 32-bit address
size, any pointer and count registers are zero-extended to 64 bits.
6. The default operand size can be overridden to 16 bits with 66h prefix, but there is no 32-bit operand-size override
in 64-bit mode.
ROL—Rotate Left
D1 /0 Zero-extends 32-
Promoted to
32 bits bit register Uses 6-bit count.
D3 /0 64 bits.
results to 64 bits.
C1 /0
ROR—Rotate Right
D1 /1 Zero-extends 32-
Promoted to
32 bits bit register Uses 6-bit count.
D3 /1 64 bits.
results to 64 bits.
C1 /1
RSM—Resume from System New SMM
Management Mode See “System-Management Mode” in
state-save Not relevant.
Volume 2.
0F AA area.
SAHF - Store AH into Flags Same as leg-
Not relevant. No GPR register results.
9E acy mode.
SAL—Shift Arithmetic Left
D1 /4 Zero-extends 32-
Promoted to
32 bits bit register Uses 6-bit count.
D3 /4 64 bits.
results to 64 bits.
C1 /4
Note:
1. See “General Rules for 64-Bit Mode” on page 373, for opcodes that do not appear in this table.
2. The type of operation, excluding considerations of operand size or extension of results. See “General Rules for 64-
Bit Mode” on page 373 for definitions of “Promoted to 64 bits” and related topics.
3. If “Type of Operation” is 64 bits, a REX prefix is needed for 64-bit operand size, unless the instruction size defaults
to 64 bits. If the operand size is fixed, operand-size overrides are silently ignored.
4. Special actions in 64-bit mode, in addition to legacy-mode actions. Zero or sign extensions apply only to result oper-
ands, not source operands. Unless otherwise stated, 8-bit and 16-bit results leave the high 56 or 48 bits, respec-
tively, of 64-bit destination registers unchanged. Immediates and branch displacements are sign-extended to 64
bits.
5. Any pointer registers (rDI, rSI) or count registers (rCX) are address-sized and default to 64 bits. For 32-bit address
size, any pointer and count registers are zero-extended to 64 bits.
6. The default operand size can be overridden to 16 bits with 66h prefix, but there is no 32-bit operand-size override
in 64-bit mode.
SHR—Shift Right
D1 /5 Zero-extends 32-
Promoted to
32 bits bit register Uses 6-bit count.
D3 /5 64 bits.
results to 64 bits.
C1 /5
SHRD—Shift Right Double Zero-extends 32-
Promoted to
0F AC 32 bits bit register Uses 6-bit count.
64 bits.
0F AD results to 64 bits.
Table B-3 lists instructions that are reassigned to different functions in 64-bit mode. Attempted use of
these instructions generates the reassigned function.
Table B-4 lists instructions that are illegal in long mode. Attempted use of these instructions generates
an invalid-opcode exception (#UD).
The 64-bit default operand size can be overridden to 16 bits using the 66h operand-size override.
However, it is not possible to override the operand size to 32 bits because there is no 32-bit operand-
size override prefix for 64-bit mode. See “Operand-Size Override Prefix” on page 4 for details.
This special handling does not apply to the two-byte ModRM form of the XCHG instruction. Unless a
64-bit operand size is specified using a REX prefix byte, using the two byte form of XCHG to
exchange a register with itself will not result in a no-operation because the default operation size is 32
bits in 64-bit mode.
Table C-1. Differences Between Long Mode and Legacy Mode (continued)
Applies To
Type Subject 64-Bit Mode Difference Compatibility
Mode?
x86 Modes Real and virtual-8086 modes not supported yes
Task Switching Task switching not supported yes
64-bit virtual addresses
Addressing 4-level paging structures yes
PAE must always be enabled
CS, DS, ES, SS segment bases are ignored
Segmentation CS, DS, ES, FS, GS, SS segment limits are ignored no
CS, DS, ES, SS Segment prefixes are ignored
All pushes are 8 bytes
16-bit interrupt and trap gates are illegal
Exception and 32-bit interrupt and trap gates are redefined as 64-bit
System yes
Interrupt Handling gates and are expanded to 16 bytes
Programming
SS is set to null on stack switch
SS:RSP is pushed unconditionally
All pushes are 8 bytes
16-bit call gates are illegal
Call Gates 32-bit call gate type is redefined as 64-bit call gate yes
and is expanded to 16 bytes.
SS is set to null on stack switch
System-Descriptor GDT, IDT, LDT, TR base registers expanded to 64
yes
Registers bits
System-Descriptor LGDT and LIDT use expanded 10-byte pseudo-
Table Entries and descriptors. no
Pseudo-descriptors LLDT and LTR use expanded 16-byte table entries.
General-Purpose Instructions
Long-Mode
Instructions Instructions
Basic
SVM
System Instructions Instructions
x87 Instructions
x87 Instructions
SSE3
Instructions
AMD Extensions
MMX™ to MMX™ SSE
Instructions Instructions
Instructions
64-Bit Media
Instructions 128-Bit Media
Instructions
Time of Introduction
SSE4A
Instructions
Dashed-line boxes show instruction subsets.
Circles show major CPUID feature sets.
(Minor features sets are not shown.)
• AMD Extensions to 3DNow!™ Instructions—Vector floating-point instructions that use the MMX
registers and are supported if the following bit is set:
- AMD extensions to 3DNow! instructions, indicated by EDX bit 30 of CPUID function
8000_0001h.
• SSE Instructions—Vector integer instructions that use the MMX registers, single-precision vector
and scalar floating-point instructions that use the XMM registers, plus other instructions for data-
type conversion, prefetching, cache control, and memory-access ordering. These instructions are
supported if the following bits are set:
- SSE, indicated by EDX bit 25 of CPUID function 0000_0001h.
- FXSAVE and FXRSTOR, indicated by EDX bit 24 of CPUID function 0000_0001h and
function 8000_0001h.
Several SSE opcodes are also implemented by the AMD Extensions to MMX™ Instructions.
• SSE2 Instructions—Vector and scalar integer and double-precision floating-point instructions that
use the XMM registers, plus other instructions for data-type conversion, cache control, and
memory-access ordering. These instructions are supported if the following bit is set:
- SSE2, indicated by EDX bit 26 of CPUID function 0000_0001h.
Several instructions originally implemented as MMX™ instructions are extended in the SSE2
instruction set to include opcodes that use XMM registers.
• SSE3 Instructions—Horizontal addition and subtraction of packed single-precision and double-
precision floating point values, simultaneous addition and subtraction of packed single-precision
and double-precision values, move with duplication, and floating-point-to-integer conversion.
These instructions are supported if the following bit is set:
- SSE3, indicated by ECX bit 0 of CPUID function 0000_0001h.
• SSE4A Instructions—The SSE4A instructions are EXTRQ, INSERTQ, MOVNTSD, and
MOVNTSS.
- SSE4A, indicated by ECX bit 6 of CPUID function 8000_0001h.
• Long-Mode Instructions—Instructions introduced by AMD with the AMD64 architecture. These
instructions are supported if the following bit is set:
- Long mode, indicated by EDX bit 29 of CPUID function 8000_0001h.
• SVM Instructions—Instructions introduced by AMD with the Secure Virtual Machine feature.
These instructions are supported if the following bit is set:
- SVM, indicated by ECX bit 2 of CPUID function 8000_0001h.
For complete details on the CPUID feature sets listed in Table D-1, see the AMD CPUID
Specification, order# 25481.
Index
Symbols CLGI .................................................................... 254
CLI ....................................................................... 255
#VMEXIT............................................................. 332 CLTS .................................................................... 257
Numerics CMC ....................................................................... 90
CMOVcc ......................................................... 91, 348
16-bit mode ............................................................ xvi CMP ....................................................................... 94
32-bit mode ............................................................ xvi CMPSx ................................................................... 97
64-bit mode ........................................................... xvii CMPXCHG ............................................................. 99
A CMPXCHG16B ..................................................... 101
CMPXCHG8B....................................................... 101
AAA ....................................................................... 53 commit .................................................................. xvii
AAD ....................................................................... 54 compatibility mode ................................................ xvii
AAM ...................................................................... 55 condition codes
AAS ....................................................................... 56 rFLAGS ..................................................... 348, 363
ADC ....................................................................... 57 count ..................................................................... 373
ADD ....................................................................... 59 CPUID .................................................................. 103
address size prefix................................................ 6, 20 extended functions .............................................. 103
addressing feature sets ......................................................... 407
byte registers ........................................................ 14 standard functions ............................................... 103
effective address ........................... 365, 368, 369, 371 CPUID instruction
PC-relative ........................................................... 19 testing for ........................................................... 103
RIP-relative ................................................... xxi, 19
CQO ....................................................................... 85
AND ....................................................................... 61
CWD ...................................................................... 85
ARPL ................................................................... 252
CWDE .................................................................... 84
B D
base field ........................................................ 370, 371
DAA ..................................................................... 105
biased exponent ..................................................... xvii
DAS ...................................................................... 106
BOUND .................................................................. 63 data types
BSF ........................................................................ 65 128-bit media ....................................................... 30
BSR ........................................................................ 66 64-bit media ......................................................... 32
BSWAP .................................................................. 67 general-purpose .................................................... 26
BT .......................................................................... 68 x87 ...................................................................... 34
BTC ....................................................................... 70 DEC......................................................... 14, 107, 401
BTR ....................................................................... 72 direct referencing ................................................... xvii
BTS ........................................................................ 74 displacements ................................................. xviii, 19
byte order of instructions ............................................ 1 DIV ...................................................................... 109
byte register addressing ............................................ 14 double quadword .................................................. xviii
C doubleword........................................................... xviii
E
CALL ..................................................................... 12
far call ................................................................. 78 eAX–eSP register .................................................. xxiii
near call ............................................................... 76 effective address .............................. 365, 368, 369, 371
CBW ...................................................................... 84 effective address size ............................................. xviii
CDQ ....................................................................... 85 effective operand size ............................................ xviii
CDQE ..................................................................... 84 eFLAGS register ................................................... xxiii
CLC ....................................................................... 86 eIP register ........................................................... xxiv
CLD ....................................................................... 87 element ................................................................ xviii
CLFLUSH .............................................................. 88 endian order...................................................... xxvi, 1
Index 439
AMD64 Technology 24594—Rev. 3.14—September 2007
440 Index
24594—Rev. 3.14—September 2007 AMD64 Technology
Index 441
AMD64 Technology 24594—Rev. 3.14—September 2007
442 Index
24594—Rev. 3.14—September 2007 AMD64 Technology
Index 443
AMD64 Technology 24594—Rev. 3.14—September 2007
444 Index