AMD Vol 3
AMD Vol 3
AMD Vol 3
AMD64 Architecture
Programmer’s Manual
Volume 3:
General-Purpose and
System Instructions
The information contained herein is for informational purposes only, and is subject to change without notice.
While every precaution has been taken in the preparation of this document, it may contain technical
inaccuracies, omissions and typographical errors, and AMD is under no obligation to update or otherwise
correct this information. Advanced Micro Devices, Inc. makes no representations or warranties with respect to
the accuracy or completeness of the contents of this document, and assumes no liability of any kind, including
the implied warranties of noninfringement, merchantability or fitness for particular purposes, with respect to
the operation or use of AMD hardware, software or other products described herein. No license, including
implied or arising by estoppel, to any intellectual property rights is granted by this document. Terms and
limitations applicable to the purchase or use of AMD’s products are as set forth in a signed agreement between
the parties or in AMD's Standard Terms and Conditions of Sale. Any unauthorized copying, alteration,
distribution, transmission, performance, display or other use of this material is prohibited.
Trademarks
AMD, the AMD Arrow logo, and combinations thereof, and 3DNow! are trademarks of Advanced
Micro Devices, Inc. Other product names used in this publication are for identification purposes only
and may be trademarks of their respective companies.
MMX is a trademark and Pentium is a registered trademark of Intel Corporation.
Contents
Figures. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi
Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
Revision History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv
About This Book. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv
Audience . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv
Organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv
Conventions and Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxvi
Related Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxviii
1 Instruction Encoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1
1.1 Instruction Encoding Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1.1 Encoding Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1.2 Representation in Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.2 Instruction Prefixes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.2.1 Summary of Legacy Prefixes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.2.2 Operand-Size Override Prefix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.2.3 Address-Size Override Prefix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.2.4 Segment-Override Prefixes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.2.5 Lock Prefix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.2.6 Repeat Prefixes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.2.7 REX Prefix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
1.2.8 VEX and XOP Prefixes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
1.3 Opcode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
1.4 ModRM and SIB Bytes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
1.4.1 ModRM Byte Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
1.4.2 SIB Byte Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
1.4.3 Operand Addressing in Legacy 32-bit and Compatibility Modes . . . . . . . . . . . . . . . . . 20
1.4.4 Operand Addressing in 64-bit Mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
1.5 Displacement Bytes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
1.6 Immediate Bytes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
1.7 RIP-Relative Addressing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
1.7.1 Encoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
1.7.2 REX Prefix and RIP-Relative Addressing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
1.7.3 Address-Size Prefix and RIP-Relative Addressing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
1.8 Encoding Considerations Using REX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
1.8.1 Byte-Register Addressing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
1.8.2 Special Encodings for Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
1.9 Encoding Using the VEX and XOP Prefixes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
1.9.1 Three-Byte Escape Sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
1.9.2 Two-Byte Escape Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Contents i
ii Contents
Contents iii
LAHF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
LDS
LES
LFS
LGS
LSS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
LEA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
LEAVE. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
LFENCE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
LLWPCB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
LODS
LODSB
LODSW
LODSD
LODSQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
LOOP
LOOPE
LOOPNE
LOOPNZ
LOOPZ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
LWPINS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
LWPVAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
LZCNT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
MCOMMIT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
MFENCE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
MONITORX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
MOV . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
MOVBE. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
MOVD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
MOVMSKPD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
MOVMSKPS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
MOVNTI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247
MOVS
MOVSB
MOVSW
MOVSD
MOVSQ. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
MOVSX. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
MOVSXD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
MOVZX. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
MUL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
MULX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
MWAITX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258
NEG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
NOP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
NOT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
OR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264
iv Contents
OUT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267
OUTS
OUTSB
OUTSW
OUTSD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268
PAUSE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
PDEP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
PEXT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
POP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
POPA
POPAD. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277
POPCNT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278
POPF
POPFD
POPFQ. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280
PREFETCH
PREFETCHW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
PREFETCHlevel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285
PUSH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287
PUSHA
PUSHAD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
PUSHF
PUSHFD
PUSHFQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
RCL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292
RCR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294
RDFSBASE
RDGSBASE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296
RDPID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297
RDPRU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
RDRAND . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299
RDSEED . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300
RET (Near) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301
RET (Far). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
ROL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308
ROR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310
RORX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312
SAHF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314
SAL
SHL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315
SAR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
SARX. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320
SBB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322
SCAS
SCASB
SCASW
SCASD
Contents v
SCASQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324
SETcc. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326
SFENCE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328
SHL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329
SHLD. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 330
SHLX. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 332
SHR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334
SHRD. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336
SHRX. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338
SLWPCB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340
STC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342
STD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343
STOS
STOSB
STOSW
STOSD
STOSQ. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344
SUB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346
T1MSKC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348
TEST . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 350
TZCNT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352
TZMSK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354
UD0, UD1, UD2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356
WRFSBASE
WRGSBASE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357
XADD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358
XCHG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 360
XLAT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362
XLATB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362
XOR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 363
4 System Instruction Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .367
ARPL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369
CLAC. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371
CLGI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372
CLI. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 373
CLTS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375
CLRSSBSY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 376
HLT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 378
INCSSP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379
INT 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381
INVD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 384
INVLPG. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385
INVLPGA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 386
INVLPGB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 387
INVPCID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391
IRET
IRETD
vi Contents
IRETQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 393
LAR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401
LGDT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403
LIDT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405
LLDT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407
LMSW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 409
LSL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 410
LTR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412
MONITOR. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 414
MOV CRn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 416
MOV DRn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 418
MWAIT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 420
PSMASH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 422
PVALIDATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425
RDMSR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 428
RDPKRU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429
RDPMC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 430
RDSSP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 432
RDTSC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433
RDTSCP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435
RMPADJUST . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437
RMPQUERY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 440
RMPREAD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443
RSM. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 450
RSTORSSP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 452
SAVEPREVSSP. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 455
SETSSBSY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457
SGDT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 459
SIDT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 460
SKINIT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 461
SLDT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 463
SMSW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 465
STAC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 466
STI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 467
STGI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 469
STR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 470
SWAPGS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 471
SYSCALL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 473
SYSENTER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 477
SYSEXIT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 479
SYSRET. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 481
TLBSYNC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 485
VERR. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 486
VERW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 488
VMLOAD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 489
VMMCALL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491
VMGEXIT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491
Contents vii
VMRUN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 492
VMSAVE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497
WBINVD. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 499
WBNOINVD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 499
WRMSR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 501
WRPKRU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 503
WRSS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 504
WRUSS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 507
Appendix A Opcode and Operand Encodings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .509
A.1 Opcode Maps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 512
Legacy Opcode Maps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 512
3DNow!™ Opcodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 528
x87 Encodings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 531
rFLAGS Condition Codes for x87 Opcodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 540
Extended Instruction Opcode Maps. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 540
A.2 Operand Encodings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 551
ModRM Operand References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 551
SIB Operand References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 556
Appendix B General-Purpose Instructions in 64-Bit Mode . . . . . . . . . . . . . . . . . . . . . . . .561
B.1 General Rules for 64-Bit Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 561
B.2 Operation and Operand Size in 64-Bit Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 562
B.3 Invalid and Reassigned Instructions in 64-Bit Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 587
B.4 Instructions with 64-Bit Default Operand Size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 588
B.5 Single-Byte INC and DEC Instructions in 64-Bit Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . 589
B.6 NOP in 64-Bit Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 590
B.7 Segment Override Prefixes in 64-Bit Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 590
Appendix C Differences Between Long Mode and Legacy Mode. . . . . . . . . . . . . . . . . . . .591
Appendix D Instruction Subsets and CPUID Feature Flags . . . . . . . . . . . . . . . . . . . . . . . .593
D.1 Instruction Set Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 594
D.2 CPUID Feature Flags Related to Instruction Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 596
Appendix E Obtaining Processor Information Via the CPUID Instruction . . . . . . . . . . .599
E.1 Special Notational Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 599
E.2 Standard and Extended Function Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 600
E.3 Standard Feature Function Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 600
Function 0h—Maximum Standard Function Number and Vendor String. . . . . . . . . . . . . . . 600
Function 1h—Processor and Processor Feature Identifiers. . . . . . . . . . . . . . . . . . . . . . . . . . 601
Functions 2h–4h—Reserved . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 604
Function 5h—Monitor and MWait Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 605
Function 6h—Power Management Related Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 605
Function 7h—Structured Extended Feature Identifiers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 606
Functions 8h–Ah—Reserved. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 608
Function Bh — Extended Topology Enumeration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 608
Function Ch—Reserved. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 610
Function Dh—Processor Extended State Enumeration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 610
Function Eh—Reserved. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 614
viii Contents
Contents ix
x Contents
Figures
Figure 1-1. Instruction Encoding Syntax. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Figure 1-2. An Instruction as Stored in Memory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Figure 1-3. REX Prefix Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Figure 1-4. ModRM-Byte Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Figure 1-5. SIB Byte Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Figure 1-6. Encoding Examples Using REX R, X, and B Bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Figure 1-7. VEX/XOP Three-byte Escape Sequence Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Figure 1-8. VEX Two-byte Escape Sequence Format. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Figure 2-1. Format of Instruction-Detail Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Figure 2-2. General Registers in Legacy and Compatibility Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Figure 2-3. General Registers in 64-Bit Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Figure 2-4. Segment Registers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Figure 2-5. General-Purpose Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Figure 2-6. System Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Figure 2-7. System Data Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Figure 2-8. SSE Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Figure 2-9. 128-Bit SSE Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Figure 2-10. SSE 256-bit Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Figure 2-11. SSE 256-Bit Data Types (Continued). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Figure 2-12. 64-Bit Media Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Figure 2-13. 64-Bit Media Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Figure 2-14. x87 Registers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Figure 2-15. x87 Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Figure 2-16. Syntax for Typical Two-Operand Instruction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Figure 3-1. MOVD Instruction Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240
Figure A-1. ModRM-Byte Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 521
Figure A-2. ModRM-Byte Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 551
Figure A-3. SIB Byte Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 557
Figure D-1. AMD64 ISA Instruction Subsets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 595
Figures xi
xii Figures
Tables
Table 1-1. Legacy Instruction Prefixes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Table 1-2. Operand-Size Overrides . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Table 1-3. Address-Size Overrides. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Table 1-4. Pointer and Count Registers and the Address-Size Prefix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Table 1-5. Segment-Override Prefixes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Table 1-6. REP Prefix Opcodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Table 1-7. REPE and REPZ Prefix Opcodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Table 1-8. REPNE and REPNZ Prefix Opcodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Table 1-9. Instructions Not Requiring REX Prefix in 64-Bit Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Table 1-10. ModRM.reg and .r/m Field Encodings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Table 1-11. SIB.scale Field Encodings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Table 1-12. SIB.index and .base Field Encodings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Table 1-13. SIB.base encodings for ModRM.r/m = 100b . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Table 1-14. Operand Addressing Using ModRM and SIB Bytes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Table 1-15. REX Prefix-Byte Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Table 1-16. Encoding for RIP-Relative Addressing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Table 1-17. Special REX Encodings for Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Table 1-18. Three-byte Escape Sequence Field Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Table 1-19. VEX.map_select Encoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Table 1-20. XOP.map_select Encoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Table 1-21. VEX/XOP.vvvv Encoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Table 1-22. VEX/XOP.pp Encoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Table 1-23. VEX Two-byte Escape Sequence Field Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Table 1-24. Fixed Field Values for VEX 2-Byte Format. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Table 2-1. Interrupt-Vector Source and Cause. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Table 2-2. +rb, +rw, +rd, and +rq Register Value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Table 3-1. Instruction Support Indicated by CPUID Feature Bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Table 3-2. Processor Vendor Return Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
Table 3-3. Locality References for the Prefetch Instructions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285
Table 4-1. System Instruction Support Indicated by CPUID Feature Bits. . . . . . . . . . . . . . . . . . . . . . . . . 367
Table A-1. Primary Opcode Map (One-byte Opcodes), Low Nibble 0–7h . . . . . . . . . . . . . . . . . . . . . . . . 513
Table A-2. Primary Opcode Map (One-byte Opcodes), Low Nibble 8–Fh . . . . . . . . . . . . . . . . . . . . . . . . 514
Table A-3. Secondary Opcode Map (Two-byte Opcodes), Low Nibble 0–7h . . . . . . . . . . . . . . . . . . . . . . 516
Table A-4. Secondary Opcode Map (Two-byte Opcodes), Low Nibble 8–Fh . . . . . . . . . . . . . . . . . . . . . . 518
Tables xiii
Table A-5. rFLAGS Condition Codes for CMOVcc, Jcc, and SETcc . . . . . . . . . . . . . . . . . . . . . . . . . . . . 520
Table A-6. ModRM.reg Extensions for the Primary Opcode Map1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 521
Table A-7. ModRM.reg Extensions for the Secondary Opcode Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 523
Table A-8. Opcode 01h ModRM Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 525
Table A-9. 0F_38h Opcode Map, Low Nibble = [0h:7h] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 526
Table A-10. 0F_38h Opcode Map, Low Nibble = [8h:Fh] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 526
Table A-11. 0F_3Ah Opcode Map, Low Nibble = [0h:7h] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 527
Table A-12. 0F_3Ah Opcode Map, Low Nibble = [8h:Fh] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 527
Table A-13. Immediate Byte for 3DNow!™ Opcodes, Low Nibble 0–7h . . . . . . . . . . . . . . . . . . . . . . . . . . 529
Table A-14. Immediate Byte for 3DNow!™ Opcodes, Low Nibble 8–Fh . . . . . . . . . . . . . . . . . . . . . . . . . . 530
Table A-15. x87 Opcodes and ModRM Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 532
Table A-16. rFLAGS Condition Codes for FCMOVcc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 540
Table A-17. VEX Opcode Map 1, Low Nibble = [0h:7h] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 541
Table A-18. VEX Opcode Map 1, Low Nibble = [0h:7h] Continued. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 542
Table A-19. VEX Opcode Map 1, Low Nibble = [8h:Fh] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 543
Table A-20. VEX Opcode Map 2, Low Nibble = [0h:7h] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 544
Table A-21. VEX Opcode Map 2, Low Nibble = [8h:Fh] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 545
Table A-22. VEX Opcode Map 3, Low Nibble = [0h:7h] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 546
Table A-23. VEX Opcode Map 3, Low Nibble = [8h:Fh] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 547
Table A-24. VEX Opcode Groups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 548
Table A-25. XOP Opcode Map 8h, Low Nibble = [0h:7h]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 548
Table A-26. XOP Opcode Map 8h, Low Nibble = [8h:Fh] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 549
Table A-27. XOP Opcode Map 9h, Low Nibble = [0h:7h]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 549
Table A-28. XOP Opcode Map 9h, Low Nibble = [8h:Fh] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 550
Table A-29. XOP Opcode Map Ah, Low Nibble = [0h:7h] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 550
Table A-30. XOP Opcode Map Ah, Low Nibble = [8h:Fh] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 550
Table A-31. XOP Opcode Groups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 550
Table A-32. ModRM reg Field Encoding, 16-Bit Addressing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 552
Table A-33. ModRM Byte Encoding, 16-Bit Addressing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 552
Table A-34. ModRM reg Field Encoding, 32-Bit and 64-Bit Addressing . . . . . . . . . . . . . . . . . . . . . . . . . . 554
Table A-35. ModRM Byte Encoding, 32-Bit and 64-Bit Addressing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 555
Table A-36. Addressing Modes: SIB base Field Encoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 557
Table A-37. Addressing Modes: SIB Byte Encoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 558
Table B-1. Operations and Operands in 64-Bit Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 562
Table B-2. Invalid Instructions in 64-Bit Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 587
Table B-3. Reassigned Instructions in 64-Bit Mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 588
xiv Tables
Tables xv
xvi Tables
Revision History
xx Revision History
Preface
Audience
This volume (APM 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 APM Volume 1.
Descriptions of system instructions assume an understanding of the system-level programming topics
described in APM Volume 2.
Organization
APM 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
• Streaming SIMD Extensions–SSE (includes 128-bit and 256-bit media instructions)
• 64-bit media instructions (MMX™)
• 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 xxv
information on instructions in other subsets, see the tables of contents and indexes of the other APM
volumes.
xxvi Preface
CR0[PE] = 1, CR0.PE = 1
Notation indicating that the PE bit of the CR0 register has a value of 1.
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, EFER.LME = 0
Notation indicating that the LME bit of the EFER register has a value of 0.
RFLAGS[13:12]
A field within a register identified by its bit range. In this example, corresponding to the IOPL
field.
Definitions
Many of the following definitions assume an in-depth knowledge of the legacy x86 architecture. See
“Related Documents” on page xxxviii for descriptions of the legacy x86 architecture.
128-bit media instructions
Instructions that operate on the various 128-bit vector data types. Supported within both the legacy
SSE and extended SSE instruction sets.
256-bit media instructions
Instructions that operate on the various 256-bit vector data types. Supported within the extended
SSE instruction set.
64-bit media instructions
Instructions that operate on the 64-bit vector data types. These are primarily a combination of
MMX™ and 3DNow!™ instruction sets, with some additional instructions from the SSE1 and
SSE2 instruction sets.
16-bit mode
Legacy mode or compatibility mode in which a 16-bit address size is active. See legacy mode and
compatibility mode.
32-bit mode
Legacy mode or compatibility mode in which a 32-bit address size is active. See legacy mode and
compatibility mode.
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.
Preface xxvii
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.
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.
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.
xxviii Preface
Preface xxix
IVT
The real-address mode interrupt-vector table.
LDT
Local descriptor table.
legacy x86
The legacy x86 architecture. See “Related Documents” on page xxxviii 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.
LIP
Linear Instruction Pointer. LIP = (CS.base + rIP).
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.
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.
xxx Preface
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.
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.
procedure stack
A portion of a stack segment in memory that is used to link procedures. Also known as a program
Preface xxxi
stack.
program stack
See procedure stack.
protected mode
A submode of legacy mode.
quadword
Four words, or eight bytes, or 64 bits.
RAZ
Read as zero. Value returned on a read is always zero (0) regardless of what was previously
written. See reserved.
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. Software must not depend on the state of a reserved field (unless
qualified as RAZ), nor upon the ability of such fields to return a previously written state.
If a field is marked reserved without qualification, software must not change the state of that field;
it must reload that field with the same value returned from a prior read.
Reserved fields may be qualified as IGN, MBZ, RAZ, or SBZ (see definitions).
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.
SBZ
Should be zero. An attempt by software to set an SBZ bit to 1 results in undefined behavior.
xxxii Preface
shadow stack
A shadow stack is a separate, protected stack that is conceptually parallel to the procedure stack
and used only by the shadow stack feature.
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.
Preface xxxiii
(2) An index into an interrupt descriptor table (IDT), used to access exception handlers. Compare
exception.
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.
xxxiv Preface
EFLAGS
32-bit (extended) flags register.
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.
Preface xxxv
RBP
64-bit version of the EBP register.
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.
SSP
Shadow-stack pointer register.
TPR
Task priority register, a new register introduced in the AMD64 architecture to speed interrupt
management.
xxxvi Preface
TR
Task register.
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.
Preface xxxvii
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, Software Optimization Guide for AMD Family 15h Processors, order number 47414.
• AMD, BIOS and Kernel Developer's Guide (BKDG) for particular hardware implementations of
older families of the AMD64 architecture.
• AMD, Processor Programming Reference (PPR) for particular hardware implementations of
newer families of the AMD64 architecture.
• 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.
• 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.
xxxviii Preface
• 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.
• 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.
Preface xxxix
• 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.
xl Preface
1 Instruction Encoding
AMD64 technology instructions are encoded as byte strings of variable length. The order and meaning
of each byte of an instruction’s encoding is specified by the architecture. Fields within the encoding
specify the instruction’s basic operation, the location of the one or more source operands, and the
destination of the result of the operation. Data to be used in the execution of the instruction or the
computation of addresses for memory-based operands may also be included. This section describes the
general format and parameters used by all instructions.
For information on the specific encoding(s) for each instruction, see:
• Chapter 3, “General-Purpose Instruction Reference.”
• Chapter 4, “System Instruction Reference.”
• “SSE Instruction Reference” in APM Volume 4.
• “64-Bit Media Instruction Reference” in APM Volume 5.
• “x87 Floating-Point Instruction Reference” in APM Volume 5.
For information on determining the instruction form and operands specified by a given binary
encoding, see Appendix A.
Instruction Encoding 1
≤ additional
3DNow!
0Fh 3DNow!
escape opcode
map
3Ah 0F_3Ah
escape opcode
map
C5 2-byte sequence NOTES:
VEX R.vvvv VEX 1. REX prefix is not allowed in extended
opcode instruction encodings that employ the
prefix .L.pp
map=01h map 1 VEX or XOP prefixes
C4 3-byte sequence map=02h 2. map = VEX/XOP.map_select field
VEX W.vvvv VEX 3. The total number of bytes in an
RXB. opcode
prefix map_sel .L.pp instruction encoding must be less than
map 2
or equal to 15
map=03h 4. Instructions that encode an 8-byte
VEX immediate field do not use a displace-
opcode ment field and vice versa.
map 3
XOP
opcode
map=08h map 8
map=09h
map=0Ah
XOP
opcode
map A
Each square in this diagram represents an instruction byte of a particular type and function. To
understand the diagram, follow the connecting paths in the direction indicated by the arrows from
“Start” to “End.” The squares passed through as the graph is traversed indicate the order and number of
2 Instruction Encoding
bytes used to encode the instruction. Note that the path shown above the legacy prefix byte loops back
indicating that up to four additional prefix bytes may be used in the encoding of a single instruction.
Branches indicate points in the syntax where alternate semantics are employed based on the instruction
being encoded. The “VEX or XOP” gate across the path leading down to the VEX prefix and XOP
prefix blocks means that only extended instructions employing the VEX or XOP prefixes use this
particular branch of the syntax diagram. This diagram will be further explained in the sections that
follow.
1.1.1.3 Opcode
The opcode is a single byte that specifies the basic operation of an instruction. Every instruction
requires an opcode. The correspondence between the binary value of an opcode and the operation it
represents is presented in a table called an opcode map. Because it is indexed by an 8-bit value, an
opcode map has 256 entries. Since there are more than 256 instructions defined by the architecture,
multiple different opcode maps must be defined and the selection of these alternate opcode maps must
be encoded in the instruction. Escape sequences provide this access to alternate opcode maps.
If there are no opcode escapes, the primary (“one-byte”) opcode map is used. In the figure this is the
path pointing from the REX Prefix block to the Primary opcode map block.
Section “Primary Opcode Map” of Appendix A provides details concerning this opcode map.
Instruction Encoding 3
legacy escape sequences and extended escape sequences. The legacy escape sequences will be covered
here. For more details on the extended escape sequences, see “VEX and XOP Prefixes” on page 16.
4 Instruction Encoding
Highest
Address Immediate Immediate
Immediate Immediate
* *1,2,4, or 8
Immediate Immediate
Immediate Immediate
see note 4
Displacement Displacement
Displacement Displacement
† †1,2,4, or 8
Displacement Displacement
Displacement Displacement
SIB† SIB† † optional, based addressing mode
≤ 15 Bytes
ModRM* ModRM* * optional, based on instruction
Opcode Opcode
Escape* W.vvvv.L.pp R.vvvv.L.pp for VEX C5
Escape* RXB.map_select not present for VEX C5
REX¹ VEX/XOP
Legacy Prefix Legacy Prefix³
Legacy Prefix Legacy Prefix³
≤ ≤4
Legacy Prefix ‡ Legacy Prefix³ ‡ optional, with most instructions
Lowest
Address Legacy Prefix Legacy Prefix³
7 0 7 0
Notes:
¹ Available only in 64-Bit Mode
² Available only in Long or Protected Mode
³ F0, F2, F3, and 66 prefixes not allowed
4
Instructions that specify an 8-byte immediate field do
not include a displacement field and vice versa.
Instruction Encoding 5
the instruction modifier prefixes, but they also provide a means to directly specify alternate opcode
maps.
The currently defined encoding escape prefixes are the VEX and XOP prefixes. They are discussed
further in the section entitled “VEX and XOP Prefixes” on page 16.
6 Instruction Encoding
Prefix
Prefix Group1 Mnemonic
Byte (Hex)
Description
Instruction Encoding 7
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 14) 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 APM Volume 1.
• All instructions, except far branches, that implicitly reference the RSP. For details, see “Stack
Operation” in APM 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
8 Instruction Encoding
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.
For other instructions (mostly SIMD instructions) the 66h, F2h, and F3h prefixes are used as opcode
extensions to extend the instruction encoding space in the 0Fh, 0F_38h, and 0F_3Ah opcode maps.
Operand-Size and REX Prefixes. The W bit field of the REX prefix takes precedence over the 66h
prefix. See “REX.W: Operand width (Bit 3)” on page 23 for details.
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
Instruction Encoding 9
Initialization and Long Mode Activation” in APM 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—
CX ECX RCX
Jump 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
10 Instruction Encoding
for such memory-referencing instructions is implied by the base register indicated in its ModRM byte,
as follows:
• Instructions that Reference a Non-Stack Segment—If an instruction encoding references any base
register other than rBP or rSP, or if an instruction contains an immediate offset, the default segment
is the data segment (DS). These instructions can use the segment-override prefix to select one of
the non-default segments, as shown in Table 1-5.
• String Instructions—String instructions reference two memory operands. By default, they
reference both the DS and ES segments (DS:rSI and ES:rDI). These instructions can override their
DS-segment reference, as shown in Table 1-5, but they cannot override their ES-segment
reference.
• Instructions that Reference the Stack Segment—If an instruction’s encoding references the rBP or
rSP base register, the default segment is the stack segment (SS). All instructions that reference the
stack (push, pop, call, interrupt, return from interrupt) use SS by default. These instructions cannot
use the segment-override prefix.
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 APM Volume 2 for details.
Instruction Encoding 11
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.
12 Instruction Encoding
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 14 shows the valid REPNE and
REPNZ prefix opcodes.
Instruction Encoding 13
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 above. For other instructions (mostly SIMD
instructions) the 66h, F2h, and F3h prefixes are used as instruction modifiers to extend the instruction
encoding space in the 0Fh, 0F_38h, and 0F_3Ah opcode maps.
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 in-line 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.
14 Instruction Encoding
7 6 5 4 3 2 1 0
4 W R X B
v3_REX_byte_format.eps
A REX prefix is normally required with an instruction that accesses a 64-bit GPR or one of the
extended GPR or YMM/XMM registers. 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 instructions are listed in
Table 1-9 below.
An instruction may have only one REX prefix which must immediately precede the opcode or first
escape byte in the instruction encoding. The use of a REX prefix in an instruction that does not access
an extended register is ignored. The instruction-size limit of 15 bytes applies to instructions that
contain a REX prefix.
Instruction Encoding 15
1.3 Opcode
The opcode is a single byte that specifies the basic operation of an instruction. In some cases, it also
specifies the operands for the instruction. Every instruction requires an opcode. The correspondence
between the binary value of the opcode and the operation it represents is defined by a table called an
opcode map. As discussed in the previous sections, the legacy prefixes 66h, F2h, and F3h and other
fields within the instruction encoding may be used to modify the operation encoded by the opcode.
The affect of the presence of a 66h, F2h, or F3h prefix on the operation performed by the opcode is
represented in the opcode map by additional rows in the table indexed by the applicable prefix. The 3-
bit reg and r/m fields of the ModRM byte (“ModRM Byte Format” on page 17 and “SIB Byte Format”
on page 18) are used as well in the encoding of certain instructions. This is represented in the opcode
maps via instruction group tables that detail the modifications represented via the extra encoding bits.
See Section A.1, “Opcode Maps” of Appendix A for examples.
Even though each instruction has a unique opcode map and opcode, assemblers often support multiple
alternate mnemonics for the same instruction to improve the readability of assembly language code.
16 Instruction Encoding
The 64-bit floating-point 3DNow! instructions utilize the two-byte escape sequence 0Fh, 0Fh to select
the 3DNow! opcode map. For these instructions the opcode is encoded in the immediate field at the
end of the instruction encoding.
For details on how the opcode byte encodes the basic operation for specif instructions, see Section A.1,
“Opcode Maps” of Appendix A
7 6 5 4 3 2 1 0
mod reg r/m ModRM
Depending on the addressing mode, the SIB byte may appear after the ModRM byte. SIB is used in the
specification of various forms of indexed register-indirect addressing. See the following section for
details.
Instruction Encoding 17
ModRM.mod (Bits[7:6]). The mod field is used with the r/m field to specify the addressing mode for
an operand. ModRM.mod = 11b specifies the register-direct addressing mode. In the register-direct
mode, the operand is held in the specified register. ModRM.mod values less than 11b specify register-
indirect addressing modes. In register-indirect addressing modes, values held in registers along with an
optional displacement specified in the instruction encoding are used to calculate the address of a
memory-based operand. Other encodings of the 5 bits {mod, r/m} are discussed below.
ModRM.reg (Bits[5:3]). The reg field is used to specify a register-based operand, although for some
instructions, this field is used to extend the operation encoding. The encodings for this field are shown
in Table 1-10 below.
ModRM.r/m (Bits[2:0]). As stated above, the r/m field is used in combination with the mod field to
encode 32 different operand specifications (See Table 1-14 on page 21). The encodings for this field
are shown in Table 1-10 below.
Similar to the reg field, r/m is used in some instructions to extend the operation encoding.
18 Instruction Encoding
The basic formula for computing the effective address of a memory-based operand using the indexed
register-indirect address modes is:
Bits: 7 6 5 4 3 2 1 0
scale index base SIB
SIB.scale (Bits[7:6]). The scale field is used to specify the scale factor used in computing the
scale*index portion of the effective address. In normal usage scale represents the size of data elements
in an array expressed in number of bytes. SIB.scale is encoded as shown in Table 1-11 below.
SIB.index (Bits[5:3]). The index field is used to specify the register containing the index portion of
the indexed register-indirect effective address. SIB.index is encoded as shown in Table 1-12 below.
SIB.base (Bits[2:0]). The base field is used to specify the register containing the base address
portion of the indexed register-indirect effective address. SIB.base is encoded as shown in Table 1-12
below.
Instruction Encoding 19
Encoded value
SIB.index SIB.base
(binary)
000 [rAX] [rAX]
001 [rCX] [rCX]
010 [rDX] [rDX]
011 [rBX] [rBX]
100 (none)1 [rSP]
101 [rBP] [rBP], (none)2
110 [rSI] DH, [rSI]
111 [rDI] BH, [rDI]
Notes:
1. Register specification is null. The scale*index portion of the indexed register-indirect effec-
tive address is set to 0.
2. If ModRM.mod = 00b, the register specification is null. The base portion of the indexed reg-
ister-indirect effective address is set to 0. Otherwise, base encodes the rBP register as
the source of the base address used in the effective address calculation.
20 Instruction Encoding
Instruction Encoding 21
Table 1-14. Operand Addressing Using ModRM and SIB Bytes (continued)
ModRM.mod ModRM.r/m Register / Effective Address
000 AL/rAX/MMX0/XMM0/YMM0
001 CL/rCX/MMX1/XMM1/YMM1
010 DL/rDX/MMX2/XMM2/YMM2
011 BL/rBX/MMX3/XMM3/YMM3
11
100 AH/SPL/rSP/MMX4/XMM4/YMM4
101 CH/BPL/rBP/MMX5/XMM5/YMM5
110 DH/SIL/rSI/MMX6/XMM6/YMM6
111 BH/DIL/rDI/MMX7/XMM7/YMM7
Notes:
0. In the following notes, scaled_index = SIB.index * (1 << SIB.scale).
1. SIB byte follows ModRM byte. Effective address is calculated using
scaled_index+base. When SIB.base = 101b, addressing mode depends on
ModRM.mod. See Table 1-13 above.
2. SIB byte follows ModRM byte. Effective address is calculated using scaled_in-
dex+base+8-bit_offset. One-byte Displacement field provides the offset.
3. SIB byte follows ModRM byte. Effective address is calculated using scaled_in-
dex+base+32-bit_offset. Four-byte Displacement field provides the offset.
Note that the addressing mode mod = 11b is a register-direct mode, that is, the operand is contained in
the specified register, while the modes mod = [00b:10b] specify different addressing modes for a
memory-based operand.
For mod = 11b, the register containing the operand is specified by the r/m field. For the other modes
(mod = [00b:10b]), the mod and r/m fields are combined to specify the addressing mode for the
memory-based operand. Most are register-indirect addressing modes meaning that the address of the
memory-based operand is contained in the register specified by r/m. For these register-indirect modes,
mod = 01b and mod = 10b include an offset encoded in the displacement field of the instruction.
The encodings {mod ≠ 11b, r/m = 100b} specify the indexed register-indirect addressing mode in
which the target address is computed using a combination of values stored in registers and a scale
factor encoded directly in the SIB byte. For these addressing modes the effective address is given by
the formula:
22 Instruction Encoding
REX.W: Operand width (Bit 3). Setting the REX.W bit to 1 specifies a 64-bit operand size. Like the
existing 66h operand-size override 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 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 W bit cleared to 0,
the 66h prefix is not ignored and the operand size becomes 16 bits.
REX.R: Register field extension (Bit 2). The REX.R bit adds a 1-bit extension (in the most
significant bit position) to the ModRM.reg field when that field encodes a GPR, YMM/XMM, control,
or debug register. REX.R does not modify ModRM.reg when that field specifies other registers or is
used to extend the opcode. REX.R is ignored in such cases.
REX.X: Index field extension (Bit 1). The REX.X bit adds a 1-bit (msb) extension to the SIB.index
field. See “ModRM and SIB Bytes” on page 17.
Instruction Encoding 23
REX.B: Base field extension (Bit 0). The REX.B bit adds a 1-bit (msb) 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 56 for more about the B bit.)
24 Instruction Encoding
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-16 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 ({mod,r/m} =
00101b) is redefined to be RIP + disp32 rather than displacement-only.
Instruction Encoding 25
26 Instruction Encoding
Instruction Encoding 27
4
4
Rrrr Bbbb
4
4
Rrrr Bbbb
4 4
4
Rrrr Xxxx Bbbb
4
Bbbb
28 Instruction Encoding
Instruction Encoding 29
Byte 1
VEX/XOP.R (Bit 7). The bit-inverted equivalent of the REX.R bit. A one-bit extension of the
ModRM.reg field in 64-bit mode, permitting access to 16 YMM/XMM and GPR registers. In 32-bit
protected and compatibility modes, the value must be 1.
VEX/XOP.X (Bit 6). The bit-inverted equivalent of the REX.X bit. A one-bit extension of the
SIB.index field in 64-bit mode, permitting access to 16 YMM/XMM and GPR registers. In 32-bit
protected and compatibility modes, this value must be 1.
VEX/XOP.B (Bit 5). The bit-inverted equivalent of the REX.B bit, available only in the 3-byte prefix
format. A one-bit extension of either the ModRM.r/m field, to specify a GPR or XMM register, or of
the SIB base field, to specify a GPR. This permits access to all 16 GPR and YMM/XMM registers. In
32-bit protected and compatibility modes, this bit is ignored.
VEX/XOP.map_select (Bits [4:0]). The five-bit map_select field is used to select an alternate
opcode map. The map select encoding spaces for VEX and XOP are disjoint. Table 1-19 below lists
the encodings for VEX.map_select and Table 1-20 lists the encodings for XOP.map_select.
30 Instruction Encoding
AVX instructions are encoded using the VEX opcode maps 1–3. The AVX instruction set includes
instructions that provide operations similar to most legacy SSE instructions. For those AVX
instructions that have an analogous legacy SSE instruction, the VEX opcode maps use the same binary
opcode value and modifiers as the legacy version. The correspondence between the VEX opcode maps
and the legacy opcode maps are shown in Table 1-19 above.
VEX opcode maps 1–3 are also used to encode the FMA4 and FMA instructions. In addition, not all
legacy SSE instructions have AVX equivalents. Therefore, the VEX opcode maps are not the same as
the legacy opcode maps.
The XOP opcode maps are unique to the XOP instructions. The XOP.map_select value is restricted to
the range [08h:1Fh]. If the value of the XOP.map_select field is less than 8, the first two bytes of the
three-byte XOP escape sequence are interpreted as a form of the POP instruction.
Both legacy and extended opcode maps are covered in detail in Appendix A.
Byte 2
VEX/XOP.W (Bit 7). Function is instruction-specific. The bit is often used to configure source
operand order.
VEX/XOP.vvvv (Bits [6:3]). Used to specify an additional operand for three and four operand
instructions. Encodes an XMM or YMM register in inverted ones’ complement form, as shown in
Table 1-21.
Instruction Encoding 31
Values 0000h to 0111h are not valid in 32-bit modes. vvvv is typically used to encode the first source
operand, but for the VPSLLDQ, VPSRLDQ, VPSRLW, VPSRLD, VPSRLQ, VPSRAW, VPSRAD,
VPSLLW, VPSLLD, and VPSLLQ shift instructions, the field specifies the destination register.
VEX/XOP.L (Bit 2). L = 0 specifies 128-bit vector length (XMM registers/128-bit memory
locations). L=1 specifies 256-bit vector length (YMM registers/256-bit memory locations). For SSE or
XOP instructions with scalar operands, the L bit is ignored. Some vector SSE instructions support only
the 128 bit vector size. For these instructions, L is cleared to 0.
VEX/XOP.pp (Bits [1:0]). Specifies an implied 66h, F2h, or F3h opcode extension which is used in a
way analogous to the legacy instruction encodings to extend the opcode encoding space. The
correspondence between the encoding of the VEX/XOP.pp field and its function as an opcode modifier
is shown in Table 1-22. The legacy prefixes 66h, F2h, and F3h are not allowed in the encoding of
extended instructions.
32 Instruction Encoding
Byte 0 Byte 1
7 0 7 6 3 2 1 0
VEX R vvvv L pp
Byte 1
Note that the bit 7 of this byte is used to encode VEX.R instead of VEX.W as in the three-byte escape
sequence form. The R, vvvv, L, and pp fields are defined as in the three-byte escape sequence.
When the two-byte escape sequence is used, specific fields from the three-byte format take on fixed
values as shown in Table 1-24 below.
Although they may be encoded using the VEX three-byte escape sequence, all instructions that
conform with the constraints listed in Table 1-24 may be encoded using the two-byte escape sequence.
Note that the implied value of map_select is 00001b, which means that only instructions included in
the VEX opcode map 1 may be encoded using this format.
VEX-encoded instructions that use the other defined values of map_select (00010b and 00011b)
cannot be encoded using this a two-byte escape sequence format. Note that the VEX.pp field value is
explicitly encoded in this form and can be used to specify any of the implied legacy prefixes as defined
in Table 1-22.
Instruction Encoding 33
34 Instruction Encoding
2 Instruction Overview
Instruction Overview 35
36 Instruction Overview
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 37
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
Figure 2-3 on page 39 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-
38 Instruction Overview
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).
zero-extended
for 32-bit operands
not modified for 16-bit operands low
not modified for 8-bit operands 8 bits 16-bit 32-bit 64-bit
0 AH* AL AX EAX RAX
3 BH* BL BX EBX RBX
1 CH* CL CX ECX RCX
2 DH* DL DX EDX RDX
6 SIL** SI ESI RSI
7 DIL** DI EDI RDI
Register Encoding
0 RFLAGS
RIP
63 32 31 0
For most instructions running in 64-bit mode, access to the extended GPRs requires a either a REX
instruction modification prefix or extended encoding using the VEX or XOP sequences (page 16).
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
Instruction Overview 39
(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 APM Volume 2.
CS CS
(Attributes only)
DS ignored
ES ignored
FS FS
(Base only)
GS GS
(Base only)
SS ignored
15 0 15 0
Data Types. Figure 2-5 on page 41 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.
40 Instruction Overview
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
0
Registers. The system instructions use several specialized registers shown in Figure 2-6 on page 42.
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 41
DR7 MCG_STAT
Data Structures. Figure 2-7 on page 43 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.
42 Instruction Overview
Descriptor Tables
Page-Translation Tables
Registers. The SSE instructions operate primarily on 128-bit and 256-bit floating-point vector
operands located in the 256-bit YMM/XMM registers. Each 128-bit XMM register is defined as the
lower octword of the corresponding YMM register. The number of available YMM/XMM data
registers depends on the operating mode, as shown in Figure 2-8 below. In legacy and compatibility
modes, eight YMM/XMM registers (YMM/XMM0–7) are available. In 64-bit mode, eight additional
YMM/XMM data registers (YMM/XMM8–15) are available. These eight additional registers are
addressed via the encoding extensions provided by the REX, VEX, and XOP prefixes.
Instruction Overview 43
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
the MMX registers (Figure 2-12 on page 48) or set or clear flags in the rFLAGS register (see
Figure 2-2 and Figure 2-3).
255 127 0
XMM0 YMM0
XMM1 YMM1
XMM2 YMM2
XMM3 YMM3
XMM4 YMM4
XMM5 YMM5
XMM6 YMM6
XMM7 YMM7
XMM8 YMM8
XMM9 YMM9
XMM10 YMM10
XMM11 YMM11
XMM12 YMM12
XMM13 YMM13
XMM14 YMM14
XMM15 YMM15
Data Types. The SSE instruction set architecture provides support for 128-bit and 256-bit packed
floating-point and integer data types as well as integer and floating-point scalars. Figure 2-9 below
shows the 128-bit data types. Figure 2-10 on page 46 and Figure 2-11 on page 47 show the 256-bit
data types. The floating-point data types include IEEE-754 single precision and double precision
types.
44 Instruction Overview
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
7 0
Scalar Unsigned Integers
127 double quadword (octword) 0
127 quadword
63 doubleword
31 word
15 byte
7
bit
Note: 1) A 16 bit Half-Precision Floating-Point Scalar is also defined.
0
Instruction Overview 45
Vector (Packed) Signed Integer – Double Quadword, Quadword, Doubleword, Word, Byte
46 Instruction Overview
Vector (Packed) Unsigned Integer – Double Quadword, Quadword, Doubleword, Word, Byte
quadword quadword
byte byte byte byte byte byte byte byte byte byte byte byte byte byte byte byte
255 247 239 231 223 215 207 199 191 183 175 167 159 151 143 135 128
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
7 0
Instruction Overview 47
Registers. The 64-bit media instructions use the eight 64-bit MMX registers, as shown in
Figure 2-12. 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
Data Types. Figure 2-13 on page 49 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.
48 Instruction Overview
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
Instruction Overview 49
Registers. The x87 floating-point instructions use the x87 registers shown in Figure 2-14. 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-15 on page 51 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.
50 Instruction Overview
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
Instruction Overview 51
52 Instruction Overview
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-16 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 53
54 Instruction Overview
Instruction Overview 55
56 Instruction Overview
Table 2-2. +rb, +rw, +rd, and +rq Register Value (continued)
REX.B Specified Register
Value
Bit1 +rb +rw +rd +rq
0 R8B R8W R8D R8
1 R9B R9W R9D R9
2 R10B R10W R10D R10
3 R11B R11W R11D R11
1
4 R12B R12W R12D R12
5 R13B R13W R13D R13
6 R14B R14W R14D R14
7 R15B R15W R15D R15
1. See “REX Prefix” on page 14.
// in the following, '&&' is the logical AND operator. See "Logical Operators"
// below.
// reg[fld] identifies a field (one or more bits) within architected register
// or within a sub-element of a larger data structure. A dot separates the
// higher-level data structure name from the sub-element name.
//
CS.desc = Code Segment descriptor // CS.desc has sub-elements: base, limit, attr
SS.desc = Stack Segment descriptor // SS.desc has the same sub-elements
CS.desc.base = base subfield of CS.desc
CS = Code Segment Register
SS = Stack Segment Register
CPL = Current Privilege Level (0 <= CPL <= 3)
REAL_MODE = (CR0[PE] == 0)
Instruction Overview 57
/////////////////////////////////////////////////////////////////////////////////
// Architected Registers
/////////////////////////////////////////////////////////////////////////////////
// Identified using abbreviated names assigned by the Architecture; can represent
// the register or its contents depending on context.
RAX = the 64-bit contents of the general-purpose register
EAX = 32-bit contents of GPR EAX
AX = 16-bit contents of GPR AX
AL = lower 8 bits of GPR AX
AH = upper 8 bits of GPR AX
/////////////////////////////////////////////////////////////////////////////////
// Defined Variables
/////////////////////////////////////////////////////////////////////////////////
58 Instruction Overview
/////////////////////////////////////////////////////////////////////////////////
// Exceptions
/////////////////////////////////////////////////////////////////////////////////
EXCEPTION [#GP(0)] // Signals an exception; error code in parenthesis
EXCEPTION [#UD] // if no error code
Instruction Overview 59
/////////////////////////////////////////////////////////////////////////////////
// Implicit Assignments
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
// Bit Range Inside a Register
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
// Variables and data types
/////////////////////////////////////////////////////////////////////////////////
NxtValue = 5 //default data type is unsigned int.
60 Instruction Overview
/////////////////////////////////////////////////////////////////////////////////
// Elements Within a packed data type
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
// Moving Data From One Register To Another
/////////////////////////////////////////////////////////////////////////////////
temp_dest.b = temp_src; // 1-byte move (copies lower 8 bits of temp_src to
// temp_dest, preserving the upper 56 bits of temp_dest)
temp_dest.w = temp_src; // 2-byte move (copies lower 16 bits of temp_src to
// temp_dest, preserving the upper 48 bits of temp_dest)
temp_dest.d = temp_src; // 4-byte move (copies lower 32 bits of temp_src to
// temp_dest; zeros out the upper 32 bits of temp_dest)
temp_dest.q = temp_src; // 8-byte move (copies all 64 bits of temp_src to
// temp_dest)
temp_dest.v = temp_src; // 2-byte move if V==2
// 4-byte move if V==4
// 8-byte move if V==8
temp_dest.z = temp_src; // 2-byte move if Z==2
// 4-byte move if Z==4
temp_dest.a = temp_src; // 2-byte move if A==2
// 4-byte move if A==4
// 8-byte move if A==8
temp_dest.s = temp_src; // 2-byte move if S==2
// 4-byte move if S==4
// 8-byte move if S==8
/////////////////////////////////////////////////////////////////////////////////
// Arithmetic Operators
/////////////////////////////////////////////////////////////////////////////////
a + b // integer addition
a - b // integer subtraction
a * b // integer multiplication
a / b // integer division. Result is the quotient
a % b // modulo. Result is the remainder after a is divided by b
// multiplication has precedence over addition where precedence is not explicitly
// indicated by grouping terms with parentheses
/////////////////////////////////////////////////////////////////////////////////
// Bitwise Operators
/////////////////////////////////////////////////////////////////////////////////
// temp, a, and b are values or register contents of the same size
temp = a AND b; // Corresponding bits of a and b are logically ANDed together
Instruction Overview 61
// Concatenation
value = {field1,field2,100b}; //pack values of field1, field2 and 100b
size_of(value) = (size_of(field1) + size_of(field2) + 3)
/////////////////////////////////////////////////////////////////////////////////
// Logical Shift Operators
/////////////////////////////////////////////////////////////////////////////////
temp = a << b; // Result is a shifted left by _b_ bit positions. Zeros are
// shifted into vacant positions. Bits shifted out are lost.
temp = a >> b; // Result is a shifted right by _b_ bit positions. Zeros are
// shifted into vacant positions. Bits shifted out are lost.
/////////////////////////////////////////////////////////////////////////////////
// Logical Operators
/////////////////////////////////////////////////////////////////////////////////
// a boolean variable can assume one of two values (TRUE or FALSE)
// In these examples, FOO, BAR, CONE, and HEAD have been defined to be boolean
// variables
FOO && BAR // Logical AND
FOO || BAR // Logical OR
!FOO // Logical complement (NOT)
/////////////////////////////////////////////////////////////////////////////////
// Comparison Operators
/////////////////////////////////////////////////////////////////////////////////
// a and b are integer values. The result is a boolean value.
a == b // if a and b are equal, the result is TRUE; otherwise it is FALSE.
a != b // if a and b are not equal, the result is TRUE; otherwise it is FALSE.
a > b // if a is greater than b, the result is TRUE; otherwise it is FALSE.
a < b // if a is less than b, the result is TRUE; otherwise it is FALSE.
a >= b // if a is greater than or equal to b, the result is TRUE; otherwise
// it is FALSE.
a <= b // if a is less than or equal to b, the result is TRUE; otherwise
// it is FALSE.
/////////////////////////////////////////////////////////////////////////////////
// Logical Expressions
/////////////////////////////////////////////////////////////////////////////////
// Logical binary (two operand) and unary (one operand) operators can be combined
// with comparison operators to form more complex expressions. Parentheses are
// used to enclose comparison terms and to show precedence. If precedence is not
// explicitly shown, logical AND has precedence over logical OR. Unary operators
// have precedence over binary operators.
FOO && (a < b) || !BAR // evaluate the comparison a < b first, then
// AND this with FOO. Finally OR this intermediate result
62 Instruction Overview
IF (it is raining)
close the window
/////////////////////////////////////////////////////////////////////////////////
// Assignment Operators
/////////////////////////////////////////////////////////////////////////////////
a = a + b // The value a is assigned the sum of the values a and b
//
temp = R1 // The contents of the register temp is replaced by a copy of the
// contents of register R1.
R0 += 2 // R0 is assigned the sum of the contents of R0 and the integer 2.
//
R5 |= R6 // R5 is assigned the result of the bit-wise OR of the contents of R5
// and R6. Contents of R6 is unchanged.
R4 &= R7 // R4 is assigned the result of the bit-wise AND of the contents of
// R4 and R7. Contents of R7 is unchanged.
/////////////////////////////////////////////////////////////////////////////////
// IF-THEN-ELSE
/////////////////////////////////////////////////////////////////////////////////
IF (FOO) <expression> // evaluation of <expression> is dependent on FOO
// being TRUE. If FOO is FALSE, <expression> is not
// evaluated.
IF (FOO)
<dependent expression1> // scope of IF is indicated by indentation
...
<dependent expressionx>
IF ((FOO && BAR) || (CONE && HEAD)) // The condition can be an expression.
<dependent expressions>
/////////////////////////////////////////////////////////////////////////////////
// Loops
Instruction Overview 63
/////////////////////////////////////////////////////////////////////////////////
FOR i = <init_val> to <final_val>, BY <step>
<expression> // scope of loop is indicated by indentation
// if <step> = 1, may omit "BY" clause
/////////////////////////////////////////////////////////////////////////////////
// Functions
/////////////////////////////////////////////////////////////////////////////////
// Syntax for function definition
<return data type> <function_name>(argument,..)
<expressions>
RETURN <result>
/////////////////////////////////////////////////////////////////////////////////
// Built-in Functions
/////////////////////////////////////////////////////////////////////////////////
SignExtend(arg) // returns value of _arg_ sign extended to the width of the data
// type of the function. Data type of function is inferred from
// the context of the function's invocation.
ZeroExtend(arg) // returns value of _arg_ zero extended to the width of the data
// type of the function. Data type of function is inferred from
// the context of the function's invocation.
/////////////////////////////////////////////////////////////////////////////////
// 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
64 Instruction Overview
definition:
Instruction Overview 65
/////////////////////////////////////////////////////////////////////////////////
// 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
// size of the memory write
definition:
66 Instruction Overview
/////////////////////////////////////////////////////////////////////////////////
// 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
/////////////////////////////////////////////////////////////////////////////////
Instruction Overview 67
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:
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
68 Instruction Overview
definition:
IF (temp_desc.attr.p==0)
// segment-not-present exception, with an error code that
// indicates this IDT gate
EXCEPTION [#NP(vector*8+2)]
RETURN (temp_desc)
/////////////////////////////////////////////////////////////////////////////////
// READ_INNER_LEVEL_SP
// Read a new stack pointer (RSP or SS:ESP) from the TSS
/////////////////////////////////////////////////////////////////////////////////
usage:
temp_SS_desc:temp_RSP = READ_INNER_LEVEL_SP (new_cpl, ist_index)
definition:
IF (LONG_MODE)
{
IF (ist_index>0)
temp_RSP = READ_MEM.q [tss:ist_index*8+28] // read ISTn stack
// pointer from the TSS
ELSE // (ist_index==0)
temp_RSP = READ_MEM.q [tss:new_cpl*8+4] // read RSPn stack
// pointer from the TSS
ELSE // (LEGACY_MODE)
{
Instruction Overview 69
return (temp_RSP:temp_SS_desc)
/////////////////////////////////////////////////////////////////////////////////
// READ_BIT_ARRAY // Read 1 bit from a bit array in memory
/////////////////////////////////////////////////////////////////////////////////
usage:
temp_value = READ_BIT_ARRAY ([mem], bit_number)
definition:
///////////////////////////////////////////////////////////////////////////////
// Shadow Stack Functions
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// SSTK_READ_MEM // read shadow stack memory
// Usage: temp = SSTK_READ_MEM.x [linear_addr]
// where x is either d or q (4 or 8 bytes)
///////////////////////////////////////////////////////////////////////////////
IF (PAGING_ENABLED) && (
( the linear address maps to a not-present page )
|| ( the linear address maps to a non-shadow stack page )
|| ( the access is user-mode &&
the linear address maps to a supervisor shadow stack page )
70 Instruction Overview
///////////////////////////////////////////////////////////////////////////////
// SSTK_WRITE_MEM // write shadow stack memory
// Usage: SSTK_WRITE_MEM.x [linear_addr] = temp.x
// where x is either d or q (4 or 8 bytes)
///////////////////////////////////////////////////////////////////////////////
IF (PAGING_ENABLED) && (
( the linear address maps to a not-present page )
|| ( the linear address maps to a non-shadow stack page )
|| ( the access is user-mode &&
the linear address maps to a supervisor shadow stack page )
|| ( the access is supervisor-mode &&
the linear address maps to a user shadow stack page ))
EXCEPTION [PF(error_code)] // page fault, w/ the SS (shadow stack) bit
// set in error_code and the present and
// protection violation bits as appropriate
memory [linear_addr].x = temp.x
///////////////////////////////////////////////////////////////////////////////
// SET_SSTK_TOKEN_BUSY (new_SSP)
// Checks shadow stack token and if valid set the token's busy bit
// Usage: SET_SSTK_TOKEN_BUSY (new_SSP)
///////////////////////////////////////////////////////////////////////////////
Instruction Overview 71
72 Instruction Overview
General-Purpose 73
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
For more information on using the CPUID instruction, see the reference page for the CPUID
instruction on page 165. For a comprehensive list of all instruction support feature flags, see
Appendix D, “Instruction Subsets and CPUID Feature Flags,” on page 593.
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:
• “General-Purpose Programming” in APM Volume 1.
• “Summary of Registers and Data Types” on page 38.
• “Notation” on page 53.
• “Instruction Prefixes” on page 5.
• Appendix B, “General-Purpose Instructions in 64-Bit Mode.” In particular, see “General Rules for
64-Bit Mode” on page 561.
74 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 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, X This instruction was executed in 64-bit mode.
#UD
General-Purpose 75
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
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 Protecte
Exception Real 8086 d Cause of Exception
Invalid opcode, X This instruction was executed in 64-bit mode.
#UD
76 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 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).
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 Protecte
Exception Real 8086 d Cause of Exception
Divide by zero, #DE X X X 8-bit immediate value was 0.
Invalid opcode, X This instruction was executed in 64-bit mode.
#UD
General-Purpose 77
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
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 Protecte
Exception Real 8086 d Cause of Exception
Invalid opcode, X This instruction was executed in 64-bit mode.
#UD
78 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
General-Purpose 79
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
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 Protecte
Exception Real 8086 d 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.
80 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
Related Instructions
ADOX
rFLAGS Affected
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 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.
A page fault resulted from the execution of the
Page fault, #PF X X instruction.
An unaligned memory reference was performed while
Alignment check, #AC X X alignment checking was enabled.
General-Purpose 81
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Virtual
Exception Real 8086 Protected Cause of Exception
Instruction not supported by CPUID
X X X
Invalid opcode, #UD Fn0000_0007_EBX[ADX] = 0.
X X Lock prefix (F0h) preceding opcode.
82 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
General-Purpose 83
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
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 Protecte
Exception Real 8086 d 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.
84 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
Related Instructions
ADCX
rFLAGS Affected
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 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.
A page fault resulted from the execution of the
Page fault, #PF X X instruction.
An unaligned memory reference was performed while
Alignment check, #AC X X alignment checking was enabled.
General-Purpose 85
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Virtual
Exception Real 8086 Protected Cause of Exception
Instruction not supported by CPUID
X X X
Invalid opcode, #UD Fn0000_0007_EBX[ADX] = 0.
X X Lock prefix (F0h) preceding opcode.
86 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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 11.
AND AL, imm8 24 ib and the contents of AL with an immediate 8-bit value and store
the result in AL.
AND AX, imm16 25 iw and the contents of AX with an immediate 16-bit value and store
the result in AX.
AND EAX, imm32 25 id and the contents of EAX with an immediate 32-bit value and
store the result in EAX.
AND RAX, imm32 25 id and the contents of RAX with a sign-extended 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 reg/mem64, imm32 81 /4 id and the contents of reg/mem64 with sign-extended imm32.
AND reg/mem16, imm8 83 /4 ib and the contents of reg/mem16 with a sign-extended 8-bit value.
AND reg/mem32, imm8 83 /4 ib and the contents of reg/mem32 with a sign-extended 8-bit value.
AND reg/mem64, imm8 83 /4 ib and the contents of reg/mem64 with a sign-extended 8-bit value.
General-Purpose 87
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
AND reg/mem8, reg8 20 /r and the contents of an 8-bit register or memory location with the
contents of an 8-bit register.
AND reg/mem16, reg16 21 /r and the contents of a 16-bit register or memory location with the
contents of a 16-bit register.
AND reg/mem32, reg32 21 /r and the contents of a 32-bit register or memory location with the
contents of a 32-bit register.
AND reg/mem64, reg64 21 /r and the contents of a 64-bit register or memory location with the
contents of a 64-bit register.
AND reg8, reg/mem8 22 /r and the contents of an 8-bit register with the contents of an 8-bit
memory location or register.
AND reg16, reg/mem16 23 /r and the contents of a 16-bit register with the contents of a 16-bit
memory location or register.
AND reg32, reg/mem32 23 /r and the contents of a 32-bit register with the contents of a 32-bit
memory location or register.
AND reg64, reg/mem64 23 /r and the contents of a 64-bit register with the contents of a 64-bit
memory location or register.
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.
88 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
The flags are set according to the result of the and pseudo-operation.
The ANDN instruction is a BMI1 instruction. Support for this instruction is indicated by CPUID
Fn0000_0007_EBX_x0[BMI1] = 1.
For more information on using the CPUID instruction, see the instruction reference page for the
CPUID instruction on page 165. For a description of all feature flags related to instruction subset
support, see Appendix D, “Instruction Subsets and CPUID Feature Flags,” on page 593.
Mnemonic Encoding
Related Instructions
BEXTR, BLCI, BLCIC, BLCMSK, BLCS, BLSFILL, BLSI, BLSIC, BLSR, BLSMSK, BSF, BSR,
LZCNT, POPCNT, T1MSKC, TZCNT, TZMSK
General-Purpose 89
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
0 M M U U 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 Protected Cause of Exception
80806
X X BMI instructions are only recognized in protected mode.
BMI instructions are not supported as indicated by
Invalid opcode, #UD X CPUID Fn0000_0007_EBX_x0[BMI] = 0.
X VEX.L is 1.
A memory address exceeded the stack segment limit or
Stack, #SS X was non-canonical.
A memory address exceeded a data segment limit or
General protection, 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 instruction.
An unaligned memory reference was performed while
Alignment check, #AC X alignment checking was enabled.
90 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
Mnemonic Encoding
General-Purpose 91
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Related Instructions
ANDN, BLCI, BLCIC, BLCMSK, BLCS, BLSFILL, BLSI, BLSIC, BLSR, BLSMSK, BSF, BSR,
LZCNT, POPCNT, T1MSKC, TZCNT, TZMSK
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
0 U M U U 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
Mode
Exception Virtual Cause of Exception
Real 8086 Protected
X X BMI instructions are only recognized in protected mode.
BMI instructions are not supported, as indicated by
Invalid opcode, #UD X CPUID Fn0000_0007_EBX_x0[BMI] = 0.
X VEX.L is 1.
A memory address exceeded the stack segment limit or
Stack, #SS X was non-canonical.
A memory address exceeded a data segment limit or was
X
General protection, #GP 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.
An unaligned memory reference was performed while
Alignment check, #AC X alignment checking was enabled.
92 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
Mnemonic Encoding
General-Purpose 93
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Related Instructions
ANDN, BLCI, BLCIC, BLCMSK, BLCS, BLSFILL, BLSI, BLSIC, BLSR, BLSMSK, BSF, BSR,
LZCNT, POPCNT, T1MSKC, TZCNT, TZMSK
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
0 U M U U 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
X X TBM instructions are only recognized in protected mode.
TBM instructions are not supported, as indicated by
Invalid opcode, #UD X CPUID Fn8000_0001_ECX[TBM] = 0.
X XOP.L is 1.
A memory address exceeded the stack segment limit or
Stack, #SS X was non-canonical.
A memory address exceeded a data segment limit or was
X
General protection, #GP 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.
An unaligned memory reference was performed while
Alignment check, #AC X alignment checking was enabled.
94 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
The value of the carry flag of rFLAGS is generated according to the result of the add pseudo-
instruction and the remaining arithmetic flags are generated by the and pseudo-instruction.
The BLCFILL instruction is a TBM instruction. Support for this instruction is indicated by CPUID
Fn8000_0001_ECX[TBM] = 1.
For more information on using the CPUID instruction, see the instruction reference page for the
CPUID instruction on page 165. For a description of all feature flags related to instruction subset
support, see Appendix D, “Instruction Subsets and CPUID Feature Flags,” on page 593.
Mnemonic Encoding
Related Instructions
ANDN, BEXTR, BLCI, BLCIC, BLCMSK, BLCS, BLSFILL, BLSI, BLSIC, BLSR, BLSMSK, BSF,
BSR, LZCNT, POPCNT, T1MSKC, TZCNT, TZMSK
General-Purpose 95
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
0 M 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 Cause of Exception
Real 8086 Protected
X X TBM instructions are only recognized in protected mode.
TBM instructions are not supported, as indicated by
Invalid opcode, #UD X CPUID Fn8000_0001_ECX[TBM] = 0.
X XOP.L is 1.
A memory address exceeded the stack segment limit or
Stack, #SS X was non-canonical.
A memory address exceeded a data segment limit or was
X
General protection, #GP 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.
An unaligned memory reference was performed while
Alignment check, #AC X alignment checking was enabled.
96 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
The value of the carry flag of rFLAGS is generated according to the result of the add pseudo-
instruction and the remaining arithmetic flags are generated by the or pseudo-instruction.
The BLCI instruction is a TBM instruction. Support for this instruction is indicated by CPUID
Fn8000_0001_ECX[TBM] = 1.
For more information on using the CPUID instruction, see the instruction reference page for the
CPUID instruction on page 165. For a description of all feature flags related to instruction subset
support, see Appendix D, “Instruction Subsets and CPUID Feature Flags,” on page 593.
Mnemonic Encoding
Related Instructions
ANDN, BEXTR, BLCFILL, BLCIC, BLCMSK, BLCS, BLSFILL, BLSI, BLSIC, BLSR, BLSMSK,
BSF, BSR, LZCNT, POPCNT, T1MSKC, TZCNT, TZMSK
General-Purpose 97
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
0 M 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 Cause of Exception
Real 8086 Protected
X X TBM instructions are only recognized in protected mode.
TBM instructions are not supported, as indicated by
Invalid opcode, #UD X CPUID Fn8000_0001_ECX[TBM] = 0.
X XOP.L is 1.
A memory address exceeded the stack segment limit or
Stack, #SS X was non-canonical.
A memory address exceeded a data segment limit or was
X
General protection, #GP 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.
An unaligned memory reference was performed while
Alignment check, #AC X alignment checking was enabled.
98 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
The value of the carry flag of rFLAGS is generated according to the result of the add pseudo-
instruction and the remaining arithmetic flags are generated by the and pseudo-instruction.
The BLCIC instruction is a TBM instruction. Support for this instruction is indicated by CPUID
Fn8000_0001_ECX[TBM] = 1.
For more information on using the CPUID instruction, see the instruction reference page for the
CPUID instruction on page 165. For a description of all feature flags related to instruction subset
support, see Appendix D, “Instruction Subsets and CPUID Feature Flags,” on page 593.
Mnemonic Encoding
Related Instructions
ANDN, BEXTR, BLCFILL, BLCI, BLCMSK, BLCS, BLSFILL, BLSI, BLSIC, BLSR, BLSMSK,
BSF, BSR, LZCNT, POPCNT, T1MSKC, TZCNT, TZMSK
General-Purpose 99
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
0 M 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 Cause of Exception
Real 8086 Protected
X X TBM instructions are only recognized in protected mode.
TBM instructions are not supported, as indicated by
Invalid opcode, #UD X CPUID Fn8000_0001_ECX[TBM] = 0.
X XOP.L is 1.
A memory address exceeded the stack segment limit or
Stack, #SS X was non-canonical.
A memory address exceeded a data segment limit or was
X
General protection, #GP 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.
An unaligned memory reference was performed while
Alignment check, #AC X alignment checking was enabled.
100 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
The value of the carry flag of rFLAGS is generated according to the result of the add pseudo-
instruction and the remaining arithmetic flags are generated by the xor pseudo-instruction.
If the input is all ones, the output is a value with all bits set to 1.
The BLCMSK instruction is a TBM instruction. Support for this instruction is indicated by CPUID
Fn8000_0001_ECX[TBM] = 1.
For more information on using the CPUID instruction, see the instruction reference page for the
CPUID instruction on page 165. For a description of all feature flags related to instruction subset
support, see Appendix D, “Instruction Subsets and CPUID Feature Flags,” on page 593.
Instruction Encoding
Mnemonic Encoding
Related Instructions
ANDN, BEXTR, BLCFILL, BLCI, BLCS, BLSFILL, BLSI, BLSIC, BLSR, BLSMSK, BSF, BSR,
LZCNT, POPCNT, T1MSKC, TZCNT, TZMSK
General-Purpose 101
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
0 M 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 Cause of Exception
Real 8086 Protected
X X TBM instructions are only recognized in protected mode.
TBM instructions are not supported, as indicated by
Invalid opcode, #UD X CPUID Fn8000_0001_ECX[TBM] = 0.
X XOP.L is 1.
A memory address exceeded the stack segment limit or
Stack, #SS X was non-canonical.
A memory address exceeded a data segment limit or was
X
General protection, #GP 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.
An unaligned memory reference was performed while
Alignment check, #AC X alignment checking was enabled.
102 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
The value of the carry flag of rFLAGS is generated by the add pseudo-instruction and the remaining
arithmetic flags are generated by the or pseudo-instruction.
The BLCS instruction is a TBM instruction. Support for this instruction is indicated by CPUID
Fn8000_0001_ECX[TBM] = 1.
For more information on using the CPUID instruction, see the instruction reference page for the
CPUID instruction on page 165. For a description of all feature flags related to instruction subset
support, see Appendix D, “Instruction Subsets and CPUID Feature Flags,” on page 593.
Mnemonic Encoding
Related Instructions
ANDN, BEXTR, BLCFILL, BLCI, BLCIC, BLCMSK, BLSFILL, BLSI, BLSIC, BLSR, BLSMSK,
BSF, BSR, LZCNT, POPCNT, T1MSKC, TZCNT, TZMSK
General-Purpose 103
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
0 M 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 Cause of Exception
Real 8086 Protected
X X TBM instructions are only recognized in protected mode.
TBM instructions are not supported, as indicated by
Invalid opcode, #UD X CPUID Fn8000_0001_ECX[TBM] = 0.
X XOP.L is 1.
A memory address exceeded the stack segment limit or
Stack, #SS X was non-canonical.
A memory address exceeded a data segment limit or was
X
General protection, #GP 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.
An unaligned memory reference was performed while
Alignment check, #AC X alignment checking was enabled.
104 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
The value of the carry flag of rFLAGs is generated by the sub pseudo-instruction and the remaining
arithmetic flags are generated by the or pseudo-instruction.
The BLSFILL instruction is a TBM instruction. Support for this instruction is indicated by CPUID
Fn8000_0001_ECX[TBM] = 1.
For more information on using the CPUID instruction, see the instruction reference page for the
CPUID instruction on page 165. For a description of all feature flags related to instruction subset
support, see Appendix D, “Instruction Subsets and CPUID Feature Flags,” on page 593.
Mnemonic Encoding
Related Instructions
ANDN, BEXTR, BLCFILL, BLCI, BLCIC, BLCMSK, BLCS, BLSI, BLSIC, BLSR, BLSMSK, BSF,
BSR, LZCNT, POPCNT, T1MSKC, TZCNT, TZMSK
General-Purpose 105
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
0 M 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 Cause of Exception
Real 8086 Protected
X X TBM instructions are only recognized in protected mode.
TBM instructions are not supported, as indicated by
Invalid opcode, #UD X CPUID Fn8000_0001_ECX[TBM] = 0.
X XOP.L is 1.
A memory address exceeded the stack segment limit or
Stack, #SS X was non-canonical.
A memory address exceeded a data segment limit or was
X
General protection, #GP 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.
An unaligned memory reference was performed while
Alignment check, #AC X alignment checking was enabled.
106 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
The value of the carry flag is generated by the neg pseudo-instruction and the remaining status flags
are generated by the and pseudo-instruction.
The BLSI instruction is a BMI1 instruction. Support for this instruction is indicated by CPUID
Fn0000_0007_EBX_x0[BMI1] = 1.
For more information on using the CPUID instruction, see the instruction reference page for the
CPUID instruction on page 165. For a description of all feature flags related to instruction subset
support, see Appendix D, “Instruction Subsets and CPUID Feature Flags,” on page 593.
Mnemonic Encoding
Related Instructions
ANDN, BEXTR, BLCI, BLCIC, BLCMSK, BLCS, BLSFILL, BLSIC, BLSR, BLSMSK, BSF, BSR,
LZCNT, POPCNT, T1MSKC, TZCNT, TZMSK
General-Purpose 107
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
0 M 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
Mode
Exception Virtual Cause of Exception
Real 8086 Protected
X X BMI instructions are only recognized in protected mode.
BMI instructions are not supported, as indicated by
Invalid opcode, #UD X CPUID Fn0000_0007_EBX_x0[BMI] = 0.
X VEX.L is 1.
A memory address exceeded the stack segment limit or
Stack, #SS X was non-canonical.
A memory address exceeded a data segment limit or was
X
General protection, #GP non-canonical.
X A null data segment was used to reference memory.
A page fault resulted from the execution of the
Page fault, #PF X instruction.
An unaligned memory reference was performed while
Alignment check, #AC X alignment checking was enabled.
108 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
The value of the carry flag of rFLAGS is generated by the sub pseudo-instruction and the remaining
arithmetic flags are generated by the or pseudo-instruction.
The BLSR instruction is a TBM instruction. Support for this instruction is indicated by CPUID
Fn8000_0001_ECX[TBM] = 1.
For more information on using the CPUID instruction, see the instruction reference page for the
CPUID instruction on page 165. For a description of all feature flags related to instruction subset
support, see Appendix D, “Instruction Subsets and CPUID Feature Flags,” on page 593.
Mnemonic Encoding
Related Instructions
ANDN, BEXTR, BLCFILL, BLCI, BLCIC, BLCMSK, BLCS, BLSFILL, BLSI, BLSIC, BLSR,
BLSMSK, BSF, BSR, LZCNT, POPCNT, T1MSKC, TZCNT, TZMSK
General-Purpose 109
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
0 M 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 Cause of Exception
Real 8086 Protected
X X TBM instructions are only recognized in protected mode.
TBM instructions are not supported, as indicated by
Invalid opcode, #UD X CPUID Fn8000_0001_ECX[TBM] = 0.
X XOP.L is 1.
A memory address exceeded the stack segment limit or
Stack, #SS X was non-canonical.
A memory address exceeded a data segment limit or was
X
General protection, #GP 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.
An unaligned memory reference was performed while
Alignment check, #AC X alignment checking was enabled.
110 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
The value of the carry flag is generated by the sub pseudo-instruction and the remaining status flags
are generated by the xor pseudo-instruction.
If the input is zero, the output is a value with all bits set to 1. If this is considered a corner case input,
software may test the carry flag to detect the zero input value.
The BLSMSK instruction is a BMI1 instruction. Support for this instruction is indicated by CPUID
Fn0000_0007_EBX_x0[BMI1] = 1.
For more information on using the CPUID instruction, see the instruction reference page for the
CPUID instruction on page 165. For a description of all feature flags related to instruction subset
support, see Appendix D, “Instruction Subsets and CPUID Feature Flags,” on page 593.
Mnemonic Encoding
Related Instructions
ANDN, BEXTR, BLCI, BLCIC, BLCMSK, BLCS, BLSFILL, BLSI, BLSIC, BLSR, BSF, BSR,
LZCNT, POPCNT, T1MSKC, TZCNT, TZMSK
General-Purpose 111
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
0 M 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
Mode
Exception Virtual Cause of Exception
Real 8086 Protected
X X BMI instructions are only recognized in protected mode.
BMI instructions are not supported, as indicated by
Invalid opcode, #UD X CPUID Fn0000_0007_EBX_x0[BMI] = 0.
X VEX.L is 1.
A memory address exceeded the stack segment limit or
Stack, #SS X was non-canonical.
A memory address exceeded a data segment limit or was
X
General protection, #GP 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.
An unaligned memory reference was performed while
Alignment check, #AC X alignment checking was enabled.
112 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
The value of the carry flag is generated by the sub pseudo-instruction and the remaining status flags
are generated by the and pseudo-instruction.
The BLSR instruction is a BMI1 instruction. Support for this instruction is indicated by CPUID
Fn0000_0007_EBX_x0[BMI1] = 1.
For more information on using the CPUID instruction, see the instruction reference page for the
CPUID instruction on page 165. For a description of all feature flags related to instruction subset
support, see Appendix D, “Instruction Subsets and CPUID Feature Flags,” on page 593.
Mnemonic Encoding
Related Instructions
ANDN, BEXTR, BLCI, BLCIC, BLCMSK, BLCS, BLSFILL, BLSI, BLSIC, BLSMSK, BSF, BSR,
LZCNT, POPCNT, T1MSKC, TZCNT, TZMSK
General-Purpose 113
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
0 M 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
Mode
Exception Virtual Cause of Exception
Real 8086 Protected
X X BMI instructions are only recognized in protected mode.
BMI instructions are not supported, as indicated by
Invalid opcode, #UD X CPUID Fn0000_0007_EBX_x0[BMI] = 0.
X VEX.L is 1.
A memory address exceeded the stack segment limit or
Stack, #SS X was non-canonical.
A memory address exceeded a data segment limit or was
X
General protection, #GP 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.
An unaligned memory reference was performed while
Alignment check, #AC X alignment checking was enabled.
114 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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.
Invalid opcode, X X X The source operand was a register.
#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.
General-Purpose 115
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
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.
116 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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 Protecte
Exception Real 8086 d 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.
General-Purpose 117
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
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.
118 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
Related Instructions
XCHG
rFLAGS Affected
None
Exceptions
None
General-Purpose 119
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
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
120 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 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
X X
#AC alignment checking was enabled.
General-Purpose 121
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Related Instructions
BT, BTR, BTS
122 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 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-
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.
General-Purpose 123
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Related Instructions
BT, BTC, BTS
124 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 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-
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.
General-Purpose 125
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Related Instructions
BT, BTC, BTR
126 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 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-
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.
General-Purpose 127
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Mnemonic Encoding
Related Instructions
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
0 M 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.
128 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
Exceptions
Mode
Exception Virtual Cause of Exception
Real 8086 Protected
X X BMI2 instructions are only recognized in protected mode.
BMI2 instructions are not supported, as indicated by
Invalid opcode, #UD X CPUID Fn0000_0007_EBX_x0[BMI2] = 0.
X VEX.L is 1.
A memory address exceeded the stack segment limit or
Stack, #SS X was non-canonical.
A memory address exceeded a data segment limit or was
X
General protection, #GP 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.
An unaligned memory reference was performed while
Alignment check, #AC X alignment checking was enabled.
General-Purpose 129
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
For details about control-flow instructions, see “Control Transfers” in APM Volume 1, and “Control-
Transfer Privilege Checks” in APM Volume 2.
130 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
Action
// For function ShadowStacksEnabled()
// see "Pseudocode Definition" on page 57
CALLN_START:
PUSH.v next_RIP
RIP = temp_RIP
EXIT
Related Instructions
CALL(Far), RET(Near), RET(Far)
General-Purpose 131
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
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.
Alignment Check, An unaligned memory reference was performed while
X X
#AC alignment checking was enabled.
Page Fault, #PF X X A page fault resulted from the execution of the instruction.
132 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
General-Purpose 133
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Action
// For functions READ_DESCRIPTOR, READ_INNER_LEVEL_SP,
// ShadowStacksEnabled and SET_TOKEN_BUSY see "Pseudocode Definition"
// on page 57
CALLF_START:
IF (REAL_MODE)
CALLF_REAL_OR_VIRTUAL // CALLF real mode
ELSEIF (PROTECTED_MODE)
CALLF_PROTECTED // CALLF protected mode
ELSE // virtual mode
CALLF_REAL_OR_VIRTUAL // CALLF virtual mode
CALLF_REAL_OR_VIRTUAL:
CS.sel = temp_CS
CS.base = temp_CS SHL 4
RIP = temp_RIP
134 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
CALLF_PROTECTED:
IF (temp_desc.attr.type == ’available_tss’)
TASK_SWITCH // Using temp_sel as the target TSS
ELSEIF (temp_desc.attr.type == ’taskgate’)
TASK_SWITCH // Using the TSS selector in the task gate as the target TSS
ELSEIF (temp_desc.attr.type == ’callgate’)
CALLF_CALLGATE // CALLF through callgate
ELSE // (temp_desc.attr.type == ’code’)
{ // the selector refers to a code descriptor
temp_RIP = temp_offset // the target RIP is the instruction offset field
CS = temp_desc
PUSH.v old_CS
PUSH.v next_RIP
General-Purpose 135
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
EXIT
} // end CALLF selector=code segment
CALLF_CALLGATE:
IF (LONG_MODE) // the gate size controls the size of the stack pushes
v=8-byte // Long mode only uses 64-bit call gates, force 8-byte opsize
ELSEIF (temp_desc.attr.type == 'callgate32')
v=4-byte // Legacy mode, using a 32-bit call-gate, force 4-byte
ELSE // (temp_desc.attr.type == 'callgate16')
v=2-byte // Legacy mode, using a 16-bit call-gate, force 2-byte opsize
// the target CS and RIP both come from the call gate.
temp_RIP = temp_desc.offset
IF (LONG_MODE)
{ // read 2nd half of 16-byte call-gate
temp_upper = READ_MEM.q [temp_sel+8] // to get upper 32 bits of target RIP
IF (temp_upper's extended attribute bits != 0)
EXCEPTION [#GP(temp_sel)]
temp_RIP = tempRIP + (temp_upper SHL 32) // Concatenate both halves of RIP
}
IF (CS.attr.conforming == 1)
temp_CPL = CPL
ELSE
temp_CPL = CS.attr.dpl
136 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
PUSH.v old_SS // #SS on this or next pushes use SS.sel as error code
PUSH.v old_RSP
PUSH.v old_CS
PUSH.v next_RIP
RIP = temp_RIP
IF old_CPL != 3
{
General-Purpose 137
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
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
Invalid opcode, X X X The far CALL indirect opcode (FF /3) had a register operand.
#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.
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.
138 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
Virtual
Exception Real 8086 Protected Cause of Exception
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.
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.
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 a
X 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.
General protection, The DPL of the conforming code segment descriptor specified
#GP X by the instruction was greater than the CPL.
(selector)
The DPL of the callgate, taskgate, or TSS descriptor specified
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.
The DPL of the segment descriptor specified by the call gate
X was greater than the CPL.
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.
General-Purpose 139
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Related Instructions
CWD, CDQ, CQO
rFLAGS Affected
None
Exceptions
None
140 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
Related Instructions
CBW, CWDE, CDQE
rFLAGS Affected
None
Exceptions
None
General-Purpose 141
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
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
142 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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
General-Purpose 143
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
144 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
Related Instructions
INVD, WBINVD, CLFLUSHOPT, CLZERO
rFLAGS Affected
None
Exceptions
Virtual
Exception (vector) Real 8086 Protected Cause of Exception
CLFLUSH instruction is not supported, as indicated by
Invalid opcode, #UD X X X CPUID Fn0000_0001_EDX[CLFSH] = 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
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.
General-Purpose 145
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
146 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
Related Instructions
CLFLUSH
rFLAGS Affected
None
Exceptions
Virtual
Exception (vector) Real 8086 Protected Cause of Exception
CLFLUSH instruction is not supported, as indicated by
X X X CPUID Fn0000_0001_EDX[CLFSH] = 0.
Invalid opcode, #UD
Instruction not supported by CPUID
X X X Fn0000_0007_EBX_x0[CLFLUSHOPT] = 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
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.
General-Purpose 147
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Related Instructions
CLFLUSH, CLFLUSHOPT, WBINVD, WBNOINVD
148 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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 (vector) Real 8086 Protected Cause of Exception
Instruction not supported by CPUID
Invalid opcode, #UD X X X Fn0000_0007_EBX[24] = 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
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.
General-Purpose 149
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Related Instructions
CLFLUSH
rFLAGS Affected
None
Exceptions
Virtual
Exception (vector) Real 8086 Protected Cause of Exception
Instruction not supported by CPUID
Invalid opcode, #UD X X X Fn8000_0008_EBX[CLZERO] = 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
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.
150 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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
General-Purpose 151
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
152 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
General-Purpose 153
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Related Instructions
MOV
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
CMOVcc instruction is not supported, as indicated by CPUID
Invalid opcode, X X X Fn0000_0001_EDX[CMOV] or Fn8000_0001_EDX[CMOV] =
#UD 0.
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.
154 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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.
General-Purpose 155
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
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 F, “Instruction Effects on
RFLAGS” shows how instructions affect the rFLAGS status flags.
.
156 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
Operands CF ZF
dest = source 0 1
Operands OF ZF
dest = source 0 1
Related Instructions
SUB, CMPSx, SCASx
General-Purpose 157
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
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.
158 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
General-Purpose 159
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
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.
160 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
Related Instructions
CMPXCHG8B, CMPXCHG16B
General-Purpose 161
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
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.
162 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
Related Instructions
CMPXCHG
General-Purpose 163
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
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
CMPXCHG8B instruction is not supported, as indicated by
X X X CPUID Fn0000_0001_EDX[CMPXCHG8B] or
Fn8000_0001_EDX[CMPXCHG8B] = 0.
Invalid opcode,
#UD CMPXCHG16B instruction is not supported, as indicated by
X CPUID Fn0000_0001_ECX[CMPXCHG16B] = 0.
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.
164 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
General-Purpose 165
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
For a description of all feature flags related to instruction subset support, see Appendix D, “Instruction
Subsets and CPUID Feature Flags,” on page 593. For a description of all defined feature numbers and
return values, see Appendix E, “Obtaining Processor Information Via the CPUID Instruction,” on
page 599.
Related Instructions
None
rFLAGS Affected
None
166 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
Exceptions
Mode
Exception Virtual Cause of Exception
Real 8086 Protected
General Protection, HWCR[CpuidUserDis] = 1 and CPL was
X X X
#GP not 0
General-Purpose 167
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Instruction Encoding
168 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
rFLAGS Affected
None
Exceptions
Mode
Exception Virtual Cause of Exception
Real 8086 Protected
X X X Lock prefix used
Invalid opcode,
#UD SSE42 instructions are not supported as indicated by CPUID
X X X Fn0000_0001_ECX[SSE42] = 0.
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.
General-Purpose 169
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
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, X This instruction was executed in 64-bit mode.
#UD
170 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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, X This instruction was executed in 64-bit mode.
#UD
General-Purpose 171
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
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 Prefix” on page 14.
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 11.
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.
172 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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.
General-Purpose 173
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
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
174 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 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 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.
General-Purpose 175
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
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 Definition” on page 57.
ENTER_START:
PUSH.v old_RBP
176 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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, An unaligned memory reference was performed while
X X
#AC alignment checking was enabled.
General-Purpose 177
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
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.
178 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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.
General-Purpose 179
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
180 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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.
General-Purpose 181
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Related Instructions
INSx, OUT, OUTSx
rFLAGS Affected
None
182 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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.
General-Purpose 183
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
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 Prefix” on page 14.
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 11.
To perform an increment operation that updates the CF flag, use an ADD instruction with an
immediate operand of 1.
Related Instructions
ADD, DEC
184 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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, An unaligned memory reference was performed while
X X
#AC alignment checking was enabled.
General-Purpose 185
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
186 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
Related Instructions
IN, OUT, OUTSx
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
A memory address exceeded a data segment limit or was non-
X X X canonical.
One or more I/O permission bits were set in the TSS for the
X accessed port.
General protection,
#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.
X A null data segment was used to reference memory.
X The destination operand was in a non-writable 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.
General-Purpose 187
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Action
// For functions READ_IDT, READ_DESCRIPTOR, READ_INNER_LEVEL_SP,
// ShadowStacksEnabled and SET_TOKEN_BUSY see "Pseudocode Definition"
// on page 57
INT_N_START:
IF (REAL_MODE)
INT_N_REAL // INTn real mode
ELSEIF (PROTECTED_MODE)
INT_N_PROTECTED // INTn protected mode
ELSE // (VIRTUAL_MODE)
INT_N_VIRTUAL // INTn virtual mode
INT_N_REAL:
PUSH.w old_RFLAGS
PUSH.w old_CS
PUSH.w next_RIP
CS.sel = temp_CS
CS.base = temp_CS SHL 4
188 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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
// The size of the gate controls the size of the stack pushes
IF (LONG_MODE)
v = 8-byte // Long mode only uses 64-bit gates
ELSEIF ((temp_idt_desc.attr.type == ’intgate32’) ||
(temp_idt_desc.attr.type == ’trapgate32’))
v = 4-byte // Legacy mode, using a 32-bit gate
ELSE
v = 2-byte // Legacy mode, using a 16-bit gate
temp_RIP = temp_idt_desc.offset
IF (CS.attr.conforming == 1)
temp_CPL = CPL
ELSE
temp_CPL = CS.attr.dpl
General-Purpose 189
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
IF (ShadowStacksEnabled(current CPL))
{
temp_isst_addr = INTERRUPT_SSP_TABLE_ADDR + (temp_idt_desc.ist*8)
SSP = READ_MEM.q [tss:temp_isst_addr]
IF (SSP[2:0] != 0)
EXCEPTION [#GP(0)] // new SSP must be 8-byte aligned
temp_CheckToken = TRUE
}
}
PUSH.q old_SS // in long mode, save old SS:RSP to stack
PUSH.q old_RSP
} // end long mode
PUSH.v old_RFLAGS
PUSH.v old_CS
PUSH.v next_RIP
IF (ShadowStacksEnabled(current CPL))
{
IF (temp_CheckToken == TRUE)
SET_SSTK_TOKEN_BUSY(SSP) // validate token, set busy
Align SSP to next 8B boundary, storing 4B of 0 if needed
SSTK_WRITE_MEM.q [SSP-24] = old_CS // push CS,LIP,SSP to shadow stack
SSTK_WRITE_MEM.q [SSP-16] = (CS.base + old_RIP)
SSTK_WRITE_MEM.q [SSP-8] = old_SSP
SSP = SSP - 24
} // end shadow stacks enabled @ CPL
IF (LONG_MODE)
temp_RSP = temp_RSP AND 0xFFFFFFFFFFFFFFF0 // force 16-byte alignment
RSP = temp_RSP
SS = temp_SS_desc
IF (ShadowStacksEnabled(new CPL))
{
old_SSP = SSP
190 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
IF ((temp_idt_desc.ist == 0) || (!LONG_MODE))
SSP = PLn_SSP // where n=new CPL
ELSE
{
temp_isst_addr = INTERRUPT_SSP_TABLE_ADDR + (temp_idt_desc.ist*8)
SSP = READ_MEM.q [tss:temp_isst_addr]
}
IF (SSP[2:0] != 0) // new SSP must be 8-byte aligned
EXCEPTION [#GP(0)]
}
// Any #SS from the following pushes uses SS.sel as error code
PUSH.v old_SS
PUSH.v old_RSP
PUSH.v old_RFLAGS
PUSH.v old_CS
PUSH.v next_RIP
IF (ShadowStacksEnabled(new CPL))
{
old_SSP = SSP
SSP = PLn_SSP // where n=new CPL
SET_SSTK_TOKEN_BUSY(SSP) // validate token, set busy
IF (old_CPL != 3)
SSTK_WRITE_MEM.q [SSP-24] = old_CS // push CS, LIP, SSP
SSTK_WRITE_MEM.q [SSP-16] = LIP // onto the shadow stack
SSTK_WRITE_MEM.q [SSP-8] = old_SSP
SSP = SSP - 24
} // end shadow stacks enabled at new CPL
RFLAGS.VM,NT,TF,RF cleared
RFLAGS.IF cleared if interrupt gate
RIP = temp_RIP
EXIT
} end INTn to more privileged level
INT_N_VIRTUAL:
General-Purpose 191
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
INT_N_VIRTUAL_TO_PROTECTED
ELSE
EXCEPTION [#GP(0)]
INT_N_VIRTUAL_TO_PROTECTED:
// The size of the gate controls the size of the stack pushes
IF ((temp_idt_desc.attr.type == ’intgate32’) ||
(temp_idt_desc.attr.type == ’trapgate32’))
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
192 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
temp_RIP = temp_idt_desc.offset
old_CPL = CPL
CS = READ_DESCRIPTOR(temp_idt_desc.segment, intcs_chk)
CPL = 0
temp_ist = 0 // Legacy mode doesn’t use IST pointers
temp_SS_desc:temp_RSP = READ_INNER_LEVEL_SP(CPL, temp_ist)
RSP = temp_RSP
SS = temp_SS_desc
// Any #SS from the following pushes uses SS.sel as error code
PUSH.v old_GS
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 = 0
PUSH.v old_CS
PUSH.v next_RIP
IF (ShadowStacksEnabled(CPL 0))
{
old_SSP = SSP
SSP = PL0_SSP // fetch new SSP
SET_SSTK_TOKEN_BUSY(SSP) // vaidate token, set busy
IF (old_CPL) != 3
{
SSTK_WRITE_MEM.q [SSP-24] = old_CS // push CS, LIP, SSP
SSTK_WRITE_MEM.q [SSP-16] = LIP // onto the shadow stack
SSTK_WRITE_MEM.q [SSP-8] = old_SSP
SSP = SSP - 24
}
}
General-Purpose 193
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
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 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, 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.
194 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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
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.
General-Purpose 195
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
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, X Instruction was executed in 64-bit mode.
#UD
196 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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 APM Volume 1, and “Control-
Transfer Privilege Checks” in APM Volume 2.
General-Purpose 197
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
198 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
Related Instructions
JMP (Near), JMP (Far), JrCXZ
rFLAGS Affected
None
General-Purpose 199
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
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.
200 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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
General-Purpose 201
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Related Instructions
JMP (Far), Jcc, JrCX
rFLAGS Affected
None.
202 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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.
General-Purpose 203
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
204 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
Action
// Far jumps (JMPF)
// See “Pseudocode Definition” on page 57.
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
General-Purpose 205
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
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.
206 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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.
General-Purpose 207
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
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
General protection, by the instruction was greater than the CPL.
#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.
The DPL of the segment descriptor specified the call gate was
X 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.
208 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
Related Instructions
SAHF
rFLAGS Affected
None.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Invalid opcode, The LAHF instruction is not supported in 64-bit mode, as
X
#UD indicated by CPUID Fn8000_0001_ECX[LahfSahf] = 0.
General-Purpose 209
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Related Instructions
None
rFLAGS Affected
None
210 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
X X X The source operand was a register.
Invalid opcode,
#UD LDS or LES was executed in 64-bit mode and not subject to
X interpretation as a VEX prefix.
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.
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
#GP X and the segment descriptor DPL were not equal to the CPL.
(selector)
The SS register was loaded and the segment pointed to was
X 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.
The DS, ES, FS, or GS register was loaded and the segment
X 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.
General-Purpose 211
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
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.
212 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
Related Instructions
MOV
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Invalid opcode, X X X The source operand was a register.
#UD
General-Purpose 213
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
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.
214 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
Related Instructions
MFENCE, SFENCE, MCOMMIT
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Invalid opcode, SSE2 instructions are not supported, as indicated by CPUID
X X X
#UD Fn0000_0001_EDX[SSE2] = 0.
General-Purpose 215
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Action
1. If LWP is not available or if the machine is not in protected mode, LLWPCB immediately causes
a #UD exception.
2. If LWP is already enabled, the processor flushes the LWP state to memory in the old LWPCB. See
description of the SLWPCB instruction on page 340 for details on saving the active LWP state.
If the flush causes a #PF exception, LWP remains enabled with the old LWPCB still active. Note
that the flush is done before LWP attempts to access the new LWPCB.
3. If the specified LWPCB address is 0, LWP is disabled and the execution of LLWPCB is complete.
4. The LWPCB address is non-zero. LLWPCB validates it as follows:
- If any part of the LWPCB or the ring buffer is beyond the data segment limit, LLWPCB causes
a #GP exception.
- If the ring buffer size is below the implementation’s minimum ring buffer size, LLWPCB
causes a #GP exception.
- While doing these checks, LWP reads and writes the LWPCB, which may cause a #PF
exception.
If any of these exceptions occurs, LLWPCB aborts and LWP is left disabled. Usually, the operating
system will handle a #PF exception by making the memory available and returning to retry the
LLWPCB instruction. The #GP exceptions indicate application programming errors.
5. LWP converts the LWPCB address and the ring buffer address to linear address form by adding
the DS base address and stores the addresses internally.
6. LWP examines the LWPCB.Flags field to determine which events should be enabled and whether
threshold interrupts should be taken. It clears the bits for any features that are not available and
stores the result back to LWPCB.Flags to inform the application of the actual LWP state.
7. For each event being enabled, LWP examines the EventIntervaln value and, if necessary, sets it to
an implementation-defined minimum. (The minimum event interval for LWPVAL is zero.) It
loads its internal counter for the event from the value in EventCountern. A zero or negative value
216 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
in EventCountern means that the next event of that type will cause an event record to be stored. To
count every jth event, a program should set EventIntervaln to j-1 and EventCountern to some
starting value (where j-1 is a good initial count). If the counter value is larger than the interval, the
first event record will be stored after a larger number of events than subsequent records.
8. LWP is started. The execution of LLWPCB is complete.
Notes
If none of the bits in the LWPCB.Flags specifies an available event, LLWPCB still enables LWP to
allow the use of the LWPINS instruction. However, no other event records will be stored.
A program can temporarily disable LWP by executing SLWPCB to obtain the current LWPCB
address, saving that value, and then executing LLWPCB with a register containing 0. It can later re-
enable LWP by executing LLWPCB with a register containing the saved address.
When LWP is enabled, it is typically an error to execute LLWPCB with the address of the active
LWPCB. When the hardware flushes the existing LWP state into the LWPCB, it may overwrite fields
that the application may have set to new LWP parameter values. The flushed values will then be loaded
as LWP is restarted. To reuse an LWPCB, an application should stop LWP by passing a zero to
LLWPCB, then prepare the LWPCB with new parameters and execute LLWPCB again to restart LWP.
Internally, LWP keeps the linear address of the LWPCB and the ring buffer. If the application changes
the value of DS, LWP will continue to collect samples even if the new DS value would no longer allow
access the LWPCB or the ring buffer. However, a #GP fault will occur if the application uses XRSTOR
to restore LWP state saved by XSAVE. Programs should avoid using XSAVE/XRSTOR on LWP state
if DS has changed. This only applies when the CPL != 0; kernel mode operation of XRSTOR is
unaffected by changes to DS. See instruction listing for XSAVE in APM Volume 4 for details.
Operating system and hypervisor code that runs when CPL ≠ 3 should use XSAVE and XRSTOR to
control LWP rather than using LLWPCB. Use WRMSR to write 0 to the LWP_CBADDR MSR to
immediately stop LWP without saving its current state.
It is possible to execute LLWPCB when the CPL != 3 or when SMM is active, but the system software
must ensure that the LWPCB and the entire ring buffer are properly mapped into writable memory in
order to avoid a #PF or #GP fault. Furthermore, if LWP is enabled when a kernel executes LLWPCB,
both the old and new control blocks and ring buffers must be accessible. Using LLWPCB in these
situations is not recommended.
LLWPCB is an LWP instruction. Support for LWP instructions is indicated by CPUID
Fn8000_0001_ECX[LWP] = 1.
For more information on using the CPUID instruction, see the instruction reference page for the
CPUID instruction on page 165. For a description of all feature flags related to instruction subset
support, see Appendix D, “Instruction Subsets and CPUID Feature Flags,” on page 593.
General-Purpose 217
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Instruction Encoding
Mnemonic Encoding
XOP RXB.map_select W.vvvv.L.pp Opcode
LLWPCB reg32 8F RXB.09 0.1111.0.00 12 /0
LLWPCB reg64 8F RXB.09 1.1111.0.00 12 /0
ModRM.reg augments the opcode and is assigned the value 0. ModRM.r/m (augmented by XOP.R)
specifies the register containing the effective address of the LWPCB. ModRM.mod is 11b.
Related Instructions
SLWPCB, LWPVAL, LWPINS
rFLAGS Affected
None
Exceptions
Virtual
Exception Cause of Exception
Real 8086 Protected
LWP instructions are not supported, as indicated by CPUID
X X X
Invalid opcode, Fn8000_0001_ECX[LWP] = 0.
#UD X X The system is not in protected mode.
X LWP is not available, or mod != 11b, or vvvv != 1111b.
Any part of the LWPCB or the event ring buffer is beyond the
General protection, X
DS segment limit.
#GP
X Any restrictions on the contents of the LWPCB are violated
X A page fault resulted from reading or writing the LWPCB.
LWP was already enabled and a page fault resulted from
X
Page fault, #PF reading or writing the old LWPCB.
LWP was already enabled and a page fault resulted from
X
flushing an event to the old ring buffer.
218 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
General-Purpose 219
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
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
X X
#AC alignment checking was enabled.
220 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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.
Related Instructions
None
General-Purpose 221
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
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.
222 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
General-Purpose 223
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Instruction Encoding
Mnemonic Encoding
XOP RXB.map_select W.vvvv.L.pp Opcode
LWPINS reg32.vvvv, reg/mem32, imm32 8F RXB.0A 0.src1.0.00 12 /0 /imm32
LWPINS reg64.vvvv, reg/mem32, imm32 8F RXB.0A 1.src1.0.00 12 /0 /imm32
ModRM.reg augments the opcode and is assigned the value 0. The {mod, r/m} field of the ModRM
byte (augmented by XOP.R) encodes the second operand. A 4-byte immediate field follows ModRM.
Related Instructions
LLWPCB, SLWPCB, LWPVAL
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 Cause of Exception
Real 8086 Protected
LWP instructions are not supported, as indicated by CPUID
X X X
Invalid opcode, Fn8000_0001_ECX[LWP] = 0.
#UD X X The system is not in protected mode.
X LWP is not available.
X A page fault resulted from reading or writing the LWPCB.
X A page fault resulted from writing the event to the ring buffer.
Page fault, #PF
A page fault resulted from reading a modrm operand from
X
memory.
General protection,
X A modrm operand in memory exceeded the segment limit.
#GP
224 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
General-Purpose 225
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Note
When LWPVAL completes (whether or not it stored an event record in the event ring buffer), it counts
as an instruction retired. If the Instructions Retired event is active, this might cause that counter to
become negative and immediately store an event record. If LWPVAL also stored an event record, the
buffer will contain two records with the same instruction address (but different EventId values).
LWPVAL is an LWP instruction. Support for LWP instructions is indicated by CPUID
Fn8000_0001_ECX[LWP] = 1.
For more information on using the CPUID instruction, see the instruction reference page for the
CPUID instruction on page 165. For a description of all feature flags related to instruction subset
support, see Appendix D, “Instruction Subsets and CPUID Feature Flags,” on page 593.
Instruction Encoding
Mnemonic Encoding
XOP RXB.map_select W.vvvv.L.pp Opcode
LWPVAL reg32.vvvv, reg/mem32, imm32 8F RXB.0A 0.src1.0.00 12 /1 /imm32
LWPVAL reg64.vvvv, reg/mem32, imm32 8F RXB.0A 1.src1.0.00 12 /1 /imm32
ModRM.reg augments the opcode and is assigned the value 001b. The {mod, r/m} field of the
ModRM byte (augmented by XOP.R) encodes the second operand. A four-byte immediate field
follows ModRM.
Related Instructions
LLWPCB, SLWPCB, LWPINS
rFLAGS Affected
None
226 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
Exceptions
Virtual
Exception Cause of Exception
Real 8086 Protected
LWP instructions are not supported, as indicated by CPUID
X X X
Invalid opcode, Fn8000_0001_ECX[LWP] = 0.
#UD X X The system is not in protected mode.
X LWP is not available.
X A page fault resulted from reading or writing the LWPCB.
X A page fault resulted from writing the event to the ring buffer.
Page fault, #PF
A page fault resulted from reading a modrm operand from
X
memory.
General protection,
X A modrm operand in memory exceeded the segment limit.
#GP
General-Purpose 227
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Related Instructions
ANDN, BEXTR, BLCI, BLCIC, BLCMSK, BLCS, BLSFILL, BLSI, BLSIC, BLSR, BLSMSK, BSF,
BSR, POPCNT, T1MSKC, TZCNT, TZMSK
228 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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
Mode
Exception Virtual Cause of Exception
Real 8086 Protected
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
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.
An unaligned memory reference was performed while
Alignment check, #AC X X alignment checking was enabled.
General-Purpose 229
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Instruction Encoding
Related Instructions
LFENCE, SFENCE, MFENCE
rFLAGS Affected
0 0 0 0 0 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.
230 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
Instruction Encoding
Related Instructions
LFENCE, SFENCE, MCOMMIT
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Invalid opcode, SSE2 instructions are not supported, as indicated by CPUID
X X X
#UD Fn0000_0001_EDX[SSE2] = 0.
General-Purpose 231
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
232 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
Related Instructions
MWAITX, MONITOR, MWAIT
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Invalid opcode, MONITORX/MWAITX instructions are not supported, as
X X X
#UD indicated by CPUID Fn8000_0001_ECX[MONITORX] =0
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 ECX was non-zero
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
General-Purpose 233
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
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” in APM Volume 2.
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.
234 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
General-Purpose 235
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
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, X X X An attempt was made to load the CS register.
#UD
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.
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.
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
#GP X and the segment descriptor DPL were not equal to the CPL.
(selector)
The SS register was loaded and the segment pointed to was
X 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.
The DS, ES, FS, or GS register was loaded and the segment
X 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.
236 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
Instruction Encoding
Related Instruction
BSWAP
General-Purpose 237
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Invalid opcode, Instruction not supported as indicated by CPUID
X X X
#UD Fn0000_0001_ECX[MOVBE] = 0.
A memory address exceeded the stack segment limit or was non-
Stack, #SS X X X 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 alignment
X X
#AC checking was enabled.
238 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
General-Purpose 239
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
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
240 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
Instruction Encoding
Related Instructions
MOVDQA, MOVDQU, MOVDQ2Q, MOVQ, MOVQ2DQ
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Description
MMX instructions are not supported, as indicated by
X X X CPUID Fn0000_0001_EDX[MMX] or
Fn0000_0001_EDX[MMX] = 0.
SSE2 instructions are not supported, as indicated by
Invalid opcode, #UD X X X CPUID Fn0000_0001_EDX[SSE2] = 0.
X X X The emulate bit (EM) of CR0 was set to 1.
The instruction used XMM registers while
X X X CR4.OSFXSR = 0.
Device not available, X X X The task-switch bit (TS) of CR0 was set to 1.
#NM
General-Purpose 241
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Virtual
Exception Real 8086 Protected Description
A memory address exceeded the stack segment limit
Stack, #SS X X X or was non-canonical.
General protection, A memory address exceeded a data segment limit or
X X X
#GP was non-canonical.
A page fault resulted from the execution of the
Page fault, #PF X X instruction.
x87 floating-point An x87 floating-point exception was pending and the
exception pending, X X X instruction referenced an MMX register.
#MF
An unaligned memory reference was performed while
Alignment check, #AC X X alignment checking was enabled.
242 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
reg32 xmm
31 1 0 127 63 0
0
copy sign
copy sign
movmskpd.eps
The MOVMSKPD instruction is an SSE2 instruction. Support for SSE2 instructions is indicated by
CPUID Fn0000_0001_EDX[SSE2] = 1.
For more information on using the CPUID instruction, see the instruction reference page for the
CPUID instruction on page 165. For a description of all feature flags related to instruction subset
support, see Appendix D, “Instruction Subsets and CPUID Feature Flags,” on page 593.
Instruction Encoding
Related Instructions
MOVMSKPS, PMOVMSKB
rFLAGS Affected
None
General-Purpose 243
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Exceptions
Virtual
Exception (vector) Real 8086 Protected Cause of Exception
SSE2 instructions are not supported, as indicated by
X X X CPUID Fn0000_0001_EDX[SSE2] = 0.
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
244 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
reg32 xmm
31 3 0 127 95 63 31 0
0
movmskps.eps
Related Instructions
MOVMSKPD, PMOVMSKB
rFLAGS Affected
None
General-Purpose 245
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
SSE2 instructions are not supported, as indicated by
X X X CPUID Fn0000_0001_EDX[SSE2] = 0.
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
246 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
Related Instructions
MOVNTDQ, MOVNTPD, MOVNTPS, MOVNTQ
rFLAGS Affected
None
Exceptions
Virtual
Exception (vector) Real 8086 Protected Cause of Exception
SSE2 instructions are not supported, as indicated by
Invalid opcode, #UD X X X CPUID Fn0000_0001_EDX[SSE2] = 0.
A memory address exceeded the stack segment limit
Stack, #SS X X X or was non-canonical.
General-Purpose 247
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Virtual
Exception (vector) Real 8086 Protected Cause of Exception
A memory address exceeded a data segment limit or
X X X was non-canonical.
General protection, X A null data segment was used to reference memory.
#GP
The destination operand was in a non-writable
X segment.
A page fault resulted from the execution of the
Page fault, #PF X X instruction.
An unaligned memory reference was performed while
Alignment check, #AC X X alignment checking was enabled.
248 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
General-Purpose 249
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
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.
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.
250 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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.
General-Purpose 251
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Related Instructions
MOVSX, MOVZX
rFLAGS Affected
None
Exceptions
Virtual Protecte
Exception Real 8086 d Cause of Exception
Stack, #SS X A memory address was non-canonical.
General protection, X A memory address was non-canonical.
#GP
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.
252 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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.
General-Purpose 253
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
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.
254 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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.
General-Purpose 255
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Mnemonic Encoding
Related Instructions
rFLAGS Affected
None.
Exceptions
Virtual
Exception Cause of Exception
Real 8086 Protected
X X BMI2 instructions are only recognized in protected mode.
BMI2 instructions are not supported, as indicated by
Invalid opcode, #UD X CPUID Fn0000_0007_EBX_x0[BMI2] = 0.
X VEX.L is 1.
256 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
Virtual
Exception Cause of Exception
Real 8086 Protected
A memory address exceeded the stack segment limit or
Stack, #SS X was non-canonical.
A memory address exceeded a data segment limit or was
X
General protection, #GP 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.
An unaligned memory reference was performed while
Alignment check, #AC X alignment checking was enabled.
General-Purpose 257
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
258 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
Related Instructions
MONITORX, MONITOR, MWAIT
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Invalid opcode, MONITORX/MWAITX instructions are not supported, as
X X X
#UD indicated by CPUID Fn8000_0001_ECX[MONITORX] =0
General protection, X X X Unsupported extension bits in ECX
#GP
General-Purpose 259
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
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.
260 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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.
General-Purpose 261
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
NOP No Operation
Does nothing. This instruction increments the rIP to point to next instruction, but does not affect the
machine state in any other way.
The single-byte variant is an alias for XCHG rAX,rAX.
Related Instructions
None
rFLAGS Affected
None
Exceptions
None
262 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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
X X
#AC checking was enabled.
General-Purpose 263
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
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 11.
264 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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.
General-Purpose 265
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
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.
266 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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.
General-Purpose 267
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
268 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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, X X An unaligned memory reference is performed while alignment
#AC checking was enabled.
General-Purpose 269
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
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
270 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
b b b10 b9 b8 b7 b6 b5 b4 b3 b2 b1 b0 src
n-1 n-2
d 0 b6 b5 b4 0 0 b3 b2 0 b1 0 0 0 b0 0 0 dest
n-1
m 0 1 1 1 0 0 1 1 0 1 0 0 0 1 0 0 mask
n-1
v3_PDEP_instruct.eps
If the mask is all ones, the execution of this instruction effectively copies the source to the destination.
In 64-bit mode, the operand size is determined by the value of VEX.W. If VEX.W is 1, the operand
size is 64 bits; if VEX.W is 0, the operand size is 32 bits. In 32-bit mode, VEX.W is ignored. 16-bit
operands are not supported.
The destination (dest) and the source (src) are general-purpose registers. The second source operand
(mask) is either a general-purpose register or a memory operand.
This instruction is a BMI2 instruction. Support for this instruction is indicated by CPUID
Fn0000_0007_EBX_x0[BMI2] = 1.
For more information on using the CPUID instruction, see the instruction reference page for the
CPUID instruction on page 165. For a description of all feature flags related to instruction subset
support, see Appendix D, “Instruction Subsets and CPUID Feature Flags,” on page 593.
Mnemonic Encoding
General-Purpose 271
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Related Instructions
rFLAGS Affected
None.
Exceptions
Mode
Exception Virtual Cause of Exception
Real 8086 Protected
X X BMI2 instructions are only recognized in protected mode.
BMI2 instructions are not supported, as indicated by
Invalid opcode, #UD X CPUID Fn0000_0007_EBX_x0[BMI2] = 0.
X VEX.L is 1.
A memory address exceeded the stack segment limit or
Stack, #SS X was non-canonical.
A memory address exceeded a data segment limit or was
X
General protection, #GP 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.
An unaligned memory reference was performed while
Alignment check, #AC X alignment checking was enabled.
272 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
m 0 1 1 1 0 0 1 1 0 1 0 0 0 1 0 0 mask
n-1
v3_PEXT_instruct.eps
If the mask is all ones, the execution of this instruction effectively copies the source to the destination.
In 64-bit mode, the operand size is determined by the value of VEX.W. If VEX.W is 1, the operand
size is 64 bits; if VEX.W is 0, the operand size is 32 bits. In 32-bit mode, VEX.W is ignored. 16-bit
operands are not supported.
The destination (dest) and the source (src) are general-purpose registers. The second source operand
(mask) is either a general-purpose register or a memory operand.
This instruction is a BMI2 instruction. Support for this instruction is indicated by CPUID
Fn0000_0007_EBX_x0[BMI2] = 1.
For more information on using the CPUID instruction, see the instruction reference page for the
CPUID instruction on page 165. For a description of all feature flags related to instruction subset
support, see Appendix D, “Instruction Subsets and CPUID Feature Flags,” on page 593.
Mnemonic Encoding
General-Purpose 273
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Related Instructions
rFLAGS Affected
None.
Exceptions
Mode
Exception Virtual Cause of Exception
Real 8086 Protected
X X BMI2 instructions are only recognized in protected mode.
BMI2 instructions are not supported, as indicated by
Invalid opcode, #UD X CPUID Fn0000_0007_EBX_x0[BMI2] = 0.
X VEX.L is 1.
A memory address exceeded the stack segment limit or
Stack, #SS X was non-canonical.
A memory address exceeded a data segment limit or was
X
General protection, #GP 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.
An unaligned memory reference was performed while
Alignment check, #AC X alignment checking was enabled.
274 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
General-Purpose 275
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Related Instructions
PUSH
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Invalid opcode, X POP DS, POP ES, or POP SS was executed in 64-bit mode.
#UD
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.
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.
A segment register was loaded and 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
#GP X and the segment descriptor DPL were not equal to the CPL.
(selector)
The SS register was loaded and the segment pointed to was
X 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 the CPL was greater than the DPL.
The DS, ES, FS, or GS register was loaded and the segment
X 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.
276 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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.
General-Purpose 277
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
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.
278 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Invalid opcode, The POPCNT instruction is not supported, as indicated by
X X X
#UD CPUID Fn0000_0001_ECX[POPCNT].
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.
General-Purpose 279
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Action
// See “Pseudocode Definition” on page 57.
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
280 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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.
General-Purpose 281
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
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.
282 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
General-Purpose 283
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Related Instructions
PREFETCHlevel
rFLAGS Affected
None
Exceptions
Virtual
Exception (vector) Real 8086 Protected Cause of Exception
PREFETCH and PREFETCHW instructions are not
supported, as indicated by CPUID
X X X Fn8000_0001_ECX[3DNowPrefetch] AND
Invalid opcode, #UD Fn8000_0001_EDX[LM] AND
Fn8000_0001_EDX[3DNow] = 0.
X X X The operand was a register.
284 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
Related Instructions
PREFETCH, PREFETCHW
General-Purpose 285
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
rFLAGS Affected
None
Exceptions
None
286 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
General-Purpose 287
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Related Instructions
POP
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Invalid opcode, PUSH CS, PUSH DS, PUSH ES, or PUSH SS was executed
X
#UD in 64-bit mode.
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.
288 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
Related Instructions
POPA, POPAD
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.
General-Purpose 289
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Action
// See “Pseudocode Definition” on page 57.
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
}
290 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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.
General-Purpose 291
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
292 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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.
General-Purpose 293
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
294 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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.
General-Purpose 295
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Related Instructions
WRFSBASE, WRGSBASE
rFLAGS Affected
None.
Exceptions
Compat-
Exception Legacy ibility 64-bit Cause of Exception
Instruction is not valid in compatibility or legacy
X X modes.
#UD Instruction not supported as indicated by CPUID
X Fn0000_0007_EBX_x0[FSGSBASE] = 0 or, if
supported, not enabled in CR4.
296 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
Related Instructions
RDTSCP
rFLAGS Affected
rNone
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, Instruction not supported by CPUID Fn0000_0007_ECX[22] =
X X X
#UD 0.
General-Purpose 297
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
0 0 0 0 0 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
Instruction not supported by
Invalid opcode, X X X CPUID Fn8000_0008_EBX[RDPRU] = 0 or CPL>0 and
#UD CR4.TSD=1.
298 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
0 0 0 0 0 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, Instruction not supported as indicated by
X X X
#UD CPUID Fn0000_0001_ECX[RDRAND] = 0.
General-Purpose 299
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Related Instructions
RDRAND
rFLAGS Affected
0 0 0 0 0 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
Instruction not supported as indicated by CPUID
Invalid opcode, #UD X X X Fn0000_0007_EBX_x0[RDSEED] = 0
300 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
Action
RETN_START:
POP.v temp_RIP
General-Purpose 301
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
}
ELSEIF (v == 4) // operand size = 32
{
temp_sstk_RIP = SSTK_READ_MEM.d [SSP]
SSP = SSP + 4
}
ELSE // (v == 8) // operand size = 64
{
temp_sstk_RIP = SSTK_READ_MEM.q [SSP]
SSP = SSP + 8
}
IF (temp_RIP != temp_sstk_RIP)
EXCEPTION [#CP(RETN)]
} end shadow stacks 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.
Control-protection, The return address on the program stack did not match the
X
#CP address on the shadow stack.
302 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
Action
// For functions READ_DESCRIPTOR, ShadowStacksEnabled
// see "Pseudocode Definition" on page 57
RETF_START:
IF (PROTECTED_MODE)
RETF_PROTECTED
ELSE // (REAL_MODE or VIRTUAL_MODE)
RETF_REAL_OR_VIRTUAL
RETF_REAL_OR_VIRTUAL:
General-Purpose 303
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
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
RETF_PROTECTED_TO_SAME_PRIV:
// CPL = temp_CS.rpl (RETF to same privilege level)
CS = READ_DESCRIPTOR (temp_CS, iret_chk)
RIP = temp_RIP
RSP.s = RSP + temp_IMM
IF (ShadowStacksEnabled(current CPL))
{
IF (SSP[2:0] != 0)
EXCEPTION [#CP(RETF/IRET)] // SSP must be 8-byte aligned
temp_sstk_CS = SSTK_READ_MEM.q [SSP + 16] // read CS from sstk
temp_sstk_LIP = SSTK_READ_MEM.q [SSP + 8] // read LIP
temp_sstk_prevSSP = SSTK_READ_MEM.q [SSP] // read previous SSP
SSP = SSP + 24
304 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
IF (temp_CS != temp_sstk_CS)
EXCEPTION [#CP(RETF/IRET)] // CS mismatch
IF ((CS.base + RIP) != temp_sstk_LIP)
EXCEPTION [#CP(RETF/IRET)] // LIP mismatch
IF (temp_sstk_prevSSP[1:0] != 0)
EXCEPTION [#CP(RETF/IRET)] // prevSSP must be 4-byte aligned
IF ((COMPATIBILITY_MODE) && (tmp_sstk_prevSSP[63:32] != 0))
EXCEPTION [#GP(0)] // prevSSP must be <4GB in compat mode
IF ((64BIT_MODE) && (temp_sstk_prevSSP is non-canonical))
EXCEPTION [#GP(0)]
SSP = temp_sstk_prevSSP
} // end shadow stacks enabled at current CPL
RETF_PROTECTED_TO_OUTER_PRIV:
// CPL != temp_CS.rpl (RETF changing privilege level)
POP.v temp_RSP
POP.v temp_SS
CPL = temp_CPL
SS = READ_DESCRIPTOR (temp_SS, ss_chk)
RIP = temp_RIP
RSP.s = temp_RSP + temp_IMM
IF (ShadowStacksEnabled(old CPL))
{
IF (SSP[2:0] != 0)
EXCEPTION [#CP(RETF/IRET)] // SSP must be 8-byte aligned
temp_sstk_CS = SSTK_READ_MEM.q [SSP + 16] // read CS from sstk
temp_sstk_LIP = SSTK_READ_MEM.q [SSP + 8] // read LIP
temp_SSP = SSTK_READ_MEM.q [SSP] // read previous SSP
SSP = SSP +24
IF (temp_CS != temp_sstk_CS)
EXCEPTION [#CP(RETF/IRET)] // CS mismatch
IF ((CS.base + RIP) != temp_sstk_LIP)
EXCEPTION [#CP(RETF/IRET)] // LIP mismatch
IF (temp_SSP[1:0] != 0)
EXCEPTION [#CP(RETF/IRET)] // prevSSP must be 4-byte aligned
IF ((COMPATIBILITY_MODE) && (tmp_sstk_prevSSP[63:32] != 0))
EXCEPTION [#GP(0)] // prevSSP must be <4GB in compat mode
}
temp_oldSSP = SSP
General-Purpose 305
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
IF (ShadowStacksEnabled(new CPL))
{
IF ((ShadowStacksEnabled(CPL 3) && (old_CPL == 3))
temp_SSP = PL3_SSP
IF ((COMPATIBILITY_MODE) && (temp_SSP[63:32] != 0))
EXCEPTION [#GP(0)] // SSP must be <4GB in compat mode
SSP = temp_SSP
}
IF (ShadowStacksEnabled(old CPL))
{ // check shadow stack token and clear busy
bool invalid_token = FALSE
< start atomic section >
temp_Token= SSTK_READ_MEM.q [temp_oldSSP] // read supervisor sstk token
IF ((temp_Token AND 0x01) != 1)
invalid_Token = TRUE // token busy bit must be 1
IF ((temp_Token AND ~0x01) != temp_oldSSP)
invalid_Token = TRUE // address in token must = old SSP
IF (!invalid_Token)
temp_Token = temp_Token AND ~0x01 // if valid clear token busy bit
SSTK_WRITE_MEM.q [temp_oldSSP] = temp_Token // writeback token
< end atomic section >
} // end shadow stacks enabled
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)
306 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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.
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
X X
#AC alignment checking was enabled.
The return address on the program stack did not match the
Control-protection,
#CP X address on the shadow stack, or the previous SSP is not 4
byte aligned.
General-Purpose 307
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Related Instructions
RCL, RCR, ROR
308 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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.
General-Purpose 309
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Related Instructions
RCL, RCR, ROL
310 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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.
General-Purpose 311
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Mnemonic Encoding
Related Instructions
SARX, SHLX, SHRX
rFLAGS Affected
None.
312 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
Exceptions
Virtual
Exception Cause of Exception
Real 8086 Protected
X X BMI2 instructions are only recognized in protected mode.
BMI2 instructions are not supported, as indicated by
Invalid opcode, #UD X CPUID Fn0000_0007_EBX_x0[BMI2] = 0.
X VEX.L is 1.
A memory address exceeded the stack segment limit or
Stack, #SS X was non-canonical.
A memory address exceeded a data segment limit or was
X
General protection, #GP 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.
An unaligned memory reference was performed while
Alignment check, #AC X alignment checking was enabled.
General-Purpose 313
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
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
Invalid opcode, The SAHF instruction is not supported in 64-bit mode, as
X
#UD indicated by CPUID Fn8000_0001_ECX[LahfSahf] = 0.
314 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
General-Purpose 315
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
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.
316 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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.
General-Purpose 317
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
318 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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.
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.
General-Purpose 319
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Mnemonic Encoding
Related Instructions
RORX, SHLX, SHRX
rFLAGS Affected
None.
320 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
Exceptions
Virtual
Exception Cause of Exception
Real 8086 Protected
X X BMI2 instructions are only recognized in protected mode.
BMI2 instructions are not supported, as indicated by
Invalid opcode, #UD X CPUID Fn0000_0007_EBX_x0[BMI2] = 0.
X VEX.L is 1.
A memory address exceeded the stack segment limit or
Stack, #SS X was non-canonical.
A memory address exceeded a data segment limit or was
X
General protection, #GP 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.
An unaligned memory reference was performed while
Alignment check, #AC X alignment checking was enabled.
General-Purpose 321
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
322 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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
X X
#AC alignment checking was enabled.
General-Purpose 323
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
324 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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 A memory address exceeded the ES segment limit or was
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.
General-Purpose 325
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
326 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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.
General-Purpose 327
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Related Instructions
LFENCE, MFENCE, MCOMMIT
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
The SSE instructions are not supported, as indicated by
Invalid Opcode, CPUID Fn0000_0001_EDX[25]=0; and the AMD extensions to
X X X
#UD MMX are not supported, as indicated by CPUID
Fn8000_0001_EDX[22]=0.
328 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
General-Purpose 329
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Related Instructions
SHRD, SAL, SAR, SHR, SHL
330 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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, An unaligned memory reference was performed while
X X
#AC alignment checking was enabled.
General-Purpose 331
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Mnemonic Encoding
Related Instructions
RORX, SARX, SHRX
rFLAGS Affected
None.
332 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
Exceptions
Virtual
Exception Cause of Exception
Real 8086 Protected
X X BMI2 instructions are only recognized in protected mode.
BMI2 instructions are not supported, as indicated by
Invalid opcode, #UD X CPUID Fn0000_0007_EBX_x0[BMI2] = 0.
X VEX.L is 1.
A memory address exceeded the stack segment limit or
Stack, #SS X was non-canonical.
A memory address exceeded a data segment limit or was
X
General protection, #GP 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.
An unaligned memory reference was performed while
Alignment check, #AC X alignment checking was enabled.
General-Purpose 333
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
334 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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, An unaligned memory reference was performed while
X X
#AC alignment checking was enabled.
General-Purpose 335
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Related Instructions
SHLD, SHR, SHL, SAR, SAL
336 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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, An unaligned memory reference was performed while
X X
#AC alignment checking was enabled.
General-Purpose 337
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Mnemonic Encoding
Related Instructions
RORX, SARX, SHLX
rFLAGS Affected
None.
338 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
Exceptions
Virtual
Exception Cause of Exception
Real 8086 Protected
X X BMI2 instructions are only recognized in protected mode.
BMI2 instructions are not supported, as indicated by
Invalid opcode, #UD X CPUID Fn0000_0007_EBX_x0[BMI2] = 0.
X VEX.L is 1.
A memory address exceeded the stack segment limit or
Stack, #SS X was non-canonical.
A memory address exceeded a data segment limit or was
X
General protection, #GP 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.
An unaligned memory reference was performed while
Alignment check, #AC X alignment checking was enabled.
General-Purpose 339
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
Instruction Encoding
Mnemonic Encoding
XOP RXB.map_select W.vvvv.L.pp Opcode
SLWPCB reg32 8F RXB.09 0.1111.0.00 12 /1
SLWPCB reg64 8F RXB.09 1.1111.0.00 12 /1
ModRM.reg augments the opcode and is assigned the value 001b. ModRM.r/m (augmented by
XOP.R) specifies the register in which to put the LWPCB address. ModRM.mod must be 11b.
340 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
Related Instructions
LLWPCB, LWPINS, LWPVAL
rFLAGS Affected
None
Exceptions
Virtual
Exception Cause of Exception
Real 8086 Protected
The SLWPCB instruction is not supported, as indicated by
X X X
Invalid opcode, CPUID Fn8000_0001_ECX[LWP] = 0.
#UD X X The system is not in protected mode.
X LWP is not available, or mod != 11b, or vvvv != 1111b.
X A page fault resulted from reading or writing the LWPCB.
Page fault, #PF
X A page fault resulted from flushing an event to the ring buffer.
General-Purpose 341
Instruction Reference
[AMD Public Use]
AMD64 Technology 24594—Rev. 3.36—March 2024
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
342 General-Purpose
Instruction Reference
[AMD Public Use]
24594—Rev. 3.36—March 2024 AMD64 Technology
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 11.
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.
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.
The value of the carry flag of rFLAGs is generated by the add pseudo-instruction and the remaining
arithmetic flags are generated by the or pseudo-instruction.
The T1MSKC instruction is a TBM instruction. Support for this instruction is indicated by CPUID
Fn8000_0001_ECX[TBM] = 1.
For more information on using the CPUID instruction, see the instruction reference page for the
CPUID instruction on page 165. For a description of all feature flags related to instruction subset
support, see Appendix D, “Instruction Subsets and CPUID Feature Flags,” on page 593.
Mnemonic Encoding
Related Instructions
ANDN, BEXTR, BLCFILL, BLCI, BLCIC, BLCMSK, BLCS, BLSFILL, BLSI, BLSIC, BLSR,
BLSMSK, BSF, BSR, LZCNT, POPCNT, TZMSK, TZCNT
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
0 M 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 Cause of Exception
Real 8086 Protected
X X TBM instructions are only recognized in protected mode.
TBM instructions are not supported, as indicated by
Invalid opcode, #UD X CPUID Fn8000_0001_ECX[TBM] = 0.
X XOP.L is 1.
A memory address exceeded the stack segment limit or
Stack, #SS X was non-canonical.
A memory address exceeded a data segment limit or was
X
General protection, #GP 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.
An unaligned memory reference was performed while
Alignment check, #AC X alignment checking was enabled.
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.
TEST AX, imm16 A9 iw and an immediate 16-bit value with the contents of the 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.
TEST RAX, imm32 A9 id and a sign-extended immediate 32-bit value with the contents
of the RAX register and set rFLAGS to reflect the result.
TEST reg/mem8, imm8 F6 /0 ib and an immediate 8-bit value with the contents of an 8-bit
register or memory operand and set rFLAGS to reflect the result.
TEST reg/mem16, imm16 F7 /0 iw and an immediate 16-bit value with the contents of a 16-bit
register or memory operand and set rFLAGS to reflect the result.
TEST reg/mem32, imm32 F7 /0 id and an immediate 32-bit value with the contents of a 32-bit
register or memory operand and set rFLAGS to reflect the result.
and a sign-extended immediate32-bit value with the contents of
TEST reg/mem64, imm32 F7 /0 id a 64-bit register or memory operand and set rFLAGS to reflect
the result.
TEST reg/mem8, reg8 84 /r and the contents of an 8-bit register with the contents of an 8-bit
register or memory operand and set rFLAGS to reflect the result.
TEST reg/mem16, reg16 85 /r and the contents of a 16-bit register with the contents of a 16-bit
register or memory operand and set rFLAGS to reflect the result.
TEST reg/mem32, reg32 85 /r and the contents of a 32-bit register with the contents of a 32-bit
register or memory operand and set rFLAGS to reflect the result.
TEST reg/mem64, reg64 85 /r and the contents of a 64-bit register with the contents 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, An unaligned memory reference was performed while
X X
#AC alignment checking was enabled.
Related Instructions
ANDN, BEXTR, BLCI, BLCIC, BLCMSK, BLCS, BLSFILL, BLSI, BLSIC, BLSR, BLSMSK, BSF,
BSR, LZCNT, POPCNT, T1MSKC, TZMSK
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
Mode
Exception Virtual Cause of Exception
Real 8086 Protected
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.
The value of the carry flag of rFLAGs is generated by the sub pseudo-instruction and the remaining
arithmetic flags are generated by the and pseudo-instruction.
The TZMSK instruction is a TBM instruction. Support for this instruction is indicated by CPUID
Fn8000_0001_ECX[TBM] = 1.
For more information on using the CPUID instruction, see the instruction reference page for the
CPUID instruction on page 165. For a description of all feature flags related to instruction subset
support, see Appendix D, “Instruction Subsets and CPUID Feature Flags,” on page 593.
Mnemonic Encoding
Related Instructions
ANDN, BEXTR, BLCFILL, BLCI, BLCIC, BLCMSK, BLCS, BLSFILL, BLSI, BLSIC, BLSR,
BLSMSK, BSF, BSR, LZCNT, POPCNT, T1MSKC, TZCNT
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
0 M 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 Cause of Exception
Real 8086 Protected
X X TBM instructions are only recognized in protected mode.
TBM instructions are not supported, as indicated by
Invalid opcode, #UD X CPUID Fn8000_0001_ECX[TBM] = 0.
X XOP.L is 1.
A memory address exceeded the stack segment limit or
Stack, #SS X was non-canonical.
A memory address exceeded a data segment limit or was
X
General protection, #GP 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.
An unaligned memory reference was performed while
Alignment check, #AC X alignment checking was enabled.
Related Instructions
None
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Invalid opcode, X X X This instruction is not recognized.
#UD
Related Instructions
RDFSBASE, RDGSBASE
rFLAGS Affected
None.
Exceptions
Exception Legacy Compatibility 64-bit Cause of Exception
X X Instruction is not valid in compatibility or legacy modes.
#UD Instruction not supported as indicated by CPUID
X Fn0000_0007_EBX_x0[FSGSBASE] = 0 or, if supported,
not enabled in CR4.
Attempt to write non-canonical address to segment base
#GP X address.
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 11.
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.
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.
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.
X Y X xor Y
0 0 0
0 1 1
1 0 1
1 1 0
XOR EAX, imm32 35 id xor the contents of EAX with an immediate 32-bit
operand and store the result in EAX.
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.
There are also several other CPUID feature bits that indicate support for certain paging functions,
virtual-mode extensions, machine-check exceptions, advanced programmable interrupt control
(APIC), memory-type range registers (MTRRs), etc.
For more information on using the CPUID instruction, see the reference page for the CPUID
instruction on page 165. For a comprehensive list of all instruction support feature flags, see
Appendix D, “Instruction Subsets and CPUID Feature Flags,” on page 593. For a comprehensive list
of all defined CPUID feature numbers and return values, see Appendix E, “Obtaining Processor
Information Via the CPUID Instruction,” on page 599.
For further information about the system instructions and register resources, see:
• “System Instructions” in APM Volume 2.
• “Summary of Registers and Data Types” on page 38.
• “Notation” on page 53.
• “Instruction Prefixes” on page 5.
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
STAC
rFLAGS Affected
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 Instruction not supported by CPUID
X X Instruction is not supported in virtual mode
Invalid opcode, #UD
X X Lock prefix (F0h) preceding opcode.
X CPL was not 0
Related Instructions
STGI
rFLAGS Affected
None.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
The SVM instructions are not supported as indicated by
X X X CPUID Fn8000_0001_ECX[SVM] = 0.
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 0.
#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
Actions
// see "Pseudocode Definition" on page 57
IF (CR4.CET == 0)
EXCEPTION [#UD]
IF (S_CET.SH_STK_EN == 0)
EXCEPTION [#UD]
IF (CPL != 0)
EXCEPTION [#GP(0)]
temp_linAdr = Linear_Address(mem64)
RFLAGS.ZF,PF,AF,OF,SF = 0
IF (INVALID_TOKEN)
RFLAGS.CF = 1 // set CF if token not valid
ELSE
{
RFLAGS.CF = 0 // else clear CF
SSP = 0 // and set SSP = 0
}
EXIT
Related Instructions
SETSSBSY
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
0 0 0 0 0 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 (vector) Real 8086 Protected Cause of Exception
X X Instruction is only recognized in protected mode.
Invalid opcode, #UD X CR4.CET = 0
X Shadow stacks not enabled at supervisor level
X CPL ! = 0
X The linear address is not 8-byte aligned.
X A memory address exceeded a data segment limit.
In long mode, the address of the memory operand was
General protection, X non-canonical.
#GP
X A null data segment was used to reference memory.
X A non-writable data segment was used.
An execute-only code segment was used to reference
X memory.
The linear address is not a supervisor shadow stack
X page in the OS page tables.
Page fault, #PF
A page fault resulted from the execution of the
X instruction.
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 APM Volume 2, 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
Action
IF ((CPL == 3) && (!SSTK_USER_ENABLED))
EXCEPTION [#UD]
ELSEIF ((CPL < 3) && (!SSTK_SUPV_ENABLED))
EXCEPTION [#UD]
IF (OPERAND_SIZE == 64)
{
temp_numItems = (reg64[7:0] == 0) ? 1 : reg64[7:0]
temp = SSTK_READ_MEM.q [SSP] // touch TOS and last
temp = SSTK_READ_MEM.q [SSP + temp_numItems*8 - 8] // element in range
SSP = SSP + reg64[7:0]*8 // increment SSP
}
ELSE
{
temp_numItems = (reg32[7:0] == 0) ? 1 : reg32[7:0]
temp = SSTK_READ_MEM.d [SSP] // touch TOS and last
temp = SSTK_READ_MEM.d [SSP + temp_numItems*4 - 4] // element in range
SSP = SSP + reg32[7:0]*4 // increment SSP
}
EXIT
Related Instructions
RDSSP, RSTORSSP
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
X X Instruction is only recognized in protected mode.
X CR4.CET = 0
Invalid opcode, #UD
Shadow stacks are not enabled at the current privilege
X level.
A page fault occurred when touching the first or last
X element of the shadow stack in the range specified.
Page fault, #PF
The first or last element in the range specified is not in
X a shadow stack page.
In long mode, the address of the memory operand was
X non-canonical.
General protection, #GP X A memory address exceeded a data segment limit.
X A null data segment was used to reference memory.
For complete descriptions of the steps performed by INT instructions, see the following:
• Legacy-Mode Interrupts: “Legacy Protected-Mode Interrupt Control Transfers” in APM
Volume 2.
• Long-Mode Interrupts: “Long-Mode Interrupt Control Transfers” in APM 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 As part of a stack switch, the target stack segment selector’s
X X
(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
General protection, non-canonical.
#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, WBNOINVD, CLWB, 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, INVLPGB, INVPCID, 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, INVLPGB, INVPCID
rFLAGS Affected
None.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
The SVM instructions are not supported as indicated by
X X X CPUID Fn8000_0001_ECX[SVM] = 0.
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 0.
#GP
rAX Attributes
0 Valid VA
1 Valid PCID
2 Valid ASID
3 Include Global
4 Final Translation Only
5 Include Nested Translations
11:6 Reserved, MBZ
63:12 or 31:12 VA
rAX[3:0] provides for various types of invalidations. A few examples are listed in the following table,
but all values are legal.
0xF Invalidate all TLB entries that match {ASID, PCID, VA}
including Global
0xD Invalidate all TLB entries that match {ASID, VA} including
Global
Invalidate all TLB entries that match {ASID} excluding
0x4 Global
EDX Attributes
15:0 ASID
27:16 PCID
31:28 Reserved, MBZ
ECX[15:0] contains a count of the number of sequential pages to invalidate in addition to the original
virtual address, starting from the virtual address specified in rAX. A count of 0 invalidates a single
page. ECX[31]=0 indicates to increment the virtual address at the 4K boundary. ECX[31]=1 indicates
to increment the virtual address at the 2M boundary. The maximum count supported is reported in
CPUID function 8000_0008h, EDX[15:0].
This instruction invalidates the TLB entry or entries, regardless of the page size (4 Kbytes, 2 Mbytes, 4
Mbytes, or 1 Gbyte). It may invalidate any number of additional TLB entries in addition to the targeted
entry or entries to accomplish the specified function. INVLPGB follows the same rules for cached
upper TLB entries as INVLPG which is controlled by EFER.TCE. However, since this is a broadcast,
the invalidation is controlled by the EFER.TCE value on the processor executing the INVLPGB
instruction. (See Section 3, “Translation Cache Extension” in APM Volume 2 for more information on
EFER.TCE.)
Under the following circumstances, execution of INVLPGB will result in a General Protection fault
(#GP):
• If SVM is disabled, requesting the ASID field with any value but zero, even if the ASID is not
necessary for the flush.
• If PCID is disabled, requesting the PCID field with any value but zero, even if the PCID is not
necessary for the flush.
• If the request exceeds the number of valid ASIDs for the processor, even if the ASID is not valid.
• Attempts to request a count larger than the maximum count supported, even if the VA is not valid
• Attempts to execute an INVLPGB while in 4M paging mode.
Guest Usage of INVLPGB. Guest usage of INVLPGB is supported only when the instruction has
been explicitly enabled by the hypervisor in the VMCB (see APM Volume 2, Appendix B, Table B-1:
VMCB Layout, Control Area). Support for INVLPGB/TLBSYNC hypervisor enable in VMCB is
indicated by CPUID Fn8000_000A_EDX[24] = 1.
A guest that executes a legal INVLPGB that is not intercepted will have the requested ASID field
replaced by the current ASID and the valid ASID bit set before doing the broadcast invalidation.
Because of its broadcast nature, the ASID field must be global and all processors must allocate the
same ASID to the same Guest for proper operation. Hypervisors that do not support a global ASID
must intercept the Guest usage of INVLPGB, if enabled, for proper behavior.
Two forms of INVLPGB intercepts, conditional and unconditional, are available to the hypervisor.
The unconditional intercept traps all guest usage of INVLPGB. The conditional intercept traps only
illegally-specified INVLPGB instructions. An illegally specified INVLPGB is one that would, if not
intercepted, cause a #GP for any reason other than not being executed at CPL 0.
INVLPGB is a privileged instruction but not a serializing instruction. It must be executed at CPL 0, but
will broadcast the invalidate to the rest of the processors which may be running at any privilege level.
INVLPGB is weakly ordered as it broadcasts the invalidation types throughout the system to all
processors, so that a batch of invalidations can be done in a parallel fashion. For software to guarantee
that all processors have seen and done the TLB invalidations, a TLBSYNC must be executed on the
initiating processor.
Related Instructions
TLBSYNC, INVLPG, INVLPGA, INVPCID
rFLAGS Affected
None.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
X X This instruction is only recognized in protected mode.
Virtual
Exception Real 8086 Protected Cause of Exception
X CPL was not 0.
X EAX[11:6] is not zero or EAX[5] not zero if not supported.
EDX[31:28] is not zero.
General protection, X CR4.PCID =0 and EDX[PCID] is not zero.
#GP X EFER.SVME =0 and EDX[ASID] is not zero.
X EDX[ASID] > number of supported ASIDs.
X ECX[15:0] > maximum page count supported.
X 4M paging is active.
This instruction invalidates the TLB entry or entries, regardless of the page size (4 Kbytes, 2 Mbytes, 4
Mbytes, or 1 Gbyte). It may invalidate any number of additional TLB entries, in addition to the
targeted entry or entries to accomplish the specified function. INVPCID follows the same rules for
cached upper TLB entries as INVLPG which is controlled by EFER.TCE. (See Section 3, “Translation
Cache Extension” in APM Volume 2 for more information on EFER.TCE.)
If PCID is disabled (CR4.PCID = 0), all TLB entries are being cached with PCID = 0. When
CR4.PCID = 0, executing INVPCID with type 0 and 1 is only allowed if the PCID specified in the
descriptor is zero. Furthermore, when CR4.PCID = 0, executing INVPCID with type 2 or 3 invalidate
mappings only for PCID = 0.
INVPCID is a serializing instruction and a privileged instruction. The current privilege level must be 0
to execute this instruction.
Related Instructions
INVLPG, INVLPGA, INVLPGB, TLBSYNC
rFLAGS Affected
None.
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
X X This instruction is only recognized in protected mode.
This instruction not supported as indicated by CPUID
X
Invalid opcode, #UD Fn0000_0007_EBX_x0[INVPCID] = 0.
X If mod=11 (register is specified instead of memory for desc).
X If the LOCK prefix is used.
X CPL was not 0.
X An invalid type (>3) was specified in register operand.
X Bits 63:12 of descriptor in memory operand are not all zero.
Invalidation type 0 was specified and the virtual address in
X bits 127:64 of descriptor is not canonical.
General protection, Invalidation type 0 or 1 and bits 11:0 of descriptor are not
X
#GP zero when CR4.PCIDE = 0.
An execute-only code segment was used to reference
X memory.
X A memory address exceeded a data segment limit.
In long mode, the address of the memory operand was non-
X canonical.
X A null data segment was used to reference memory.
A memory address exceeded the stack segment limit or was
Stack, #SS X non-canonical.
Page Fault, #PF X A page fault resulted from the execution of the instruction.
Action
// For functions READ_DESCRIPTOR, ShadowStacksEnabled
// see "Pseudocode Definition" on page 57
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
RFLAGS.v = temp_RFLAGS // VIF,VIP,VM unchanged
RIP = temp_RIP
EXIT
IRET_PROTECTED:
IF (RFLAGS.NT == 1)
IF (LEGACY_MODE) // IRET does a task-switch to a previous task
TASK_SWITCH // using the ’back link’ field in the TSS
ELSE // (LONG_MODE)
EXCEPTION [#GP(0)] // task switches aren’t supported in long mode
POP.v temp_RIP
POP.v temp_CS
POP.v temp_RFLAGS
IF (temp_CS.rpl = CPL)
changing_CPL = FALSE
ELSEIF (temp_CS.rpl > CPL)
changing_CPL = TRUE
ELSE // (temp_CS.rpl < CPL)
EXCEPTION [#GP(temp_CS)] // IRET to greater priv not allowed
IF ((64BIT_MODE) || (changing_CPL))
POP.v temp_RSP // in 64-bit mode or changing CPL, IRET always pops SS:RSP
POP.v temp_SS
IF (changing_CPL)
IRET_PROTECTED_TO_OUTER_PRIV
ELSE
IRET_PROTECTED_TO_SAME_PRIV
IRET_PROTECTED_TO_OUTER_PRIV:
CPL = CS.rpl
temp_oldSSP = SSP
IF (ShadowStacksEnabled(new CPL))
IF (new CPL == 3)
temp_SSP = PL3_SSP
IF ((COMPATIBILITY_MODE) && (temp_SSP[63:32] != 0))
EXCEPTION [#GP(0)] // SSP must be <4GB in compat mode
SSP = temp_SSP
IRET_PROTECTED_TO_SAME_PRIV:
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
}
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
RSP.d = temp_RSP
RFLAGS.d = temp_RFLAGS
CPL = 3
temp_oldSSP = SSP
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.
The target offset exceeded the code segment limit or was non-
X X X 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
X X
#AC alignment checking was enabled.
The return address on the program stack did not match the
Control-protection, address on the shadow stack, or the previous SSP is not 4
X
#CP byte aligned, or the previous SSP was not <4GB when
returning to 32-bit mode or compatibility mode.
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.
A memory address exceeded the data segment limit or was
General protection, X non-canonical.
#GP
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.
Related Instructions
LIDT, LLDT, LTR, SGDT, SIDT, SLDT, STR
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
X
Invalid opcode, #UD X X The operand was a register.
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.
A memory address exceeded a data segment limit or was
X non-canonical.
General protection,
#GP X CPL was not 0.
X A null data segment was used to reference memory.
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, X X This instruction is only recognized in protected mode.
#UD
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 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
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, MONITORX, MWAITX
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
Invalid opcode, #UD CPUID Fn0000_0001_ECX[MONITOR] = 0.
CPL was not 0 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
Invalid Instruction, CR9–CR15).
#UD The use of the LOCK prefix to read CR8 is not supported, as
X X X indicated by CPUID Fn8000_0001_ECX[AltMovCr8] = 0.
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.
An attempt was made to write 1 to any reserved bit in CR0,
X X CR3, CR4 or CR8.
General protection, An attempt was made to set CR0.PG while long mode was
#GP 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).
An attempt was made to set CR4.PCIDE=1 when long mode
X was disabled (EFER.LMA=0).
An attempt was made to set CR4.PCIDE=1 when CR3[11:0]
X <>0.
X An attempt was made to set CR0.PG=0 when CR4.PCIDE=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.
• MONITOR must precede the MWAIT and occur in the same loop.
• MWAIT must be conditionally executed only if the awaited store has not already occurred. (This
prevents a race condition between the MONITOR instruction arming the monitoring hardware and
the store intended to trigger the monitoring hardware.)
The following pseudo-code shows typical usage of a MONITOR/MWAIT pair:
EAX = Linear_Address_to_Monitor;
ECX = 0; // Extensions
EDX = 0; // Hints
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
Invalid opcode, #UD CPUID Fn0000_0001_ECX[MONITOR] = 0.
CPL was not 0 and
X X MSRC001_0015[MonMwaitUserEn] = 0.
General protection, X X X Unsupported extension bits were set in ECX
#GP
Action
SYSTEM_PA = RAX & ~0x1FFFFF
EAX = FAIL_BADADDR
EXIT
EAX = SUCCESS
EXIT
Return Codes
Value Name Description
0 SUCCESS Successful completion
1 FAIL_INPUT Illegal input parameters
2 FAIL_PERMISSION Current ASID not 0
3 FAIL_INUSE Another processor is modifying the same RMP entry
7 FAIL_BADADDR The page did not meet smashing criteria
Related Instructions
RMPUPDATE, PVALIDATE, RMPADJUST
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
The SNP instructions are not supported as indicated by
X X X CPUID Fn8000_001F_EAX[SNP] = 0
Invalid opcode,
#UD X X X This instruction is only recognized in 64-bit mode
X SYSCFG[SNP_EN] was not set to 1
General Protection, X CPL was not 0
#GP
Action
GUEST_VA = rAX & ~0xFFF
PAGE_SIZE = ECX[0]
VALIDATE_PAGE = EDX[0]
IF (!SNP_ACTIVE)
rFLAGS.CF = 1 // Set CF to indicate that the RMP was not changed
EAX = SUCCESS
EXIT
IF (CURRENT_VMPL != 0)
EXCEPTION [#GP(0)] // This instruction is only allowed at VMPL 0
IF (temp_RMP.IMMUTABLE || !temp_RMP.ASSIGNED ||
(temp_RMP.GUEST_PA != GUEST_PA) || (temp_RMP.ASID != ASID) ||
(temp_RMP.PAGE_SIZE != nPT page size) ||
((temp_RMP.PAGE_SIZE == 2MB) && (PAGE_SIZE == 4KB)))
#VMEXIT(NPF)
IF (temp_RMP.VALIDATED == VALIDATE_PAGE)
rFLAGS.CF = 1
ELSE
rFLAGS.CF = 0
temp_RMP.VALIDATED = VALIDATE_PAGE
WRITE_MEM_PA.o [RMP_ENTRY_PA] = temp_RMP
EAX = SUCCESS
EXIT
Return Codes
Value Name Description
Successful completion (regardless of whether Validated bit
0 SUCCESS changed state)
1 FAIL_INPUT Illegal input parameters
6 FAIL_SIZEMISMATCH Page size mismatch between guest (2M) and RMP entry (4K)
Related Instructions
RMPUPDATE, PSMASH, RMPADJUST
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
Invalid opcode, The SNP instructions are not supported as indicated by
X X X
#UD CPUID Fn8000_001F_EAX[SNP] = 0
General Protection, X X CPL was not 0
#GP X X X Current VMPL was not zero
X X A page fault resulted from the execution of the instruction
Page Fault, #PF
X The effective C-bit was a 0 during the guest page table walk
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, X X X CPUID Fn0000_0001_EDX[MSR] = 0 or CPUID
#UD Fn8000_0001_EDX[MSR] = 0.
X X CPL was not 0.
General protection,
#GP The value in ECX specifies a reserved or unimplemented
X X MSR address.
Related Instructions
WRPKRU
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Invalid opcode, X X X CR4.PKE=0
#UD
General protection, X ECX was not zero
#GP
For more information on using the CPUID instruction, see the description of the CPUID instruction on
page 165.
Programs running at any privilege level can read performance monitor counters if the PCE flag in CR4
is set to 1; otherwise this instruction must be executed at a privilege level of 0.
This instruction is not serializing. Therefore, there is no guarantee that all instructions have completed
at the time the performance counter is read.
For more information about performance-counter registers, see the documentation for various
hardware implementations and “Performance Counters” in APM Volume 2.
Instruction Encoding
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.
Action
IF (((CPL==3) && SSTK_USER_ENABLED) || ((CPL!=3) && SSTK_SUPV_ENABLED))
IF (OPERAND_SIZE == 64)
reg64 = SSP
ELSE
reg32 = SSP[31:0]
EXIT
Related Instructions
RDSSP, RSTORSSP
rFLAGS Affected
None
Exceptions
None.
Instruction Encoding
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 CPUID Fn0000_0001_EDX[TSC] = 0 OR
CPUID Fn8000_0001_EDX[TSC] = 0.
General protection, X X CPL was not 0 and CR4.TSD = 1.
#GP
Instruction Encoding
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 CPUID Fn8000_0001_EDX[RDTSCP] = 0.
General protection, X X CPL was not 0 and CR4.TSD = 1.
#GP
The RMPADJUST instruction is used by an SNP-active guest to modify RMP permissions of a lesser-
privileged VMPL. The RMPADJUST instruction will attempt to access the specified page and will
take a #VMEXIT(NPF) if a nested translation error occurs or the translated address is outside the
range of memory covered by the RMP. Assuming no such error is detected, the target VMPL is
numerically higher than the current VMPL, and the specified permissions for the target VMPL are not
greater than the permissions of the current VMPL, the RMPADJUST instruction will modify the target
permission mask in the RMP entry.
Upon completion, a return code is stored in EAX. rFLAGS bits OF, ZF, AF, PF and SF are set based on
this return code.
RMPADJUST performs the same segmentation and paging checks as a 1-byte read. RMPADJUST
does not invalidate TLB caches.
This is a privileged instruction. Attempted execution at a privilege level other than CPL0 will result in
a #GP(0) exception. In addition, this instruction is only valid in 64-bit mode in an SNP-active guest; in
all other modes a #UD exception will be generated.
Support for this instruction is indicated by CPUID Fn8000_001F_EAX[SNP]=1.
Action
GUEST_VA = RAX & ~0xFFF
PAGE_SIZE = RCX[0]
TARGET_VMPL = RDX[7:0]
TARGET_PERM_MASK = RDX[15:8]
VMSA = RDX[16]
IF (!SNP_ACTIVE)
EXCEPTION [#UD]
IF (temp_RMP.IMMUTABLE || !temp_RMP.ASSIGNED ||
(temp_RMP.GUEST_PA != GUEST_PA) || (temp_RMP.ASID != ASID) ||
(temp_RMP.PAGE_SIZE != nPT page size) ||
((temp_RMP.PAGE_SIZE == 2MB) && (PAGE_SIZE == 4KB)))
#VMEXIT(NPF)
IF (!temp_RMP.VALIDATED)
#VC(PAGE_NOT_VALIDATED)
IF (CURRENT_VMPL == 0)
temp_RMP.VMSA = VMSA
temp_RMP.PERMISSIONS[TARGET_VMPL] = TARGET_PERM_MASK
Return Codes
Value Name Description
0 SUCCESS Successful completion
1 FAIL_INPUT Illegal input parameters
2 FAIL_PERMISSION Insufficient permissions
6 FAIL_SIZEMISMATCH Page size mismatch between guest and RMP
Related Instructions
PVALIDATE, RMPUPDATE, PSMASH
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
The SNP instructions are not supported as indicated by
X X X CPUID Fn8000_001F_EAX[SNP] = 0
Invalid opcode,
#UD X X X This instruction is only recognized in 64-bit mode
X Guest is not SNP-Active
General Protection, X CPL was not 0
#GP
X A page fault resulted from the execution of the instruction
Page Fault, #PF
X The effective C-bit was a 0 during the guest page table walk
VMM
Communication, X RMP.VALIDATED was not set to 1
#VC
The RMPQUERY instruction is used by an SNP-active guest to read RMP permissions of a lesser-
privileged VMPL. The RMPQUERY instruction will attempt to access the specified page and can take
a #VMEXIT(NPF) if a nested translation error occurs or the translated address is outside the range of
memory covered by the RMP. Assuming no such error is detected and the target VMPL is numerically
higher than the current VMPL, the RMPQUERY instruction will read RMP permissions from the
RMP entry and return them in RDX and RCX registers.
Upon completion, a return code is stored in EAX. rFLAGS bits OF, ZF, AF, PF and SF are set based on
return code.
RMPQUERY performs the same segmentation and paging checks as a 1-byte read at the current
VMPL.
This is a privileged instruction. Attempted execution at a privilege level other than CPL0 will result in
a #GP(0) exception. In addition, this instruction is only valid in 64-bit mode in an SNP-active guest; in
all other modes a #UD exception will be generated.
Support for this instruction is indicated by CPUID Fn8000_001F_EAX[RMPQUERY] (bit 6) = 1.
Action
GUEST_VA = RAX & ~0xFFF
TARGET_VMPL = RDX[7:0]
IF (!SNP_ACTIVE)
EXCEPTION [#UD]
IF (RMP_ENTRY_PA > RMP_END) // Translated system address must have an RMP entry
#VMEXIT(NPF)
IF (!temp_RMP.VALIDATED)
#VC(PAGE_NOT_VALIDATED)
RDX[63:16] = 0
RDX[15:8] = temp_RMP.PERMISSIONS[TARGET_VMPL]
IF (CURRENT_VMPL == 0)
RDX[16] = temp_RMP.VMSA
RCX[63:1] = 0
RCX[0] = temp_RMP.PAGE_SIZE
EAX = SUCCESS
EXIT
Return Codes
Value Name Description
0 SUCCESS Successful completion
2 FAIL_PERMISSION Current ASID not 0 or RMP entry is Immutable
Related Instructions
PVALIDATE, PSMASH, RMPADJUST
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
The RMPQUERY instruction is not supported as indicated
X X X by CPUID Fn8000_001F_EAX[RMPQUERY](bit 6)=0
Invalid opcode,
#UD X X X This instruction is only recognized in 64-bit mode
X Guest is not SNP-Active
General Protection, X X X CPL was not zero
#GP
X X A page fault resulted from the execution of the instruction
Page Fault, #PF
X The effective C-bit was a 0 during the guest page table walk
VMM
Communication, X RMP.VALIDATED was not set to 1
#VC
If the page address specified in RAX is 2MB-aligned, the value of 2MB_REGION_STATUS indicates
if any other pages within the same 2MB region are assigned in the RMP. Specifically, if any page from
RAX+0x1000 to RAX+0x1FF000 inclusive have the ASSIGNED flag set in their RMP entry,
2MB_REGION_STATUS will be set to 1. If none of these pages have the ASSIGNED flag set,
2MB_REGION_STATUS will be set to 0. If the page address specified in RAX is not 2MB-aligned,
the value of 2MB_REGION_STATUS is always set to 0.
Upon completion, a return code is stored in EAX. rFLAGS bits OF, ZF, AF, PF and SF are set based on
return code.
This instruction is intended for hypervisor use. Attempted execution at an ASID other than 0 will
result in a FAIL_PERMISSION return code.
This is a privileged instruction. Attempted execution at a privilege level other than CPL0 will result in
a #GP(0) exception. In addition, this instruction is only valid in 64-bit mode with SNP enabled; in all
other modes a #UD exception will be generated.
Support for this instruction is indicated by CPUID Fn8000_001F_EAX[RMPREAD] (bit 21) = 1.
Action
SYSTEM_PA = RAX & ~0xFFF
RMP_PTR = RCX
temp_DATA.o = 0
temp_DATA.GUEST_PA = temp_RMP.GUEST_PA
temp_DATA.ASSIGNED = temp_RMP.ASSIGNED
temp_DATA.PAGE_SIZE = temp_RMP.PAGE_SIZE
temp_DATA.IMMUTABLE = temp_RMP.IMMUTABLE
temp_DATA.ASID = temp_RMP.ASID
EAX = SUCCESS
EXIT
Return Codes
Value Name Description
0 SUCCESS Successful completion
1 FAIL_INPUT Illegal input parameters
2 FAIL_PERMISSION Current ASID not 0
Related Instructions
RMPUPDATE, RMPQUERY
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
The RMPREAD instruction is not supported as indicated by
X X X CPUID Fn8000_001F_EAX[RMPREAD] (bit 21) = 0
Invalid opcode,
#UD X X X This instruction is only recognized in 64-bit mode
X SYSCFG[SNP_EN] was not set to 1
General Protection, X CPL was not 0
#GP
The RMPUPDATE instruction checks that new RMP state is legal before it updates the RMP table.
Upon completion, a return code is stored in EAX. rFLAGS bits OF, ZF, AF, PF and SF are set based on
this return code.
The RMPUPDATE instruction invalidates all TLB entries in the system that translate to the page being
modified.
This instruction is intended for hypervisor use. Attempted execution at an ASID other than 0 will
result in a FAIL_PERMISSION return code.
This is a privileged instruction. Attempted execution at a privilege level other than CPL0 will result in
a #GP(0) exception. In addition, this instruction is only valid in 64-bit mode with SNP enabled; in all
other modes a #UD exception will be generated.
Support for this instruction is indicated by the feature flag CPUID Fn8000_001F_EAX[SNP]=1.
Action
SYSTEM_PA = RAX & ~0xFFF
NEW_RMP_PTR = RCX
IF (OLD_RMP.IMMUTABLE)
EAX = FAIL_PERMISSION
EXIT
IF (NEW_RMP.PAGE_SIZE == 4KB)
IF ((SYSTEM_PA[20:12] == 0) && (OLD_RMP.PAGE_SIZE == 2MB))
EAX = FAIL_OVERLAP
EXIT
ELSE IF (SYSTEM_PA[20:12] != 0)
2MB_RMP = READ_MEM_PA.o [2MB_RMP_ENTRY_PA]
IF (2MB_RMP.ASSIGNED && (2MB_RMP.PAGE_SIZE == 2MB))
EAX = FAIL_OVERLAP
EXIT
ELSE IF (Another processor is modifying a page in 2MB region)
EAX = FAIL_OVERLAP
EXIT
ELSE
IF (Any 4KB RMP entry with (RMP.ASSIGNED == 1) exists in 2MB region)
EAX = FAIL_OVERLAP
EXIT
ELSE
FOR (I = 1; I < 512, I++)
{
temp_RMP = 0
temp_RMP.ASSIGNED = NEW_RMP.ASSIGNED
IF (!NEW_RMP.ASSIGNED)
temp_RMP = 0
ELSE
temp_RMP.ASID = NEW_RMP.ASID
temp_RMP.GUEST_PA = NEW_RMP.GUEST_PA
temp_RMP.PAGE_SIZE = NEW_RMP.PAGE_SIZE
temp_RMP.ASSIGNED = NEW_RMP.ASSIGNED
temp_RMP.IMMUTABLE = NEW_RMP.IMMUTABLE
temp_RMP.VALIDATED = OLD_RMP.VALIDATED
temp_RMP.PERMISSIONS = OLD_RMP.PERMISSIONS
temp_RMP.VMSA = OLD_RMP.VMSA
IF (NEW_RMP.ASID == 0)
temp_RMP.GUEST_PA = 0
IF ((OLD_RMP.ASID ^ NEW_RMP.ASID) ||
(OLD_RMP.GUEST_PA ^ NEW_RMP.GUEST_PA) ||
(OLD_RMP.PAGE_SIZE ^ NEW_RMP.PAGE_SIZE) ||
(OLD_RMP.ASSIGNED ^ NEW_RMP.ASSIGNED))
N = CPUID Fn8000001F_EBX[15:12]
temp_RMP.VALIDATED = 0
temp_RMP.VMSA = 0
temp_RMP.PERMISSIONS[0] = FULL_PERMISSIONS
temp_RMP.PERMISSIONS[1:(N-1)] = 0
Return Codes
Value Name Description
0 SUCCESS Successful completion
1 FAIL_INPUT Illegal input parameters
2 FAIL_PERMISSION Current ASID not 0 or RMP entry is Immutable
3 FAIL_INUSE Another processor is modifying the same RMP entry
4 FAIL_OVERLAP 4KB page and 2MB page RMP overlap detected
Related Instructions
PVALIDATE, PSMASH, RMPADJUST
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
The SNP instructions are not supported as indicated by
X X X CPUID Fn8000_001F_EAX[SNP] = 0
Invalid opcode,
#UD X X X This instruction is only recognized in 64-bit mode
X SYSCFG[SNP_EN] was not set to 1
General Protection, X CPL was not 0
#GP X A null data segment was used to reference memory
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, X X X The processor was not in System Management Mode (SMM).
#UD
Action
// see "Pseudocode Definition" on page 57
temp_linAdr = Linear_Address(mem64)
IF (temp_linAdr is not 8-byte aligned)
EXCEPTION [#GP(0)]
IF (temp_prevSSP != temp_linAdr)
INVALID_TOKEN = TRUE // prev SSP from token must match lin addr
IF (INVALID_TOKEN)
EXCEPTION [#CP(RSTORSSP)]
ELSE
{
SSP = temp_linAdr // SSP = linear address of memory operand
RFLAGS.ZF,PF,AF,OF,SF = 0
RFLAGS.CF = (temp_rstorToken AND 0x04) ? 1 : 0; // set CF if SSP in token
// was 4-byte aligned
}
EXIT
Related Instructions
SAVEPREVSSP
rFLAGS Affected
ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF
0 0 0 0 0 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 CR4.CET = 0
Invalid opcode, #UD
X Shadow stacks not enabled at current privilege level.
X The linear address was not 8-byte aligned.
X A memory address exceeded a data segment limit.
In long mode, the address of the memory operand was non-
X
General protection, canonical.
#GP X A null data segment was used to reference memory.
X A non-writeable data segment was used.
An execute-only code segment was used to reference
X memory.
Virtual
Exception Real 8086 Protected Cause of Exception
The mode bit (bit 0) in the token did not match the current
X mode.
Control Protection, X The type bit (bit 1) in the token was not 0.
#CP
The SSP address in the token did not match the linear
X address of the memory operand.
X The linear address was not a shadow stack page.
Page fault, #PF
X A page fault resulted from the execution of the instruction.
Action
// see "Pseudocode Definition" on page 57
Related Instructions
RSTORSSP
rFLAGS Affected
None.
Exceptions
Virtual
Exception Cause of Exception
Real 8086 Protected
X X Instruction is only recognized in protected mode.
Invalid opcode, #UD X CR4.CET = 0
X Shadow stacks not enabled at current privilege level.
X The SSP was not 8-byte aligned.
X The type bit (bit 1) in the token was not 1.
X CF was set in 64-bit mode.
General protection, #GP
X The previous SSP was >4Gb when not in 64-bit mode.
A non-zero alignment hole was found in legacy or
X compatibility mode.
X A page fault resulted from the execution of the instruction.
Page fault, #PF A shadow stack reference was made to a non-shadow
X stack page.
Action
// see "Pseudocode Definition" on page 57
IF (CR4.CET == 0)
EXCEPTION [#UD]
IF (S_CET.SH_STK_EN == 0)
EXCEPTION [#UD]
IF (CPL != 0)
EXCEPTION [#GP(0)]
temp_newSSP = PL0_SSP
IF (FAULT)
EXCEPTION [#CP(SETSSBSY)]
ELSE
SSP = temp_newSSP // if no faults, SSP = PL0_SSP
EXIT
Related Instructions
CLRSSBSY
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
X X X Instruction is only recognized in protected mode.
Invalid Opcode, X CR4.CET = 0.
#UD
X Shadow stacks not enabled at supervisor level.
General Protection, X CPL ! = 0
#GP X PL0_SSP MSR is not 8-byte aligned.
X The shadow stack token is busy.
X The shadow stack token reserved bits are not 0.
Control, #CP
X PL0_SSP MSR >4Gb when not in 64-bit mode.
X The new SSP in the token != PL0_SSP.
X PL0_SSP MSR is not a supervisor shadow stack page.
Page Fault, #PF
X A page fault resulted from the execution of the instruction.
Related Instructions
SIDT, SLDT, STR, LGDT, LIDT, LLDT, LTR
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Invalid opcode, X X X The operand was a register.
#UD
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
SGDT, SLDT, STR, LGDT, LIDT, LLDT, LTR
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Invalid opcode, X X X The operand was a register.
#UD
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.
Action
IF ((EFER.SVME == 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
X CPUID Fn8000_000A_EDX[SVML] = 0.
Invalid opcode, #UD
• DEV is not available, as indicated by CPUID
Fn8000_0001_ECX[SKINIT] = 0.
X X Instruction is only recognized in protected mode.
General protection, X CPL was not 0.
#GP
Related Instructions
SIDT, SGDT, STR, LIDT, LGDT, LLDT, LTR
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Invalid opcode, X X This instruction is only recognized in protected mode.
#UD
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.
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
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
X X
#AC alignment checking was enabled.
Related Instructions
CLAC
rFLAGS Affected
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 Instruction not supported by CPUID
X Instruction is not supported in virtual mode
Invalid opcode, #UD
X Lock prefix (F0h) preceding opcode.
X CPL was not 0
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 APM 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
X CPUID Fn8000_000A_EDX[SVML] = 0.
Invalid opcode, #UD
• DEV is not available, as indicated by
CPUID Fn8000_0001_ECX[SKINIT] = 0.
X X Instruction is only recognized in protected mode.
General protection, X CPL was not 0.
#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.
Alignment check, An unaligned memory reference was performed while
X
#AC 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
APM Volume 2.
Support for the SYSCALL instruction is indicated by CPUID Fn8000_0001_EDX[SysCallSysRet] =
1. For more information on using the CPUID instruction, see the description of the CPUID instruction
on page 165.
Instruction Encoding
Action
// See “Pseudocode Definition” on page 57.
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
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 CPUID
Fn8000_0001_EDX[SysCallSysRet] = 0.
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.)
Instruction Encoding
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
Invalid opcode, #UD CPUID Fn0000_0001_EDX[SysEnterSysExit] = 0.
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.
Instruction Encoding
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
Invalid opcode, #UD CPUID Fn0000_0001_EDX[SysEnterSysExit] = 0.
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 APM Volume 2.
Support for the SYSRET instruction is indicated by CPUID Fn8000_0001_EDX[SysCallSysRet] = 1.
For more information on using the CPUID instruction, see the description of the CPUID instruction on
page 165.
Instruction Encoding
Action
// See “Pseudocode Definition” on page 57.
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 CPUID
Fn8000_0001_EDX[SysCallSysRet] = 0.
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
INVLPGB
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Instruction not supported as indicated by CPUID
X X X Fn8000_0008_EBX[INVLPGB] = 0
Invalid opcode, X X Instruction is only recognized in protected mode
#UD
The hypervisor has not enabled Guest usage of this
X instruction.
General protection, X CPL was not 0
#GP
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, X X This instruction is only recognized in protected mode.
#UD
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, X X This instruction is only recognized in protected mode.
#UD
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
X X X CPUID Fn8000_0001_ECX[SVM] = 0.
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 0.
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
X X X
CPUID Fn8000_0001_ECX[SVM] = 0.
Invalid opcode, #UD
X X X Secure Virtual Machine was not enabled (EFER.SVME=0).
X X X VMMCALL was not intercepted.
Instruction Encoding
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
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
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
X X X CPUID Fn8000_0001_ECX[SVM] = 0.
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 0.
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.
Instruction Encoding
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
X X X CPUID Fn8000_0001_ECX[SVM] = 0.
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 0.
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, CLWB, 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, X X X CPUID Fn0000_0001_EDX[MSR] = 0 OR CPUID
#UD Fn8000_0001_EDX[MSR] = 0.
Virtual
Exception Real 8086 Protected Cause of Exception
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.
Related Instructions
RDPKRU
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
Invalid opcode, X X X CR4.PKE=0
#UD
General protection, X ECX was not zero or EDX was not zero
#GP
Action
// see "Pseudocode Definition" on page 57
IF (CPL == 3)
{
IF ((CR4.CET && U_CET.SH_STK_EN) == 0)
EXCEPTION [#UD]
IF (U_CET.WR_SSTK_EN == 0)
EXCEPTION [#UD] // WRSS not enabled in U_CET
}
ELSE // CPL <3
{
IF ((CR4.CET && S_CET.SH_STK_EN) == 0)
EXCEPTION [#UD]
IF (S_CET.WR_SSTK_EN == 0)
EXCEPTION [#UD] // WRSS not enabled in S_CET
}
IF (OPERAND_SIZE == 64)
{
temp_LinAdr = Linear_Address(mem64)
IF (temp_LinAdr is 8-byte aligned)
SSTK_WRITE_MEM.q[temp_LinAdr] = reg64[63:0] // write reg64
// to shadow stack
ELSE
EXCEPTION [#GP(0)]
}
ELSE
{
temp_LinAdr = Linear_Address(mem32)
IF (tmp_LinAdr is 4-byte aligned)
SSTK_WRITE_MEM.d[temp_LinAdr] = reg32[31:0] // write reg32
// to shadow stack
ELSE
EXCEPTION [#GP(0)]
}
EXIT
Related Instructions
WRUSS
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
X X X Instruction is only recognized in protected mode.
X CR4.CET = 0.
Shadow stacks are not enabled at the current privilege
X
Invalid opcode, #UD level.
X If CPL == 3 and U_CET.WR_SHSTK_EN = 0.
X If CPL !=3 and S_CET.WR_SHSTK_EN = 0.
X If mod=11b (register destination was specified).
X Address not 8-byte aligned for 64-bit operand size.
X Address not 4-byte aligned for 32-bit operand size.
X A memory address exceeded a data segment limit.
General protection, In long mode, the address of the memory operand was non-
#GP X canonical.
X A null data segment was used to reference memory.
X A non-writeable data segment was used.
An execute-only code segment was used to reference
X memory.
A memory address exceeded the stack segment limit or
Stack, #SS X was non-canonical.
X A page fault resulted from the execution of the instruction.
Page fault, #PF
X The destination was not a shadow stack page.
Action
// see "Pseudocode Definition" on page 57
IF (CR4.CET == 0)
EXCEPTION [#UD]
IF (CPL != 0)
EXCEPTION [#GP(0)]
IF (OPERAND_SIZE == 64)
{
temp_LinAdr = Linear_Address(mem64)
IF (temp_LinAdr is 8-byte aligned)
SSTK_WRITE_MEM.q[tmp_LinAdr] = reg64[63:0] // write as user access
ELSE
EXCEPTION [#GP(0)]
}
ELSE
{
temp_LinAdr = Linear_Address(mem32)
IF (tmp_LinAdr is 4-byte aligned)
SSTK_WRITE_MEM.d[temp_LinAdr] = reg32[31:0] // write as user access
ELSE
EXCEPTION [#GP(0)]
}
EXIT
Related Instructions
WRSS
rFLAGS Affected
None
Exceptions
Virtual
Exception Real 8086 Protected Cause of Exception
X X X Instruction is only recognized in protected mode.
Invalid opcode, #UD X CR4.CET = 0.
X If mod=11b (register destination was specified).
X If CPL ! = 0.
X Address not 8-byte aligned for 64-bit operand size.
X Address not 4-byte aligned for 32-bit operand size.
X A memory address exceeded a data segment limit.
General protection,
#GP In long mode, the address of the memory operand was non-
X canonical.
X A null data segment was used to reference memory.
X A non-writable data segment was used.
An execute-only code segment was used to reference
X memory.
A memory address exceeded the stack segment limit or
Stack, #SS X was non-canonical.
X The linear address is not a user shadow stack page.
Page fault, #PF
X A page fault resulted from the execution of the instruction.
Opcode-Syntax Notation
In the opcode maps which follow, each table entry represents a specific form of an instruction,
identifying the instruction by its mnemonic and listing the operand or operands peculiar to that
opcode. If a register-based operand is specified by the opcode itself, the operand is represented directly
using the register mnemonic as defined in “Summary of Registers and Data Types” on page 38. If the
operand is encoded in one or more bytes following the opcode byte, the following special notation is
used to represent the operand and its encoding in more generic terms.
This special notation, used exclusively in the opcode maps, is composed of three parts:
• an initial capital letter that represents the operand source / destination (register-based, memory-
based, or immediate) and how it is encoded in the instruction (either as an immediate, or via the
ModRM.reg, ModRM.{mod,r/m}, or VEX/XOP.vvvv fields). For register-based operands, the
initial letter also specifies the register type (General-purpose, MMX, YMM/XMM, debug, or
control register).
• one, two, or three letter modifier (in lowercase) that represents the data type (for example, byte,
word, quadword, packed single-precision floating-point vector).
• x, which indicates for an SSE instruction that the instruction supports both vector sizes (128 bits
and 256 bits). The specific vector size is encoded in the VEX/XOP.L field. L=0 indicates 128 bits
and L=1 indicates 256 bits.
The following list describes the meaning of each letter that is used in the first position of the operand
notation:
A A far pointer encoded in the instruction. No ModRM byte in the instruction encoding.
B General-purpose register specified by the VEX or XOP vvvv field.
C Control register specified by the ModRM.reg field.
D Debug register specified by the ModRM.reg field.
E General purpose register or memory operand specified by the r/m field of the ModRM byte. For
memory operands, the ModRM byte may be followed by a SIB byte to specify one of the indexed
register-indirect addressing forms.
F rFLAGS register.
G General purpose register specified by the ModRM.reg field.
H YMM or XMM register specified by the VEX/XOP.vvvv field.
I Immediate value encoded in the instruction immediate field.
J The instruction encoding includes a relative offset that is added to the rIP.
L YMM or XMM register specified using the most-significant 4 bits of an 8-bit immediate value.
In legacy or compatibility mode the most significant bit is ignored.
M A memory operand specified by the {mod, r/m} field of the ModRM byte. ModRM.mod ≠ 11b.
M* A sparse array of memory operands addressed using the VSIB addressing mode. See “VSIB
Addressing” in APM Volume 4.
N 64-bit MMX register specified by the ModRM.r/m field. The ModRM.mod field must be 11b.
O The offset of an operand is encoded in the instruction. There is no ModRM byte in the instruction
encoding. Indexed register-indirect addressing using the SIB byte is not supported.
P 64-bit MMX register specified by the ModRM.reg field.
Q 64-bit MMX-register or memory operand specified by the {mod, r/m} field of the ModRM byte.
For memory operands, the ModRM byte may be followed by a SIB byte to specify one of the
indexed register-indirect addressing forms.
R General purpose register specified by the ModRM.r/m field. The ModRM.mod field must be
11b.
S Segment register specified by the ModRM.reg field.
U YMM/XMM register specified by the ModRM.r/m field. The ModRM.mod field must be 11b.
V YMM/XMM register specified by the ModRM.reg field.
W YMM/XMM register or memory operand specified by the {mod, r/m} field of the ModRM byte.
For memory operands, the ModRM byte may be followed by a SIB byte to specify one of the
indexed register-indirect addressing forms.
Primary Opcode Map. Tables A-1 and A-2 below show the primary opcode map (known in legacy
terminology as one-byte opcodes).
Table A-1 below shows those instructions for which the low nibble is in the range 0–7h. Table A-2 on
page 514 shows those instructions for which the low nibble is in the range 8–Fh. In both tables, the
rows show the full range (0–Fh) of the high nibble, and the columns show the specified range of the
low nibble.
Table A-1. Primary Opcode Map (One-byte Opcodes), Low Nibble 0–7h
Nibble1 0 1 2 3 4 5 6 7
ADD
0 PUSH ES3 POP ES3
Eb, Gb Ev, Gv Gb, Eb Gv, Ev AL, Ib rAX, Iz
ADC
1 PUSH SS3 POP SS3
Eb, Gb Ev, Gv Gb, Eb Gv, Ev AL, Ib rAX, Iz
AND
2 seg ES6 DAA3
Eb, Gb Ev, Gv Gb, Eb Gv, Ev AL, Ib rAX, Iz
XOR
3 seg SS6 AAA3
Eb, Gb Ev, Gv Gb, Eb Gv, Ev AL, Ib rAX, Iz
INC / REX prefix5
4
eAX eCX eDX eBX eSP eBP eSI eDI
PUSH
5
rAX/r8 rCX/r9 rDX/r10 rBX/r11 rSP/r12 rBP/r13 rSI/r14 rDI/r15
ARPL3
operand size address
PUSHA3 POPA3 BOUND 3 Ew, Gw seg FS seg GS
6 override size override
PUSHD3 POPD3 Gv, Ma MOVSXD4 prefix prefix
prefix prefix
Gv, Ez
Table A-2. Primary Opcode Map (One-byte Opcodes), Low Nibble 8–Fh
Nibble1 8 9 A B C D E F
escape to
PUSH
0 OR secondary
CS3
Eb, Gb Ev, Gv Gb, Eb Gv, Ev AL, Ib rAX, Iz opcode map
SBB PUSH POP
1
Eb, Gb Ev, Gv Gb, Eb Gv, Ev AL, Ib rAX, Iz DS3 DS3
SUB
2 seg CS6 DAS3
Eb, Gb Ev, Gv Gb, Eb Gv, Ev AL, Ib rAX, Iz
CMP
3 seg DS6 AAS3
Eb, Gb Ev, Gv Gb, Eb Gv, Ev AL, Ib rAX, Iz
DEC3 / REX prefix5
4
eAX eCX eDX eBX eSP eBP eSI eDI
POP
5
rAX/r8 rCX/r9 rDX/r10 rBX/r11 rSP/r12 rBP/r13 rSI/r14 rDI/r15
OUTS/ OUTS
PUSH IMUL PUSH IMUL INSB INSW/D
6 OUTSB OUTSW/D
Iz Gv, Ev, Iz Ib Gv, Ev, Ib Yb, DX Yz, DX
DX, Xb DX, Xz
Secondary Opcode Map. As described in “Encoding Syntax” on page 1, the escape code 0Fh
indicates the switch from the primary to the secondary opcode map. In legacy terminology, the
secondary opcode map is presented as a listing of “two-byte” opcodes where the first byte is 0Fh.
Tables A-3 and A-4 show the secondary opcode map.
Table A-3 below shows those instructions for which the low nibble is in the range 0–7h. Table A-4 on
page 518 shows those instructions for which the low nibble is in the range 8–Fh. In both tables, the
rows show the full range (0–Fh) of the high nibble, and the columns show the specified range of the
low nibble. Note the added column labeled “prefix.”
For the secondary opcode map shown below, the legacy prefixes 66h, F2h, and F3 are repurposed to
provide additional opcode encoding space. For those rows that utilize them, the presence of a 66h,
F2h, or F3h prefix changes the operation or the operand types specified by the corresponding opcode
value.
As discussed in “Encoding Extensions Using the ModRM Byte” on page 521, some opcode values
represent a group of instructions. This is denoted in the map entry by “Group n”, where n = [1:17,P].
Instructions within a group are encoded by the reg field of the ModRM byte. These encodings are
specified in Table A-7 on page 523. For some opcodes, both the reg and the r/m field of the ModRM
byte are used to extend the encoding. See Table A-8 on page 525.
Table A-3. Secondary Opcode Map (Two-byte Opcodes), Low Nibble 0–7h
Prefix Nibble1 0 1 2 3 4 5 6 7
LAR LSL
n/a 0 Group 62 Group 72
Gv, Ew Gv, Ew
SYSCALL CLTS SYSRET
MOVLPS MOVHPS
MOVUPS Vq, Mq MOVLPS UNPCKLPS UNPCKHPS Vo.q, Mq MOVHPS
none
MOVHLPS Mq, Vq Vps,Wps Vps,Wps MOVLHPS Mq, Vo.q
Vps, Wps Wps, Vps
Vo.q, Uo.q Vo.q, Uo.q
MOVSS MOVSLDUP MOVSHDUP
F3 1 Vss, Wss Wss, Vss Vps, Wps Vps, Wps
MOVUPD MOVLPD UNPCKLPD UNPCKHPD MOVHPD
66
Vpd, Wpd Wpd, Vpd Vo.q, Mq Mq, Vo.q Vo.q, Wo.q Vo.q, Wo.q Vo.q, Mq Mq, Vo.q
MOVSD MOVDDUP
F2
Vsd, Wsd Wsd, Vsd Vo, Wsd
MOV4
n/a 2
Rd/q, Cd/q Rd/q, Dd/q Cd/q, Rd/q Dd/q, Rd/q
F3
6
PUNPCK- PUNPCK- PUNPCK-
PACKSSWB PCMPGTB PCMPGTW PCMPGTD PACKUSWB
66 LBW LWD LDQ
Vpi, Wpi Vpk, Wpk Vpi, Wpi Vpj, Wpj Vpi, Wpi
Vo.q, Wo.q Vo.q, Wo.q Vo.q, Wo.q
F2
PSHUFW PCMPEQB PCMPEQW PCMPEQD
none Pq, Qq, Ib Ppk, Qpk Ppi, Qpi Ppj, Qpj
EMMS
PSHUFHW
F3 Vq, Wq, Ib
7 PSHUFD
Group 122 Group 132 Group 142
PCMPEQB PCMPEQW PCMPEQD
66 Vo, Wo, Ib Vpk, Wpk Vpi, Wpi Vpj, Wpj
PSHUFLW
F2
Vq, Wq, Ib
Notes:
1. Rows show the high opcode nibble, columns show the low opcode nibble (both in hexadecimal). All opcodes in this
map are immediately preceded in the instruction encoding by the escape byte 0Fh.
2. An opcode extension is specified using the reg field of the ModRM byte (ModRM bits [5:3]) which follows the opcode.
See Table A-7 on page 523 for details.
3. Invalid in long mode.
4. Operand size is based on processor mode.
Table A-3. Secondary Opcode Map (Two-byte Opcodes), Low Nibble 0–7h (continued)
Prefix Nibble1 0 1 2 3 4 5 6 7
SHLD
n/a A PUSH FS POP FS CPUID BT Ev, Gv
Ev, Gv, Ib Ev, Gv, CL
CMPXCHG MOVZX
n/a B LSS Gz, Mp BTR Ev, Gv LFS Gz, Mp LGS Gz, Mp
Eb, Gb Ev, Gv Gv, Eb Gv, Ew
PINSRW
CMPPS MOVNTI PEXTRW SHUFPS
none XADD
Vps, Wps, Ib My, Gy
Pq, Ry/Mw,
Gd, Nq, Ib Vps, Wps, Ib
Ib
CMPSS
F3 Vss, Wss, Ib Group 92
C PINSRW Mq
CMPPD PEXTRW SHUFPD
66 Eb, Gb Ev, Gv Vo, Ry/Mw,
Vpd, Wpd, Ib Gd, Uo, Ib Vpd, Wpd, Ib
Ib
CMPSD
F2
Vsd, Wsd, Ib
PSRLW PSRLD PSRLQ PADDQ PMULLW PMOVMSKB
none Pq, Qq Pq, Qq Pq, Qq Pq, Qq Pq, Qq Gd, Nq
MOVQ2DQ
F3 Vo, Nq
D
ADDSUBPD PSRLW PSRLD PSRLQ PADDQ PMULLW MOVQ PMOVMSKB
66 Vpd, Wpd Vo, Wo Vo, Wo Vo, Wo Vo, Wo Vo, Wo Wq, Vq Gd, Uo
ADDSUBPS MOVDQ2Q
F2 Vps, Wps Pq, Uq
PAVGB PSRAW PSRAD PAVGW PMULHUW PMULHW MOVNTQ
none Pq, Qq Pq, Qq Pq, Qq Pq, Qq Pq, Qq Pq, Qq Mq, Pq
CVTDQ2PD
F3 Vpd, Wpj
E
PAVGB PSRAW PSRAD PAVGW PMULHUW PMULHW CVTTPD2DQ MOVNTDQ
66 Vo, Wo Vo, Wo Vo, Wo Vo, Wo Vo, Wo Vo, Wo Vpj, Wpd Mo, Vo
CVTPD2DQ
F2 Vpj, Wpd
PSLLW PSLLD PSLLQ PMULUDQ PMADDWD PSADBW MASKMOVQ
none Pq, Qq Pq, Qq Pq, Qq Pq, Qq Pq, Qq Pq, Qq Pq, Nq
F3
F
PSLLW PSLLD PSLLQ PMULUDQ PMADDWD PSADBW MASKMOVDQU
66 Vpw, Wo.q Vpwd, Wo.q Vpqw, Wo.q Vpj, Wpj Vpi, Wpi Vpk, Wpk Vpb, Upb
LDDQU
F2
Vo, Mo
Notes:
1. Rows show the high opcode nibble, columns show the low opcode nibble (both in hexadecimal). All opcodes in this
map are immediately preceded in the instruction encoding by the escape byte 0Fh.
2. An opcode extension is specified using the reg field of the ModRM byte (ModRM bits [5:3]) which follows the opcode.
See Table A-7 on page 523 for details.
3. Invalid in long mode.
4. Operand size is based on processor mode.
Table A-4. Secondary Opcode Map (Two-byte Opcodes), Low Nibble 8–Fh
Prefix Nibble1 8 9 A B C D E F
Group P2 3DNow!
WBINVD See
n/a 0 INVD (F3) UD2 FEMMS “3DNow!™
PREFETCH
WBNOINVD Opcodes”
on page 528
NOP3
(F3) RDSSP
Group 162 NOP3 NOP3 NOP3 NOP3 NOP3 NOP3
n/a 1 reg=1,
mod=11
F2
Notes:
1. Rows show the high opcode nibble, columns show the low opcode nibble (both in hexadecimal). All opcodes in this
map are immediately preceded in the instruction encoding by the escape byte 0Fh.
2. An opcode extension is specified using the reg field of the ModRM byte (ModRM bits [5:3]) which follows the opcode.
See Table A-7 on page 523 for details.
3. This instruction takes a ModRM byte.
Table A-4. Secondary Opcode Map (Two-byte Opcodes), Low Nibble 8–Fh
Prefix Nibble1 8 9 A B C D E F
MOVD MOVQ
none
Ey, Py Qq, Pq
MOVQ MOVDQU
F3
Vq, Wq Wo, Vo
7 Group 172 EXTRQ HADDPD HSUBPD MOVD MOVDQA
66
Vo.q, Uo Vpd, Wpd Vpd, Wpd Ey, Vy Wo, Vo
INSERTQ INSERTQ HADDPS HSUBPS
F2 Vo.q, Uo.q,
Vo.q, Uo Vps, Wps Vps, Wps
Ib, Ib
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
Group 102 Group 82 BTC BSF BSR MOVSX
none
Ev, Ib Ev, Gv Gv, Ev Gv, Ev Gv, Eb Gv, Ew
POPCNT TZCNT LZCNT
F3 B
Gv, Ev Gv, Ev Gv, Ev
F2
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
F3
D
PSUBUSB PSUBUSW PMINUB PAND PADDUSB PADDUSW PMAXUB PANDN
66
Vo, Wo Vo, Wo Vo, Wo Vo, Wo Vo, Wo Vo, Wo Vo, Wo Vo, Wo
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
F3
E
PSUBSB PSUBSW PMINSW POR PADDSB PADDSW PMAXSW PXOR
66
Vo, Wo Vo, Wo Vo, Wo Vo, Wo Vo, Wo Vo, Wo Vo, Wo Vo, Wo
F2
Notes:
1. Rows show the high opcode nibble, columns show the low opcode nibble (both in hexadecimal). All opcodes in this
map are immediately preceded in the instruction encoding by the escape byte 0Fh.
2. An opcode extension is specified using the reg field of the ModRM byte (ModRM bits [5:3]) which follows the opcode.
See Table A-7 on page 523 for details.
3. This instruction takes a ModRM byte.
Table A-4. Secondary Opcode Map (Two-byte Opcodes), Low Nibble 8–Fh
Prefix Nibble1 8 9 A B C D E F
PSUBB PSUBW PSUBD PSUBQ PADDB PADDW PADDD
none
Pq, Qq Pq, Qq Pq, Qq Pq, Qq Pq, Qq Pq, Qq Pq, Qq
F3
F UD0
PSUBB PSUBW PSUBD PSUBQ PADDB PADDW PADDD
66
Vo, Wo Vo, Wo Vo, Wo Vo, Wo Vo, Wo Vo, Wo Vo, Wo
F2
Notes:
1. Rows show the high opcode nibble, columns show the low opcode nibble (both in hexadecimal). All opcodes in this
map are immediately preceded in the instruction encoding by the escape byte 0Fh.
2. An opcode extension is specified using the reg field of the ModRM byte (ModRM bits [5:3]) which follows the opcode.
See Table A-7 on page 523 for details.
3. This instruction takes a ModRM byte.
rFLAGS Condition Codes for CMOVcc, Jcc, and SETcc Instructions. Table A-5 shows
the rFLAGS condition codes specified by the low nibble in the opcode of the CMOVcc, Jcc, and
SETcc instructions.
Table A-5. rFLAGS Condition Codes for CMOVcc, Jcc, and SETcc
Low Nibble of Arithmetic
rFLAGS Value cc Mnemonic Condition(s)
Opcode (hex) Type
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
Encoding Extensions Using the ModRM Byte. The ModRM byte, which immediately
follows the opcode byte, is used in certain instruction encodings to provide additional opcode bits with
which to define the function of the instruction. ModRM bytes have three fields—mod, reg, and r/m, as
shown in Figure A-1.
Bits: 7 6 5 4 3 2 1 0
mod reg r/m ModRM
In most cases, the reg field (bits [5:3]), and in some cases, the r/m field (bits [2:0]) provide the
additional bits used to extend the encodings of the opcode byte. In the case of the x87 floating-point
instructions, the entire ModRM byte is used to extend the opcode encodings.
Table A-6 shows how the ModRM.reg field is used to extend the range of opcodes in the primary
opcode map. The opcode ranges are organized into groups of opcode extensions. The group number is
shown in the left-most column. These groups are referenced in the primary opcode map shown in
Table A-1 on page 513 and Table A-2 on page 514. 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 64-bit media and
SSE instructions.
Table A-7 on page 523 shows how the ModRM.reg field is used to extend the range of the opcodes in
the secondary opcode map.
The /0 through /7 notation for the ModRM reg field (bits [5:3]) in the tables below means that the
three-bit field contains a value from zero (000b) to 7 (111b).
Table A-6. ModRM.reg Extensions for the Primary Opcode Map1 (continued)
Group ModRM reg Field
Prefix Opcode
Number /0 /1 /2 /3 /4 /5 /6 /7
POP
Group 1a n/a 8F XOP
Ev
ROL ROR RCL RCR SHL/SAL SHR SHL/SAL5 SAR
C0
Eb, Ib Eb, Ib Eb, Ib Eb, Ib Eb, Ib Eb, Ib Eb, Ib Eb, Ib
ROL ROR RCL RCR SHL/SAL SHR SHL/SAL5 SAR
C1
Ev, Ib Ev, Ib Ev, Ib Ev, Ib Ev, Ib Ev, Ib Ev, Ib Ev, Ib
ROL ROR RCL RCR SHL/SAL SHR SHL/SAL5 SAR
D0
Eb, 1 Eb, 1 Eb, 1 Eb, 1 Eb, 1 Eb, 1 Eb, 1 Eb, 1
Group 2 n/a
ROL ROR RCL RCR SHL/SAL SHR SHL/SAL5 SAR
D1
Ev, 1 Ev, 1 Ev, 1 Ev, 1 Ev, 1 Ev, 1 Ev, 1 Ev, 1
ROL ROR RCL RCR SHL/SAL SHR SHL/SAL5 SAR
D2
Eb, CL Eb, CL Eb, CL Eb, CL Eb, CL Eb, CL Eb, CL Eb, CL
ROL ROR RCL RCR SHL/SAL SHR SHL/SAL5 SAR
D3
Ev, CL Ev, CL Ev, CL Ev, CL Ev, CL Ev, CL Ev, CL Ev, CL
TEST NOT NEG MUL IMUL DIV IDIV
F6
Eb,Ib Eb Eb Eb Eb Eb Eb
Group 3 n/a
TEST NOT NEG MUL IMUL DIV IDIV
F7
Ev,Iz Ev Ev Ev Ev Ev Ev
INC DEC
Group 4 n/a FE
Eb Eb
INC DEC CALL CALL JMP JMP PUSH
Group 5 n/a FF
Ev Ev Ev Mp Ev Mp Ev
MOV
n/a C6
Eb, Ib
Group 11
MOV
n/a C7
Ev, Iz
Notes:
1. See Table A-7 on page 523 for ModRM extensions for the secondary (two-byte) ocode map.
2. Invalid in 64-bit mode.
3. This instruction takes a ModRM byte.
4. Reserved prefetch encodings are aliased to the /0 encoding (PREFETCH Exclusive) for future compatibility.
5. Redundant encoding generally unsupported by tools.
SLDT
Group 6 n/a 0F 00 STR Mw/Rv LLDT Ew LTR Ew VERR Ew VERW Ew
Mw/Rv
SIDT INVLPG
LGDT Ms LIDT Ms
SGDT Ms SMSW Mw RSTORSSP1 Mb
Group 7 n/a 0F 01 LMSW Ew
Ms MONITOR1 XGETBV1 / Rv (mod!=11) SWAPGS1
SVM1
MWAIT XSETBV RDTSCP
CMPX-
none
CHG8B Mq RDRAND RDSEED
CMPX- Rv Rv
66
Group 9 0F C7 CHG16B Mo
F2
RDPID
F3
Rd/q
Group
n/a 0F B9 UD1
10
F2, F3
Notes:
1. Opcode is extended further using the r/m field of the ModRM byte in conjunction with the reg field. See Table A-8
on page 525 for ModRM.r/m extensions of this opcode.
2. Invalid in 64-bit mode.
3. This instruction takes a ModRM byte.
4. Reserved prefetch encodings are aliased to the /0 encoding (PREFETCH Exclusive) for future compatibility.
5. ModRM.mod = 11b.
6. ModRM.mod ≠ 11b.
7. ModRM.mod ≠ 11b, ModRM.mod = 11b is an invalid encoding.
66 CLWB Mb6
Secondary Opcode Map, ModRM Extensions for Opcode 01h . Table A-8 below shows
the ModRM byte encodings for the 01h opcode. In the table the full ModRM byte is listed below the
instruction in hexadecimal, with ellipses representing the [0Fh, 01h] opcode bytes.
Table A-8. Opcode 01h ModRM Extensions
ModRM.r/m Field
reg Field Prefix
0 1 2 3 4 5 6 7
MONITOR MWAIT CLAC STAC
/1 none
(...C8) (...C9) (...CA) (...CB)
XGETBV XSETBV
/2 none
(...D0) (...D1)
VMRUN VMMCALL VMLOAD VMSAVE STGI CLGI SKINIT INVLPGA
none
(...D8) (...D9) (...DA) (...DB) (...DC) (...DD) (...DE) (...DF)
/3
F3 VMGEXIT
F2 (...D9)
none RDPKRU WRPKRU
/5 SAVE-
F3 SETSSBSY
PREVSSP
MON...ITORX MWAITX RDPRU
none
(FA) (...FB) (...FD)
SWAPGS RDTSCP MCOMMIT RMPQUERY RMPADJUST PSMASH
/7 F3
(...F8) (...F9) (F3...FA) (F3...FD) (F3...FE) (F3...FF)
RMPREAD RMPUPDATE PVALIDATE
F2
(F2...FD) (F2...FE) (F2...FF)
ModRM.mod = 11b
0F_38h and 0F_3Ah Opcode Maps. The 0F_38h and 0F_3Ah opcode maps are used primarily
to encode the legacy SSE instructions. In legacy terminology, these maps are presented as three-byte
opcodes where the first two bytes are {0Fh, 38h} and {0Fh, 3Ah} respectively.
In these maps the legacy prefixes F2h and F3h are repurposed to provide additional opcode encoding
space. In rows [0:E] the legacy prefix 66h is also used to modify the opcode. However, in row F, 66h is
used as an operand-size override. See the CRC32 instruction as an example.
The 0F_38h opcode map is presented below in Tables A-9 and A-10. The 0F_3Ah opcode map is
presented in Tables A-11 and A-12.
Prefix Opcode x0 x1 x2 x3 x4 x5 x6 x7
PSHUFB PHADDW PHADDD PHADDSW PMADDUBSW PHSUBW PHSUBD PHSUBSW
none
Ppb, Qpb Ppi, Qpi Ppj, Qpj Ppi, Qpi Ppk, Qpk Ppi, Qpi Ppj, Qpj Ppi, Qpi
0x
PSHUFB PHADDW PHADDD PHADDSW PMADDUBSW PHSUBW PHSUBD PHSUBSW
66
PVb, Wpb Vpi, Wpi Vpj, Vpj Vpi, Wpi Vpk, Wpk Vpi, Wpi Vpj, Wpj Vpi, Wpi
none
1x PBLENDVB BLENDVPS PBLENDVB PTEST
66
Vpb, Wpb Vps, Wps Vpb, Wpb Vo, Wo
none
2x PMOVSXBW PMOVSXBD PMOVSXBQ PMOVSXWD PMOVSXWQ PMOVSXDQ
66
Vpi, Wpk Vpj, Wpk Vpq, Wpk Vpj, Wpi Vpq, Wpi Vpq, Wpj
none
3x PMOVZXBW PMOVZXBD PMOVZXBQ PMOVZXWD PMOVZXWQ PMOVZXDQ PCMPGTQ
66
Vpi, Wpk Vpj, Wpk Vpq, Wpk Vpj, Wpi Vpq, Wpi Vpq, Wpj Vpq, Wpq
none
4x PMULLD PHMINPOSUW
66
Vpj, Wpj Vpi, Wpi
... 5x-Ex ...
MOVBE MOVBE WRSS
none
Gv, Mv Mv, Gv My, Gy
CRC32 CRC32
F2
Gy, Eb Gy, Ev
Fx MOVBE MOVBE WRUSS
66
Gv, Mv Mv, Gv My, Gy
66 CRC32 CRC32
and Gy, Eb Gy, Ev
F2
0x
PSIGNB PSIGNW PSIGND PMULHRSW
66 Vpk, Wpk Vpi, Wpi Vpj, Wpj Vpi, Wpi
none
2x
PMULDQ PCMPEQQ MOVNTDQA PACKUSDW
66 Vpq, Wpj Vpq, Wpq Vo, Mo Vpi, Wpj
none
3x
PMINSB PMINSD PMINUW PMINUD PMAXSB PMAXSD PMAXUW PMAXUD
66 Vpk, pk Vpj, Wpj Vpi, Wpi Vpj, Wpj Vpk, Wpk Vpj, Wpj Vpi, Wpi Vpj, Wpj
4xh-Cxh ...
AESIMC AESENC AESENCLAST AESDEC AESDECLAST
66 Dx Vo, Wo Vo, Wo Vo, Wo Vo, Wo Vo, Wo
n/a 0x
none
none
none
4x
DPPS DPPD MPSADBW PCLMULQDQ
66 Vps, Wps, Ib Vpd, Wpd, Ib Vpk, Wpk, Ib Vpq, Wpq, Ib
n/a 5x
none
6x
PCMPESTRM PCMPESTRI PCMPISTRM PCMPISTRI
66 Vo, Wo, Ib Vo, Wo, Ib Vo, Wo, Ib Vo, Wo, Ib
n/a Fx
none
4x
DPPS DPPD MPSADBW PCLMULQDQ
66 Vps, Wps, Ib Vpd, Wpd, Ib Vpk, Wpk, Ib Vpq, Wpq, Ib
Table A-13 and Table A-14 on page 530 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-13 shows the immediate bytes whose low nibble
is in the range 0–7h. Table A-14 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-13. Immediate Byte for 3DNow!™ Opcodes, Low Nibble 0–7h
Nibble1 0 1 2 3 4 5 6 7
8
PFCMPGE PFMIN PFRCP PFRSQRT
9
Pq, Qq Pq, Qq Pq, Qq Pq, Qq
PFCMPGT PFMAX PFRCPIT1 PFRSQIT1
A
Pq, Qq Pq, Qq Pq, Qq Pq, Qq
PFCMPEQ PFMUL PFRCPIT2 PMULHRW
B
Pq, Qq Pq, Qq Pq, Qq Pq, Qq
F
Notes:
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-14. Immediate Byte for 3DNow!™ Opcodes, Low Nibble 8–Fh
Nibble1 8 9 A B C D E F
PI2FW PI2FD
0
Pq, Qq Pq, Qq
PF2IW PF2ID
1
Pq, Qq Pq, Qq
7
PFNACC PFPNACC
8
Pq, Qq Pq, Qq
PFSUB PFADD
9
Pq, Qq Pq, Qq
PFSUBR PFACC
A
Pq, Qq Pq, Qq
PSWAPD PAVGUSB
B
Pq, Qq Pq, Qq
F
Notes:
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
FADD FMUL FCOM FCOMP FSUB FSUBR FDIV FDIVR
!11
mem32- mem32-
mem32real mem32real mem32real mem32real mem32real mem32real
real real
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)
VEX Opcode Maps. Tables A-17 to A-23 below present the VEX opcode maps and Table A-24 on
page 548 presents the VEX opcode groups.
VSQRTSD3
Vo, Ho, Wsd
6x
VPUNPCKLBW2 VPUNPCKLWD2 VPUNPCKLDQ2 VPACKSSWB2 VPCMPGTB2 VPCMPGTW2 VPCMPGTD2 VPACKUSWB2
Vpbx, Hpbx, Wpbx Vpwx, Hpwx, Wpwx Vpdwx, Hpdwx, Vpkx, Hpix, Wpix Vpbx, Hpkx, Wpkx Vpwx, Hpix, Wpix Vpdwx, Hpjx, Wpjx Vpkx, Hpix, Wpix
Wpdwx
VZEROUPPER (L=0)
VZEROALL (L=1)
VPSHUFD2 VEX group #12 VEX group #13 VEX group #14 VPCMPEQB2 VPCMPEQW2 VPCMPEQD2
Vpdwx, Wpdwx, Ib Vpbx, Hpkx, Wpkx Vpwx, Hpix, Wpix Vpdwx, Hpjx, Wpjx
7x
VPSHUFHW2
Vpwx, Wpwx, Ib
VPSHUFLW2
Vpwx, Wpwx, Ib
8x–Bx ...
VCMPccPS1 VSHUFPS2
Vpdw, Hps, Wps, Vpsx, Hpsx, Wpsx,
Ib Ib
VCMPccPD1 VPINSRW VPEXTRW VSHUFPD2
Vpqw, Hpd, Wpd, Vpw, Hpw, Mw, Ib Gw, Upw, Ib Vpdx, Hpdx, Wpdx,
Ib Vpw, Hpw, Rd, Ib Ib
Cx
VCMPccSS1
Vd, Hss, Wss, Ib
VCMPccSD1
Vq, Hsd, Wsd, Ib
Note 1: The condition codes are: EQ, LT, LE, UNORD, NEQ, NLT, NLE, and ORD; encoded as [00:07h] using Ib.
VEX encoding adds: EQ_UQ, NGE, NGT, FALSE, NEQ_OQ, GE, GT, TRUE [08:0Fh];
EQ_OS, LT_OQ, LE_OQ, UNORD_S, NEQ_US, NLT_UQ, NLE_UQ, ORD_S [10h:17h]; and
EQ_US, NGE_UQ, NGT_UQ, FALSE_OS, NEQ_OS, GE_OQ, GT_OQ, TRUE_US [18:1Fh].
Note 2: Supports both 128 bit and 256 bit vector sizes. Vector size is specified using the VEX.L bit. When L = 0, size is 128 bits; when L = 1, size is 256 bits.
Note 3: Operands are scalars. VEX.L bit is ignored.
00
VADDSUBPS2
11 Vpsx, Hpsx, Wpsx
00
VCVTPD2DQ2
11 Vpjx, Wpdx
00
10
VLDDQU
11 Vo, Mo (L=0)
Vdo, Mdo (L=1)
Note 1: The condition codes are: EQ, LT, LE, UNORD, NEQ, NLT, NLE, and ORD; encoded as [00:07h] using Ib.
VEX encoding adds: EQ_UQ, NGE, NGT, FALSE, NEQ_OQ, GE, GT, TRUE [08:0Fh];
EQ_OS, LT_OQ, LE_OQ, UNORD_S, NEQ_US, NLT_UQ, NLE_UQ, ORD_S [10h:17h]; and
EQ_US, NGE_UQ, NGT_UQ, FALSE_OS, NEQ_OS, GE_OQ, GT_OQ, TRUE_US [18:1Fh].
Note 2: Supports both 128 bit and 256 bit vector sizes. Vector size is specified using the VEX.L bit. When L = 0, size is 128 bits; when L = 1, size is 256 bits.
Note 3: Operands are scalars. VEX.L bit is ignored.
00
11
00
00
00
Note 1: Supports both 128 bit and 256 bit vector sizes. Vector size is specified using the VEX.L bit. When L = 0, size is 128 bits; when L = 1, size is 256 bits.
Note 2: Operands are scalars. VEX.L bit is ignored.
VEX.pp Opcode x0 x1 x2 x3 x4 x5 x6 x7
1 1 1 1 1 1 1
VPSHUFB VPHADDW VPHADDD VPHADDSW VPMADDUBSW VPHSUBW VPHSUBD VPHSUBSW1
01 0x Vpbx, Hpbx, Wpbx Vpix, Hpix, Wpix Vpjx, Hpjx, Wpjx Vpix, Hpix, Wpix Vpix, Hpkx, Wpkx Vpix, Hpix, Wpix Vpjx, Hpjx, Wpjx Vpix, Hpix, Wpix
PEXT SHLX
01 Gy, By, Ey Gy, Ey, By
Note 1: Supports both 128 bit and 256 bit vector sizes. Vector size is specified using the VEX.L bit. When L = 0, size is 128 bits; when L = 1, size is 256 bits.
Note 2: For all VFMADDSUBnnnPS instructions, the data type is packed single-precision floating point.
For all VFMADDSUBnnnPD instructions, the data type is packed double-precision floating point.
Note 3: For all VFMSUBADDnnnPS instructions, the data type is packed single-precision floating point.
For all VFMSUBADDnnnPD instructions, the data type is packed double-precision floating point.
Note 4: Operands are treated a bit vectors.
Note 5: Uses VSIB addressing mode.
"'í Ë«áíXˬáí̬áí Ë¡íWÌíË í Ë ¨áíWÌ ¨áíË ¨áí Ë¡áíWˤáíˤáí ËÖáíXËÖáíÌßáíÌáíXËáíËÏßáí ËÖáíËÖáí ËáíÌáí
FwpEJIEx{66 FwpEJIExzxJí FwpEJIEx{U'.9í sE:6: tEFx tEF6J
"*í ËÖíÖÖí ËíÖí ÅífÅí ̬áí̬áí ˤáí̤áí ̨áíË©áí
äNa@®í \Nb@¯í
sfaJv sIfsNvv fpmzJvE
tEI^xJ fEx^fpt6 fEx^fpsJ fEx^fps6 fEx^fpsJ
"'í ËÏá íXË ©áíį́áí ËÏá íXÌÏáíËÏáí âígâí Ë¡ííWË ªáí˪áí ÌÖáíXáífÌÖáí ÌáíXáífÌáí fÌÖáíXáíÌÖáí fÌáíWáíËáí
tfYm6: tfYm6J tfZm sfYnJ sfE6: sfE6J tfE tfEJ
"'í Ë«áíXËáí̬áí Ì ªáíX̨áíÌ ªáí Ì¡áíWÌ¡áíˤáí Ë©áíWË ªáíÌ ªáí ˬáíWËáíËáí ÌáªíX˨áíÌ ªáí ˤáíWË áíˤáí ˨áíWË©áíË ªáí
sfEx^fp sfEx^fp
"'í K áíXáífáíí K háíXáíáíAqí
# áí Xáí háí]B¯°í $ lí XáíáíB¯±í
3ÜPfEKK*20 PiKK²20èí QfxG*20 PfxG¯20èí PniKK²20èí QniKK¹20èí PnfxG²20èí PnjG¯20èí
tx áWá íáíåí xx ÅWÅ íí sx á XááíDí xx Å XÅ íBqí sx á XáíáíDí ÜÅXÅíí sx áWááíBqí xx Å XÅ íí
"*í
t%á Xá íáíB²íxK Å XÅ ÐíB²ítK á Xá áíB²íx% Å XÅ ÑíB²í s%áXá áíB²íxK ÅXÅíÑíB²í tK á Xá áíB²í xK Å XÅ ÏíB²í
RfEKK0*2 PiKK0*2 RfxG0)2 PfxG0)2 PníiKK0*2 PniKK0)2 Pnfx;0-2 PnjG0)2
"'í tx áWá áíí xx ÅWÅíí sx á XááíBqí x6 Å XÅíBqí sx á Xá íáíåí x6 ÅXÅíí sx áWááíDí x6 Å XÅ íí
tK á Wá íáíåB²íxK Å XÅ ÐíB²í tK á Xá áíB²í xK Å XÅ ÑíB²æísK á Xá íáíåB²íxK Å XÅ íÑíåB²í tK á Xá áíB²í xK Å XÅ ÏíB¯í
RfEKK02)éí PiKK02*èí Qfx;02)éí PfxG02)éí PniKK02*éí PniKK02*êí PnfxG02)éí PnjG02*éí
tx áWá íáíæí ÜÅ WÅ àíí sx á XááíBqçí x6 Å XÅíBqí sx á Xááíí 66 ÅXÅíí s6 áWá áíí 66 ÅXÅ íí
"'í
tK á Wá áíåB²íxK Å XÅ ÐíB²í tK á Xá áíB²í xK Å XÅ ÑíB²æí sK áXá íáíåB²íxK ÅXÅíÑíåB²í tK á Xá áíB²í xK Å XÅ ÏíB¯í
ENxYfIí ENxNmIí ENxNnI`Exzí ENxJNIí ENxJNIcExzí
"'í Å Åí ÅíXÅíÅí ÅíW ÅíÅí ÅíX ÅíÅí ÅíW Å íÅí
oųí+>í yÚÌÌÆÒØ×íƳí+1<í¡ØíÂí178í¡´íݳÅÒíפã×í´ÅÕíסãí¡×í×̤ íÚפÂí½íeíëíÁídíCí&íסãí¡×í+1<í¡Ø×?íßÁídíCí,íפãí¤×í178í¤º×í
oÅØí1=í rÌÓÂ×íÒí×»Ó×íOdí¡Øí¤×í¤ÁÅÔí
oųí4>í SÅÒíµ»íÞìLÁÂÁuyí¤Â׳ÓÚ³¥Ã×íØí³íÀí¤×íË«íפõÌҢסÆÁíµÅÙ¡ÃíΡÃØ í
TÅÒíµ»íÞìLÁÂÁuMí¡Â×ÙÒÛØ¡ÅÂ×íÙíØí¾Ìí£×í̬íÆÚ¶ÌҡפÅÂíÅؤÂíÎ ÂØí
oųí5>í SÅÒíµ»íÞkHÁÁÂuyí¡Á×ÙÒÚÙ ÆÂ×í³íØí¿Ìí¡×í̬íסµÌÒ¡×¥Âí¼ÆØ ÂíͤÂØí
SÅÒíµ»íÞkHÁÁÂuLí¤Â×ØÓÚ·§Ã×íÙí³í¤×íÈ«íʸÇӤצÁíÆؤÄíɤÁØ!í
VEX.pp Nibble x0 x1 x2 x3 x4 x5 x6 x7
00
00
00
VPINSRD
2x Vpdw, Hpdw, Ed, Ib
VPINSRB VINSERTPS (W=0)
01
Vpb, Hpb, Wb, Ib Vps, Hps, Ups/Md, VPINSRQ
Vpdw, Hpqw, Eq, Ib
(W=1)
... 3x ...
00
4x
VDPPS1 VDPPD VMPSADBW1 VPCLMULQDQ VPERM2I128
01 Vpsx, Hpsx, Wpsx, Vpd, Hpd, Wpd, Ib Vpix, Hpkx, Wpkx, Vo, Hpq, Wpq, Ib Vo, Ho, Wo, ib
Ib Ib
... 5x ...
00
6x
VPCMPESTRM VPCMPESTRI VPCMPISTRM VPCMPISTRI
01 Vo, Wo, Ib Vo, Wo, Ib Vo, Wo, Ib Vo, Wo, Ib
. . . 7x-Ex ...
10
Fx
RORX
11 Gy, Ey, ib
Note 1: Supports both 128 bit and 256 bit vector sizes. Vector size is specified using the VEX.L bit. When L=0, size is 128 bits; when L=1, size is 256 bits.
VEX.pp Opcode x8 x9 xA xB xC xD xE xF
1 1 1 1 1
VROUNDPS VROUNDPD VROUNDSS VROUNDSD VBLENDPS VBLENDPD VPBLENDW VPALIGNR1
01 0x Vpsx, Wpsx, Ib Vpdx, Wpdx, Ib Vss, Hss, Wss, Ib Vsd, Hsd, Wsd, Ib Vpsx, Hpsx, Wpsx, Vpdx, Hpdx, Wpdx, Vpwx, Hpwx, Wpwx,Vpbx, Hpbx, Wpbx,
Ib Ib Ib Ib
VINSERTF128 VEXTRACTF128 VCVTPS2PH1
01 1x Vdo, Hdo, Wo, Ib Wo, Vdo, Ib Wph, Vps, Ib
... 2x ...
VINSERTI128 VEXTRACTI128
01 3x Vdo, Hdo, Wo, Ib Wo, Vdo, Ib
1
15 AE 00 VLDMXCSR Md VSTMXCSR Md
Note: 1. Supports both 128 bit and 256 bit vector sizes. Vector size is specified using the VEX.L bit. When L = 0, size is 128 bits; when L = 1, size is 256 bits.
XOP Opcode Maps. Tables A-25 to A-30 below present the XOP opcode maps and Table A-31 on
page 550 presents the VEX opcode groups.
VPMACSDD VPMACSDQH
00 9x Vo,Ho,Wo,Lo Vo,Ho,Wo,Lo
00 Dx
1 1 1 1
VPCOMccUB VPCOMccUW VPCOMccUD VPCOMccUQ
00 Ex Vo,Ho,Wo,Ib Vo,Ho,Wo,Ib Vo,Ho,Wo,Ib Vo,Ho,Wo,Ib
00 Fx
Note 1: The condition codes are LT, LE, GT, GE, EQ, NEQ, FALSE, and TRUE. They are encoded via Ib, using 00...07h.
00 1x XOP group #3
... Fx ...
VPHADDUDQ
00 Dx Vo,Wo
n/a 0x-Fx
Opcodes Reserved
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-32 shows the notation and encoding
conventions for register references using the ModRM reg field. This table is comparable to Table A-34
on page 554 but applies only when the address-size is 16-bit. Table A-33 on page 552 shows the
notation and encoding conventions for 16-bit memory references using the ModRM byte. This table is
comparable to Table A-35 on page 555.
[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
Notes:
1. See Table A-32 for complete specification of ModRM “reg” field.
Register and Memory References for 32-Bit and 64-Bit Addressing. Table A-34 on
page 554 shows the encoding for register references using the ModRM reg field. The first ten rows of
Table A-34 show references when the REX.R bit is cleared to 0, and the last ten rows show references
when the REX.R bit is set to 1. In this table, entries under the Mnemonic Notation heading correspond
to register notation described in “Mnemonic Syntax” on page 53, and the /r notation under the ModRM
reg Field heading corresponds to that described in “Opcode Syntax” on page 56.
Table A-34. ModRM reg Field Encoding, 32-Bit and 64-Bit Addressing
Mnemonic ModRM reg Field
REX.R Bit
Notation /0 /1 /2 /3 /4 /5 /6 /7
reg8 AL CL DL BL AH/SPL CH/BPL DH/SIL BH/DIL
reg16 AX CX DX BX SP BP SI DI
Table A-35 on page 555 shows the encoding for 32-bit and 64-bit memory references using the
ModRM byte. This table describes 32-bit and 64-bit addressing, with the REX.B bit set or cleared. The
Effective Address is shown in the two left-most columns, followed by the binary encoding of the
ModRM-byte mod field, followed by the eight possible hex values of the complete ModRM byte (one
value for each binary encoding of the ModRM-byte reg field), followed by the binary encoding of the
ModRM r/m field.
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-35. ModRM Byte Encoding, 32-Bit and 64-Bit Addressing (continued)
ModRM ModRM reg Field1 ModRM
Effective Address 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
YMM0 YMM8
CL/rCX/MMX1/XMM1/ r9/MMX1/XMM9/
C1 C9 D1 D9 E1 E9 F1 F9 001
YMM1 YMM9
DL/rDX/MMX2/XMM2/ r10/MMX2/XMM10/
C2 CA D2 DA E2 EA F2 FA 010
YMM2 YMM10
BL/rBX/MMX3/XMM3/ r11/MMX3/XMM11/
C3 CB D3 DB E3 EB F3 FB 011
YMM3 YMM11
11
AH/SPL/rSP/MMX4/ r12/MMX4/XMM12/
C4 CC D4 DC E4 EC F4 FC 100
XMM4/YMM4 YMM12
CH/BPL/rBP/MMX5/ r13/MMX5/XMM13/
C5 CD D5 DD E5 ED F5 FD 101
XMM5/YMM5 YMM13
DH/SIL/rSI/MMX6/ r14/MMX6/XMM14/
C6 CE D6 DE E6 EE F6 FE 110
XMM6/YMM6 YMM14
BH/DIL/rDI/MMX7/ r15/MMX7/XMM15/
C7 CF D7 DF E7 EF F7 FF 111
XMM7/YMM7 YMM15
Notes:
1. See Table A-34 for complete specification of ModRM “reg” field.
2. If SIB.base = 5, the SIB byte is followed by four-byte disp32 field and addressing mode is absolute.
3. 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 32 bits.
Bits: 7 6 5 4 3 2 1 0
scale index base SIB
Table A-36 shows the encodings for the SIB byte’s base field, which specifies the base register for
addressing. Table A-37 on page 558 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.
CALL—Procedure Call Near See “Near Branches in 64-Bit Mode” in APM Volume 1.
RIP = RIP + 32-
Promoted to bit displacement
E8
64 bits.
64 bits Can’t encode.6 sign-extended to
64 bits.
RIP = 64-bit
offset from
Promoted to register or
FF /2
64 bits.
64 bits Can’t encode.6
memory.
Notes:
1. See “General Rules for 64-Bit Mode” on page 561, 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 561 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.
Notes:
1. See “General Rules for 64-Bit Mode” on page 561, 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 561 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.
APM 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
Notes:
1. See “General Rules for 64-Bit Mode” on page 561, 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 561 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 7 for details.
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.
x87 Instructions
x87 Instructions
SSE3
Instructions
AMD Extensions
MMX™ to MMX™ SSE1
Instructions Instructions
Instructions
Table D-1. Feature Flags for Instruction / Instruction Subset Support (continued)
Feature Flag Instruction or Subset CPUID Function1 Feature Flag Bit Position2
16-bit floating-point
F16C standard ECX[29]
conversion
FMA FMA standard ECX[12]
FMA4 FMA4 extended ECX[16]
FPU x87 both EDX[0]
FS and GS base read
FSGSBASE 0000_0007_0 EBX[0]
and write
FXSR FXSAVE / FXRSTOR both EDX[24]
INVLPGB INVLPGB, TLBSYNC 8000_0008 EBX[3]
INVPCID INVPCID 0000_0007_0 EBX[10]
LahfSahf LAHF / SAHF extended ECX[0]
LM Long Mode extended EDX[29]
MCOMMIT MCOMMIT 8000_0008 EBX[8]
MMX MMX both EDX[23]
MmxExt MMX Extensions extended EDX[22]
MONITOR MONITOR / MWAIT standard ECX[3]
MONITORX MONITORX / MWAITX extended ECX[29]
MOVBE MOVBE standard ECX[22]
MSR RDMSR / WRMSR both EDX[5]
OSPKE RDPKRU, WRPKRU 0000_0007_0 ECX[4]
PCLMULQDQ PCLMULQDQ standard ECX[1]
POPCNT POPCNT standard ECX[23]
RDPID RDPID 0000_0007_0 ECX[22]
RDPRU RDPRU 8000_0008 EBX[4]
RDRAND RDRAND standard ECX[30]
RDTSCP RDTSCP extended EDX[27]
RDSEED RDSEED 0000_0007_0 EBX[18]
SevEs VMGEXIT 8000_001F EAX[3]
SHA SHA 0000_0007_0 EBX[29]
SKINIT SKINIT / STGI extended ECX[12]
SMAP CLAC, STAC 0000_0007_0 EBX[20]
PSMASH, PVALIDATE,
SNP RMPADJUST, 8000_001F EAX[4]
RMPUPDATE
SNP RMPQUERY 8000_001F EAX[6]
SNP RMPREAD 8000_001F EAX[21]
Notes:
1. standard = Fn0000_0001h; extended = Fn 8000_0001h; both means that both standard and extended CPUID
functions return the same feature flag in the same bit position of the return value. For functions of the form xxxx-
_xxxx_x, the trailing digit is the value required in ECX.
2. Register and bit position of the return value that corresponds to the feature flag.
3. FCMOVcc instruction is supported if x87 and CMOVcc instructions are both supported.
4. XSAVE (and related) instructions require separate enablement.
Table D-1. Feature Flags for Instruction / Instruction Subset Support (continued)
Feature Flag Instruction or Subset CPUID Function1 Feature Flag Bit Position2
SSE SSE1 standard EDX[25]
SSE2 SSE2 standard EDX[26]
SSE3 SSE3 standard ECX[0]
SSSE3 SSSE3 standard ECX[9]
SSE4A SSE4A extended ECX[6]
SSE41 SSE4.1 standard ECX[19]
SSE42 SSE4.2 standard ECX[20]
SVM Secure Virtual Machine extended ECX[2]
SysCallSysRet SYSCALL / SYSRET extended EDX[11]
SysEnterSysExit SYSENTER / SYSEXIT standard EDX[11]
TBM Trailing bit manipulation extended ECX[21]
TSC RDTSC both EDX[4]
VAES VAES 256-bit instructions 0000_0007_0 ECX[9]
VPCMULQDQ 256-bit
VPCMULQDQ 0000_0007_0 ECX[10]
instructions
WBNOINVD WBNOINVD 8000_0008 EBX[9]
x87 && CMOV FCMOVcc3 both EDX[0] && EDX[15]
XGETBV w/ ECX=1 XGETBV w/ ECX=1 0000_000D_1 EAX[2]
XOP XOP extended ECX[11]
XSAVE XSAVE / XRSTOR4 standard ECX[26]
XSAVEC XSAVEC 0000_000D_1 EAX[1]
XSAVEOPT XSAVEOPT 0000_000D_1 EAX[0]
XSAVES/XRSTORS XSAVES / XRSTORS 0000_000D_1 EAX[3]
Notes:
1. standard = Fn0000_0001h; extended = Fn 8000_0001h; both means that both standard and extended CPUID
functions return the same feature flag in the same bit position of the return value. For functions of the form xxxx-
_xxxx_x, the trailing digit is the value required in ECX.
2. Register and bit position of the return value that corresponds to the feature flag.
3. FCMOVcc instruction is supported if x87 and CMOVcc instructions are both supported.
4. XSAVE (and related) instructions require separate enablement.
The value returned in EAX provides the largest standard function number supported by this processor.
The values returned in EBX, EDX, and ECX together provide a 12-character string identifying the
vendor of this processor. Each register supplies 4 characters. The leftmost character of each substring
is stored in the least significant bit position in the register. The string is the concatenation of the
contents of EBX, EDX, and ECX in left to right order. No null terminator is included in the string.
CPUID Fn8000_0000_E[D,C,B]X return the same values as this function.
The value returned in EAX provides the family, model, and stepping identifiers. Three values are used
by software to identify a processor: Family, Model, and Stepping.
The processor Family identifies one or more processors as belonging to a group that possesses some
common definition for software or hardware purposes. The Model specifies one instance of a
processor family. The Stepping identifies a particular version of a specific model. Therefore, Family,
Model and Stepping, when taken together, form a unique identification or signature for a processor.
The Family is an 8-bit value and is defined as: Family[7:0] = ({0000b,BaseFamily[3:0]} +
ExtFamily[7:0]). For example, if BaseFamily[3:0] = Fh and ExtFamily[7:0] = 01h, then Family[7:0] =
10h. If BaseFamily[3:0] is less than Fh, then ExtFamily is reserved and Family is equal to
BaseFamily[3:0].
The value returned in EBX provides miscellaneous information regarding the processor brand, the
number of logical threads per processor socket, the CLFLUSH instruction, and APIC.
The value returned in ECX contains the following miscellaneous feature identifiers:
The value returned in EDX contains the following miscellaneous feature identifiers:
The value returned in ECX indicates support of the processor effective frequency interface. For more
information on this feature, see “Determining Processor Effective Frequency” in APM Volume 2.
Subfunction 0 of Fn0000_000D
Subfunction 0 provides information about features within the extended processor state management
architecture that are supported by the processor.
The value returned in EAX provides a bit mask specifying which of the features defined by the
extended processor state architecture are supported by the processor.
The value returned in EBX gives the save area size requirement in bytes based on the features
currently enabled in the XFEATURE_ENABLED_MASK (XCR0).
The value returned in ECX gives the save area size requirement in bytes for all extended state
management features supported by the processor (whether enabled or not).
The value returned in EDX provides a bit mask specifying which of the features defined by the
extended processor state architecture are supported by the processor.
See “XSAVE/XRSTOR Instructions” in APM Volume 2 and reference pages for the individual
instructions in APM Volume 4.
Subfunction 1 of Fn0000_000D
Subfunction 1 provides additional information about features within the extended processor state
management architecture that are supported by the processor.
The value returned on EBX represents the fixed size of the save area (240h) plus the state size of each
enabled extended feature:
EBX = 0240h
+ ((XCR0[AVX] == 1) ? 0000_0100h : 0)
+ ((XCR0[MPK] == 1) ? 0000_0008h : 0)
+ ((XSS[CET_U] == 1) ? 0000_0010h : 0)
+ ((XSS[CET_S] == 1) ? 0000_0018h : 0)
CPUID Fn0000_000D_ECX_x1 Processor Extended State Enumeration (ECX=1)
The value returned on ECX returns a 1 for each bit that is settable in the XSS MSR. The following bits
are defined:
Bits Field Name Description
31:13 — Reserved
12 CET_S CET supervisor.
11 CET_U CET user state.
10:0 — Reserved
Subfunction 2 of Fn0000_000D
Subfunction 2 provides information about the size and offset of the 256-bit SSE vector floating point
processor unit state save area.
The value returned in EAX provides information about the size of the 256-bit SSE vector floating
point processor unit state save area.
The value returned in EBX provides information about the offset of the 256-bit SSE vector floating
point processor unit state save area from the base of the extended state (XSAVE/XRSTOR) save area.
The values returned in ECX and EDX for subfunction 2 are undefined and are reserved.
Subfunction 11 of Fn0000_000D
Subfunction 11 provides information about the CET user state save area.
The value returned in EAX, EBX, ECX and EDX provides information about the CET user state save
area.
Register Bits Field Name Description
EAX 31:0 CetUserSize CET user state save size in bytes.
EBX 31:0 CetUserOffset CET user state offset from the base of the extended state save area.
ECX 0 U/S Set to 1, indicating a supervisor state component.
ECX 31:0 — Cleared to 0.
EDX 31:0 — Unused, cleared to 0.
Subfunction 12 of Fn0000_000D
Subfunction 12 provides information about the CET supervisor state save area.
The value returned in EAX, EBX, ECX and EDX provides information about the CET supervisor state
save area.
The value returned in EAX provides the size of the Lightweight Profiling (LWP) unit state save area.
The value returned in EBX provides the offset of the Lightweight Profiling (LWP) unit state save area
from the base of the extended state (XSAVE/XRSTOR) save area.
The values returned in ECX and EDX for subfunction 3Eh are undefined and are reserved.
These function numbers are reserved for use by the virtual machine monitor.
The value returned in EAX provides the largest extended function number supported by the processor.
The values returned in EBX, ECX, and EDX together provide a 12-character string identifying the
vendor of this processor. The output string is the same as the one returned by Fn0000_0000. See
CPUID Fn0000_0000_E[D,C,B]X on page 600 for more details.
The value returned in EAX provides the family, model, and stepping identifiers. Three values are used
by software to identify a processor: Family, Model, and Stepping. The value returned in EAX is the
same as the value returned in EAX for Fn0000_0001. See CPUID Fn0000_0001_EAX on page 601
for more details on the field definitions.
The value returned in EBX provides package type and a 16-bit processor name string identifiers.
For processor families 10h and greater, PkgType is described in the BIOS and Kernel Developer’s
Guide for the product.
The three extended functions from Fn8000_0002 to Fn8000_0004 are programmed to return a null
terminated ASCII string up to 48 characters in length corresponding to the processor name.
The 48 character maximum includes the terminating null character. The 48 character string is ordered
first to last (left to right) as follows:
Fn8000_0002[EAX[7:0],..., EAX[31:24], EBX[7:0],..., EBX[31:24], ECX[7:0],...,
ECX[31:24],EDX[7:0],..., EDX[31:24]],
Fn8000_0003[EAX[7:0],..., EAX[31:24], EBX[7:0],..., EBX[31:24], ECX[7:0],..., ECX[31:24],
EDX[7:0],..., EDX[31:24]],
Fn8000_0004[EAX[7:0],..., EAX[31:24], EBX[7:0],..., EBX[31:24], ECX[7:0],..., ECX[31:24],
EDX[7:0],..., EDX[31:24]].
The extended processor name string is programmed by system firmware. See your processor revision
guide for information about how to display the extended processor name string.
The value returned in EAX provides information about the L1 TLB for 2-MB and 4-MB pages.
The value returned in EBX provides information about the L1 TLB for 4-KB pages.
The associativity fields (L1DTlb4KAssoc and L1ITlb4KAssoc) are encoded as specified in Table E-3
on page 622.
The value returned in ECX provides information about the first level data cache.
The associativity field (L1DcAssoc) is encoded as specified in Table E-3 on page 622.
The value returned in EDX provides information about the first level instruction cache.
The associativity field (L1IcAssoc) is encoded as specified in Table E-3 on page 622.
The value returned in EAX provides information about the L2 TLB for 2-MB and 4-MB pages.
The value returned in EBX provides information about the L2 TLB for 4-KB pages.
The associativity fields (L2DTlb4KAssoc and L2ITlb4KAssoc) are encoded per Table E-4 above.
The associativity field (L2Assoc) is encoded per Table E-4 on page 624.
The value returned in EDX provides the third level cache characteristics shared by all logical
processors in the package.
The associativity field (L3Assoc) is encoded per Table E-4 on page 624.
The value returned in EBX provides information about RAS features that allow system software to
detect specific hardware errors.
The value returned in ECX provides information about the implementation of the processor power
monitoring interface.
The value returned in EDX provides information about the advanced power management and power
reporting features available. Refer to the BIOS and Kernel Developer’s Guide for your specific product
for a detailed description of the definition of each power management feature.
The value returned in EAX provides information about the maximum host and guest physical and
linear address width (in bits) supported by the processor.
The address width reported is the maximum supported in any mode. For long mode capable proces-
sors, the size reported is independent of whether long mode is enabled. See “Processor Initialization
and Long-Mode Activation” in APM Volume 2.
The value returned in EBX is an extension to the Fn8000_0001 feature flags and indicates the presence
of various ISA extensions.
The value returned in ECX provides information about the number of cores supported by the
processor, the width of the APIC ID, and the width of the performance time-stamp counter.
The value returned in EDX identifies the maximum recognized register identifier for the RDPRU
instruction.
The value returned in EBX provides the number of address space identifiers (ASIDs) that the
processor supports.
The value returned in ECX for this function is undefined and is reserved.
The value returned in EDX provides Secure Virtual Machine architecture feature information. All
cross references in the table below are to sections within the “Secure Virtual Machine” chapter of
APM Volume 2.
The value returned in EAX provides information about the L1 TLB for 1 GB pages.
The value returned in EBX provides information about the L2 TLB for 1 GB pages.
The values returned in ECX and EDX for this function are undefined and reserved for future use.
The values returned in EBX, ECX, and EDX are undefined for this function and are reserved.
The value returned in EAX provides the following information about the specific features of IBS that
the processor supports:
The values returned in EBX, ECX, and EDX are undefined and are reserved.
The value returned in EAX provides the following information about LWP capabilities supported by
the processor:
The value returned in EBX provides the following additional information about LWP capabilities
supported by the processor:
The value returned in ECX provides the following additional information about LWP capabilities
supported by the processor:
The value returned in EDX provides the following additional information about LWP capabilities
supported by the processor:
15:8 ThreadsPerComputeUnit
ShareId = LocalApicId >> log2(ThreadsPerComputeUnit+1)
Logical processors with the same ShareId then belong to the same Compute
Unit. (If ThreadsPerComputeUnit+1 is not a power of two, round it up to the
next power of two).
Compute unit ID. Identifies a Compute Unit, which may be one or more
7:0 ComputeUnitId
physical cores that each implement one or more logical processors.
Subfunction 1 provides information about the L3MBE feature, if this feature is supported (CPUID
Fn8000_0020_EBX_x0[L3MBE] = 1). If L3MBE is not supported this function is reserved. For more
information on L3MBE, see “Platform Quality of Service” in APM Volume 2.
Subfunction 2 provides information about the L3SMBE feature, if this feature is supported (CPUID
Fn8000_0020_EBX_x0[L3SMBE] = 1). If L3MBE is not supported this function is reserved. For
more information on L3SMBE, see “Platform Quality of Service” in APM Volume 2.
Subfunction 3 provides information about the BMEC feature, if this feature is supported (CPUID
Fn8000_0020_EBX_x0[BMEC] = 1). If BMEC is not supported this function is reserved. For more
information on L3MBE, see “Platform Quality of Service” in APM Volume 2.
Subfunction 5 provides information about the ABMC feature, if this feature is supported (CPUID
Fn8000_0020_EAX_x0[ABMC] = 1). If ABMC is not supported this function is reserved. For more
information on ABMC see “Platform Quality of Service” in APM Volume 2.
• CPUID Fn0000_0001_EBX[LogicalProcessorCount]
• CPUID Fn0000_0001_EDX[HTT] (Hyper-Threading Technology)
• CPUID Fn8000_0001_ECX[CmpLegacy]
• CPUID Fn8000_0008_ECX[NC]
Table E-5 defines LogicalProcessorCount, HTT, CmpLegacy, and NC as a function of the number of
logical processors per package (n).
When HTT = 0, LogicalProcessorCount is reserved and the package contains one logical processor.
When HTT = 1 and CmpLegacy = 1, LogicalProcessorCount represents the number of logical processors per
package (n).
The use of CmpLegacy and LogicalProcessorCount for determining the number of logical processors is depre-
cated. Instead, use NC to determine the number of logical processors per package.
nificant bits in the CPUID Fn0000_0001_EBX[LocalApicId] that indicates logical processor ID within the
package. The size of this field determines the maximum number of logical processors (MNLP) that the pack-
age could theoretically support, and not the actual number of logical processors that are implemented or
enabled in the package, as indicated by CPUID Fn8000_0008_ECX[NC].
A value of zero for ApicIdSize[3:0] indicates that the legacy method (section E5.1) should be used to derive
the maximum number of logical processors:
Index
Numerics compatibility ...................................................... 591
long ................................................................... 591
0F_38h opcode map ............................................... 525 ModRM ................................................................ 551
0F_3Ah opcode map .............................................. 525 ModRM byte .......................................... 521, 531, 551
A N
addressing NOP...................................................................... 590
effective address ........................... 552, 555, 556, 558
AMD64 Instruction-set Architecture........................ 593 O
AMD64 ISA .......................................................... 593 one-byte opcodes ................................................... 512
B opcode
two-byte ............................................................. 514
base field........................................................ 557, 558 opcode map
C 0F_38h .............................................................. 525
0F_3Ah .............................................................. 525
CMOVcc .............................................................. 520 primary .............................................................. 512
condition codes secondary ........................................................... 514
rFLAGS...................................................... 520, 540 opcode maps .......................................................... 512
count .................................................................... 561 opcodes
CPUID 3DNow!™ ......................................................... 528
feature flags ....................................................... 596 group 1 .............................................................. 521
group 10 ............................................................ 523
D group 12 ............................................................ 523
DEC ..................................................................... 589 group 13 ............................................................ 523
group 14 ............................................................ 523
E group 16 ............................................................ 524
group 17 ............................................................ 524
effective address .............................. 552, 555, 556, 558 group 1a ............................................................. 522
F group 2 .............................................................. 522
group 3 .............................................................. 522
FCMOVcc ............................................................ 540 group 4 .............................................................. 522
I group 5 .............................................................. 522
group 6 .............................................................. 523
immediate operands ............................................... 561 group 7 .............................................................. 523
INC ...................................................................... 589 group 8 .............................................................. 523
index field ............................................................. 558 group 9 .............................................................. 523
instructions group P .............................................................. 524
effects on rFLAGS ............................................. 649 groups ................................................................ 521
invalid in 64-bit mode ......................................... 587 ModRM byte ...................................................... 521
invalid in long mode ........................................... 588 one-byte ............................................................. 512
reassigned in 64-bit mode.................................... 588 x87 opcode map ................................................. 531
operands
J immediate .......................................................... 561
size ..................................................... 561, 562, 588
Jcc ........................................................................ 520
P
M
primary opcode map ............................................... 512
mod field............................................................... 555
mode-register-memory (ModRM) ........................... 551 R
modes ................................................................... 591
r/m field ................................................................ 521
64-bit................................................................. 591
Index 653
654 Index