13.07.2015 Views

Volume 3: General-Purpose and System Instructions - Stanford ...

Volume 3: General-Purpose and System Instructions - Stanford ...

Volume 3: General-Purpose and System Instructions - Stanford ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

© 2002, 2003, 2004, 2005 Advanced Micro Devices, Inc. All rights reserved.The contents of this document are provided in connection with Advanced Micro Devices, Inc.(“AMD”) products. AMD makes no representations or warranties with respect to the accuracy orcompleteness of the contents of this publication <strong>and</strong> reserves the right to make changes tospecifications <strong>and</strong> product descriptions at any time without notice. No license, whether express,implied, arising by estoppel or otherwise, to any intellectual property rights is granted by thispublication. Except as set forth in AMD’s St<strong>and</strong>ard Terms <strong>and</strong> Conditions of Sale, AMD assumesno liability whatsoever, <strong>and</strong> disclaims any express or implied warranty, relating to its productsincluding, but not limited to, the implied warranty of merchantability, fitness for a particular purpose,or infringement of any intellectual property right.AMD’s products are not designed, intended, authorized or warranted for use as components insystems intended for surgical implant into the body, or in other applications intended to supportor sustain life, or in any other application in which the failure of AMD’s product could create asituation where personal injury, death, or severe property or environmental damage may occur.AMD reserves the right to discontinue or make changes to its products at any time withoutnotice.TrademarksAMD, the AMD arrow logo, <strong>and</strong> combinations thereof, <strong>and</strong> 3DNow! are trademarks, <strong>and</strong> AMD-K6 <strong>and</strong> AMD Athlon are registered trademarksof Advanced Micro Devices, Inc.MMX is a trademark <strong>and</strong> Pentium is a registered trademark of Intel Corporation.Other product names used in this publication are for identification purposes only <strong>and</strong> may be trademarks of their respective companies.


24594 Rev. 3.10 February 2005 AMD64 TechnologyContentsFiguresTablesRevision HistoryixxixiiiPrefacexvAbout This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvAudience . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvContact Information. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvOrganization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvDefinitions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xviRelated Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxvii1 Instruction Formats 11.1 Instruction Byte Order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2 Instruction Prefixes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3Summary of Legacy Prefixes . . . . . . . . . . . . . . . . . . . . . . . . . . . 3Oper<strong>and</strong>-Size Override Prefix . . . . . . . . . . . . . . . . . . . . . . . . . . 5Address-Size Override Prefix . . . . . . . . . . . . . . . . . . . . . . . . . . . 6Segment-Override Prefixes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9Lock Prefix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10Repeat Prefixes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10REX Prefixes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141.3 Opcode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201.4 ModRM <strong>and</strong> SIB Bytes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201.5 Displacement Bytes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221.6 Immediate Bytes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231.7 RIP-Relative Addressing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23Encoding. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24REX Prefix <strong>and</strong> RIP-Relative Addressing. . . . . . . . . . . . . . . . 24Address-Size Prefix <strong>and</strong> RIP-Relative Addressing. . . . . . . . . 252 Instruction Overview 272.1 Instruction Subsets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272.2 Reference-Page Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282.3 Summary of Registers <strong>and</strong> Data Types . . . . . . . . . . . . . . . . . . 30<strong>General</strong>-<strong>Purpose</strong> <strong>Instructions</strong>. . . . . . . . . . . . . . . . . . . . . . . . . . 30<strong>System</strong> <strong>Instructions</strong>. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33128-Bit Media <strong>Instructions</strong> . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3564-Bit Media <strong>Instructions</strong> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38x87 Floating-Point <strong>Instructions</strong> . . . . . . . . . . . . . . . . . . . . . . . . 402.4 Summary of Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412.5 Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43Contentsiii


AMD64 Technology 24594 Rev. 3.10 February 2005Mnemonic Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43Opcode Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46Pseudocode Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493 <strong>General</strong>-<strong>Purpose</strong> Instruction Reference 59AAA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61AAD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62AAM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63AAS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64ADC. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65ADD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67AND . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69BOUND . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72BSF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74BSR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76BSWAP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78BT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79BTC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81BTR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83BTS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85CALL (Near). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87CALL (Far) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89CBW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96CWDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96CDQE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96CWD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97CDQ. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97CQO. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97CLC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98CLD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99CLFLUSH. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100CMC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102CMOVcc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103CMP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107CMPS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110CMPSB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110CMPSW. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110CMPSD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110CMPSQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110CMPXCHG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113CMPXCHG8B. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115CMPXCHG16B. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115CPUID. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117DAA. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136DAS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137DEC. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138DIV . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140ENTER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142ivContents


24594 Rev. 3.10 February 2005 AMD64 TechnologyIDIV . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144IMUL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146IN. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149INC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151INS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153INSB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153INSW. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153INSD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153INT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156INTO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164Jcc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165JCXZ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169JECXZ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169JRCXZ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169JMP (Near). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171JMP (Far) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173LAHF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178LDS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179LES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179LFS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179LGS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179LSS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179LEA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182LEAVE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184LFENCE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186LODS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187LODSB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187LODSW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187LODSD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187LODSQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187LOOPcc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189MFENCE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191MOV . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192MOVD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196MOVMSKPD. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199MOVMSKPS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201MOVNTI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203MOVS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205MOVSB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205MOVSW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205MOVSD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205MOVSQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205MOVSX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207MOVSXD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208MOVZX. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209MUL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210NEG. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212Contentsv


AMD64 Technology 24594 Rev. 3.10 February 2005NOP. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214NOT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215OR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216OUT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219OUTS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221OUTSB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221OUTSW. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221OUTSD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221POP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223POPAx. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226POPFx. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227PREFETCHx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230PREFETCHlevel. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232PUSH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234PUSHAx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236PUSHFx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237RCL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239RCR. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242RET (Near). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245RET (Far) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247ROL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251ROR. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253SAHF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255SAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256SHL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256SAR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259SBB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262SCAS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265SCASB. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265SCASW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265SCASD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265SCASQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265SETcc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267SFENCE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270SHL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271SHLD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272SHR. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274SHRD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276STC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278STD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279STOS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280STOSB. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280STOSW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280STOSD. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280STOSQ. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280SUB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282TEST . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285viContents


24594 Rev. 3.10 February 2005 AMD64 TechnologyXADD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287XCHG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289XLATx. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291XOR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2934 <strong>System</strong> Instruction Reference 297ARPL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298CLI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300CLTS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302HLT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303INT 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304INVD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307INVLPG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308IRETx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309LAR. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315LGDT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318LIDT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320LLDT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322LMSW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324LSL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325LTR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327MOV(CRn) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329MOV(DRn) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331RDMSR. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333RDPMC. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334RDTSC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336RDTSCP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337RSM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339SGDT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341SIDT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343SLDT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345SMSW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347STI. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348STR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 350SWAPGS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352SYSCALL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354SYSENTER. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359SYSEXIT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361SYSRET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 363UD2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367VERR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368VERW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 370WBINVD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372WRMSR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 373Appendix A Opcode <strong>and</strong> Oper<strong>and</strong> Encodings 375A.1 Opcode-Syntax Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375A.2 Opcode Encodings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377Contentsvii


AMD64 Technology 24594 Rev. 3.10 February 2005One-Byte Opcodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377Two-Byte Opcodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380rFLAGS Condition Codes for Two-Byte Opcodes . . . . . . . . . 386ModRM Extensions to One-Byte <strong>and</strong> Two-Byte Opcodes. . . 387ModRM Extensions to Opcodes 0F 01 <strong>and</strong> 0F AE . . . . . . . . 3903DNow! Opcodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390x87 Encodings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 392rFLAGS Condition Codes for x87 Opcodes . . . . . . . . . . . . . . 402A.3 Oper<strong>and</strong> Encodings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402ModRM Oper<strong>and</strong> References. . . . . . . . . . . . . . . . . . . . . . . . . 402SIB Oper<strong>and</strong> References. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 408Appendix B <strong>General</strong>-<strong>Purpose</strong> <strong>Instructions</strong> in 64-Bit Mode 413B.1 <strong>General</strong> Rules for 64-Bit Mode. . . . . . . . . . . . . . . . . . . . . . . . 413B.2 Operation <strong>and</strong> Oper<strong>and</strong> Size in 64-Bit Mode . . . . . . . . . . . . 414B.3 Invalid <strong>and</strong> Reassigned <strong>Instructions</strong> in 64-Bit Mode . . . . . . 444B.4 <strong>Instructions</strong> with 64-Bit Default Oper<strong>and</strong> Size. . . . . . . . . . . 446B.5 Single-Byte INC <strong>and</strong> DEC <strong>Instructions</strong> in 64-Bit Mode . . . . 448B.6 NOP in 64-Bit Mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 448B.7 Segment Override Prefixes in 64-Bit Mode . . . . . . . . . . . . . 449Appendix C Differences Between Long Mode <strong>and</strong> Legacy Mode 451Appendix D Instruction Subsets <strong>and</strong> CPUID Feature Sets 453D.1 Instruction Subsets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453D.2 CPUID Feature Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 455D.3 Instruction List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457Appendix E Instruction Effects on RFLAGS 493Index 499viiiContents


AMD64 Technology 24594 Rev. 3.10 February 2005Figure A-2. ModRM-Byte Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403Figure A-3. SIB Byte Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 409Figure D-1. Instruction Subsets vs. CPUID Feature Sets . . . . . . . . . . . . . . 454xFigures


AMD64 Technology 24594 Rev. 3.10 February 2005Table 3-13. CPUID L2 TLB Bits for 2-Mbyte <strong>and</strong> 4-Mbyte Pages(Extended Function 8000_0006—EAX) . . . . . . . . . . . . . . . . . . 132Table 3-14. CPUID L2 TLB Bits for 4-Kbyte Pages(Extended Function 8000_0006—EBX) . . . . . . . . . . . . . . . . . . 132Table 3-15. CPUID L2 Cache Bits(Extended Function 8000_0006—ECX) . . . . . . . . . . . . . . . . . . 133Table 3-16. Locality References for the Prefetch <strong>Instructions</strong> . . . . . . . . . 233Table A-1. One-Byte Opcodes, Low Nibble 0–7h . . . . . . . . . . . . . . . . . . . . 378Table A-2. One-Byte Opcodes, Low Nibble 8–Fh . . . . . . . . . . . . . . . . . . . . 379Table A-3. Second Byte of Two-Byte Opcodes, Low Nibble 0–7h. . . . . . . 380Table A-4. Second Byte of Two-Byte Opcodes, Low Nibble 8–Fh . . . . . . 383Table A-5. rFLAGS Condition Codes for CMOVcc, Jcc, <strong>and</strong> SETcc . . . . . 386Table A-6. One-Byte <strong>and</strong> Two-Byte Opcode ModRM Extensions . . . . . . . 388Table A-7. Opcode 0F 01 <strong>and</strong> 0F AE ModRM Extensions. . . . . . . . . . . . . 390Table A-8. Immediate Byte for 3DNow! Opcodes, Low Nibble 0–7h . . 391Table A-9. Immediate Byte for 3DNow! Opcodes, Low Nibble 8–Fh . . 392Table A-10. x87 Opcodes <strong>and</strong> ModRM Extensions . . . . . . . . . . . . . . . . . . . 394Table A-11. rFLAGS Condition Codes for FCMOVcc . . . . . . . . . . . . . . . . . 402Table A-12. ModRM Register References, 16-Bit Addressing . . . . . . . . . . 403Table A-13. ModRM Memory References, 16-Bit Addressing . . . . . . . . . . 404Table A-14. ModRM Register References, 32-Bit <strong>and</strong> 64-Bit Addressing . 406Table A-15. ModRM Memory References, 32-Bit <strong>and</strong> 64-Bit Addressing . 407Table A-16. SIB base Field References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 409Table A-17. SIB Memory References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 410Table B-1. Operations <strong>and</strong> Oper<strong>and</strong>s in 64-Bit Mode . . . . . . . . . . . . . . . . 415Table B-2. Invalid <strong>Instructions</strong> in 64-Bit Mode . . . . . . . . . . . . . . . . . . . . . 445Table B-3. Reassigned <strong>Instructions</strong> in 64-Bit Mode. . . . . . . . . . . . . . . . . . 446Table B-4. Invalid <strong>Instructions</strong> in Long Mode . . . . . . . . . . . . . . . . . . . . . . 446Table B-5. <strong>Instructions</strong> Defaulting to 64-Bit Oper<strong>and</strong> Size . . . . . . . . . . . 447Table C-1. Differences Between Long Mode <strong>and</strong> Legacy Mode. . . . . . . . 451Table D-1. Instruction Subsets <strong>and</strong> CPUID Feature Sets . . . . . . . . . . . . . 457Table E-1. Instruction Effects on RFLAGS . . . . . . . . . . . . . . . . . . . . . . . . 493xiiTables


24594—Rev. 3.10—February 2005AMD64 TechnologyRevision HistoryDate Revision DescriptionJanuary 2005 3.10September 2003 3.09April 2003 3.08Clarified CPUID information in exception tables on instruction pages. Addedinformation under “CPUID” on page 117. Made numerous small corrections.Corrected table of valid descriptor types for LAR <strong>and</strong> LSL instructions <strong>and</strong> madeseveral minor formatting, stylistic <strong>and</strong> factual corrections. Clarified several technicaldefintions.Corrected description of the operation of flags for RCL, RCR, ROL, <strong>and</strong> RORinstructions. Clarified description of the MOVSXD <strong>and</strong> IMUL instructions. Correctedoper<strong>and</strong> specification for the STOS instruction. Corrected opcode of SETcc, Jcc,instructions. Added thermal control <strong>and</strong> thermal monitoring bits to CPUIDinstruction. Corrected exception tables for POPF, SFENCE, SUB, XLAT, IRET, LSL,MOV(CRn), SGDT/SIDT, SMSW, <strong>and</strong> STI instructions.. Corrected many small typos<strong>and</strong> incorporated br<strong>and</strong>ing terminology.Revision Historyxiii


AMD64 Technology 24594—Rev. 3.10—February 2005xivRevision History


24594 Rev. 3.10 February 2005 AMD64 TechnologyPrefaceAbout This BookThis book is part of a multivolume work entitled the AMD64Architecture Programmer’s Manual. This table lists each volume<strong>and</strong> its order number.TitleOrder No.<strong>Volume</strong> 1, Application Programming 24592<strong>Volume</strong> 2, <strong>System</strong> Programming 24593<strong>Volume</strong> 3, <strong>General</strong>-<strong>Purpose</strong> <strong>and</strong> <strong>System</strong> <strong>Instructions</strong> 24594<strong>Volume</strong> 4, 128-Bit Media <strong>Instructions</strong> 26568<strong>Volume</strong> 5, 64-Bit Media <strong>and</strong> x87 Floating-Point <strong>Instructions</strong> 26569AudienceContact InformationOrganizationThis volume (<strong>Volume</strong> 3) is intended for all programmers writingapplication or system software for a processor that implementsthe AMD64 architecture. Descriptions of general-purposeinstructions assume an underst<strong>and</strong>ing of the application-levelprogramming topics described in <strong>Volume</strong> 1. Descriptions ofsystem instructions assume an underst<strong>and</strong>ing of the systemlevelprogramming topics described in <strong>Volume</strong> 2.To submit questions or comments concerning this document,contact our technical documentation staff atAMD64.Feedback@amd.com.<strong>Volume</strong>s 3, 4, <strong>and</strong> 5 describe the AMD64 architecture’sinstruction set in detail. Together, they cover each instruction’smnemonic syntax, opcodes, functions, affected flags, <strong>and</strong>possible exceptions.The AMD64 instruction set is divided into five subsets:Prefacexv


AMD64 Technology 24594 Rev. 3.10 February 2005• <strong>General</strong>-purpose instructions• <strong>System</strong> instructions• 128-bit media instructions• 64-bit media instructions• x87 floating-point instructionsSeveral instructions belong to—<strong>and</strong> are described identicallyin—multiple instruction subsets.This volume describes the general-purpose <strong>and</strong> systeminstructions. The index at the end cross-references topics withinthis volume. For other topics relating to the AMD64architecture, <strong>and</strong> for information on instructions in othersubsets, see the tables of contents <strong>and</strong> indexes of the othervolumes.DefinitionsMany of the following definitions assume an in-depthknowledge of the legacy x86 architecture. See “RelatedDocuments” on page xxvii for descriptions of the legacy x86architecture.Terms <strong>and</strong> NotationIn addition to the notation described below, “Opcode-SyntaxNotation” on page 375 describes notation relating specificallyto opcodes.1011bA binary value—in this example, a 4-bit value.F0EAhA hexadecimal value—in this example a 2-byte value.[1,2)A range that includes the left-most value (in this case, 1) butexcludes the right-most value (in this case, 2).7–4A bit range, from bit 7 to 4, inclusive. The high-order bit isshown first.128-bit media instructions<strong>Instructions</strong> that use the 128-bit XMM registers. These are acombination of the SSE <strong>and</strong> SSE2 instruction sets.xviPreface


24594 Rev. 3.10 February 2005 AMD64 Technology64-bit media instructions<strong>Instructions</strong> that use the 64-bit MMX registers. These areprimarily a combination of MMX <strong>and</strong> 3DNow!instruction sets, with some additional instructions from theSSE <strong>and</strong> SSE2 instruction sets.16-bit modeLegacy mode or compatibility mode in which a 16-bitaddress size is active. See legacy mode <strong>and</strong> compatibilitymode.32-bit modeLegacy mode or compatibility mode in which a 32-bitaddress size is active. See legacy mode <strong>and</strong> compatibilitymode.64-bit modeA submode of long mode. In 64-bit mode, the default addresssize is 64 bits <strong>and</strong> new features, such as register extensions,are supported for system <strong>and</strong> application software.#GP(0)Notation indicating a general-protection exception (#GP)with error code of 0.absoluteSaid of a displacement that references the base of a codesegment rather than an instruction pointer. Contrast withrelative.biased exponentThe sum of a floating-point value’s exponent <strong>and</strong> a constantbias for a particular floating-point data type. The bias makesthe range of the biased exponent always positive, whichallows reciprocation without overflow.byteEight bits.clearTo write a bit value of 0. Compare set.Prefacexvii


AMD64 Technology 24594 Rev. 3.10 February 2005compatibility modeA submode of long mode. In compatibility mode, the defaultaddress size is 32 bits, <strong>and</strong> legacy 16-bit <strong>and</strong> 32-bitapplications run without modification.commitTo irreversibly write, in program order, an instruction’sresult to software-visible storage, such as a register(including flags), the data cache, an internal write buffer, ormemory.CPLCurrent privilege level.CR0–CR4A register range, from register CR0 through CR4, inclusive,with the low-order register first.CR0.PE = 1Notation indicating that the PE bit of the CR0 register has avalue of 1.directReferencing a memory location whose address is included inthe instruction’s syntax as an immediate oper<strong>and</strong>. Theaddress may be an absolute or relative address. Compareindirect.dirty dataData held in the processor’s caches or internal buffers that ismore recent than the copy held in main memory.displacementA signed value that is added to the base of a segment(absolute addressing) or an instruction pointer (relativeaddressing). Same as offset.doublewordTwo words, or four bytes, or 32 bits.double quadwordEight words, or 16 bytes, or 128 bits. Also called octword.xviiiPreface


24594 Rev. 3.10 February 2005 AMD64 TechnologyDS:rSIThe contents of a memory location whose segment address isin the DS register <strong>and</strong> whose offset relative to that segmentis in the rSI register.EFER.LME = 0Notation indicating that the LME bit of the EFER registerhas a value of 0.effective address sizeThe address size for the current instruction after accountingfor the default address size <strong>and</strong> any address-size overrideprefix.effective oper<strong>and</strong> sizeThe oper<strong>and</strong> size for the current instruction afteraccounting for the default oper<strong>and</strong> size <strong>and</strong> any oper<strong>and</strong>sizeoverride prefix.elementSee vector.exceptionAn abnormal condition that occurs as the result of executingan instruction. The processor’s response to an exceptiondepends on the type of the exception. For all exceptionsexcept 128-bit media SIMD floating-point exceptions <strong>and</strong>x87 floating-point exceptions, control is transferred to theh<strong>and</strong>ler (or service routine) for that exception, as defined bythe exception’s vector. For floating-point exceptions definedby the IEEE 754 st<strong>and</strong>ard, there are both masked <strong>and</strong>unmasked responses. When unmasked, the exceptionh<strong>and</strong>ler is called, <strong>and</strong> when masked, a default response isprovided instead of calling the h<strong>and</strong>ler.FF /0Notation indicating that FF is the first byte of an opcode,<strong>and</strong> a subopcode in the ModR/M byte has a value of 0.flushAn often ambiguous term meaning (1) writeback, ifmodified, <strong>and</strong> invalidate, as in “flush the cache line,” or (2)invalidate, as in “flush the pipeline,” or (3) change a value,as in “flush to zero.”Prefacexix


AMD64 Technology 24594 Rev. 3.10 February 2005GDTGlobal descriptor table.IDTInterrupt descriptor table.IGNIgnore. Field is ignored.indirectReferencing a memory location whose address is in aregister or other memory location. The address may be anabsolute or relative address. Compare direct.IRBThe virtual-8086 mode interrupt-redirection bitmap.ISTThe long-mode interrupt-stack table.IVTThe real-address mode interrupt-vector table.LDTLocal descriptor table.legacy x86The legacy x86 architecture. See “Related Documents” onpage xxvii for descriptions of the legacy x86 architecture.legacy modeAn operating mode of the AMD64 architecture in whichexisting 16-bit <strong>and</strong> 32-bit applications <strong>and</strong> operating systemsrun without modification. A processor implementation ofthe AMD64 architecture can run in either long mode or legacymode. Legacy mode has three submodes, real mode, protectedmode, <strong>and</strong> virtual-8086 mode.long modeAn operating mode unique to the AMD64 architecture. Aprocessor implementation of the AMD64 architecture canrun in either long mode or legacy mode. Long mode has twosubmodes, 64-bit mode <strong>and</strong> compatibility mode.xxPreface


24594 Rev. 3.10 February 2005 AMD64 TechnologylsbLeast-significant bit.LSBLeast-significant byte.main memoryPhysical memory, such as RAM <strong>and</strong> ROM (but not cachememory) that is installed in a particular computer system.mask(1) A control bit that prevents the occurrence of a floatingpointexception from invoking an exception-h<strong>and</strong>lingroutine. (2) A field of bits used for a control purpose.MBZMust be zero. If software attempts to set an MBZ bit to 1, ageneral-protection exception (#GP) occurs.memoryUnless otherwise specified, main memory.ModRMA byte following an instruction opcode that specifiesaddress calculation based on mode (Mod), register (R), <strong>and</strong>memory (M) variables.moffsetA 16, 32, or 64-bit offset that specifies a memory oper<strong>and</strong>directly, without using a ModRM or SIB byte.msbMost-significant bit.MSBMost-significant byte.multimedia instructionsA combination of 128-bit media instructions <strong>and</strong> 64-bit mediainstructions.octwordSame as double quadword.offsetSame as displacement.Prefacexxi


AMD64 Technology 24594 Rev. 3.10 February 2005overflowThe condition in which a floating-point number is larger inmagnitude than the largest, finite, positive or negativenumber that can be represented in the data-type formatbeing used.packedSee vector.PAEPhysical-address extensions.physical memoryActual memory, consisting of main memory <strong>and</strong> cache.probeA check for an address in a processor’s caches or internalbuffers. External probes originate outside the processor, <strong>and</strong>internal probes originate within the processor.protected modeA submode of legacy mode.quadwordFour words, or eight bytes, or 64 bits.RAZRead as zero (0), regardless of what is written.real-address modeSee real mode.real modeA short name for real-address mode, a submode of legacymode.relativeReferencing with a displacement (also called offset) from aninstruction pointer rather than the base of a code segment.Contrast with absolute.reservedFields marked as reserved may be used at some future time.xxiiPreface


24594 Rev. 3.10 February 2005 AMD64 TechnologyTo preserve compatibility with future processors, reservedfields require special h<strong>and</strong>ling when read or written bysoftware.Reserved fields may be further qualified as MBZ, RAZ, SBZor IGN (see definitions).Software must not depend on the state of a reserved field,nor upon the ability of such fields to return to a previouslywritten state.If a reserved field is not marked with one of the abovequalifiers, software must not change the state of that field; itmust reload that field with the same values returned from aprior read.REXAn instruction prefix that specifies a 64-bit oper<strong>and</strong> size <strong>and</strong>provides access to additional registers.RIP-relative addressingAddressing relative to the 64-bit RIP instruction pointer.setTo write a bit value of 1. Compare clear.SIBA byte following an instruction opcode that specifiesaddress calculation based on scale (S), index (I), <strong>and</strong> base(B).SIMDSingle instruction, multiple data. See vector.SSEStreaming SIMD extensions instruction set. See 128-bitmedia instructions <strong>and</strong> 64-bit media instructions.SSE2Extensions to the SSE instruction set. See 128-bit mediainstructions <strong>and</strong> 64-bit media instructions.SSE3Further extensions to the SSE instruction set. See 128-bitmedia instructions.Prefacexxiii


AMD64 Technology 24594 Rev. 3.10 February 2005sticky bitA bit that is set or cleared by hardware <strong>and</strong> that remains inthat state until explicitly changed by software.TOPThe x87 top-of-stack pointer.TPRTask-priority register (CR8).TSSTask-state segment.underflowThe condition in which a floating-point number is smaller inmagnitude than the smallest nonzero, positive or negativenumber that can be represented in the data-type formatbeing used.vector(1) A set of integer or floating-point values, called elements,that are packed into a single oper<strong>and</strong>. Most of the 128-bit<strong>and</strong> 64-bit media instructions use vectors as oper<strong>and</strong>s.Vectors are also called packed or SIMD (single-instructionmultiple-data) oper<strong>and</strong>s.(2) An index into an interrupt descriptor table (IDT), used toaccess exception h<strong>and</strong>lers. Compare exception.virtual-8086 modeA submode of legacy mode.wordTwo bytes, or 16 bits.x86See legacy x86.RegistersIn the following list of registers, the names are used to refereither to a given register or to the contents of that register:AH–DHThe high 8-bit AH, BH, CH, <strong>and</strong> DH registers. CompareAL–DL.xxivPreface


24594 Rev. 3.10 February 2005 AMD64 TechnologyAL–DLThe low 8-bit AL, BL, CL, <strong>and</strong> DL registers. Compare AH–DH.AL–r15BThe low 8-bit AL, BL, CL, DL, SIL, DIL, BPL, SPL, <strong>and</strong>R8B–R15B registers, available in 64-bit mode.BPBase pointer register.CRnControl register number n.CSCode segment register.eAX–eSPThe 16-bit AX, BX, CX, DX, DI, SI, BP, <strong>and</strong> SP registers or the32-bit EAX, EBX, ECX, EDX, EDI, ESI, EBP, <strong>and</strong> ESPregisters. Compare rAX–rSP.EFERExtended features enable register.eFLAGS16-bit or 32-bit flags register. Compare rFLAGS.EFLAGS32-bit (extended) flags register.eIP16-bit or 32-bit instruction-pointer register. Compare rIP.EIP32-bit (extended) instruction-pointer register.FLAGS16-bit flags register.GDTRGlobal descriptor table register.GPRs<strong>General</strong>-purpose registers. For the 16-bit data size, these areAX, BX, CX, DX, DI, SI, BP, <strong>and</strong> SP. For the 32-bit data size,these are EAX, EBX, ECX, EDX, EDI, ESI, EBP, <strong>and</strong> ESP. ForPrefacexxv


AMD64 Technology 24594 Rev. 3.10 February 2005the 64-bit data size, these include RAX, RBX, RCX, RDX,RDI, RSI, RBP, RSP, <strong>and</strong> R8–R15.IDTRInterrupt descriptor table register.IP16-bit instruction-pointer register.LDTRLocal descriptor table register.MSRModel-specific register.r8–r15The 8-bit R8B–R15B registers, or the 16-bit R8W–R15Wregisters, or the 32-bit R8D–R15D registers, or the 64-bitR8–R15 registers.rAX–rSPThe 16-bit AX, BX, CX, DX, DI, SI, BP, <strong>and</strong> SP registers, orthe 32-bit EAX, EBX, ECX, EDX, EDI, ESI, EBP, <strong>and</strong> ESPregisters, or the 64-bit RAX, RBX, RCX, RDX, RDI, RSI,RBP, <strong>and</strong> RSP registers. Replace the placeholder r withnothing for 16-bit size, “E” for 32-bit size, or “R” for 64-bitsize.RAX64-bit version of the EAX register.RBP64-bit version of the EBP register.RBX64-bit version of the EBX register.RCX64-bit version of the ECX register.RDI64-bit version of the EDI register.RDX64-bit version of the EDX register.xxviPreface


24594 Rev. 3.10 February 2005 AMD64 TechnologyrFLAGS16-bit, 32-bit, or 64-bit flags register. Compare RFLAGS.RFLAGS64-bit flags register. Compare rFLAGS.rIP16-bit, 32-bit, or 64-bit instruction-pointer register. CompareRIP.RIP64-bit instruction-pointer register.RSI64-bit version of the ESI register.RSP64-bit version of the ESP register.SPStack pointer register.SSStack segment register.TPRTask priority register, a new register introduced in theAMD64 architecture to speed interrupt management.TRTask register.Endian OrderThe x86 <strong>and</strong> AMD64 architectures address memory using littleendianbyte-ordering. Multibyte values are stored with theirleast-significant byte at the lowest byte address, <strong>and</strong> they areillustrated with their least significant byte at the right side.Strings are illustrated in reverse order, because the addresses oftheir bytes increase from right to left.Related Documents• Peter Abel, IBM PC Assembly Language <strong>and</strong> Programming,Prentice-Hall, Englewood Cliffs, NJ, 1995.• Rakesh Agarwal, 80x86 Architecture & Programming: <strong>Volume</strong>II, Prentice-Hall, Englewood Cliffs, NJ, 1991.Prefacexxvii


AMD64 Technology 24594 Rev. 3.10 February 2005• AMD, AMD-K6 MMX Enhanced Processor MultimediaTechnology, Sunnyvale, CA, 2000.• AMD, 3DNow! Technology Manual, Sunnyvale, CA, 2000.• AMD, AMD Extensions to the 3DNow! <strong>and</strong> MMXInstruction Sets, Sunnyvale, CA, 2000.• Don Anderson <strong>and</strong> Tom Shanley, Pentium Processor <strong>System</strong>Architecture, Addison-Wesley, New York, 1995.• Nabajyoti Barkakati <strong>and</strong> R<strong>and</strong>all Hyde, Microsoft MacroAssembler Bible, Sams, Carmel, Indiana, 1992.• Barry B. Brey, 8086/8088, 80286, 80386, <strong>and</strong> 80486 AssemblyLanguage Programming, Macmillan Publishing Co., NewYork, 1994.• Barry B. Brey, Programming the 80286, 80386, 80486, <strong>and</strong>Pentium Based Personal Computer, Prentice-Hall, EnglewoodCliffs, NJ, 1995.• Ralf Brown <strong>and</strong> Jim Kyle, PC Interrupts, Addison-Wesley,New York, 1994.• Penn Brumm <strong>and</strong> Don Brumm, 80386/80486 AssemblyLanguage Programming, Windcrest McGraw-Hill, 1993.• Geoff Chappell, DOS Internals, Addison-Wesley, New York,1994.• Chips <strong>and</strong> Technologies, Inc. Super386 DX Programmer’sReference Manual, Chips <strong>and</strong> Technologies, Inc., San Jose,1992.• John Crawford <strong>and</strong> Patrick Gelsinger, Programming the80386, Sybex, San Francisco, 1987.• Cyrix Corporation, 5x86 Processor BIOS Writer's Guide, CyrixCorporation, Richardson, TX, 1995.• Cyrix Corporation, M1 Processor Data Book, CyrixCorporation, Richardson, TX, 1996.• Cyrix Corporation, MX Processor MMX Extension OpcodeTable, Cyrix Corporation, Richardson, TX, 1996.• Cyrix Corporation, MX Processor Data Book, CyrixCorporation, Richardson, TX, 1997.• Ray Duncan, Extending DOS: A Programmer's Guide toProtected-Mode DOS, Addison Wesley, NY, 1991.• William B. Giles, Assembly Language Programming for theIntel 80xxx Family, Macmillan, New York, 1991.xxviiiPreface


24594 Rev. 3.10 February 2005 AMD64 Technology• Frank van Gilluwe, The Undocumented PC, Addison-Wesley,New York, 1994.• John L. Hennessy <strong>and</strong> David A. Patterson, ComputerArchitecture, Morgan Kaufmann Publishers, San Mateo, CA,1996.• Thom Hogan, The Programmer’s PC Sourcebook, MicrosoftPress, Redmond, WA, 1991.• Hal Katircioglu, Inside the 486, Pentium, <strong>and</strong> Pentium Pro,Peer-to-Peer Communications, Menlo Park, CA, 1997.• IBM Corporation, 486SLC Microprocessor Data Sheet, IBMCorporation, Essex Junction, VT, 1993.• IBM Corporation, 486SLC2 Microprocessor Data Sheet, IBMCorporation, Essex Junction, VT, 1993.• IBM Corporation, 80486DX2 Processor Floating Point<strong>Instructions</strong>, 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, IBMCorporation, Essex Junction, VT, 1994.• Institute of Electrical <strong>and</strong> Electronics Engineers, IEEESt<strong>and</strong>ard for Binary Floating-Point Arithmetic, ANSI/IEEEStd 754-1985.• Institute of Electrical <strong>and</strong> Electronics Engineers, IEEESt<strong>and</strong>ard for Radix-Independent Floating-Point Arithmetic,ANSI/IEEE Std 854-1987.• Muhammad Ali Mazidi <strong>and</strong> Janice Gillispie Mazidi, 80X86IBM PC <strong>and</strong> Compatible Computers, Prentice-Hall, EnglewoodCliffs, NJ, 1997.• Hans-Peter Messmer, The Indispensable Pentium Book,Addison-Wesley, New York, 1995.• Karen Miller, An Assembly Language Introduction toComputer Architecture: Using the Intel Pentium, OxfordUniversity Press, New York, 1999.• Stephen Morse, Eric Isaacson, <strong>and</strong> Douglas Albert, The80386/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.Prefacexxix


AMD64 Technology 24594 Rev. 3.10 February 2005• Bipin Patwardhan, Introduction to the Streaming SIMDExtensions in the Pentium III, www.x86.org/articles/sse_pt1/simd1.htm, June, 2000.• Peter Norton, Peter Aitken, <strong>and</strong> Richard Wilton, PCProgrammer’s Bible, Microsoft Press, Redmond, WA, 1993.• PharLap 386|ASM Reference Manual, Pharlap, CambridgeMA, 1993.• PharLap TNT DOS-Extender Reference Manual, Pharlap,Cambridge MA, 1995.• Sen-Cuo Ro <strong>and</strong> Sheau-Chuen Her, i386/i486 AdvancedProgramming, Van Nostr<strong>and</strong> Reinhold, New York, 1993.• Jeffrey P. Royer, Introduction to Protected ModeProgramming, course materials for an onsite class, 1992.• Tom Shanley, Protected Mode <strong>System</strong> Architecture, AddisonWesley, NY, 1996.• SGS-Thomson Corporation, 80486DX Processor SMMProgramming Manual, SGS-Thomson Corporation, 1995.• Walter A. Triebel, The 80386DX Microprocessor, Prentice-Hall, Englewood Cliffs, NJ, 1992.• John Wharton, The Complete x86, MicroDesign Resources,Sebastopol, California, 1994.• Web sites <strong>and</strong> newsgroups:- www.amd.com- news.comp.arch- news.comp.lang.asm.x86- news.intel.microprocessors- news.microsoftxxxPreface


24594 Rev. 3.10 February 2005 AMD64 Technology1 Instruction FormatsThe format of an instruction encodes its operation, as well asthe locations of the instruction’s initial oper<strong>and</strong>s <strong>and</strong> the resultof the operation. This section describes the general format <strong>and</strong>parameters used by all instructions. For information on thespecific format(s) for each instruction, see:• Chapter 3, “<strong>General</strong>-<strong>Purpose</strong> Instruction Reference.”• Chapter 4, “<strong>System</strong> Instruction Reference.”• “128-Bit Media Instruction Reference” in <strong>Volume</strong> 4.• “64-Bit Media Instruction Reference” in <strong>Volume</strong> 5.• “x87 Floating-Point Instruction Reference” in <strong>Volume</strong> 5.1.1 Instruction Byte OrderAn instruction can be between one <strong>and</strong> 15 bytes in length.Figure 1-1 shows the byte order of the instruction format.LegacyPrefixREXPrefixOpcode(1 or 2 bytes) ModRM SIBDisplacement(1, 2, or 4 bytes)Immediate(1, 2, or 4 bytes)Instruction Length ≤ 15 BytesFigure 1-1.Instruction Byte-Order<strong>Instructions</strong> are stored in memory in little-endian order. Theleast-significant byte of an instruction is stored at its lowestmemory address, as shown in Figure 1-2 on page 2.Chapter 1: Instruction Formats 1


AMD64 Technology 24594 Rev. 3.10 February 2005£ 15 BytesMost-signifcant(highest) addressLeast-signifcant(lowest) address7 0Immediate *Immediate *Immediate *ImmediateDisplacement**Displacement *Displacement *DisplacementSIB**ModRM *Opcode *Opcode (all two-byte opcodes have 0Fh as their first byte)REX Prefix + (available only in 64-bit mode)Legacy PrefixLegacy Prefix++Legacy Prefix +* optional, depending on the instructionLegacy Prefix ++ optional, with most instructions513-304.epsFigure 1-2.Little-Endian Byte-Order of Instruction Stored in MemoryThe basic operation of an instruction is specified by an opcode.The opcode is one or two bytes long, as described in “Opcode”on page 20. An opcode can be preceded by any number of legacyprefixes. These prefixes can be classified as belonging to any ofthe five groups of prefixes described in “Instruction Prefixes”on page 3. The legacy prefixes modify an instruction’s defaultaddress size, oper<strong>and</strong> size, or segment, or they invoke a specialfunction such as modification of the opcode, atomic buslocking,or repetition. The REX prefix can be used in 64-bitmode to access the register extensions illustrated in“Application-Programming Register Set” in <strong>Volume</strong> 1. If a REXprefix is used, it must immediately precede the first opcodebyte.An instruction’s opcode consists of one or two bytes. In several128-bit <strong>and</strong> 64-bit media instructions, a legacy oper<strong>and</strong>-size orrepeat prefix byte is used in a special-purpose way to modifythe opcode. The opcode can be followed by a mode-registermemory(ModRM) byte, which further describes the operation2 Chapter 1: Instruction Formats


24594 Rev. 3.10 February 2005 AMD64 Technology<strong>and</strong>/or oper<strong>and</strong>s. The opcode, or the opcode <strong>and</strong> ModRM byte,can also be followed by a scale-index-base (SIB) byte, whichdescribes the scale, index, <strong>and</strong> base forms of memoryaddressing. The ModRM <strong>and</strong> SIB bytes are described in“ModRM <strong>and</strong> SIB Bytes” on page 20, but their legacy functionscan be modified by the REX prefix (“Instruction Prefixes” onpage 3).The 15-byte instruction-length limit can only be exceeded byusing redundant prefixes. If the limit is exceeded, a generalprotectionexception occurs.1.2 Instruction PrefixesThe instruction prefixes shown in Figure 1-1 on page 1 are oftwo types: legacy prefixes <strong>and</strong> REX prefixes. Each of the legacyprefixes has a unique byte value. By contrast, the REX prefixes,which enable use of the AMD64 register extensions in 64-bitmode, are organized as a group of byte values in which the valueof the prefix indicates the combination of register-extensionfeatures to be enabled.1.2.1 Summary ofLegacy PrefixesTable 1-1 on page 4 shows the legacy prefixes—that is, allprefixes except the REX prefixes, which are described onpage 14. The legacy prefixes are organized into five groups, asshown in the left-most column of Table 1-1. A single instructionshould include a maximum of one prefix from each of the fivegroups. The legacy prefixes can appear in any order within theposition shown in Figure 1-1 for legacy prefixes. The result ofusing multiple prefixes from a single group is unpredictable.Some of the restrictions on legacy prefixes are:• Oper<strong>and</strong>-Size Override—This prefix affects only generalpurposeinstructions <strong>and</strong> a few x87 instructions. When usedwith 128-bit <strong>and</strong> 64-bit media instructions, this prefix acts ina special way to modify the opcode.• Address-Size Override—This prefix affects only memoryoper<strong>and</strong>s.• Segment Override—In 64-bit mode, the CS, DS, ES, <strong>and</strong> SSsegment override prefixes are ignored.• LOCK Prefix—This prefix is allowed only with certaininstructions that modify memory.Chapter 1: Instruction Formats 3


AMD64 Technology 24594 Rev. 3.10 February 2005• Repeat Prefixes—These prefixes affect only certain stringinstructions. When used with 128-bit <strong>and</strong> 64-bit mediainstructions, these prefixes act in a special way to modify theopcode.Table 1-1.Legacy Instruction PrefixesPrefix Group 1MnemonicPrefix Byte(Hex)DescriptionOper<strong>and</strong>-Size Override none 66 2 Changes the default oper<strong>and</strong> size of a memory or registeroper<strong>and</strong>, as shown in Table 1-2 on page 5.Address-Size Override none 67 3 Changes the default address size of a memory oper<strong>and</strong>, asshown in Table 1-3 on page 7.CS 2E 4 Forces use of the current CS segment for memory oper<strong>and</strong>s.DS 3E 4 Forces use of the current DS segment for memory oper<strong>and</strong>s.Segment OverrideES 26 4 Forces use of the current ES segment for memory oper<strong>and</strong>s.FS 64 Forces use of the current FS segment for memory oper<strong>and</strong>s.GS 65 Forces use of the current GS segment for memory oper<strong>and</strong>s.SS 36 4 Forces use of the current SS segment for memory oper<strong>and</strong>s.Lock LOCK F0 5 Causes certain kinds of memory read-modify-writeinstructions to occur atomically.RepeatREPREPE orREPZF3 6Repeats a string operation (INS, MOVS, OUTS, LODS, <strong>and</strong>STOS) until the rCX register equals 0.Repeats a compare-string or scan-string operation(CMPSx <strong>and</strong> SCASx) until the rCX register equals 0 or thezero flag (ZF) is cleared to 0.REPNE orREPNZF2 6Repeats a compare-string or scan-string operation(CMPSx <strong>and</strong> SCASx) until the rCX register equals 0 or thezero flag (ZF) is set to 1.Note:1. A single instruction should include a maximum of one prefix from each of the five groups.2. When used with 128-bit <strong>and</strong> 64-bit media instructions, this prefix acts in a special way to modify the opcode. The prefix is ignoredby 64-bit media floating-point (3DNow!) instructions. See “<strong>Instructions</strong> that Cannot Use the Oper<strong>and</strong>-Size Prefix” on page 6.3. This prefix also changes the size of the RCX register when used as an implied count register.4. In 64-bit mode, the CS, DS, ES, <strong>and</strong> SS segment overrides are ignored.5. The LOCK prefix should not be used for instructions other than those listed in “Lock Prefix” on page 10.6. This prefix should be used only with compare-string <strong>and</strong> scan-string instructions. When used with 128-bit <strong>and</strong> 64-bit media instructions,the prefix acts in a special way to modify the opcode.4 Chapter 1: Instruction Formats


24594 Rev. 3.10 February 2005 AMD64 Technology1.2.2 Oper<strong>and</strong>-SizeOverride PrefixThe default oper<strong>and</strong> size for an instruction is determined by acombination of its opcode, the D (default) bit in the currentcode-segment descriptor, <strong>and</strong> the current operating mode, asshown in Table 1-2. The oper<strong>and</strong>-size override prefix (66h)selects the non-default oper<strong>and</strong> size. The prefix can be usedwith any general-purpose instruction that accesses non-fixedsizeoper<strong>and</strong>s in memory or general-purpose registers (GPRs),<strong>and</strong> it can also be used with the x87 FLDENV, FNSTENV,FNSAVE, <strong>and</strong> FRSTOR instructions.In 64-bit mode, the prefix allows mixing of 16-bit, 32-bit, <strong>and</strong> 64-bit data on an instruction-by-instruction basis. In compatibility<strong>and</strong> legacy modes, the prefix allows mixing of 16-bit <strong>and</strong> 32-bitoper<strong>and</strong>s on an instruction-by-instruction basis.Table 1-2.Oper<strong>and</strong>-Size OverridesLongModeOperating Mode64-BitModeCompatibilityModeLegacy Mode(Protected, Virtual-8086,or Real Mode)DefaultOper<strong>and</strong>Size (Bits)EffectiveOper<strong>and</strong>Size(Bits)Instruction Prefix 166h REX.W 332 2 32 no no64 don’t care yes3216321616 yes no32 no16 yes32 yes16 no32 no16 yes32 yes16 noNotApplicableNote:1. A “no’ indicates that the default oper<strong>and</strong> size is used.2. This is the typical default, although some instructions default to other oper<strong>and</strong> sizes. SeeAppendix B, “<strong>General</strong>-<strong>Purpose</strong> <strong>Instructions</strong> in 64-Bit Mode,” for details.3. See “REX Prefixes” on page 14.Chapter 1: Instruction Formats 5


AMD64 Technology 24594 Rev. 3.10 February 2005In 64-bit mode, most instructions default to a 32-bit oper<strong>and</strong>size. For these instructions, a REX prefix (page 16) can specifya 64-bit oper<strong>and</strong> size, <strong>and</strong> a 66h prefix specifies a 16-bit oper<strong>and</strong>size. The REX prefix takes precedence over the 66h prefix.However, if an instruction defaults to a 64-bit oper<strong>and</strong> size, itdoes not need a REX prefix <strong>and</strong> it can only be overridden to a16-bit oper<strong>and</strong> size. It cannot be overridden to a 32-bit oper<strong>and</strong>size, because there is no 32-bit oper<strong>and</strong>-size override prefix in64-bit mode. Two groups of instructions have a default 64-bitoper<strong>and</strong> size in 64-bit mode:• Near branches. For details, see “Near Branches in 64-BitMode” in <strong>Volume</strong> 1.• All instructions, except far branches, that implicitlyreference the RSP. For details, see “Stack Operation” in<strong>Volume</strong> 1.<strong>Instructions</strong> that Cannot Use the Oper<strong>and</strong>-Size Prefix. The oper<strong>and</strong>-sizeprefix should be used only with general-purpose instructions<strong>and</strong> the x87 FLDENV, FNSTENV, FNSAVE, <strong>and</strong> FRSTORinstructions, in which the prefix selects between 16-bit <strong>and</strong> 32-bit oper<strong>and</strong> size. The prefix is ignored by all other x87instructions <strong>and</strong> by 64-bit media floating-point (3DNow!)instructions.When used with 64-bit media integer instructions, the 66h prefixacts in a special way to modify the opcode. This modificationtypically causes an access to an XMM register or 128-bitmemory oper<strong>and</strong> <strong>and</strong> thereby converts the 64-bit mediainstruction into its comparable 128-bit media instruction. Theresult of using an F2h or F3h repeat prefix along with a 66hprefix in 128-bit or 64-bit media instructions is unpredictable.Oper<strong>and</strong>-Size <strong>and</strong> REX Prefixes. The REX oper<strong>and</strong>-size prefix takesprecedence over the 66h prefix. See “REX.W: Oper<strong>and</strong> Width”on page 16 for details.1.2.3 Address-SizeOverride PrefixThe default address size for instructions that access non-stackmemory is determined by the current operating mode, as shownin Table 1-3. The address-size override prefix (67h) selects thenon-default address size. Depending on the operating mode,this prefix allows mixing of 16-bit <strong>and</strong> 32-bit, or of 32-bit <strong>and</strong> 64-bit addresses, on an instruction-by-instruction basis. The prefixchanges the address size for memory oper<strong>and</strong>s. It also changes6 Chapter 1: Instruction Formats


24594 Rev. 3.10 February 2005 AMD64 Technologythe size of the RCX register for instructions that use RCXimplicitly.For instructions that implicitly access the stack segment (SS),the address size for stack accesses is determined by the D(default) bit in the stack-segment descriptor. In 64-bit mode,the D bit is ignored, <strong>and</strong> all stack references have a 64-bitaddress size. However, if an instruction accesses both stack <strong>and</strong>non-stack memory, the address size of the non-stack access isdetermined as shown in Table 1-3.Table 1-3.Address-Size OverridesLong ModeOperating Mode64-BitModeCompatibilityModeLegacy Mode(Protected, Virtual-8086, or RealMode)DefaultAddress Size(Bits)6432163216EffectiveAddress Size(Bits)Address-Size Prefix(67h) 1Required?64 no32 yes32 no16 yes32 yes16 no32 no16 yes32 yes16 noNote:1. A “no” indicates that the default address size is used.As Table 1-3 shows, the default address size is 64 bits in 64-bitmode. The size can be overridden to 32 bits, but 16-bitaddresses are not supported in 64-bit mode. In compatibility<strong>and</strong> legacy modes, the default address size is 16 bits or 32 bits,depending on the operating mode (see “Processor Initialization<strong>and</strong> Long-Mode Activation” in <strong>Volume</strong> 2 for details). In thesemodes, the address-size prefix selects the non-default size, butthe 64-bit address size is not available.Chapter 1: Instruction Formats 7


AMD64 Technology 24594 Rev. 3.10 February 2005Certain instructions reference pointer registers or countregisters implicitly, rather than explicitly. In such instructions,the address-size prefix affects the size of such addressing <strong>and</strong>count registers, just as it does when such registers are explicitlyreferenced. Table 1-4 lists all such instructions <strong>and</strong> the registersreferenced using the three possible address sizes.Table 1-4.Pointer <strong>and</strong> Count Registers <strong>and</strong> the Address-Size PrefixInstructionCMPS, CMPSB, CMPSW,CMPSD, CMPSQ—CompareStringsINS, INSB, INSW, INSD—InputStringJCXZ, JECXZ, JRCXZ—Jump onCX/ECX/RCX ZeroLODS, LODSB, LODSW,LODSD, LODSQ—Load StringLOOP, LOOPE, LOOPNZ,LOOPNE, LOOPZ—LoopMOVS, MOVSB, MOVSW,MOVSD, MOVSQ—Move StringOUTS, OUTSB, OUTSW,OUTSD—Output StringREP, REPE, REPNE, REPNZ,REPZ—Repeat PrefixesSCAS, SCASB, SCASW, SCASD,SCASQ—Scan StringSTOS, STOSB, STOSW, STOSD,STOSQ—Store StringXLAT, XLATB—Table Look-upTranslation16-BitAddress SizePointer or Count Register32-BitAddress Size64-BitAddress SizeSI, DI, CX ESI, EDI, ECX RSI, RDI, RCXDI, CX EDI, ECX RDI, RCXCX ECX RCXSI, CX ESI, ECX RSI, RCXCX ECX RCXSI, DI, CX ESI, EDI, ECX RSI, RDI, RCXSI, CX ESI, ECX RSI, RCXCX ECX RCXDI, CX EDI, ECX RDI, RCXDI, CX EDI, ECX RDI, RCXBX EBX RBX8 Chapter 1: Instruction Formats


24594 Rev. 3.10 February 2005 AMD64 Technology1.2.4 Segment-Override PrefixesSegment overrides can be used only with instructions thatreference non-stack memory. Most instructions that referencememory are encoded with a ModRM byte (page 20). The defaultsegment for such memory-referencing instructions is implied bythe base register indicated in its ModRM byte, as follows:• <strong>Instructions</strong> that Reference a Non-Stack Segment—If aninstruction encoding references any base register other thanrBP or rSP, or if an instruction contains an immediate offset,the default segment is the data segment (DS). Theseinstructions can use the segment-override prefix to selectone of the non-default segments, as shown in Table 1-5.• String <strong>Instructions</strong>—String instructions reference twomemory oper<strong>and</strong>s. By default, they reference both the DS<strong>and</strong> ES segments (DS:rSI <strong>and</strong> ES:rDI). These instructionscan override their DS-segment reference, as shown inTable 1-5, but they cannot override their ES-segmentreference.• <strong>Instructions</strong> that Reference the Stack Segment—If aninstruction’s encoding references the rBP or rSP baseregister, the default segment is the stack segment (SS). Allinstructions that reference the stack (push, pop, call,interrupt, return from interrupt) use SS by default. Theseinstructions cannot use the segment-override prefix.Table 1-5.MnemonicSegment-Override PrefixesPrefix Byte(Hex)DescriptionCS 1 2E Forces use of current CS segment for memory oper<strong>and</strong>s.DS 1 3E Forces use of current DS segment for memory oper<strong>and</strong>s.ES 1 26 Forces use of current ES segment for memory oper<strong>and</strong>s.FS 64 Forces use of current FS segment for memory oper<strong>and</strong>s.GS 65 Forces use of current GS segment for memory oper<strong>and</strong>s.SS 1 36 Forces use of current SS segment for memory oper<strong>and</strong>s.Note:1. In 64-bit mode, the CS, DS, ES, <strong>and</strong> SS segment overrides are ignored.Chapter 1: Instruction Formats 9


AMD64 Technology 24594 Rev. 3.10 February 2005Segment Overrides in 64-Bit Mode. In 64-bit mode, the CS, DS, ES,<strong>and</strong> SS segment-override prefixes have no effect. These fourprefixes are not treated as segment-override prefixes for thepurposes of multiple-prefix rules. Instead, they are treated asnull prefixes.The FS <strong>and</strong> GS segment-override prefixes are treated as truesegment-override prefixes in 64-bit mode. Use of the FS or GSprefix causes their respective segment bases to be added to theeffective address calculation. See “FS <strong>and</strong> GS Registers in 64-Bit Mode” in <strong>Volume</strong> 2 for details.1.2.5 Lock Prefix The LOCK prefix causes certain kinds of memory read-modifywriteinstructions to occur atomically. The mechanism for doingso is implementation-dependent (for example, the mechanismmay involve bus signaling or packet messaging between theprocessor <strong>and</strong> a memory controller). The prefix is intended togive the processor exclusive use of shared memory in amultiprocessor system.The LOCK prefix can only be used with forms of the followinginstructions that write a memory oper<strong>and</strong>: ADC, ADD, AND,BTC, BTR, BTS, CMPXCHG, CMPXCHG8B, DEC, INC, NEG,NOT, OR, SBB, SUB, XADD, XCHG, <strong>and</strong> XOR. An invalidopcodeexception occurs if the LOCK prefix is used with anyother instruction.1.2.6 Repeat Prefixes The repeat prefixes cause repetition of certain instructions thatload, store, move, input, or output strings. The prefixes shouldonly be used with such string instructions. Two pairs of repeatprefixes, REPE/REPZ <strong>and</strong> REPNE/REPNZ, perform the samerepeat functions for certain compare-string <strong>and</strong> scan-stringinstructions. The repeat function uses rCX as a count register.The size of rCX is based on address size, as shown in Table 1-4on page 8.REP. The REP prefix repeats its associated string instruction thenumber of times specified in the counter register (rCX). Itterminates the repetition when the value in rCX reaches 0. Theprefix can only be used with the INS, LODS, MOVS, OUTS, <strong>and</strong>STOS instructions. Table 1-6 shows the valid REP prefixopcodes.10 Chapter 1: Instruction Formats


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable 1-6.REP Prefix OpcodesMnemonicREP INS reg/mem8, DXREP INSBREP INS reg/mem16/32, DXREP INSWREP INSDREP LODS mem8REP LODSBREP LODS mem16/32/64REP LODSWREP LODSDREP LODSQREP MOVS mem8, mem8REP MOVSBREP MOVS mem16/32/64, mem16/32/64REP MOVSWREP MOVSDREP MOVSQREP OUTS DX, reg/mem8REP OUTSBREP OUTS DX, reg/mem16/32REP OUTSWREP OUTSDREP STOS mem8REP STOSBREP STOS mem16/32/64REP STOSWREP STOSDREP STOSQOpcodeF3 6CF3 6DF3 ACF3 ADF3 A4F3 A5F3 6EF3 6FF3 AAF3 ABREPE <strong>and</strong> REPZ. REPE <strong>and</strong> REPZ are synonyms <strong>and</strong> haveidentical opcodes. These prefixes repeat their associated stringinstruction the number of times specified in the counterChapter 1: Instruction Formats 11


AMD64 Technology 24594 Rev. 3.10 February 2005register (rCX). The repetition terminates when the value in rCXreaches 0 or when the zero flag (ZF) is cleared to 0. The REPE<strong>and</strong> REPZ prefixes can only be used with the CMPS, CMPSB,CMPSD, CMPSW, SCAS, SCASB, SCASD, <strong>and</strong> SCASWinstructions. Table 1-7 shows the valid REPE <strong>and</strong> REPZ prefixopcodes.Table 1-7.REPE <strong>and</strong> REPZ Prefix OpcodesMnemonicREPx CMPS mem8, mem8REPx CMPSBREPx CMPS mem16/32/64, mem16/32/64REPx CMPSWREPx CMPSDREPx CMPSQREPx SCAS mem8REPx SCASBREPx SCAS mem16/32/64REPx SCASWREPx SCASDREPx SCASQOpcodeF3 A6F3 A7F3 AEF3 AFREPNE <strong>and</strong> REPNZ. REPNE <strong>and</strong> REPNZ are synonyms <strong>and</strong> haveidentical opcodes. These prefixes repeat their associated stringinstruction the number of times specified in the counterregister (rCX). The repetition terminates when the value in rCXreaches 0 or when the zero flag (ZF) is set to 1. The REPNE <strong>and</strong>REPNZ prefixes can only be used with the CMPS, CMPSB,CMPSD, CMPSW, SCAS, SCASB, SCASD, <strong>and</strong> SCASWinstructions. Table 1-8 on page 13 shows the valid REPNE <strong>and</strong>REPNZ prefix opcodes.12 Chapter 1: Instruction Formats


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable 1-8.MnemonicREPNE <strong>and</strong> REPNZ Prefix OpcodesOpcodeREPNx CMPS mem8, mem8REPNx CMPSBREPNx CMPS mem16/32/64, mem16/32/64REPNx CMPSWREPNx CMPSDREPNx CMPSQREPNx SCAS mem8REPNx SCASBREPNx SCAS mem16/32/64REPNx SCASWREPNx SCASDREPNx SCASQF2 A6F2 A7F2 AEF2 AF<strong>Instructions</strong> that Cannot Use Repeat Prefixes. In general, the repeatprefixes should only be used in the string instructions listed intables 1-6, 1-7, <strong>and</strong> 1-8, <strong>and</strong> in 128-bit or 64-bit mediainstructions. When used in media instructions, the F2h <strong>and</strong> F3hprefixes act in a special way to modify the opcode rather thancause a repeat operation. The result of using a 66h oper<strong>and</strong>-sizeprefix along with an F2h or F3h prefix in 128-bit or 64-bit mediainstructions is unpredictable.Optimization of Repeats. Depending on the hardware implementation,the repeat prefixes can have a setup overhead. If therepeated count is variable, the overhead can sometimes beavoided by substituting a simple loop to move or store the data.Repeated string instructions can be exp<strong>and</strong>ed into equivalentsequences of inline loads <strong>and</strong> stores or a sequence of stores canbe used to emulate a REP STOS.For repeated string moves, performance can be maximized bymoving the largest possible oper<strong>and</strong> size. For example, use REPMOVSD rather than REP MOVSW <strong>and</strong> REP MOVSW ratherthan REP MOVSB. Use REP STOSD rather than REP STOSW<strong>and</strong> REP STOSW rather than REP MOVSB.Chapter 1: Instruction Formats 13


AMD64 Technology 24594 Rev. 3.10 February 2005Depending on the hardware implementation, string moves withthe direction flag (DF) cleared to 0 (up) may be faster thanstring moves with DF set to 1 (down). DF = 1 is only needed forcertain cases of overlapping REP MOVS, such as when thesource <strong>and</strong> the destination overlap.1.2.7 REX Prefixes REX prefixes are a group of instruction-prefix bytes that can beused only in 64-bit mode. They enable access to the AMD64register extensions. Figure 1-1 on page 1 <strong>and</strong> Figure 1-2 onpage 2 show how a REX prefix fits within the byte order ofinstructions. REX prefixes enable the following features in 64-bit mode:• Use of the extended GPR (Figure 2-3 on page 31) or XMMregisters (Figure 2-8 on page 36).• Use of the 64-bit oper<strong>and</strong> size when accessing GPRs.• Use of the extended control <strong>and</strong> debug registers, asdescribed in “64-Bit-Mode Extended Control Registers” in<strong>Volume</strong> 2 <strong>and</strong> “64-Bit-Mode Extended Debug Registers” in<strong>Volume</strong> 2.• Use of the uniform byte registers (AL–R15).Table 1-9 shows the REX prefixes. The value of a REX prefix isin the range 40h through 4Fh, depending on the particularcombination of AMD64 register extensions desired.Table 1-9.REX Instruction PrefixesPrefix TypeMnemonicPrefix Code(Hex)DescriptionRegister ExtensionsREX.WREX.RREX.XREX.B40 1through4F 1Access an AMD64 registerextension.Note:1. See Table 1-11 for encoding of REX prefixes.A REX prefix is normally required with an instruction thataccesses a 64-bit GPR or one of the extended GPR or XMMregisters. Only a few instructions have an oper<strong>and</strong> size thatdefaults to (or is fixed at) 64 bits in 64-bit mode, <strong>and</strong> thus do not14 Chapter 1: Instruction Formats


24594 Rev. 3.10 February 2005 AMD64 Technologyneed a REX prefix. These exceptions to the normal rule arelisted in Table 1-10.An instruction can have only one REX prefix, although theprefix can express several extension features. If a REX prefix isused, it must immediately precede the first opcode byte in theinstruction format. Any other placement of a REX prefix, or anyuse of a REX prefix in an instruction that does not access anextended register, is ignored. The legacy instruction-size limitof 15 bytes still applies to instructions that contain a REXprefix.Table 1-10.CALL (Near)ENTERJccJrCXZJMP (Near)LEAVELGDTLIDTLLDTLOOPLOOPccLTRMOV CR(n)<strong>Instructions</strong> Not Requiring REX Size Prefix in 64-Bit ModePOP reg/memPOP regPOP FSPOP GSPOPFQPUSH imm8PUSH imm32PUSH reg/memPUSH regPUSH FSPUSH GSPUSHFQRET (Near)MOV DR(n)Chapter 1: Instruction Formats 15


AMD64 Technology 24594 Rev. 3.10 February 2005REX prefixes are a set of sixteen values that span one row ofthe main opcode map <strong>and</strong> occupy entries 40h through 4Fh.Table 1-11 <strong>and</strong> Figure 1-3 on page 18 show the prefix fields <strong>and</strong>their uses.Table 1-11.REX Prefix-Byte FieldsMnemonic Bit Position Definition— 7–4 0100REX.W 3REX.R 2REX.X 1REX.B 00 = Default oper<strong>and</strong> size1 = 64-bit oper<strong>and</strong> size1-bit (high) extension of the ModRM reg field 1 ,thus permitting access to 16 registers.1-bit (high) extension of the SIB index field 1 ,thus permitting access to 16 registers.1-bit (high) extension of the ModRM r/m field 1 ,SIB base field 1 , or opcode reg field, thuspermitting access to 16 registers.Note:1. For a description of the ModRM <strong>and</strong> SIB bytes, see “ModRM <strong>and</strong> SIB Bytes” on page 20.REX.W: Oper<strong>and</strong> Width. Setting the REX.W bit to 1 specifies a 64-bit oper<strong>and</strong> size. Like the existing 66h oper<strong>and</strong>-size prefix, theREX 64-bit oper<strong>and</strong>-size override has no effect on byteoperations. For non-byte operations, the REX oper<strong>and</strong>-sizeoverride takes precedence over the 66h prefix. If a 66h prefix isused together with a REX prefix that has the REX.W bit set to1, the 66h prefix is ignored. However, if a 66h prefix is usedtogether with a REX prefix that has the REX.W bit cleared to 0,the 66h prefix is not ignored <strong>and</strong> the oper<strong>and</strong> size becomes16 bits.REX.R: Register. The REX.R bit adds a 1-bit (high) extension tothe ModRM reg field (page 20) when that field encodes a GPR,XMM, control, or debug register. REX.R does not modifyModRM reg when that field specifies other registers or opcodes.REX.R is ignored in such cases.REX.X: Index. The REX.X bit adds a 1-bit (high) extension to theSIB index field (page 20).16 Chapter 1: Instruction Formats


24594 Rev. 3.10 February 2005 AMD64 TechnologyREX.B: Base. The REX.B bit either adds a 1-bit (high) extensionto the base in the ModRM r/m field or SIB base field, or it adds a1-bit (high) extension to the opcode reg field used for accessingGPRs. (See Table 2-2 on page 47 for more about the REX.B bit.)Encoding Examples. Figure 1-3 on page 18 shows four examples ofhow the R, X, <strong>and</strong> B bits of REX prefixes are concatenated withfields from the ModRM byte, SIB byte, <strong>and</strong> opcode to specifyregister <strong>and</strong> memory addressing. The R, X, <strong>and</strong> B bits aredescribed in Table 1-11 on page 16.Byte-Register Addressing. In the legacy architecture, the byteregisters (AH, AL, BH, BL, CH, CL, DH, <strong>and</strong> DL, shown inFigure 2-2 on page 30) are encoded in the ModRM reg or r/mfield or in the opcode reg field as registers 0 through 7. The REXprefix provides an additional byte-register addressingcapability that makes the least-significant byte of any GPRavailable for byte operations (Figure 2-3 on page 31). Thisprovides a uniform set of byte, word, doubleword, <strong>and</strong>quadword registers better suited for register allocation bycompilers.Special Encodings for Registers. Readers who need to know thedetails of instruction encodings should be aware that certaincombinations of the ModRM <strong>and</strong> SIB fields have specialmeaning for register encodings. For some of thesecombinations, the instruction fields exp<strong>and</strong>ed by the REXprefix are not decoded (treated as don’t cares), thereby creatingaliases of these encodings in the extended registers. Table 1-12on page 19 describes how each of these cases behaves.Implications for INC <strong>and</strong> DEC <strong>Instructions</strong>. The REX prefix values aretaken from the 16 single-byte INC <strong>and</strong> DEC instructions, one foreach of the eight GPRs. Therefore, these single-byte opcodes forINC <strong>and</strong> DEC are not available in 64-bit mode, although theyare available in legacy <strong>and</strong> compatibility modes. Thefunctionality of these INC <strong>and</strong> DEC instructions is stillavailable in 64-bit mode, however, using the ModRM forms ofthose instructions (opcodes FF /0 <strong>and</strong> FF /1).Chapter 1: Instruction Formats 17


AMD64 Technology 24594 Rev. 3.10 February 2005Case 1: Register-Register Addressing (No Memory Oper<strong>and</strong>)ModRM ByteREX PrefixOpcode mod reg r/m4WRXB11 rrr bbbREX.X is not used44Rrrr BbbbCase 2: Memory Addressing Without an SIB ByteModRM ByteREX PrefixOpcode mod reg r/m4WRXB!11 rrr bbbREX.X is not usedModRM reg field != 1004Rrrr4BbbbCase 3: Memory Addressing With an SIB ByteModRM ByteREX PrefixOpcode mod reg r/m4WRXB!11 rrr 100SIB Bytescale index basebb xxx bbb4Rrrr4Xxxx4BbbbCase 4: Register Oper<strong>and</strong> Coded in Opcode ByteREX Prefix4WRXBOpcode Byteop regbbbREX.R is not usedREX.X is not used4Bbbb513-302.epsFigure 1-3.Encoding Examples of REX-Prefix R, X, <strong>and</strong> B Bits18 Chapter 1: Instruction Formats


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable 1-12.Special REX Encodings for RegistersModRM <strong>and</strong> SIBEncodings 2Meaning in Legacy <strong>and</strong>Compatibility ModesImplications in Legacy<strong>and</strong> Compatibility ModesAdditional REXImplicationsModRM Byte:• mod≠ 11• r/m 1 = 100 (ESP)SIB byte is present.SIB byte is required forESP-based addressing.REX prefix adds a fourth bit(b), which is decoded <strong>and</strong>modifies the base registerin the SIB byte. Therefore,the SIB byte is alsorequired for R12-basedaddressing.ModRM Byte:• mod =00• r/m 1 =x101 (EBP)Base register is not used.Using EBP without adisplacement must bedone by setting mod = 01with a displacement of 0(with or without an indexregister).REX prefix adds a fourth bit(x), which is not decoded(don’t care). Therefore,using RBP or R13 without adisplacement must bedone via mod = 01 with adisplacement of 0.SIB Byte:• index 1 = x100 (ESP)Index register is not used.ESP cannot be used as anindex register.REX prefix adds a fourth bit(x), which is decoded.Therefore, there are noadditional implications.The exp<strong>and</strong>ed index field isused to distinguish RSPfrom R12, allowing R12 tobe used as an index.SIB Byte:• base = b101 (EBP)• ModRM.mod = 00Base register is not used ifModRM.mod = 00.Base register depends onmod encoding. Using EBPwith a scaled index <strong>and</strong>without a displacementmust be done by settingmod = 01 with adisplacement of 0.REX prefix adds a fourth bit(b), which is not decoded(don’t care). Therefore,using RBP or R13 without adisplacement must bedone via mod = 01 with adisplacement of 0 (with orwithout an index register).Notes:1. The REX-prefix bit is shown in the fourth (most-significant) bit position of the encodings for the ModRM r/m, SIB index, <strong>and</strong> SIBbase fields. The lower-case “x” for ModRM r/m (rather than the upper-case “B” shown in Figure 1-3 on page 18) indicates thatthe REX-prefix bit is not decoded (don’t care).2. For a description of the ModRM <strong>and</strong> SIB bytes, see “ModRM <strong>and</strong> SIB Bytes” on page 20.Chapter 1: Instruction Formats 19


AMD64 Technology 24594 Rev. 3.10 February 20051.3 OpcodeEach instruction has a unique opcode, although assemblers cansupport multiple mnemonics for a single instruction opcode.The opcode specifies the operation that the instructionperforms <strong>and</strong>, in certain cases, the kinds of oper<strong>and</strong>s it uses. Anopcode consists of one or two bytes, but certain 128-bit mediainstructions also use a prefix byte in a special way to modify theopcode. The 3-bit reg field of the ModRM byte (“ModRM <strong>and</strong>SIB Bytes” on page 20) is also used in certain instructionseither for three additional opcode bits or for a registerspecification.128-Bit <strong>and</strong> 64-Bit Media Instruction Opcodes. Many 128-bit <strong>and</strong> 64-bitmedia instructions include a 66h, F2h, or F3h prefix byte in aspecial way to modify the opcode. These same byte values canbe used in certain general-purpose <strong>and</strong> x87 instructions tomodify oper<strong>and</strong> size (66h) or repeat the operation (F2h, F3h). In128-bit <strong>and</strong> 64-bit media instructions, however, such prefixbytes modify the opcode. If a 128-bit or 64-bit media instructionuses one of these three prefixes, <strong>and</strong> also includes any otherprefix in the 66h, F2h, <strong>and</strong> F3h group, the result isunpredictable.All opcodes for 64-bit media instructions begin with a 0Fh byte.In the case of 64-bit floating-point (3DNow!) instructions, the0Fh byte is followed by a second 0Fh opcode byte. A thirdopcode byte occupies the same position at the end of a 3DNow!instruction as would an immediate byte. The value of theimmediate byte is shown as the third opcode byte-value in thesyntax for each instruction in “64-Bit Media InstructionReference” in <strong>Volume</strong> 5. The format is:0Fh 0Fh ModRM [SIB] [displacement] 3DNow!_third_opcode_byteFor details on opcode encoding, see Appendix A, “Opcode <strong>and</strong>Oper<strong>and</strong> Encodings.”1.4 ModRM <strong>and</strong> SIB BytesThe ModRM byte is used in certain instruction encodings to:• Define a register reference.• Define a memory reference.20 Chapter 1: Instruction Formats


24594 Rev. 3.10 February 2005 AMD64 Technology• Provide additional opcode bits with which to define theinstruction’s function.ModRM bytes have three fields—mod, reg, <strong>and</strong> r/m. The reg fieldprovides additional opcode bits with which to define thefunction of the instruction or one of its oper<strong>and</strong>s. The mod <strong>and</strong>r/m fields are used together with each other <strong>and</strong>, in 64-bitmode, with the REX.R <strong>and</strong> REX.B bits of the REX prefix(page 14), to specify the location of an instruction’s oper<strong>and</strong>s<strong>and</strong> certain of the possible addressing modes (specifically, thenon-complex modes).Figure 1-4 shows the format of a ModRM byte.Bits:76543210modreg r/m ModRMREX.R bit of REX prefix canextend this field to 4 bitsREX.B bit of REX prefix canextend this field to 4 bits513-305.epsFigure 1-4.ModRM-Byte FormatIn some instructions, the ModRM byte is followed by an SIBbyte, which defines memory addressing for the complexaddressingmodes described in “Effective Addresses” in<strong>Volume</strong> 1. The SIB byte has three fields—scale, index, <strong>and</strong>base—that define the scale factor, index-register number, <strong>and</strong>base-register number for 32-bit <strong>and</strong> 64-bit complex addressingmodes. In 64-bit mode, the REX.B <strong>and</strong> REX.X bits extend theencoding of the SIB byte’s base <strong>and</strong> index fields.Figure 1-5 shows the format of an SIB byte.Chapter 1: Instruction Formats 21


AMD64 Technology 24594 Rev. 3.10 February 2005Bits:7 6 5 4 3 2 1 0scale index base SIBREX.X bit of REX prefix canextend this field to 4 bitsREX.B bit of REX prefix canextend this field to 4 bits513-306.epsFigure 1-5.SIB-Byte Format1.5 Displacement BytesThe encodings of ModRM <strong>and</strong> SIB bytes not only definememory-addressing modes, but they also specify oper<strong>and</strong>registers. The encodings do this by using 3-bit fields in theModRM <strong>and</strong> SIB bytes, depending on the format:• ModRM: the reg <strong>and</strong> r/m fields of the ModRM byte. (Case 1 inFigure 1-3 on page 18 shows an example of this).• ModRM with SIB: the reg field of the ModRM byte <strong>and</strong> thebase <strong>and</strong> index fields of the SIB byte. (Case 3 in Figure 1-3 onpage 18 shows an example of this).• <strong>Instructions</strong> without ModRM: the reg field of the opcode.(Case 4 in Figure 1-3 on page 18 shows an example of this).In 64-bit mode, the bits needed to extend each field foraccessing the additional registers are provided by the REXprefixes, as shown in Figure 1-4 <strong>and</strong> Figure 1-5.For details on opcode encoding, see Appendix A, “Opcode <strong>and</strong>Oper<strong>and</strong> Encodings.”A displacement (also called an offset) is a signed value that isadded to the base of a code segment (absolute addressing) or toan instruction pointer (relative addressing), depending on theaddressing mode. The size of a displacement is 1, 2, or 4 bytes. Ifan addressing mode requires a displacement, the bytes (1, 2, or4) for the displacement follow the opcode, ModRM, or SIB byte(whichever comes last) in the instruction encoding.22 Chapter 1: Instruction Formats


24594 Rev. 3.10 February 2005 AMD64 Technology1.6 Immediate Bytes1.7 RIP-Relative AddressingIn 64-bit mode, the same ModRM <strong>and</strong> SIB encodings are used tospecify displacement sizes as those used in legacy <strong>and</strong>compatibility modes. However, the displacement is signextendedto 64 bits during effective-address calculations. Also,in 64-bit mode, support is provided for some 64-bitdisplacement <strong>and</strong> immediate forms of the MOV instruction. See“Immediate Oper<strong>and</strong> Size” in <strong>Volume</strong> 1 for more informationon this.An immediate is a value—typically an oper<strong>and</strong> value—encodeddirectly into the instruction. Depending on the opcode <strong>and</strong> theoperating mode, the size of an immediate oper<strong>and</strong> can be 1, 2,or 4 bytes. Immediate oper<strong>and</strong>s in 64-bit mode are limited tothese same sizes. In 64-bit mode, support is provided for some64-bit displacement <strong>and</strong> immediate forms of the MOVinstruction. See “Immediate Oper<strong>and</strong> Size” in <strong>Volume</strong> 1 formore information on this.If an instruction takes an immediate oper<strong>and</strong>, the bytes (1, 2, or4) for the immediate follow the opcode, ModRM, SIB, ordisplacement bytes (whichever come last) in the instructionencoding. Some 128-bit media instructions use the immediatebyte as a condition code.In 64-bit mode, addressing relative to the contents of the 64-bitinstruction pointer (program counter)—called RIP-relativeaddressing or PC-relative addressing—is implemented forcertain instructions. In such cases, the effective address isformed by adding the displacement to the 64-bit RIP of the nextinstruction.In the legacy x86 architecture, addressing relative to theinstruction pointer is available only in control-transferinstructions. In the 64-bit mode, any instruction that usesModRM addressing can use RIP-relative addressing. Thisfeature is particularly useful for addressing data in positionindependentcode <strong>and</strong> for code that addresses global data.Without RIP-relative addressing, ModRM instructions addressmemory relative to zero. With RIP-relative addressing, ModRMChapter 1: Instruction Formats 23


AMD64 Technology 24594 Rev. 3.10 February 2005instructions can address memory relative to the 64-bit RIPusing a signed 32-bit displacement. This provides an offsetrange of ±2 Gbytes from the RIP.Programs usually have many references to data, especiallyglobal data, that are not register-based. To load such a program,the loader typically selects a location for the program inmemory <strong>and</strong> then adjusts program references to global databased on the load location. RIP-relative addressing of datamakes this adjustment unnecessary.1.7.1 Encoding Table 1-13 shows the ModRM <strong>and</strong> SIB encodings for RIPrelativeaddressing. Redundant forms of 32-bit displacementonlyaddressing exist in the current ModRM <strong>and</strong> SIB encodings.There is one ModRM encoding with several SIB encodings. RIPrelativeaddressing is encoded using one of the redundantforms. In 64-bit mode, the ModRM Disp32 (32-bit displacement)encoding is redefined to be RIP + Disp32 rather th<strong>and</strong>isplacement-only.Table 1-13.Encoding for RIP-Relative AddressingModRM <strong>and</strong> SIBEncodingsMeaning in Legacy <strong>and</strong>Compatibility ModesMeaning in 64-bit ModeAdditional 64-bitImplicationsModRM Byte:• mod= 00• r/m = 101 (none)Disp32RIP + Disp32Zero-based (normal)displacement addressingmust use SIB form (seenext row).SIB Byte:• base = 101 (none)• index = 100 (none)• scale = 1, 2, 4,8If mod = 00, Disp32 Same as Legacy None1.7.2 REX Prefix <strong>and</strong>RIP-RelativeAddressingModRM encoding for RIP-relative addressing does not dependon a REX prefix. In particular, the r/m encoding of 101, used toselect RIP-relative addressing, is not affected by the REXprefix. For example, selecting R13 (REX.B = 1, r/m = 101) withmod = 00 still results in RIP-relative addressing.The four-bit r/m field of ModRM is not fully decoded. Therefore,in order to address R13 with no displacement, software mustencode it as R13 + 0 using a one-byte displacement of zero.24 Chapter 1: Instruction Formats


24594 Rev. 3.10 February 2005 AMD64 Technology1.7.3 Address-SizePrefix <strong>and</strong> RIP-Relative AddressingRIP-relative addressing is enabled by 64-bit mode, not by a 64-bit address-size. Conversely, use of the address-size prefix(“Address-Size Override Prefix” on page 6) does not disableRIP-relative addressing. The effect of the address-size prefix isto truncate <strong>and</strong> zero-extend the computed effective address to32 bits, like any other addressing mode.Chapter 1: Instruction Formats 25


AMD64 Technology 24594 Rev. 3.10 February 200526 Chapter 1: Instruction Formats


24594 Rev. 3.10 February 2005 AMD64 Technology2 Instruction Overview2.1 Instruction SubsetsFor easier reference, the instruction descriptions are dividedinto five instruction subsets. The following sections describethe function, mnemonic syntax, opcodes, affected flags, <strong>and</strong>possible exceptions generated by all instructions in the AMD64architecture:• Chapter 3, “<strong>General</strong>-<strong>Purpose</strong> Instruction Reference”—Thegeneral-purpose instructions are used in basic softwareexecution. Most of these load, store, or operate on data inthe general-purpose registers (GPRs), in memory, or in both.Other instructions are used to alter sequential program flowby branching to other locations within the program or toentirely different programs.• Chapter 4, “<strong>System</strong> Instruction Reference”—The systeminstructions establish the processor operating mode, accessprocessor resources, h<strong>and</strong>le program <strong>and</strong> system errors, <strong>and</strong>manage memory.• “128-Bit Media Instruction Reference” in <strong>Volume</strong> 4—The 128-bit media instructions load, store, or operate on data locatedin the 128-bit XMM registers. These instructions define bothvector <strong>and</strong> scalar operations on floating-point <strong>and</strong> integerdata types. They include the SSE <strong>and</strong> SSE2 instructions thatoperate on the XMM registers. Some of these instructionsconvert source oper<strong>and</strong>s in XMM registers to destinationoper<strong>and</strong>s in GPR, MMX, or x87 registers or otherwise affectXMM state.• “64-Bit Media Instruction Reference” in <strong>Volume</strong> 5—The 64-bitmedia instructions load, store, or operate on data located inthe 64-bit MMX registers. These instructions define bothvector <strong>and</strong> scalar operations on integer <strong>and</strong> floating-pointdata types. They include the legacy MMX instructions, the3DNow! instructions, <strong>and</strong> the AMD extensions to the MMX<strong>and</strong> 3DNow! instruction sets. Some of these instructionsconvert source oper<strong>and</strong>s in MMX registers to destinationoper<strong>and</strong>s in GPR, XMM, or x87 registers or otherwise affectMMX state.Chapter 2: Instruction Overview 27


AMD64 Technology 24594 Rev. 3.10 February 20052.2 Reference-Page Format• “x87 Floating-Point Instruction Reference” in <strong>Volume</strong> 5—Thex87 instructions are used in legacy floating-pointapplications. Most of these instructions load, store, oroperate on data located in the x87 ST(0)–ST(7) stackregisters (the FPR0–FPR7 physical registers). Theremaining instructions within this category are used tomanage the x87 floating-point environment.The description of each instruction covers its behavior in alloperating modes, including legacy mode (real, virtual-8086, <strong>and</strong>protected modes) <strong>and</strong> long mode (compatibility <strong>and</strong> 64-bitmodes). Details of certain kinds of complex behavior—such ascontrol-flow changes in CALL, INT, or FXSAVE instructions—have cross-references in the instruction-detail pages to detaileddescriptions in volumes 1 <strong>and</strong> 2.Two instructions—CMPSD <strong>and</strong> MOVSD—use the samemnemonic for different instructions. Assemblers c<strong>and</strong>istinguish them on the basis of the number <strong>and</strong> type ofoper<strong>and</strong>s with which they are used.Figure 2-1 on page 29 shows the format of an instruction-detailpage. The instruction mnemonic is shown in bold at the top-left,along with its name. In this example, POPFD is the mnemonic<strong>and</strong> POP to EFLAGS Doubleword is the name. Next, there is ageneral description of the instruction’s operation. Manydescriptions have cross-references to more detail in other partsof the manual.Beneath the general description, the mnemonic is shown again,together with the related opcode(s) <strong>and</strong> a description summary.Related instructions are listed below this, followed by a tableshowing the flags that the instruction can affect. Finally, eachinstruction has a summary of the possible exceptions that canoccur when executing the instruction. The columns labeled“Real” <strong>and</strong> “Virtual-8086” apply only to execution in legacymode. The column labeled “Protected” applies both to legacymode <strong>and</strong> long mode, because long mode is a superset of legacyprotected mode.The 128-bit <strong>and</strong> 64-bit media instructions also have diagramsillustrating the operation. A few instructions have examples orpseudocode describing the action.28 Chapter 2: Instruction Overview


24594 Rev. 3.10 February 2005 AMD64 TechnologyMnemonic <strong>and</strong> any oper<strong>and</strong>s Opcode Description of operation24594 Rev. 3.07 September 2003 AMD64 TechnologyAAMASCII Adjust After MultiplyConverts the value in the AL register from binary to two unpacked BCD digits in theAH (most significant) <strong>and</strong> AL (least significant) registers using the following formula:AH = (AL/10d)AL = (AL mod 10d).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 theimmediate byte value (ib) suffixed onto the D4h opcode. For example, code D408h foroctal, D40Ah for decimal, <strong>and</strong> D40Ch for duodecimal (base 12).Using this instruction in 64-bit mode generates an invalid-opcode exception.Mnemonic Opcode DescriptionAAM D4 0A Create a pair of unpacked BCD values in AH <strong>and</strong> AL.(Invalid in 64-bit mode.)(None) D4 ib Create a pair of unpacked values to the immediate byte base.(Invalid in 64-bit mode.)Related <strong>Instructions</strong>AAA, AAD, AASrFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFU M M U M U21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M. Unaffected flags are blank. Undefined flags are U.ExceptionsException RealVirtual8086 Protected Cause of ExceptionDivide by zero, #DE X X X 8-bit immediate value was 0.Invalid opcode, #UD X This instruction was executed in 64-bit mode.“M” means the flag is either set orcleared, depending on the result.AAM 63Possible exceptions<strong>and</strong> causes, by modeof operation“Protected” columncovers both legacy<strong>and</strong> long modeAlphabetic mnemonic locatorFigure 2-1.Format of Instruction-Detail PagesChapter 2: Instruction Overview 29


AMD64 Technology 24594 Rev. 3.10 February 20052.3 Summary of Registers <strong>and</strong> Data TypesThis section summarizes the registers available to softwareusing the five instruction subsets described in “InstructionSubsets” on page 27. For details on the organization <strong>and</strong> use ofthese registers, see their respective chapters in volumes 1 <strong>and</strong> 2.2.3.1 <strong>General</strong>-<strong>Purpose</strong><strong>Instructions</strong>Registers. The size <strong>and</strong> number of general-purpose registers(GPRs) depends on the operating mode, as do the size of theflags <strong>and</strong> instruction-pointer registers. Figure 2-2 shows theregisters available in legacy <strong>and</strong> compatibility modes.registerencodinghigh8-bitlow8-bit16-bit32-bit0AH (4)ALAXEAX3BH (7)BLBXEBX1CH (5)CLCXECX2DH (6)DLDXEDX6SISIESI7DIDIEDI5BPBPEBP4SPSPESP31 16 15 0FLAGSIP31 0FLAGSIPEFLAGSEIP513-311.epsFigure 2-2.<strong>General</strong> Registers in Legacy <strong>and</strong> Compatibility ModesFigure 2-3 on page 31 shows the registers accessible in 64-bitmode. Compared with legacy mode, registers become 64 bitswide, eight new data registers (R8–R15) are added <strong>and</strong> the lowbyte of all 16 GPRs is available for byte operations, <strong>and</strong> the fourhigh-byte registers of legacy mode (AH, BH, CH, <strong>and</strong> DH) arenot available if the REX prefix is used. The high 32 bits of30 Chapter 2: Instruction Overview


24594 Rev. 3.10 February 2005 AMD64 Technologydoubleword oper<strong>and</strong>s are zero-extended to 64 bits, but the highbits of word <strong>and</strong> byte oper<strong>and</strong>s are not modified by operationsin 64-bit mode. The RFLAGS register is 64 bits wide, but thehigh 32 bits are reserved. They can be written with anything butthey read as zeros (RAZ).not modified for 8-bit oper<strong>and</strong>snot modified for 16-bit oper<strong>and</strong>sregisterencodingzero-extendedfor 32-bit oper<strong>and</strong>slow8-bit16-bit 32-bit 64-bit0AH*ALAXEAXRAX3BH*BLBXEBXRBX1CH*CLCXECXRCX2DH*DLDXEDXRDX6SIL**SIESIRSI7DIL**DIEDIRDI5BPL**BPEBPRBP4SPL**SPESPRSP8R8BR8WR8DR89R9BR9WR9DR910R10BR10WR10DR1011R11BR11WR11DR1112R12BR12WR12DR1213R13BR13WR13DR1314R14BR14WR14DR1415R15BR15WR15DR1563 32 31 16 15 8 7 0Figure 2-3.063 32 31 0<strong>General</strong> Registers in 64-Bit ModeRFLAGSRIP513-309.eps* Not addressable whena REX prefix is used.** Only addressable whena REX prefix is used.Chapter 2: Instruction Overview 31


AMD64 Technology 24594 Rev. 3.10 February 2005For most instructions running in 64-bit mode, access to theextended GPRs requires a REX instruction prefix (page 14).Figure 2-4 shows the segment registers which, like theinstruction pointer, are used by all instructions. In legacy <strong>and</strong>compatibility modes, all segments are accessible. In 64-bitmode, which uses the flat (non-segmented) memory model, onlythe CS, FS, <strong>and</strong> GS segments are recognized, whereas thecontents of the DS, ES, <strong>and</strong> SS segment registers are ignored(the base for each of these segments is assumed to be zero, <strong>and</strong>neither their segment limit nor attributes are checked). Fordetails, see “Segmented Virtual Memory” in <strong>Volume</strong> 2.Legacy Mode <strong>and</strong>Compatibility ModeCSDSESFSGSSS15 064-BitModeCS(Attributes only)ignoredignoredFS(Base only)GS(Base only)ignored15 0513-312.epsFigure 2-4.Segment RegistersData Types. Figure 2-5 on page 33 shows the general-purposedata types. They are all scalar, integer data types. The 64-bit(quadword) data types are only available in 64-bit mode, <strong>and</strong> formost instructions they require a REX instruction prefix.32 Chapter 2: Instruction Overview


24594 Rev. 3.10 February 2005 AMD64 Technology127sSigned Integer16 bytes (64-bit mode only)s8 bytes (64-bit mode only)0DoubleQuadwordQuadword63s4 bytesDoubleword31s2 bytesWord15sByte7 0Unsigned Integer12716 bytes (64-bit mode only)8 bytes (64-bit mode only)0DoubleQuadwordQuadword634 bytesDoubleword312 bytesWord15BytePacked BCDBCD Digit513-326.eps7 30BitFigure 2-5.2.3.2 <strong>System</strong><strong>Instructions</strong><strong>General</strong>-<strong>Purpose</strong> Data TypesRegisters. The system instructions use several specializedregisters shown in Figure 2-6 on page 34. <strong>System</strong> software usesthese registers to, among other things, manage the processor’soperating environment, define system resource characteristics,<strong>and</strong> monitor software execution. With the exception of theRFLAGS register, system registers can be read <strong>and</strong> written onlyfrom privileged software.All system registers are 64 bits wide, except for the descriptortableregisters <strong>and</strong> the task register, which include 64-bit baseaddressfields <strong>and</strong> other fields.Chapter 2: Instruction Overview 33


AMD64 Technology 24594 Rev. 3.10 February 2005Control RegistersCR0CR2CR3CR4CR8<strong>System</strong>-Flags RegisterRFLAGSDebug RegistersDR0DR1DR2DR3DR6DR7Descriptor-Table RegistersGDTRIDTRLDTRExtended-Feature-Enable RegisterEFER<strong>System</strong>-Configuration RegisterSYSCFG<strong>System</strong>-Linkage RegistersSTARLSTARCSTARSFMASKFS.baseGS.baseKernelGSbaseSYSENTER_CSSYSENTER_ESPSYSENTER_EIPDebug-Extension RegistersDebugCtlMSRLastBranchFromIPLastBranchToIPLastIntFromIPLastIntToIPMemory-Typing RegistersMTRRcapMTRRdefTypeMTRRphysBasenMTRRphysMasknMTRRfixnPATTOP_MEMTOP_MEM2Performance-Monitoring RegistersTSCPerfEvtSelnPerfCtrnMachine-Check RegistersMCG_CAPMCG_STATMCG_CTLMCi_CTLMCi_STATUSMCi_ADDRMCi_MISCTask RegisterTRModel-Specific Registers513-260.epsFigure 2-6.<strong>System</strong> RegistersData Structures. Figure 2-7 on page 35 shows the system datastructures. These are created <strong>and</strong> maintained by systemsoftware for use in protected mode. A processor running inprotected mode uses these data structures to manage memory<strong>and</strong> protection, <strong>and</strong> to store program-state information when aninterrupt or task switch occurs.34 Chapter 2: Instruction Overview


24594 Rev. 3.10 February 2005 AMD64 TechnologySegment Descriptors (Contained in Descriptor Tables)CodeGateTask-State SegmentStackDataTask-State SegmentLocal-Descriptor TableDescriptor TablesGlobal-Descriptor TableDescriptorDescriptor. . .DescriptorInterrupt-Descriptor TableGate DescriptorGate Descriptor. . .Gate DescriptorLocal-Descriptor TableDescriptorDescriptor. . .DescriptorPage-Translation TablesPage-Map Level-4Page-Directory PointerPage DirectoryPage Table513-261.epsFigure 2-7.<strong>System</strong> Data Structures2.3.3 128-Bit Media<strong>Instructions</strong>Registers. The 128-bit media instructions use the 128-bit XMMregisters. The number of available XMM data registers dependson the operating mode, as shown in Figure 2-8 on page 36. Inlegacy <strong>and</strong> compatibility modes, the eight legacy XMM dataregisters (XMM0–XMM7) are available. In 64-bit mode, eightadditional XMM data registers (XMM8–XMM15) are availablewhen a REX instruction prefix is used.The MXCSR register contains floating-point <strong>and</strong> other control<strong>and</strong> status flags used by the 128-bit media instructions. Some128-bit media instructions also use the GPR (Figure 2-2 <strong>and</strong>Chapter 2: Instruction Overview 35


AMD64 Technology 24594 Rev. 3.10 February 2005Figure 2-3) <strong>and</strong> the MMX registers (Figure 2-10 on page 38) orset or clear flags in the rFLAGS register (see Figure 2-2 <strong>and</strong>Figure 2-3).XMM Data Registers127 0xmm0xmm1xmm2xmm3xmm4xmm5xmm6xmm7xmm8xmm9xmm10xmm11xmm12xmm13xmm14xmm15Available in all modesAvailable only in 64-bit mode128-Bit Media Control <strong>and</strong> Status RegisterMXCSR31 0513-314.epsFigure 2-8.128-Bit Media RegistersData Types. Figure 2-9 on page 37 shows the 128-bit media datatypes. They include floating-point <strong>and</strong> integer vectors <strong>and</strong>floating-point scalars. The floating-point data types includeIEEE-754 single precision <strong>and</strong> double precision types.36 Chapter 2: Instruction Overview


24594 Rev. 3.10 February 2005 AMD64 Technology127 115sexpVector (Packed) Floating-Point Double Precision <strong>and</strong> Single Precisionsignific<strong>and</strong>63 51sexpsignific<strong>and</strong>0sexpsignific<strong>and</strong>sexpsignific<strong>and</strong>sexpsignific<strong>and</strong>sexpsignific<strong>and</strong>127 118 95 8663 5431 220Vector (Packed) Signed Integer Quadword, Doubleword, Word, Bytesquadwordsquadwordsdoublewordsdoublewordsdoublewordsdoublewordswordswordswordswordswordswordswordswordsbytesbytesbytesbytesbytesbytesbytesbytesbytesbytesbytesbytesbytesbytesbytesbyte127 119 111 103 95 87 79 71 63 55 47 39 31 23 15 7 0Vector (Packed) Unsigned Integer Quadword, Doubleword, Word, Bytequadwordquadworddoubleworddoubleworddoubleworddoublewordwordwordwordwordwordwordwordwordbytebytebytebytebytebytebytebytebytebytebytebytebytebytebytebyte127 119 111 103 95 87 79 71 63 55 47 39 31 23 15 7 0Scalar Floating-Point Double Precision <strong>and</strong> Single Precisionsexpsignific<strong>and</strong>63 51 sexpsignific<strong>and</strong>Scalar Unsigned Integers31 22 0double quadword127 0127quadword63doubleword31word15byte513-316.eps7bit0Figure 2-9.128-Bit Media Data TypesChapter 2: Instruction Overview 37


AMD64 Technology 24594 Rev. 3.10 February 20052.3.4 64-Bit Media<strong>Instructions</strong>Registers. The 64-bit media instructions use the eight 64-bitMMX registers, as shown in Figure 2-10. These registers aremapped onto the x87 floating-point registers, <strong>and</strong> 64-bit mediainstructions write the x87 tag word in a way that prevents anx87 instruction from using MMX data.Some 64-bit media instructions also use the GPR (Figure 2-2<strong>and</strong> Figure 2-3) <strong>and</strong> the XMM registers (Figure 2-8).MMX Data Registers63 0mmx0mmx1mmx2mmx3mmx4mmx5mmx6mmx7513-327.epsFigure 2-10.64-Bit Media RegistersData Types. Figure 2-11 on page 39 shows the 64-bit media datatypes. They include floating-point <strong>and</strong> integer vectors <strong>and</strong>integer scalars. The floating-point data type, used by 3DNow!instructions, consists of a packed vector or two IEEE-754 32-bitsingle-precision data types. Unlike other kinds of floating-pointinstructions, however, the 3DNow! instructions do notgenerate floating-point exceptions. For this reason, there is noregister for reporting or controlling the status of exceptions inthe 64-bit-media instruction subset.38 Chapter 2: Instruction Overview


24594 Rev. 3.10 February 2005 AMD64 TechnologyVector (Packed) Single-Precision Floating-Pointexpsignific<strong>and</strong>ss ssexpsignific<strong>and</strong>63 54 31 220Vector (Packed) Signed Integerssdoublewordsdoublewordswordswordswordswordsbytesbytesbytesbytesbytesbytesbytesbyte63 55 47 39 31 23 15 7 0Vector (Packed) Unsigned Integersdoubleworddoublewordwordwordwordwordbytebytebytebytebytebytebytebyte63 55 47 39 31 23 15 7 0Signed Integerss63quadwordsdoubleword31sword15sbyteUnsigned Integers7 0quadword63doubleword31word15byte7513-319.eps0Figure 2-11.64-Bit Media Data TypesChapter 2: Instruction Overview 39


AMD64 Technology 24594 Rev. 3.10 February 20052.3.5 x87 Floating-Point <strong>Instructions</strong>Registers. The x87 floating-point instructions use the x87registers shown in Figure 2-12. There are eight 80-bit dataregisters, three 16-bit registers that hold the x87 control word,status word, <strong>and</strong> tag word, <strong>and</strong> three registers (last instructionpointer, last opcode, last data pointer) that hold informationabout the last x87 operation.The physical data registers are named FPR0–FPR7, althoughx87 software references these registers as a stack of registers,named ST(0)–ST(7). The x87 instructions store oper<strong>and</strong>s only intheir own 80-bit floating-point registers or in memory. They donot access the GPR or XMM registers.x87 Data Registers79 0fpr0fpr1fpr2fpr3fpr4fpr5fpr6fpr7Instruction Pointer (rIP)Control WordData Pointer (rDP)Status Word63OpcodeTag Word100150513-321.epsFigure 2-12.x87 RegistersData Types. Figure 2-13 on page 41 shows all x87 data types. Theyinclude three floating-point formats (80-bit double-extendedprecision, 64-bit double precision, <strong>and</strong> 32-bit single precision),three signed-integer formats (quadword, doubleword, <strong>and</strong>40 Chapter 2: Instruction Overview


24594 Rev. 3.10 February 2005 AMD64 Technologyword), <strong>and</strong> an 80-bit packed binary-coded decimal (BCD)format.Floating-Point79s79exp63isexpsignific<strong>and</strong>signific<strong>and</strong>0Double-ExtendedPrecisionDouble Precision6351sexpsignific<strong>and</strong>Single Precision31220Signed Integers8 bytesQuadword63s4 bytesDoubleword31s2 bytesWord15 0Binary-Coded Decimal (BCD)s79 710Packed Decimal513-317.epsFigure 2-13.x87 Data Types2.4 Summary of ExceptionsTable 2-1 on page 42 lists all possible exceptions. The tableshows the interrupt-vector numbers, names, mnemonics,source, <strong>and</strong> possible causes. Exceptions that apply to specificinstructions are documented with each instruction in theinstruction-detail pages that follow.Chapter 2: Instruction Overview 41


AMD64 Technology 24594 Rev. 3.10 February 2005Table 2-1.Interrupt-Vector Source <strong>and</strong> CauseVector Interrupt (Exception) Mnemonic Source Cause0 Divide-By-Zero-Error #DE Software DIV, IDIV, AAM instructions1 Debug #DB Internal Instruction accesses <strong>and</strong> data accesses2 Non-Maskable-Interrupt #NMI External External NMI signal3 Breakpoint #BP Software INT3 instruction4 Overflow #OF Software INTO instruction5 Bound-Range #BR Software BOUND instruction6 Invalid-Opcode #UD Internal Invalid instructions7 Device-Not-Available #NM Internal x87 instructions8 Double-Fault #DF Internal Interrupt during an interrupt9 Coprocessor-Segment-Overrun — External Unsupported (reserved)10 Invalid-TSS #TS Internal Task-state segment access <strong>and</strong> task switch11 Segment-Not-Present #NP Internal Segment access through a descriptor12 Stack #SS Internal SS register loads <strong>and</strong> stack references13 <strong>General</strong>-Protection #GP Internal Memory accesses <strong>and</strong> protection checks14 Page-Fault #PF Internal Memory accesses when paging enabled15 Reserved —16 Floating-Point Exception-Pending #MF Softwarex87 floating-point <strong>and</strong> 64-bit mediafloating-point instructions17 Alignment-Check #AC Internal Memory accesses18 Machine-Check #MCInternalExternalModel specific19 SIMD Floating-Point #XF Internal 128-bit media floating-point instructions20—31 Reserved (Internal <strong>and</strong> External) —0—255 External Interrupts (Maskable) #INTR External External interrupt signal0—255 Software Interrupts — Software INTn instruction42 Chapter 2: Instruction Overview


24594 Rev. 3.10 February 2005 AMD64 Technology2.5 Notation2.5.1 MnemonicSyntaxEach instruction has a syntax that includes the mnemonic <strong>and</strong>any oper<strong>and</strong>s that the instruction can take. Figure 2-14 showsan example of a syntax in which the instruction takes twooper<strong>and</strong>s. In most instructions that take two oper<strong>and</strong>s, the first(left-most) oper<strong>and</strong> is both a source oper<strong>and</strong> (the first sourceoper<strong>and</strong>) <strong>and</strong> the destination oper<strong>and</strong>. The second (right-most)oper<strong>and</strong> serves only as a source, not a destination.ADDPD xmm1, xmm2/mem128MnemonicFirst Source Oper<strong>and</strong><strong>and</strong> Destination Oper<strong>and</strong>Second Source Oper<strong>and</strong>513-322.epsFigure 2-14.Syntax for Typical Two-Oper<strong>and</strong> InstructionThe following notation is used to denote the size <strong>and</strong> type ofsource <strong>and</strong> destination oper<strong>and</strong>s:• 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 oper<strong>and</strong> of unspecified size in memory.• mem8—Byte (8-bit) oper<strong>and</strong> in memory.• mem16—Word (16-bit) oper<strong>and</strong> in memory.• mem16/32—Word (16-bit) or doubleword (32-bit) oper<strong>and</strong> inmemory.• mem32—Doubleword (32-bit) oper<strong>and</strong> in memory.Chapter 2: Instruction Overview 43


AMD64 Technology 24594 Rev. 3.10 February 2005• mem32/48—Doubleword (32-bit) or 48-bit oper<strong>and</strong> inmemory.• mem48—48-bit oper<strong>and</strong> in memory.• mem64—Quadword (64-bit) oper<strong>and</strong> in memory.• mem128—Double quadword (128-bit) oper<strong>and</strong> in memory.• mem16:16—Two sequential word (16-bit) oper<strong>and</strong>s in memory.• mem16:32—A doubleword (32-bit) oper<strong>and</strong> followed by aword (16-bit) oper<strong>and</strong> in memory.• mem32real—Single-precision (32-bit) floating-point oper<strong>and</strong>in memory.• mem32int—Doubleword (32-bit) integer oper<strong>and</strong> in memory.• mem64real—Double-precision (64-bit) floating-point oper<strong>and</strong>in memory.• mem64int—Quadword (64-bit) integer oper<strong>and</strong> in memory.• mem80real—Double-extended-precision (80-bit) floatingpointoper<strong>and</strong> in memory.• mem80dec—80-bit packed BCD oper<strong>and</strong> in memory, containing18 4-bit BCD digits.• mem2env—16-bit x87 control word or x87 status word.• mem14/28env—14-byte or 28-byte x87 environment. The x87environment consists of the x87 control word, x87 statusword, x87 tag word, last non-control instruction pointer, lastdata pointer, <strong>and</strong> opcode of the last non-control instructioncompleted.• mem94/108env—94-byte or 108-byte x87 environment <strong>and</strong>register stack.• mem512env—512-byte environment for 128-bit media, 64-bitmedia, <strong>and</strong> x87 instructions.• mmx—Quadword (64-bit) oper<strong>and</strong> in an MMX register.• mmx1—Quadword (64-bit) oper<strong>and</strong> in an MMX register,specified as the left-most (first) oper<strong>and</strong> in the instructionsyntax.• mmx2—Quadword (64-bit) oper<strong>and</strong> in an MMX register,specified as the right-most (second) oper<strong>and</strong> in theinstruction syntax.• mmx/mem32—Doubleword (32-bit) oper<strong>and</strong> in an MMXregister or memory.44 Chapter 2: Instruction Overview


24594 Rev. 3.10 February 2005 AMD64 Technology• mmx/mem64—Quadword (64-bit) oper<strong>and</strong> in an MMXregister or memory.• mmx1/mem64—Quadword (64-bit) oper<strong>and</strong> in an MMXregister or memory, specified as the left-most (first) oper<strong>and</strong>in the instruction syntax.• mmx2/mem64—Quadword (64-bit) oper<strong>and</strong> in an MMXregister or memory, specified as the right-most (second)oper<strong>and</strong> in the instruction syntax.• moffset—Direct memory offset that specifies an oper<strong>and</strong> inmemory.• moffset8—Direct memory offset that specifies a byte (8-bit)oper<strong>and</strong> in memory.• moffset16—Direct memory offset that specifies a word (16-bit) oper<strong>and</strong> in memory.• moffset32—Direct memory offset that specifies adoubleword (32-bit) oper<strong>and</strong> in memory.• moffset64—Direct memory offset that specifies a quadword(64-bit) oper<strong>and</strong> in memory.• pntr16:16—Far pointer with 16-bit selector <strong>and</strong> 16-bit offset.• pntr16:32—Far pointer with 16-bit selector <strong>and</strong> 32-bit offset.• reg—Oper<strong>and</strong> of unspecified size in a GPR register.• reg8—Byte (8-bit) oper<strong>and</strong> in a GPR register.• reg16—Word (16-bit) oper<strong>and</strong> in a GPR register.• reg16/32—Word (16-bit) or doubleword (32-bit) oper<strong>and</strong> in aGPR register.• reg32—Doubleword (32-bit) oper<strong>and</strong> in a GPR register.• reg64—Quadword (64-bit) oper<strong>and</strong> in a GPR register.• reg/mem8—Byte (8-bit) oper<strong>and</strong> in a GPR register ormemory.• reg/mem16—Word (16-bit) oper<strong>and</strong> in a GPR register ormemory.• reg/mem32—Doubleword (32-bit) oper<strong>and</strong> in a GPR registeror memory.• reg/mem64—Quadword (64-bit) oper<strong>and</strong> in a GPR register ormemory.• rel8off—Signed 8-bit offset relative to the instructionpointer.Chapter 2: Instruction Overview 45


AMD64 Technology 24594 Rev. 3.10 February 2005• rel16off—Signed 16-bit offset relative to the instructionpointer.• rel32off—Signed 32-bit offset relative to the instructionpointer.• segReg or sReg—Word (16-bit) oper<strong>and</strong> in a segment register.• ST(0)—x87 stack register 0.• ST(i)—x87 stack register i, where i is between 0 <strong>and</strong> 7.• xmm—Double quadword (128-bit) oper<strong>and</strong> in an XMMregister.• xmm1—Double quadword (128-bit) oper<strong>and</strong> in an XMMregister, specified as the left-most (first) oper<strong>and</strong> in theinstruction syntax.• xmm2—Double quadword (128-bit) oper<strong>and</strong> in an XMMregister, specified as the right-most (second) oper<strong>and</strong> in theinstruction syntax.• xmm/mem64—Quadword (64-bit) oper<strong>and</strong> in a 128-bit XMMregister or memory.• xmm/mem128—Double quadword (128-bit) oper<strong>and</strong> in anXMM register or memory.• xmm1/mem128—Double quadword (128-bit) oper<strong>and</strong> in anXMM register or memory, specified as the left-most (first)oper<strong>and</strong> in the instruction syntax.• xmm2/mem128—Double quadword (128-bit) oper<strong>and</strong> in anXMM register or memory, specified as the right-most(second) oper<strong>and</strong> in the instruction syntax.2.5.2 Opcode Syntax In addition to the notation shown above in “Mnemonic Syntax”on page 43, the following notation indicates the size <strong>and</strong> type ofoper<strong>and</strong>s in the syntax of an instruction opcode:• /digit—Indicates that the ModRM byte specifies only oneregister or memory (r/m) oper<strong>and</strong>. The digit is specified bythe ModRM reg field <strong>and</strong> is used as an instruction-opcodeextension. Valid digit values range from 0 to 7.• /r—Indicates that the ModRM byte specifies both a registeroper<strong>and</strong> <strong>and</strong> a reg/mem (register or memory) oper<strong>and</strong>.• cb, cw, cd, cp—Specifies a code-offset value <strong>and</strong> possibly anew code-segment register value. The value following theopcode is either one byte (cb), two bytes (cw), four bytes(cd), or six bytes (cp).46 Chapter 2: Instruction Overview


24594 Rev. 3.10 February 2005 AMD64 Technology• ib, iw, id—Specifies an immediate-oper<strong>and</strong> value. Theopcode determines whether the value is signed or unsigned.The value following the opcode, ModRM, or SIB byte iseither one byte (ib), two bytes (iw), or four bytes (id). Word<strong>and</strong> doubleword values start with the low-order byte.• +rb, +rw, +rd, +rq—Specifies a register value that is added tothe hexadecimal byte on the left, forming a one-byte opcode.The result is an instruction that operates on the registerspecified by the register code. Valid register-code values areshown in Table 2-2.• m64—Specifies a quadword (64-bit) oper<strong>and</strong> in memory.• +i—Specifies an x87 floating-point stack oper<strong>and</strong>, ST(i). Thevalue is used only with x87 floating-point instructions. It isadded to the hexadecimal byte on the left, forming a onebyteopcode. Valid values range from 0 to 7.Table 2-2.+rb, +rw, +rd, <strong>and</strong> +rq Register ValueREX.BBit 1ValueSpecified Register+rb +rw +rd +rq0 AL AX EAX RAX1 CL CX ECX RCX0or no REXPrefix2 DL DX EDX RDX3 BL BX EBX RBX4 AH, SPL 1 SP ESP RSP5 CH, BPL 1 BP EBP RBP1. See “REX Prefixes” on page 14.6 DH, SIL 1 SI ESI RSI7 BH, DIL 1 DI EDI RDIChapter 2: Instruction Overview 47


AMD64 Technology 24594 Rev. 3.10 February 2005Table 2-2.REX.BBit 11+rb, +rw, +rd, <strong>and</strong> +rq Register Value (continued)Specified RegisterValue+rb +rw +rd +rq0 R8B R8W R8D R81 R9B R9W R9D R92 R10B R10W R10D R103 R11B R11W R11D R114 R12B R12W R12D R125 R13B R13W R13D R136 R14B R14W R14D R147 R15B R15W R15D R151. See “REX Prefixes” on page 14.48 Chapter 2: Instruction Overview


24594 Rev. 3.10 February 2005 AMD64 Technology2.5.3 PseudocodeDefinitionsPseudocode examples are given for the actions of severalcomplex instructions (for example, see “CALL (Near)” onpage 87). The following definitions apply to all suchpseudocode examples://///////////////////////////////////////////////////////////////////////////////// Basic Definitions/////////////////////////////////////////////////////////////////////////////////// All comments start with these double slashes.REAL_MODE = (cr0.pe=0)PROTECTED_MODE = ((cr0.pe=1) && (rflags.vm=0))VIRTUAL_MODE = ((cr0.pe=1) && (rflags.vm=1))LEGACY_MODE = (efer.lma=0)LONG_MODE = (efer.lma=1)64BIT_MODE = ((efer.lma=1) && (cs.L=1) && (cs.d=0))COMPATIBILITY_MODE = (efer.lma=1) && (cs.L=0)PAGING_ENABLED = (cr0.pg=1)ALIGNMENT_CHECK_ENABLED = ((cr0.am=1) && (eflags.ac=1) && (cpl=3))CPL = the current privilege level (0-3)OPERAND_SIZE = 16, 32, or 64 (depending on current code <strong>and</strong> 66h/rex prefixes)ADDRESS_SIZE = 16, 32, or 64 (depending on current code <strong>and</strong> 67h prefixes)STACK_SIZE = 16, 32, or 64 (depending on current code <strong>and</strong> SS.attr.B)old_RIPold_RSPold_RFLAGSold_CSold_DSold_ESold_FSold_GSold_SSRIPRSPRBPRFLAGSnext_RIPCSSSSRCDESTtemp_*= RIP at the start of current instruction= RSP at the start of current instruction= RFLAGS at the start of the instruction= CS selector at the start of current instruction= DS selector at the start of current instruction= ES selector at the start of current instruction= FS selector at the start of current instruction= GS selector at the start of current instruction= SS selector at the start of current instruction= the current RIP register= the current RSP register= the current RBP register= the current RFLAGS register= RIP at start of next instruction= the current CS descriptor, including the subfields:sel base limit attr= the current SS descriptor, including the subfields:sel base limit attr= the instruction’s Source oper<strong>and</strong>= the instruction’s Destination oper<strong>and</strong>// 64-bit temporary registerChapter 2: Instruction Overview 49


AMD64 Technology 24594 Rev. 3.10 February 2005temp_*_descNULL = 0x0000// temporary descriptor, with subfields:// if it points to a block of memory: sel base limit attr// if it’s a gate descriptor: sel offset segment attr// null selector is all zeros// V,Z,A,S are integer variables, assigned a value when an instruction begins// executing (they can be assigned a different value in the middle of an// instruction, if needed)V = 2 if OPERAND_SIZE=164 if OPERAND_SIZE=328 if OPERAND_SIZE=64Z = 2 if OPERAND_SIZE=164 if OPERAND_SIZE=324 if OPERAND_SIZE=64A = 2 if ADDRESS_SIZE=164 if ADDRESS_SIZE=328 if ADDRESS_SIZE=64S = 2 if STACK_SIZE=164 if STACK_SIZE=328 if STACK_SIZE=64/////////////////////////////////////////////////////////////////////////////////// Bit Range Inside a Register/////////////////////////////////////////////////////////////////////////////////temp_data.[X:Y]// Bit X through Y in temp_data, with the other bits// in the register masked off./////////////////////////////////////////////////////////////////////////////////// Moving Data From One Register To Another/////////////////////////////////////////////////////////////////////////////////temp_dest.b = temp_srctemp_dest.w = temp_srctemp_dest.d = temp_srctemp_dest.q = temp_srctemp_dest.v = temp_src// 1-byte move (copies lower 8 bits of temp_src to// temp_dest, preserving the upper 56 bits of temp_dest)// 2-byte move (copies lower 16 bits of temp_src to// temp_dest, preserving the upper 48 bits of temp_dest)// 4-byte move (copies lower 32 bits of temp_src to// temp_dest, <strong>and</strong> zeros out the upper 32 bits of temp_dest)// 8-byte move (copies all 64 bits of temp_src to// temp_dest)// 2-byte move if V=2,// 4-byte move if V=4,50 Chapter 2: Instruction Overview


24594 Rev. 3.10 February 2005 AMD64 Technology// 8-byte move if V=8temp_dest.z = temp_srctemp_dest.a = temp_srctemp_dest.s = temp_src// 2-byte move if Z=2,// 4-byte move if Z=4// 2-byte move if A=2,// 4-byte move if A=4,// 8-byte move if A=8// 2-byte move if S=2,// 4-byte move if S=4,// 8-byte move if S=8/////////////////////////////////////////////////////////////////////////////////// Bitwise Operations/////////////////////////////////////////////////////////////////////////////////temp = a AND btemp = a OR btemp = a XOR btemp = NOT atemp = a SHL btemp = a SHR b/////////////////////////////////////////////////////////////////////////////////// Logical Operations/////////////////////////////////////////////////////////////////////////////////IF (FOO && BAR)IF (FOO || BAR)IF (FOO = BAR)IF (FOO != BAR)IF (FOO > BAR)IF (FOO < BAR)IF (FOO >= BAR)IF (FOO


AMD64 Technology 24594 Rev. 3.10 February 2005ELSE...IF ((FOO && BAR) || (CONE && HEAD)).../////////////////////////////////////////////////////////////////////////////////// Exceptions/////////////////////////////////////////////////////////////////////////////////EXCEPTION [#GP(0)]EXCEPTION [#UD]// error code in parenthesis// if no error codepossible exception types:#DE // Divide-By-Zero-Error Exception (Vector 0)#DB // Debug Exception (Vector 1)#BP // INT3 Breakpoint Exception (Vector 3)#OF // INTO Overflow Exception (Vector 4)#BR // Bound-Range Exception (Vector 5)#UD // Invalid-Opcode Exception (Vector 6)#NM // Device-Not-Available Exception (Vector 7)#DF // Double-Fault Exception (Vector 8)#TS // Invalid-TSS Exception (Vector 10)#NP // Segment-Not-Present Exception (Vector 11)#SS // Stack Exception (Vector 12)#GP // <strong>General</strong>-Protection Exception (Vector 13)#PF // Page-Fault Exception (Vector 14)#MF // x87 Floating-Point Exception-Pending (Vector 16)#AC // Alignment-Check Exception (Vector 17)#MC // Machine-Check Exception (Vector 18)#XF // SIMD Floating-Point Exception (Vector 19)/////////////////////////////////////////////////////////////////////////////////// READ_MEM// <strong>General</strong> memory read. This zero-extends the data to 64 bits <strong>and</strong> returns it./////////////////////////////////////////////////////////////////////////////////usage:temp = READ_MEM.x [seg:offset] // where x is one of {v, z, b, w, d, q}// <strong>and</strong> denotes the size of the memory readdefinition:IF ((seg AND 0xFFFC) = NULL)EXCEPTION [#GP(0)]// GP fault for using a null segment to// reference memoryIF ((seg=CS) || (seg=DS) || (seg=ES) || (seg=FS) || (seg=GS))52 Chapter 2: Instruction Overview


24594 Rev. 3.10 February 2005 AMD64 Technology// CS,DS,ES,FS,GS check for segment limit or canonicalIF ((!64BIT_MODE) && (offset is outside seg’s limit))EXCEPTION [#GP(0)]// #GP fault for segment limit violation in non-64-bit modeIF ((64BIT_MODE) && (offset is non-canonical))EXCEPTION [#GP(0)]// #GP fault for non-canonical address in 64-bit modeELSIF (seg=SS) // SS checks for segment limit or canonicalIF ((!64BIT_MODE) && (offset is outside seg’s limit))EXCEPTION [#SS(0)]// stack fault for segment limit violation in non-64-bit modeIF ((64BIT_MODE) && (offset is non-canonical))EXCEPTION [#SS(0)]// stack fault for non-canonical address in 64-bit modeELSE // ((seg=GDT) || (seg=LDT) || (seg=IDT) || (seg=TSS))// GDT,LDT,IDT,TSS check for segment limit <strong>and</strong> canonicalIF (offset > seg.limit)EXCEPTION [#GP(0)] // #GP fault for segment limit violation// in all modesIF ((LONG_MODE) && (offset is non-canonical))EXCEPTION [#GP(0)] // #GP fault for non-canonical address in long modeIF ((ALIGNMENT_CHECK_ENABLED) && (offset misaligned, considering itssize <strong>and</strong> alignment))EXCEPTION [#AC(0)]IF ((64_bit_mode) && ((seg=CS) || (seg=DS) || (seg=ES) || (seg=SS))temp_linear = offsetELSEtemp_linear = seg.base + offsetIF ((PAGING_ENABLED) && (virtual-to-physical translation for temp_linearresults in a page-protection violation))EXCEPTION [#PF(error_code)] // page fault for page-protection violation// (U/S violation, Reserved bit violation)IF ((PAGING_ENABLED) && (temp_linear is on a not-present page))EXCEPTION [#PF(error_code)] // page fault for not-present pagetemp_data = memory [temp_linear].x // zero-extends the data to 64// bits, <strong>and</strong> saves it in temp_dataRETURN (temp_data)// return the zero-extended data/////////////////////////////////////////////////////////////////////////////////// WRITE_MEM // <strong>General</strong> memory write/////////////////////////////////////////////////////////////////////////////////usage:WRITE_MEM.x [seg:offset] = temp.x// where is one of these:Chapter 2: Instruction Overview 53


AMD64 Technology 24594 Rev. 3.10 February 2005definition:// {V, Z, B, W, D, Q} <strong>and</strong> denotes the// size of the memory writeIF ((seg & 0xFFFC)= NULL)EXCEPTION [#GP(0)]IF (seg isn’t writable)EXCEPTION [#GP(0)]// GP fault for using a null segment// to reference memory// GP fault for writing to a read-only segmentIF ((seg=CS) || (seg=DS) || (seg=ES) || (seg=FS) || (seg=GS))// CS,DS,ES,FS,GS check for segment limit or canonicalIF ((!64BIT_MODE) && (offset is outside seg’s limit))EXCEPTION [#GP(0)]// #GP fault for segment limit violation in non-64-bit modeIF ((64BIT_MODE) && (offset is non-canonical))EXCEPTION [#GP(0)]// #GP fault for non-canonical address in 64-bit modeELSIF (seg=SS) // SS checks for segment limit or canonicalIF ((!64BIT_MODE) && (offset is outside seg’s limit))EXCEPTION [#SS(0)]// stack fault for segment limit violation in non-64-bit modeIF ((64BIT_MODE) && (offset is non-canonical))EXCEPTION [#SS(0)]// stack fault for non-canonical address in 64-bit modeELSE // ((seg=GDT) || (seg=LDT) || (seg=IDT) || (seg=TSS))// GDT,LDT,IDT,TSS check for segment limit <strong>and</strong> canonicalIF (offset > seg.limit)EXCEPTION [#GP(0)]// #GP fault for segment limit violation in all modesIF ((LONG_MODE) && (offset is non-canonical))EXCEPTION [#GP(0)]// #GP fault for non-canonical address in long modeIF ((ALIGNMENT_CHECK_ENABLED) && (offset is misaligned, consideringits size <strong>and</strong> alignment))EXCEPTION [#AC(0)]IF ((64_bit_mode) && ((seg=CS) || (seg=DS) || (seg=ES) || (seg=SS))temp_linear = offsetELSEtemp_linear = seg.base + offsetIF ((PAGING_ENABLED) && (the virtual-to-physical translation fortemp_linear results in a page-protection violation)){EXCEPTION [#PF(error_code)]// page fault for page-protection violation// (U/S violation, Reserved bit violation)54 Chapter 2: Instruction Overview


24594 Rev. 3.10 February 2005 AMD64 Technology}IF ((PAGING_ENABLED) && (temp_linear is on a not-present page))EXCEPTION [#PF(error_code)] // page fault for not-present pagememory [temp_linear].x = temp.x// write the bytes to memory/////////////////////////////////////////////////////////////////////////////////// PUSH // Write data to the stack/////////////////////////////////////////////////////////////////////////////////usage:PUSH.x temp// where x is one of these: {v, z, b, w, d, q} <strong>and</strong>// denotes the size of the pushdefinition:WRITE_MEM.x [SS:RSP.s - X] = temp.xRSP.s = RSP - X// write to the stack// point rsp to the data just written/////////////////////////////////////////////////////////////////////////////////// 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} <strong>and</strong>// denotes the size of the popdefinition:temp = READ_MEM.x [SS:RSP.s]RSP.s = RSP + X// read from the stack// point rsp above the data just written/////////////////////////////////////////////////////////////////////////////////// READ_DESCRIPTOR // Read 8-byte descriptor from GDT/LDT, return the descriptor/////////////////////////////////////////////////////////////////////////////////usage:temp_descriptor = READ_DESCRIPTOR (selector, chktype)// chktype field is one of the following:// cs_chk used for far call <strong>and</strong> 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 <strong>and</strong> exceptionsdefinition:Chapter 2: Instruction Overview 55


AMD64 Technology 24594 Rev. 3.10 February 2005temp_offset = selector AND 0xfff8 // upper 13 bits give an offset// in the descriptor tableIF (selector.TI = 0)// read 8 bytes from the gdt, split it into// (base,limit,attr) if the type bitstemp_desc = READ_MEM.q [gdt:temp_offset]// indicate a block of memory, or split// it into (segment,offset,attr)// if the type bits indicate// a gate, <strong>and</strong> save the result in temp_descELSEtemp_desc = READ_MEM.q [ldt:temp_offset]// read 8 bytes from the ldt, split it into// (base,limit,attr) if the type bits// indicate a block of memory, or split// it into (segment,offset,attr) if the type// bits indicate a gate, <strong>and</strong> save the result// in temp_descIF (selector.rpl or temp_desc.attr.dpl is illegal for the current mode/cpl)EXCEPTION [#GP(selector)]IF (temp_desc.attr.type is illegal for the current mode/chktype)EXCEPTION [#GP(selector)]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 numberdefinition:IF (LONG_MODE) // long-mode idt descriptors are 16 bytes longtemp_offset = vector*16ELSE // (LEGACY_MODE) legacy-protected-mode idt descriptors are 8 bytes longtemp_offset = vector*8temp_desc = READ_MEM.q [idt:temp_offset]// read 8 bytes from the idt, split it into// (segment,offset,attr), <strong>and</strong> save it in temp_descIF (temp_desc.attr.dpl is illegal for the current mode/cpl)56 Chapter 2: Instruction Overview


24594 Rev. 3.10 February 2005 AMD64 Technology// exception, with error code that indicates this idt gateEXCEPTION [#GP(vector*8+2)]IF (temp_desc.attr.type is illegal for the current mode)// exception, with error code that indicates this idt gateEXCEPTION [#GP(vector*8+2)]IF (temp_desc.attr.p=0)EXCEPTION [#NP(vector*8+2)]// segment-not-present exception, with an error code that// indicates this idt gateRETURN (temp_desc)/////////////////////////////////////////////////////////////////////////////////// READ_INNER_LEVEL_STACK_POINTER// Read a new stack pointer (rsp or ss:esp) from the tss/////////////////////////////////////////////////////////////////////////////////usage:temp_SS_desc:temp_RSP = READ_INNER_LEVEL_STACK_POINTER (new_cpl, ist_index)definition:IF (LONG_MODE){IF (ist_index>0)// if IST is selected, read an ISTn stack pointer from the tsstemp_RSP = READ_MEM.q [tss:ist_index*8+28]ELSE // (ist_index=0)// otherwise read an RSPn stack pointer from the tsstemp_RSP = READ_MEM.q [tss:new_cpl*8+4]temp_SS_desc.sel = NULL + new_cpl// in long mode, changing to lower cpl sets SS.sel to// NULL+new_cpl}ELSE // (LEGACY_MODE){temp_RSP = READ_MEM.d [tss:new_cpl*8+4]// read ESPn from the tsstemp_sel = READ_MEM.d [tss:new_cpl*8+8]// read SSn from the tsstemp_SS_desc = READ_DESCRIPTOR (temp_sel, ss_chk)}return (temp_RSP:temp_SS_desc)/////////////////////////////////////////////////////////////////////////////////// READ_BIT_ARRAY // Read 1 bit from a bit array in memory/////////////////////////////////////////////////////////////////////////////////Chapter 2: Instruction Overview 57


AMD64 Technology 24594 Rev. 3.10 February 2005usage:temp_value = READ_BIT_ARRAY ([mem], bit_number)definition:temp_BYTE = READ_MEM.b [mem + (bit_number SHR 3)]// read the byte containing the bittemp_BIT = temp_BYTE SHR (bit_number & 7)// shift the requested bit position into bit 0return (temp_BIT & 0x01) // return ’0’ or ’1’58 Chapter 2: Instruction Overview


24594 Rev. 3.10 February 2005 AMD64 Technology3 <strong>General</strong>-<strong>Purpose</strong> Instruction ReferenceThis chapter describes the function, mnemonic syntax, opcodes,affected flags, <strong>and</strong> possible exceptions generated by thegeneral-purpose instructions. <strong>General</strong>-purpose instructions areused in basic software execution. Most of these instructionsload, store, or operate on data located in the general-purposeregisters (GPRs), in memory, or in both. The remaininginstructions are used to alter the sequential flow of the programby branching to other locations within the program, or toentirely different programs. With the exception of the MOVD,MOVMSKPD <strong>and</strong> MOVMSKPS instructions, which operate onMMX/XMM registers, the instructions within the category ofgeneral-purpose instructions do not operate on any otherregister set.Most general-purpose instructions are supported in allhardware implementations of the AMD64 architecture. Thefollowing general-purpose instructions are implemented only iftheir associated CPUID function bit is set:• CMPXCHG8B, indicated by bit 8 of CPUID st<strong>and</strong>ardfunction 1 <strong>and</strong> extended function 8000_0001h.• CMPXCHG16B, indicated by ECX bit 13 of CPUID st<strong>and</strong>ardfunction 1.• CMOVcc (conditional moves), indicated by bit 15 of CPUIDst<strong>and</strong>ard function 1 <strong>and</strong> extended function 8000_0001h.• CLFLUSH, indicated by bit 19 of CPUID st<strong>and</strong>ard function1.• PREFETCH, indicated by bit 31 of CPUID extendedfunction 8000_0001h.• MOVD, indicated by bits 25 (MMX) <strong>and</strong> 26 (XMM) ofCPUID st<strong>and</strong>ard function 1.• MOVNTI, indicated by bit 26 of CPUID st<strong>and</strong>ard function 1.• SFENCE, indicated by bit 25 of CPUID st<strong>and</strong>ard function 1.• MFENCE, LFENCE, indicated by bit 26 of CPUID st<strong>and</strong>ardfunction 1.• Long Mode instructions, indicated by bit 29 of CPUIDextended function 8000_0001h.The general-purpose instructions can be used in legacy mode or64-bit long mode. Compilation of general-purpose programs for59


AMD64 Technology 24594 Rev. 3.10 February 2005execution 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, <strong>and</strong> access to the RIP-relativeaddressing mode.For further information about the general-purpose instructions<strong>and</strong> register resources, see:• “<strong>General</strong>-<strong>Purpose</strong> Programming” in <strong>Volume</strong> 1.• “Summary of Registers <strong>and</strong> Data Types” on page 30.• “Notation” on page 43.• “Instruction Prefixes” on page 3.• Appendix B, “<strong>General</strong>-<strong>Purpose</strong> <strong>Instructions</strong> in 64-Bit Mode.”In particular, see “<strong>General</strong> Rules for 64-Bit Mode” onpage 413.60


24594 Rev. 3.10 February 2005 AMD64 TechnologyAAAASCII Adjust After AdditionAdjusts the value in the AL register to an unpacked BCD value. Use the AAAinstruction after using the ADD instruction to add two unpacked BCD numbers.If the value in the lower nibble of AL is greater than 9 or the AF flag is set to 1, theinstruction increments the AH register, adds 6 to the AL register, <strong>and</strong> sets the CF <strong>and</strong>AF flags to 1. Otherwise, it does not change the AH register <strong>and</strong> clears the CF <strong>and</strong> AFflags to 0. In either case, AAA clears bits 7–4 of the AL register, leaving the correctdecimal digit in bits 3–0.This instruction also makes it possible to add ASCII numbers without having to maskoff the upper nibble ‘3’.Using this instruction in 64-bit mode generates an invalid-opcode exception.Mnemonic Opcode DescriptionAAA 37Create an unpacked BCD number.(Invalid in 64-bit mode.)Related <strong>Instructions</strong>AAD, AAM, AASrFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFExceptionsU U U M U M21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.VirtualException Real 8086 Protected Cause of ExceptionInvalid opcode, #UD X This instruction was executed in 64-bit mode.AAA 61


AMD64 Technology 24594 Rev. 3.10 February 2005AADASCII Adjust Before DivisionConverts two unpacked BCD digits in the AL (least significant) <strong>and</strong> AH (mostsignificant) registers to a single binary value in the AL register using the followingformula:AL = ((10d * AH) + (AL))After the conversion, AH is cleared to 00h.In most modern assemblers, the AAD instruction adjusts from base-10 values.However, by coding the instruction directly in binary, it can adjust from any basespecified by the immediate byte value (ib) suffixed onto the D5h opcode. For example,code D508h for octal, D50Ah for decimal, <strong>and</strong> D50Ch for duodecimal (base 12).Using this instruction in 64-bit mode generates an invalid-opcode exception.Mnemonic Opcode DescriptionAAD(None)Related <strong>Instructions</strong>AAA, AAM, AASrFLAGS AffectedD5 0AD5 ibAdjust two BCD digits in AL <strong>and</strong> AH.(Invalid in 64-bit mode.)Adjust two BCD digits to the immediate byte base.(Invalid in 64-bit mode.)ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFExceptionsU M M U M U21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.VirtualException Real 8086 Protected Cause of ExceptionInvalid opcode, #UD X This instruction was executed in 64-bit mode.62 AAD


24594 Rev. 3.10 February 2005 AMD64 TechnologyAAMASCII Adjust After MultiplyConverts the value in the AL register from binary to two unpacked BCD digits in theAH (most significant) <strong>and</strong> AL (least significant) registers using the following formula:AH = (AL/10d)AL = (AL mod 10d).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 theimmediate byte value (ib) suffixed onto the D4h opcode. For example, code D408h foroctal, D40Ah for decimal, <strong>and</strong> D40Ch for duodecimal (base 12).Using this instruction in 64-bit mode generates an invalid-opcode exception.Mnemonic Opcode DescriptionAAM(None)Related <strong>Instructions</strong>AAA, AAD, AASrFLAGS AffectedD4 0AD4 ibCreate a pair of unpacked BCD values in AH <strong>and</strong> AL.(Invalid in 64-bit mode.)Create a pair of unpacked values to the immediate byte base.(Invalid in 64-bit mode.)ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFExceptionsU M M U M U21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M. Unaffected flags are blank. Undefined flags are U.Exception RealVirtual8086 Protected Cause of ExceptionDivide 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


AMD64 Technology 24594 Rev. 3.10 February 2005AASASCII Adjust After SubtractionAdjusts the value in the AL register to an unpacked BCD value. Use the AASinstruction after using the SUB instruction to subtract two unpacked BCD numbers.If the value in AL is greater than 9 or the AF flag is set to 1, the instructiondecrements the value in AH, subtracts 6 from the AL register, <strong>and</strong> sets the CF <strong>and</strong> AFflags to 1. Otherwise, it clears the CF <strong>and</strong> AF flags <strong>and</strong> the AH register is unchanged.In either case, the instruction clears bits 7–4 of the AL register, leaving the correctdecimal digit in bits 3–0.Using this instruction in 64-bit mode generates an invalid-opcode exception.Mnemonic Opcode DescriptionAASRelated <strong>Instructions</strong>AAA, AAD, AAMrFLAGS Affected3FCreate an unpacked BCD number from the contents of the ALregister.(Invalid in 64-bit mode.)ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFExceptionsU U U M U M21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.VirtualException Real 8086 Protected Cause of ExceptionInvalid opcode, #UD X This instruction was executed in 64-bit mode.64 AAS


24594 Rev. 3.10 February 2005 AMD64 TechnologyADCAdd with CarryAdds the carry flag (CF), the value in a register or memory location (first oper<strong>and</strong>),<strong>and</strong> an immediate value or the value in a register a memory location (secondoper<strong>and</strong>), <strong>and</strong> stores the result in the first oper<strong>and</strong> location. The instruction cannotadd two memory oper<strong>and</strong>s. The CF flag indicates a pending carry from a previousaddition operation. The instruction sign-extends an immediate value to the length ofthe destination register or memory location.This instruction evaluates the result for both signed <strong>and</strong> unsigned data types <strong>and</strong> setsthe OF <strong>and</strong> CF flags to indicate a carry in a signed or unsigned result, respectively. Itsets the SF flag to indicate the sign of a signed result.Use the ADC instruction after an ADD instruction as part of a multibyte or multiwordaddition.The forms of the ADC instruction that write to memory support the LOCK prefix. Fordetails about the LOCK prefix, see “Lock Prefix” on page 10.Mnemonic Opcode DescriptionADC AL, imm8 14 ib Add imm8 to AL + CF.ADC AX, imm16 15 iw Add imm16 to AX + CF.ADC EAX, imm32 15 id Add imm32 to EAX + CF.ADC RAX, imm32 15 id Add sign-extended imm32 to RAX + CF.ADC reg/mem8, imm8 80 /2 ib Add imm8 to reg/mem8 + CF.ADC reg/mem16, imm16 81 /2 iw Add imm16 to reg/mem16 + CF.ADC reg/mem32, imm32 81 /2 id Add imm32 to reg/mem32 + CF.ADC reg/mem64, imm32 81 /2 id Add sign-extended imm32 to reg/mem64 + CF.ADC reg/mem16, imm8 83 /2 ib Add sign-extended imm8 to reg/mem16 + CF.ADC reg/mem32, imm8 83 /2 ib Add sign-extended imm8 to reg/mem32 + CF.ADC reg/mem64, imm8 83 /2 ib Add sign-extended imm8 to reg/mem64 + CF.ADC reg/mem8, reg8 10 /r Add reg8 to reg/mem8 + CFADC reg/mem16, reg16 11 /r Add reg16 to reg/mem16 + CF.ADC reg/mem32, reg32 11 /r Add reg32 to reg/mem32 + CF.ADC 65


AMD64 Technology 24594 Rev. 3.10 February 2005Mnemonic Opcode DescriptionADC reg/mem64, reg64 11 /r Add reg64 to reg/mem64 + CF.ADC reg8, reg/mem8 12 /r Add reg/mem8 to reg8 + CF.ADC reg16, reg/mem16 13 /r Add reg/mem16 to reg16 + CF.ADC reg32, reg/mem32 13 /r Add reg/mem32 to reg32 + CF.ADC reg64, reg/mem64 13 /r Add reg/mem64 to reg64 + CF.Related <strong>Instructions</strong>ADD, SBB, SUBrFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFExceptionsM M M M M M21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.Exception RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded a data segment limit or was non-canonical.XThe destination oper<strong>and</strong> 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, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.66 ADC


24594 Rev. 3.10 February 2005 AMD64 TechnologyADDSigned or Unsigned AddAdds the value in a register or memory location (first oper<strong>and</strong>) <strong>and</strong> an immediatevalue or the value in a register a memory location (second oper<strong>and</strong>), <strong>and</strong> stores theresult in the first oper<strong>and</strong> location. The instruction cannot add two memory oper<strong>and</strong>s.The instruction sign-extends an immediate value to the length of the destinationregister or memory oper<strong>and</strong>.This instruction evaluates the result for both signed <strong>and</strong> unsigned data types <strong>and</strong> setsthe OF <strong>and</strong> CF flags to indicate a carry in a signed or unsigned result, respectively. Itsets the SF flag to indicate the sign of a signed result.The forms of the ADD instruction that write to memory support the LOCK prefix. Fordetails about the LOCK prefix, see “Lock Prefix” on page 10.Mnemonic Opcode DescriptionADD AL, imm8 04 ib Add imm8 to AL.ADD AX, imm16 05 iw Add imm16 to AX.ADD EAX, imm32 05 id Add imm32 to EAX.ADD RAX, imm32 05 id Add sign-extended imm32 to RAX.ADD reg/mem8, imm8 80 /0 ib Add imm8 to reg/mem8.ADD reg/mem16, imm16 81 /0 iw Add imm16 to reg/mem16ADD reg/mem32, imm32 81 /0 id Add imm32 to reg/mem32.ADD reg/mem64, imm32 81 /0 id Add sign-extended imm32 to reg/mem64.ADD reg/mem16, imm8 83 /0 ib Add sign-extended imm8 to reg/mem16ADD reg/mem32, imm8 83 /0 ib Add sign-extended imm8 to reg/mem32.ADD reg/mem64, imm8 83 /0 ib Add sign-extended imm8 to reg/mem64.ADD reg/mem8, reg8 00 /r Add reg8 to reg/mem8.ADD reg/mem16, reg16 01 /r Add reg16 to reg/mem16.ADD reg/mem32, reg32 01 /r Add reg32 to reg/mem32.ADD reg/mem64, reg64 01 /r Add reg64 to reg/mem64.ADD reg8, reg/mem8 02 /r Add reg/mem8 to reg8.ADD 67


AMD64 Technology 24594 Rev. 3.10 February 2005Mnemonic Opcode DescriptionADD reg16, reg/mem16 03 /r Add reg/mem16 to reg16.ADD reg32, reg/mem32 03 /r Add reg/mem32 to reg32.ADD reg64, reg/mem64 03 /r Add reg/mem64 to reg64.Related <strong>Instructions</strong>ADC, SBB, SUBrFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFExceptionsM M M M M M21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.Exception RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded a data segment limit or was non-canonical.XThe destination oper<strong>and</strong> 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, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.68 ADD


24594 Rev. 3.10 February 2005 AMD64 TechnologyANDLogical ANDPerforms a bitwise AND operation on the value in a register or memory location (firstoper<strong>and</strong>) <strong>and</strong> an immediate value or the value in a register or memory location(second oper<strong>and</strong>), <strong>and</strong> stores the result in the first oper<strong>and</strong> location. The instructioncannot AND two memory oper<strong>and</strong>s.The instruction sets each bit of the result to 1 if the corresponding bit of bothoper<strong>and</strong>s is set; otherwise, it clears the bit to 0. The following table shows the truthtable for the AND operation:X Y X AND Y0 0 00 1 01 0 01 1 1The forms of the AND instruction that write to memory support the LOCK prefix. Fordetails about the LOCK prefix, see “Lock Prefix” on page 10.Mnemonic Opcode DescriptionAND AL, imm8AND AX, imm16AND EAX, imm32AND RAX, imm3224 ib25 iw25 id25 idAND the contents of AL with an immediate 8-bit value <strong>and</strong> storethe result in AL.AND the contents of AX with an immediate 16-bit value <strong>and</strong> storethe result in AX.AND the contents of EAX with an immediate 32-bit value <strong>and</strong>store the result in EAX.AND the contents of RAX with a sign-extended immediate 32-bitvalue <strong>and</strong> 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 69


AMD64 Technology 24594 Rev. 3.10 February 2005Mnemonic Opcode DescriptionAND reg/mem16, imm883 /4 ibAND reg/mem32, imm883 /4 ibAND reg/mem64, imm883 /4 ibAND reg/mem8, reg8 20 /rAND reg/mem16, reg16 21 /rAND reg/mem32, reg32 21 /rAND reg/mem64, reg64 21 /rAND reg8, reg/mem8 22 /rAND reg16, reg/mem16 23 /rAND reg32, reg/mem32 23 /rAND reg64, reg/mem64 23 /rAND the contents of reg/mem16 with a sign-extended 8-bitvalue.AND the contents of reg/mem32 with a sign-extended 8-bitvalue.AND the contents of reg/mem64 with a sign-extended 8-bitvalue.AND the contents of an 8-bit register or memory location withthe contents of an 8-bit register.AND the contents of a 16-bit register or memory location with thecontents of a 16-bit register.AND the contents of a 32-bit register or memory location withthe contents of a 32-bit register.AND the contents of a 64-bit register or memory location withthe contents of a 64-bit register.AND the contents of an 8-bit register with the contents of an 8-bitmemory location or register.AND the contents of a 16-bit register with the contents of a 16-bitmemory location or register.AND the contents of a 32-bit register with the contents of a 32-bitmemory location or register.AND the contents of a 64-bit register with the contents of a 64-bitmemory location or register.Related <strong>Instructions</strong>TEST, OR, NOT, NEG, XOR70 AND


24594 Rev. 3.10 February 2005 AMD64 TechnologyrFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFExceptions0 M M U M 021 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.Exception RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded a data segment limit or was non-canonical.XThe destination oper<strong>and</strong> 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, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.AND 71


AMD64 Technology 24594 Rev. 3.10 February 2005BOUNDCheck Array BoundsChecks whether an array index (first oper<strong>and</strong>) is within the bounds of an array(second oper<strong>and</strong>). The array index is a signed integer in the specified register. If theoper<strong>and</strong>-size attribute is 16, the array oper<strong>and</strong> is a memory location containing a pairof signed word-integers; if the oper<strong>and</strong>-size attribute is 32, the array oper<strong>and</strong> is a pairof signed doubleword-integers. The first word or doubleword specifies the lowerbound of the array <strong>and</strong> the second word or doubleword specifies the upper bound.The array index must be greater than or equal to the lower bound <strong>and</strong> less than orequal to the upper bound. If the index is not within the specified bounds, theprocessor generates a BOUND range-exceeded exception (#BR).The bounds of an array, consisting of two words or doublewords containing the lower<strong>and</strong> upper limits of the array, usually reside in a data structure just before the arrayitself, making the limits addressable through a constant offset from the beginning ofthe array. With the address of the array in a register, this practice reduces the numberof bus cycles required to determine the effective address of the array bounds.Using this instruction in 64-bit mode generates an invalid-opcode exception.Mnemonic Opcode DescriptionBOUND reg16, mem16&mem16 62 /rBOUND reg32, mem32&mem32 62 /rTest whether a 16-bit array index is within the bounds specifiedby the two 16-bit values in mem16&mem16.(Invalid in 64-bit mode.)Test whether a 32-bit array index is within the bounds specifiedby the two 32-bit values in mem32&mem32.(Invalid in 64-bit mode.)Related <strong>Instructions</strong>INT, INT3, INTOrFLAGS AffectedNone72 BOUND


24594 Rev. 3.10 February 2005 AMD64 TechnologyExceptionsException RealVirtual8086 Protected Cause of ExceptionBound range, #BR X X X The bound range was exceeded.Invalid opcode, #UD X X X The source oper<strong>and</strong> was a register.X Instruction was executed in 64-bit mode.Stack, #SS X X X A memory address exceeded the stack segment limit<strong>General</strong> protection, X X X A memory address exceeded a data segment limit.#GPX 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, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.BOUND 73


AMD64 Technology 24594 Rev. 3.10 February 2005BSFBit Scan ForwardSearches the value in a register or a memory location (second oper<strong>and</strong>) for the leastsignificantset bit. If a set bit is found, the instruction clears the zero flag (ZF) <strong>and</strong>stores the index of the least-significant set bit in a destination register (first oper<strong>and</strong>).If the second oper<strong>and</strong> contains 0, the instruction sets ZF to 1 <strong>and</strong> does not change thecontents of the destination register. The bit index is an unsigned offset from bit 0 ofthe searched value.Mnemonic Opcode DescriptionBSF reg16, reg/mem16 0F BC /r Bit scan forward on the contents of reg/mem16.BSF reg32, reg/mem32 0F BC /r Bit scan forward on the contents of reg/mem32.BSF reg64, reg/mem64 0F BC /r Bit scan forward on the contents of reg/mem64Related <strong>Instructions</strong>BSRrFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFExceptionsU U M U U U21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.Exception RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded a data segment limit or was non-canonical.XA null data segment was used to reference memory.74 BSF


24594 Rev. 3.10 February 2005 AMD64 TechnologyExceptionRealVirtual8086 Protected Cause of ExceptionPage fault, #PF X X A page fault resulted from the execution of the instruction.Alignment check, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.BSF 75


AMD64 Technology 24594 Rev. 3.10 February 2005BSRBit Scan ReverseSearches the value in a register or a memory location (second oper<strong>and</strong>) for the mostsignificantset bit. If a set bit is found, the instruction clears the zero flag (ZF) <strong>and</strong>stores the index of the most-significant set bit in a destination register (first oper<strong>and</strong>).If the second oper<strong>and</strong> contains 0, the instruction sets ZF to 1 <strong>and</strong> does not change thecontents of the destination register. The bit index is an unsigned offset from bit 0 ofthe searched value.Mnemonic Opcode DescriptionBSR reg16, reg/mem16 0F BD /r Bit scan reverse on the contents of reg/mem16.BSR reg32, reg/mem32 0F BD /r Bit scan reverse on the contents of reg/mem32.BSR reg64, reg/mem64 0F BD /r Bit scan reverse on the contents of reg/mem64.Related <strong>Instructions</strong>BSFrFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFExceptionsU U M U U U21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.Exception RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded the data segment limit or was noncanonical.XA null data segment was used to reference memory.76 BSR


24594 Rev. 3.10 February 2005 AMD64 TechnologyExceptionRealVirtual8086 Protected Cause of ExceptionPage fault, #PF X X A page fault resulted from the execution of the instruction.Alignment check, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.BSR 77


AMD64 Technology 24594 Rev. 3.10 February 2005BSWAPByte SwapReverses the byte order of the specified register. This action converts the contents ofthe register from little endian to big endian or vice versa. In a doubleword, bits 7–0 areexchanged with bits 31–24, <strong>and</strong> bits 15–8 are exchanged with bits 23–16. In aquadword, bits 7–0 are exchanged with bits 63–56, bits 15–8 with bits 55–48, bits 23–16with bits 47–40, <strong>and</strong> bits 31–24 with bits 39–32. A subsequent use of the BSWAPinstruction with the same oper<strong>and</strong> restores the original value of the oper<strong>and</strong>.The result of applying the BSWAP instruction to a 16-bit register is undefined. To swapthe bytes of a 16-bit register, use the XCHG instruction <strong>and</strong> specify the respective bytehalves of the 16-bit register as the two oper<strong>and</strong>s. For example, to swap the bytes of AX,use XCHG AL, AH.Mnemonic Opcode DescriptionBSWAP reg32 0F C8 +rd Reverse the byte order of reg32.BSWAP reg64 0F C8 +rq Reverse the byte order of reg64.Related <strong>Instructions</strong>XCHGrFLAGS AffectedNoneExceptionsNone78 BSWAP


24594 Rev. 3.10 February 2005 AMD64 TechnologyBTBit TestCopies a bit, specified by a bit index in a register or 8-bit immediate value (secondoper<strong>and</strong>), from a bit string (first oper<strong>and</strong>), also called the bit base, to the carry flag(CF) of the rFLAGS register.If the bit base oper<strong>and</strong> is a register, the instruction uses the modulo 16, 32, or 64(depending on the oper<strong>and</strong> size) of the bit index to select a bit in the register.If the bit base oper<strong>and</strong> is a memory location, bit 0 of the byte at the specified addressis the bit base of the bit string. If the bit index is in a register, the instruction selects abit position relative to the bit base in the range –2 63 to +2 63 – 1 if the oper<strong>and</strong> size is64, –2 31 to +2 31 – 1, if the oper<strong>and</strong> size is 32, <strong>and</strong> –2 15 to +2 15 – 1 if the oper<strong>and</strong> size is16. If the bit index is in an immediate value, the bit selected is that value modulo 16,32, or 64, depending on oper<strong>and</strong> size.When the instruction attempts to copy a bit from memory, it accesses 2, 4, or 8 bytesstarting from the specified memory address for 16-bit, 32-bit, or 64-bit oper<strong>and</strong> sizes,respectively, using the following formula:Effective Address + (NumBytes i * (BitOffset DIV NumBits i*8 ))When using this bit addressing mechanism, avoid referencing areas of memory closeto 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 <strong>and</strong> use a register formof the BT instruction to manipulate the data.Mnemonic Opcode DescriptionBT reg/mem16, reg16 0F A3 /r Copy the value of the selected bit to the carry flag.BT reg/mem32, reg32 0F A3 /r Copy the value of the selected bit to the carry flag.BT reg/mem64, reg64 0F A3 /r Copy the value of the selected bit to the carry flag.BT reg/mem16, imm8 0F BA /4 ib Copy the value of the selected bit to the carry flag.BT reg/mem32, imm8 0F BA /4 ib Copy the value of the selected bit to the carry flag.BT reg/mem64, imm8 0F BA /4 ib Copy the value of the selected bit to the carry flag.Related <strong>Instructions</strong>BTC, BTR, BTSBT 79


AMD64 Technology 24594 Rev. 3.10 February 2005rFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFExceptionsU U U U U M21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.Exception RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded a data segment limit or was 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.Alignment check, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.80 BT


24594 Rev. 3.10 February 2005 AMD64 TechnologyBTCBit Test <strong>and</strong> ComplementCopies a bit, specified by a bit index in a register or 8-bit immediate value (secondoper<strong>and</strong>), from a bit string (first oper<strong>and</strong>), also called the bit base, to the carry flag(CF) of the rFLAGS register, <strong>and</strong> then complements (toggles) the bit in the bit string.If the bit base oper<strong>and</strong> is a register, the instruction uses the modulo 16, 32, or 64(depending on the oper<strong>and</strong> size) of the bit index to select a bit in the register.If the bit base oper<strong>and</strong> is a memory location, bit 0 of the byte at the specified addressis the bit base of the bit string. If the bit index is in a register, the instruction selects abit position relative to the bit base in the range –2 63 to +2 63 – 1 if the oper<strong>and</strong> size is64, –2 31 to +2 31 – 1, if the oper<strong>and</strong> size is 32, <strong>and</strong> –2 15 to +2 15 – 1 if the oper<strong>and</strong> size is16. If the bit index is in an immediate value, the bit selected is that value modulo 16,32, or 64, depending the oper<strong>and</strong> size.This instruction is useful for implementing semaphores in concurrent operatingsystems. Such an application should precede this instruction with the LOCK prefix.For details about the LOCK prefix, see “Lock Prefix” on page 10.Mnemonic Opcode DescriptionBTC reg/mem16, reg16 0F BB /rBTC reg/mem32, reg32 0F BB /rBTC reg/mem64, reg64 0F BB /rBTC reg/mem16, imm80F BA /7 ibBTC reg/mem32, imm80F BA /7 ibBTC reg/mem64, imm80F BA /7 ibCopy the value of the selected bit to the carry flag, thencomplement the selected bit.Copy the value of the selected bit to the carry flag, thencomplement the selected bit.Copy the value of the selected bit to the carry flag, thencomplement the selected bit.Copy the value of the selected bit to the carry flag, thencomplement the selected bit.Copy the value of the selected bit to the carry flag, thencomplement the selected bit.Copy the value of the selected bit to the carry flag, thencomplement the selected bit.Related <strong>Instructions</strong>BT, BTR, BTSBTC 81


AMD64 Technology 24594 Rev. 3.10 February 2005rFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFExceptionsU U U U U M21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.Exception RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded a data segment limit or was non-canonical.XThe destination oper<strong>and</strong> 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, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.82 BTC


24594 Rev. 3.10 February 2005 AMD64 TechnologyBTRBit Test <strong>and</strong> ResetCopies a bit, specified by a bit index in a register or 8-bit immediate value (secondoper<strong>and</strong>), from a bit string (first oper<strong>and</strong>), also called the bit base, to the carry flag(CF) of the rFLAGS register, <strong>and</strong> then clears the bit in the bit string to 0.If the bit base oper<strong>and</strong> is a register, the instruction uses the modulo 16, 32, or 64(depending on the oper<strong>and</strong> size) of the bit index to select a bit in the register.If the bit base oper<strong>and</strong> is a memory location, bit 0 of the byte at the specified addressis the bit base of the bit string. If the bit index is in a register, the instruction selects abit position relative to the bit base in the range –2 63 to +2 63 – 1 if the oper<strong>and</strong> size is64, –2 31 to +2 31 – 1, if the oper<strong>and</strong> size is 32, <strong>and</strong> –2 15 to +2 15 – 1 if the oper<strong>and</strong> size is16. If the bit index is in an immediate value, the bit selected is that value modulo 16,32, or 64, depending on the oper<strong>and</strong> size.This instruction is useful for implementing semaphores in concurrent operatingsystems. Such applications should precede this instruction with the LOCK prefix. Fordetails about the LOCK prefix, see “Lock Prefix” on page 10.Mnemonic Opcode DescriptionBTR reg/mem16, reg16 0F B3 /rBTR reg/mem32, reg32 0F B3 /rBTR reg/mem64, reg64 0F B3 /rBTR reg/mem16, imm80F BA /6 ibBTR reg/mem32, imm80F BA /6 ibBTR reg/mem64, imm80F BA /6 ibCopy the value of the selected bit to the carry flag, then clear theselected bit.Copy the value of the selected bit to the carry flag, then clear theselected bit.Copy the value of the selected bit to the carry flag, then clear theselected bit.Copy the value of the selected bit to the carry flag, then clear theselected bit.Copy the value of the selected bit to the carry flag, then clear theselected bit.Copy the value of the selected bit to the carry flag, then clear theselected bit.Related <strong>Instructions</strong>BT, BTC, BTSBTR 83


AMD64 Technology 24594 Rev. 3.10 February 2005rFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFExceptionsU U U U U M21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.Exception RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded a data segment limit or was non-canonical.XThe destination oper<strong>and</strong> 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, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.84 BTR


24594 Rev. 3.10 February 2005 AMD64 TechnologyBTSBit Test <strong>and</strong> SetCopies a bit, specified by bit index in a register or 8-bit immediate value (secondoper<strong>and</strong>), from a bit string (first oper<strong>and</strong>), also called the bit base, to the carry flag(CF) of the rFLAGS register, <strong>and</strong> then sets the bit in the bit string to 1.If the bit base oper<strong>and</strong> is a register, the instruction uses the modulo 16, 32, or 64(depending on the oper<strong>and</strong> size) of the bit index to select a bit in the register.If the bit base oper<strong>and</strong> is a memory location, bit 0 of the byte at the specified addressis the bit base of the bit string. If the bit index is in a register, the instruction selects abit position relative to the bit base in the range –2 63 to +2 63 – 1 if the oper<strong>and</strong> size is64, –2 31 to +2 31 – 1, if the oper<strong>and</strong> size is 32, <strong>and</strong> –2 15 to +2 15 – 1 if the oper<strong>and</strong> size is16. If the bit index is in an immediate value, the bit selected is that value modulo 16,32, or 64, depending on the oper<strong>and</strong> size.This instruction is useful for implementing semaphores in concurrent operatingsystems. Such applications should precede this instruction with the LOCK prefix. Fordetails about the LOCK prefix, see “Lock Prefix” on page 10.Mnemonic Opcode DescriptionBTS reg/mem16, reg16 0F AB /rBTS reg/mem32, reg32 0F AB /rBTS reg/mem64, reg64 0F AB /rBTS reg/mem16, imm80F BA /5 ibBTS reg/mem32, imm80F BA /5 ibBTS reg/mem64, imm80F BA /5 ibCopy the value of the selected bit to the carry flag, then set theselected bit.Copy the value of the selected bit to the carry flag, then set theselected bit.Copy the value of the selected bit to the carry flag, then set theselected bit.Copy the value of the selected bit to the carry flag, then set theselected bit.Copy the value of the selected bit to the carry flag, then set theselected bit.Copy the value of the selected bit to the carry flag, then set theselected bit.Related <strong>Instructions</strong>BT, BTC, BTRBTS 85


AMD64 Technology 24594 Rev. 3.10 February 2005rFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFExceptionsU U U U U M21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.Exception RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded a data segment limit or was non-canonical.XThe destination oper<strong>and</strong> 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, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.86 BTS


24594 Rev. 3.10 February 2005 AMD64 TechnologyCALL (Near)Near Procedure CallPushes the offset of the next instruction onto the stack <strong>and</strong> branches to the targetaddress, which contains the first instruction of the called procedure. The targetoper<strong>and</strong> can specify a register, a memory location, or a label. A procedure accessed bya near CALL is located in the same code segment as the CALL instruction.If the CALL target is specified by a register or memory location, then a 16-, 32-, or 64-bit rIP is read from the oper<strong>and</strong>, depending on the oper<strong>and</strong> size. A 16- or 32-bit rIP iszero-extended to 64 bits.If the CALL target is specified by a displacement, the signed displacement is added tothe rIP (of the following instruction), <strong>and</strong> the result is truncated to 16, 32, or 64 bits,depending on the oper<strong>and</strong> size. The signed displacement is 16 or 32 bits, depending onthe oper<strong>and</strong> size.In all cases, the rIP of the instruction after the CALL is pushed on the stack, <strong>and</strong> thesize of the stack push (16, 32, or 64 bits) depends on the oper<strong>and</strong> size of the CALLinstruction.For near calls in 64-bit mode, the oper<strong>and</strong> size defaults to 64 bits. The E8 opcoderesults in RIP = RIP + 32-bit signed displacement <strong>and</strong> the FF /2 opcode results inRIP = 64-bit offset from register or memory. No prefix is available to encode a 32-bitoper<strong>and</strong> size in 64-bit mode.At the end of the called procedure, RET is used to return control to the instructionfollowing the original CALL. When RET is executed, the rIP is popped off the stack,which returns control to the instruction after the CALL.See CALL (Far) for information on far calls—calls to procedures located outside of thecurrent code segment. For details about control-flow instructions, see “ControlTransfers” in <strong>Volume</strong> 1, <strong>and</strong> “Control-Transfer Privilege Checks” in <strong>Volume</strong> 2.Mnemonic Opcode DescriptionCALL rel16offCALL rel32offE8 iwE8 idNear call with the target specified by a 16-bit relativedisplacement.Near call with the target specified by a 32-bit relativedisplacement.CALL reg/mem16 FF /2 Near call with the target specified by reg/mem16.CALL (Near) 87


AMD64 Technology 24594 Rev. 3.10 February 2005Mnemonic Opcode DescriptionCALL reg/mem32 FF /2Near call with the target specified by reg/mem32. (There is noprefix for encoding this in 64-bit mode.)CALL reg/mem64 FF /2 Near call with the target specified by reg/mem64.For details about control-flow instructions, see “Control Transfers” in <strong>Volume</strong> 1, <strong>and</strong>“Control-Transfer Privilege Checks” in <strong>Volume</strong> 2.Related <strong>Instructions</strong>CALL(Far), RET(Near), RET(Far)rFLAGS AffectedNone.ExceptionsException RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPXXXA memory address exceeded a data segment limit or was non-canonical.XXXThe target offset exceeded the code segment limit or was non-canonical.Alignment Check,#ACXA null data segment was used to reference memory.X X An unaligned memory reference was performed while alignmentchecking was enabled.Page Fault, #PF X X A page fault resulted from the execution of the instruction.88 CALL (Near)


24594 Rev. 3.10 February 2005 AMD64 TechnologyCALL (Far)Far Procedure CallPushes procedure linking information onto the stack <strong>and</strong> branches to the targetaddress, which contains the first instruction of the called procedure. The oper<strong>and</strong>specifies a target selector <strong>and</strong> offset.The instruction can specify the target directly, by including the far pointer in theCALL (Far) opcode itself, or indirectly, by referencing a far pointer in memory. In 64-bit mode, only indirect far calls are allowed, executing a direct far call (opcode 9A)generates an undefined opcode exception.The target selector used by the instruction can be a code selector in all modes.Additionally, the target selector can reference a call gate in protected mode, or a taskgate or TSS selector in legacy protected mode.• Target is a code selector—The CS:rIP of the next instruction is pushed to the stack,using oper<strong>and</strong>-size stack pushes. Then code is executed from the target CS:rIP. Inthis case, the target offset can only be a 16- or 32-bit value, depending on oper<strong>and</strong>size,<strong>and</strong> is zero-extended to 64 bits. No CPL change is allowed.• Target is a call gate—The call gate specifies the actual target code segment <strong>and</strong> offset.Call gates allow calls to the same or more privileged code. If the target segmentis at the same CPL as the current code segment, the CS:rIP of the nextinstruction is pushed to the stack.If the CALL (Far) changes privilege level, then a stack-switch occurs, using aninner-level stack pointer from the TSS. The CS:rIP of the next instruction ispushed to the new stack. If the mode is legacy mode <strong>and</strong> the param-count field inthe call gate is non-zero, then up to 31 oper<strong>and</strong>s are copied from the caller's stackto the new stack. Finally, the caller's SS:rSP is pushed to the new stack.When calling through a call gate, the stack pushes are 16-, 32-, or 64-bits, dependingon the size of the call gate. The size of the target rIP is also 16, 32, or 64 bits,depending on the size of the call gate. If the target rIP is less than 64 bits, it iszero-extended to 64 bits. Long mode only allows 64-bit call gates that must point to64-bit code segments.• Target is a task gate or a TSS—If the mode is legacy protected mode, then a taskswitch occurs. See “Hardware Task-Management in Legacy Mode” in volume 2 fordetails about task switches. Hardware task switches are not supported in longmode.See CALL (Near) for information on near calls—calls to procedures located inside thecurrent code segment. For details about control-flow instructions, see “ControlTransfers” in <strong>Volume</strong> 1, <strong>and</strong> “Control-Transfer Privilege Checks” in <strong>Volume</strong> 2.CALL (Far) 89


AMD64 Technology 24594 Rev. 3.10 February 2005Mnemonic Opcode DescriptionCALL FAR pntr16:169A cdCALL FAR pntr16:329A cpCALL FAR mem16:16 FF /3CALL FAR mem16:32 FF /3Far call direct, with the target specified by a far pointer containedin the instruction. (Invalid in 64-bit mode.)Far call direct, with the target specified by a far pointer containedin the instruction. (Invalid in 64-bit mode.)Far call indirect, with the target specified by a far pointer inmemory.Far call indirect, with the target specified by a far pointer inmemory.Action// See “Pseudocode Definitions” on page 49.CALLF_START:IF (REAL_MODE)CALLF_REAL_OR_VIRTUALELSIF (PROTECTED_MODE)CALLF_PROTECTEDELSE // (VIRTUAL_MODE)CALLF_REAL_OR_VIRTUALCALLF_REAL_OR_VIRTUAL:IF (OPCODE = callf [mem]) // CALLF Indirect{temp_RIP = READ_MEM.z [mem]temp_CS = READ_MEM.w [mem+Z]}ELSE // (OPCODE = callf direct){temp_RIP = z-sized offset specified in the instructionzero-extended to 64 bitstemp_CS = selector specified in the instruction}PUSH.v old_CSPUSH.v next_RIPIF (temp_RIP>CS.limit)EXCEPTION [#GP(0)]CS.sel = temp_CSCS.base = temp_CS SHL 4RIP = temp_RIPEXIT90 CALL (Far)


24594 Rev. 3.10 February 2005 AMD64 TechnologyCALLF_PROTECTED:IF (OPCODE = callf [mem]) //CALLF Indirect{temp_offset = READ_MEM.z [mem]temp_sel = READ_MEM.w [mem+Z]}ELSE // (OPCODE = callf direct){IF (64BIT_MODE)EXCEPTION [#UD] // ’CALLF direct’ is illegal in 64-bit mode.temp_offset = z-sized offset specified in the instructionzero-extended to 64 bitstemp_sel = selector specified in the instruction}temp_desc = READ_DESCRIPTOR (temp_sel, cs_chk)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_offsetCS = temp_descPUSH.v old_CSPUSH.v next_RIPIF ((!64BIT_MODE) && (temp_RIP > CS.limit))}ELSE{EXCEPTION [#GP(0)]RIP = temp_RIPEXIT// temp_RIP can’t be non-canonical because// it’s a 16- or 32-bit offset, zero-extended// to 64 bits.// (temp_desc.attr.type = ’callgate’)// If the selector refers to a call gate, then// the target CS <strong>and</strong> RIP both come from the call gate.IF (LONG_MODE)// The size of the gate controls the size of the stack pushes.V=8-byte// Long mode only uses 64-bit call gates, force 8-byte opsize.ELSIF (temp_desc.attr.type = ’callgate32’)V=4-byte// Legacy mode, using a 32-bit call-gate, force 4-byte opsize.CALL (Far) 91


AMD64 Technology 24594 Rev. 3.10 February 2005ELSE // (temp_desc.attr.type = ’callgate16’)V=2-byte// Legacy mode, using a 16-bit call-gate, force 2-byte opsize.temp_RIP = temp_desc.offsetIF (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)]temp_RIP = tempRIP + (temp_upper SHL 32)// Concatenate both halves of RIPCS = READ_DESCRIPTOR (temp_desc.segment, clg_chk)IF (CS.attr.conforming=1)temp_CPL = CPLELSEtemp_CPL = CS.attr.dplIF (CPL=temp_CPL){PUSH.v old_CSPUSH.v next_RIPIF ((64BIT_MODE) && (temp_RIP is non-canonical)|| (!64BIT_MODE) && (temp_RIP > CS.limit)){EXCEPTION[#GP(0)]}RIP = temp_RIPEXIT}ELSE // (CPL != temp_CPL), Changing privilege level.{CPL = temp_CPLtemp_ist = 0// Call-far doesn’t use ist pointers.temp_SS_desc:temp_RSP = READ_INNER_LEVEL_STACK_POINTER (CPL, temp_ist)RSP.q = temp_RSPSS = temp_SS_descPUSH.v old_SS// #SS on this <strong>and</strong> following pushes use// SS.sel as error code.PUSH.v old_RSPIF (LEGACY_MODE) // Legacy-mode call gates have{ // a param_count field.92 CALL (Far)


24594 Rev. 3.10 February 2005 AMD64 Technologytemp_PARAM_COUNT = temp_desc.attr.param_count}}FOR (I=temp_PARAM_COUNT; I>0; I--){temp_DATA = READ_MEM.v [old_SS:(old_RSP+I*V)]PUSH.v temp_DATA}}PUSH.v old_CSPUSH.v next_RIPIF ((64BIT_MODE) && (temp_RIP is non-canonical)|| (!64BIT_MODE) && (temp_RIP > CS.limit)){EXCEPTION [#GP(0)]}RIP = temp_RIPEXITRelated <strong>Instructions</strong>CALL (Near), RET (Near), RET (Far)rFLAGS AffectedNone, unless a task switch occurs, in which case all flags are modified.CALL (Far) 93


AMD64 Technology 24594 Rev. 3.10 February 2005ExceptionsVirtualException Real 8086 Protected Cause of ExceptionInvalid opcode, #UD X X X The far CALL indirect opcode (FF /3) had a register oper<strong>and</strong>.Invalid TSS, #TS(selector)XXXXXXXThe far CALL direct opcode (9A) was executed in 64-bit mode.As part of a stack switch, the target stack segment selector or rSP inthe TSS was beyond the TSS limit.As part of a stack switch, the target stack segment selector in the TSSwas a null selector.As part of a stack switch, the target stack selector’s TI bit was set, butLDT selector was a null selector.As part of a stack switch, the target stack segment selector in the TSSwas beyond the limit of the GDT or LDT descriptor table.As part of a stack switch, the target stack segment selector in the TSScontained a RPL that was not equal to its DPL.As part of a stack switch, the target stack segment selector in the TSScontained a DPL that was not equal to the CPL of the code segmentselector.Segment not present,#NP (selector)XXAs part of a stack switch, the target stack segment selector in the TSSwas not a writable segment.The accessed code segment, call gate, task gate, or TSS was notpresent.Stack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical,<strong>and</strong> no stack switch occurred.Stack, #SS(selector)XAfter a stack switch, a memory access exceeded the stack segmentlimit or was non-canonical.XAs part of a stack switch, the SS register was loaded with a non-nullsegment selector <strong>and</strong> the segment was marked not present.<strong>General</strong> protection,#GPXXXA memory address exceeded a data segment limit or was non-canonical.XXXThe target offset exceeded the code segment limit or was non-canonical.XA null data segment was used to reference memory.94 CALL (Far)


24594 Rev. 3.10 February 2005 AMD64 TechnologyException<strong>General</strong> protection,#GP(selector)RealVirtual8086 Protected Cause of ExceptionXXThe target code segment selector was a null selector.A code, call gate, task gate, or TSS descriptor exceeded the descriptortable limit.XXXXXXXXXA segment selector’s TI bit was set but the LDT selector was a nullselector.The segment descriptor specified by the instruction was not a codesegment, task gate, call gate or available TSS in legacy mode, or nota 64-bit code segment or a 64-bit call gate in long mode.The RPL of the non-conforming code segment selector specified bythe instruction was greater than the CPL, or its DPL was not equal tothe CPL.The DPL of the conforming code segment descriptor specified by theinstruction was greater than the CPL.The DPL of the callgate, taskgate, or TSS descriptor specified by theinstruction was less than the CPL, or less than its own RPL.The segment selector specified by the call gate or task gate was a nullselector.The segment descriptor specified by the call gate was not a code segmentin legacy mode, or not a 64-bit code segment in long mode.The DPL of the segment descriptor specified by the call gate wasgreater than the CPL.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, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.CALL (Far) 95


AMD64 Technology 24594 Rev. 3.10 February 2005CBWCWDECDQEConvert to Sign-extendedCopies the sign bit in the AL or eAX register to the upper bits of the rAX register. Theeffect of this instruction is to convert a signed byte, word, or doubleword in the AL oreAX register into a signed word, doubleword, or double quadword in the rAX register.This action helps avoid overflow problems in signed number arithmetic.The CDQE mnemonic is meaningful only in 64-bit mode.Mnemonic Opcode DescriptionCBW 98 Sign-extend AL into AX.CWDE 98 Sign-extend AX into EAX.CDQE 98 Sign-extend EAX into RAX.Related <strong>Instructions</strong>CWD, CDQ, CQOrFLAGS AffectedNoneExceptionsNone96 CBW, CWDE, CDQE


24594 Rev. 3.10 February 2005 AMD64 TechnologyCWDCDQCQOConvert to Sign-extendedCopies the sign bit in the rAX register to all bits of the rDX register. The effect of thisinstruction is to convert a signed word, doubleword, or quadword in the rAX registerinto a signed doubleword, quadword, or double-quadword in the rDX:rAX registers.This action helps avoid overflow problems in signed number arithmetic.The CQO mnemonic is meaningful only in 64-bit mode.Mnemonic Opcode DescriptionCWD 99 Sign-extend AX into DX:AX.CDQ 99 Sign-extend EAX into EDX:EAX.CQO 99 Sign-extend RAX into RDX:RAX.Related <strong>Instructions</strong>CBW, CWDE, CDQErFLAGS AffectedNoneExceptionsNoneCWD, CDQ, CQO 97


AMD64 Technology 24594 Rev. 3.10 February 2005CLCClear Carry FlagClears the carry flag (CF) in the rFLAGS register to zero.Mnemonic Opcode DescriptionCLC F8 Clear the carry flag (CF) to zero.Related <strong>Instructions</strong>STC, CMCrFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0ExceptionsNoneNote: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.098 CLC


24594 Rev. 3.10 February 2005 AMD64 TechnologyCLDClear Direction FlagClears the direction flag (DF) in the rFLAGS register to zero. If the DF flag is 0, eachiteration of a string instruction increments the data pointer (index registers rSI orrDI). If the DF flag is 1, the string instruction decrements the pointer. Use the CLDinstruction before a string instruction to make the data pointer increment.Mnemonic Opcode DescriptionCLD FC Clear the direction flag (DF) to zero.Related <strong>Instructions</strong>CMPSx, INSx, LODSx, MOVSx, OUTSx, SCASx, STD, STOSxrFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0ExceptionsNoneNote: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.0CLD 99


AMD64 Technology 24594 Rev. 3.10 February 2005CLFLUSHCache Line FlushFlushes the cache line specified by the mem8 linear-address. The instruction checksall levels of the cache hierarchy—internal caches <strong>and</strong> external caches—<strong>and</strong>invalidates the cache line in every cache in which it is found. If a cache contains a dirtycopy of the cache line (that is, the cache line is in the modified or owned MOESI state),the line is written back to memory before it is invalidated. The instruction sets thecache-line MOESI state to invalid.The instruction also checks the physical address corresponding to the linear-addressoper<strong>and</strong> against the processor’s write-combining buffers. If the write-combiningbuffer holds data intended for that physical address, the instruction writes the entirecontents of the buffer to memory. This occurs even though the data is not cached inthe cache hierarchy. In a multiprocessor system, the instruction checks the writecombiningbuffers only on the processor that executed the CLFLUSH instruction.The CLFLUSH instruction is weakly-ordered with respect to other instructions thatoperate on memory. Speculative loads initiated by the processor, or specifiedexplicitly using cache-prefetch instructions, can be reordered around a CLFLUSHinstruction. Such reordering can cause freshly-loaded cache lines to be flushedunintentionally. The only way to avoid this situation is to use the MFENCE instructionto force strong-ordering of the CLFLUSH instruction with respect to other memoryoperations. The LFENCE, SFENCE, <strong>and</strong> serializing instructions are not ordered withrespect to CLFLUSH.The CLFLUSH instruction behaves like a load instruction with respect to setting thepage-table accessed <strong>and</strong> dirty bits. That is, it sets the page-table accessed bit to 1, butdoes not set the page-table dirty bit.The CLFLUSH instruction is supported if CPUID st<strong>and</strong>ard function 1 sets EDX bit 19.CPUID function 1 returns the CLFLUSH size in EBX bits 23:16. This value reports thesize of a line flushed by CLFLUSH in quadwords. See CPUID for details.The CLFLUSH instruction executes at any privilege level. CLFLUSH performs all thesegmentation <strong>and</strong> paging checks that a 1-byte read would perform, except that it alsoallows references to execute-only segments.Mnemonic Opcode DescriptionCFLUSH mem8 0F AE /7 flush cache line containing mem8.100 CLFLUSH


24594 Rev. 3.10 February 2005 AMD64 TechnologyRelated <strong>Instructions</strong>INVD, WBINVDrFLAGS AffectedNoneExceptionsException (vector) RealVirtual8086 Protected Cause of ExceptionInvalid opcode, #UD X X X The CLFLUSH instruction is not supported, as indicated byEDX bit 19 of CPUID st<strong>and</strong>ard function 1.Stack, #SS X X X A memory address exceeded the stack segment limit or wasnon-canonical.<strong>General</strong> protection, #GP X X XA memory address exceeded a data segment limit or wasnon-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.CLFLUSH 101


AMD64 Technology 24594 Rev. 3.10 February 2005CMCComplement Carry FlagComplements (toggles) the carry flag (CF) bit of the rFLAGS register.Mnemonic Opcode DescriptionCMC F5 Complement the carry flag (CF).Related <strong>Instructions</strong>CLC, STCrFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0ExceptionsNoneNote: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.M102 CMC


24594 Rev. 3.10 February 2005 AMD64 TechnologyCMOVccConditional MoveConditionally moves a 16-bit, 32-bit, or 64-bit value in memory or a general-purposeregister (second oper<strong>and</strong>) into a register (first oper<strong>and</strong>), depending upon the settingsof condition flags in the rFLAGS register. If the condition is not satisfied, theinstruction has no effect.The mnemonics of CMOVcc instructions denote the condition that must be satisfied.Most assemblers provide instruction mnemonics with A (above) <strong>and</strong> B (below) tags tosupply the semantics for manipulating unsigned integers. Those with G (greater than)<strong>and</strong> L (less than) tags deal with signed integers. Many opcodes may be represented bysynonymous mnemonics. For example, the CMOVL instruction is synonymous with theCMOVNGE instruction <strong>and</strong> denote the instruction with the opcode 0F 4C.Support for CMOVcc instructions depends on the processor implementation. Todetermine whether a processor can perform CMOVcc instructions, use the CPUIDinstruction to determine whether EDX bit 15 of CPUID st<strong>and</strong>ard function 1 orextended function 8000_0001h is set to 1.Mnemonic Opcode DescriptionCMOVO reg16, reg/mem16CMOVO reg32, reg/mem32CMOVO reg64, reg/mem64CMOVNO reg16, reg/mem16CMOVNO reg32, reg/mem32CMOVNO reg64, reg/mem64CMOVB reg16, reg/mem16CMOVB reg32, reg/mem32CMOVB reg64, reg/mem64CMOVC reg16, reg/mem16CMOVC reg32, reg/mem32CMOVC reg64, reg/mem64CMOVNAE reg16, reg/mem16CMOVNAE reg32, reg/mem32CMOVNAE reg64, reg/mem64CMOVNB reg16,reg/mem16CMOVNB reg32,reg/mem32CMOVNB reg64,reg/mem640F 40 /r Move if overflow (OF = 1).0F 41 /r Move if not overflow (OF = 0).0F 42 /r Move if below (CF = 1).0F 42 /r Move if carry (CF = 1).0F 42 /r Move if not above or equal (CF = 1).0F 43 /r Move if not below (CF = 0).CMOVcc 103


AMD64 Technology 24594 Rev. 3.10 February 2005Mnemonic Opcode DescriptionCMOVNC reg16,reg/mem16CMOVNC reg32,reg/mem32CMOVNC reg64,reg/mem64CMOVAE reg16, reg/mem16CMOVAE reg32, reg/mem32CMOVAE reg64, reg/mem64CMOVZ reg16, reg/mem16CMOVZ reg32, reg/mem32CMOVZ reg64, reg/mem64CMOVE reg16, reg/mem16CMOVE reg32, reg/mem32CMOVE reg64, reg/mem64CMOVNZ reg16, reg/mem16CMOVNZ reg32, reg/mem32CMOVNZ reg64, reg/mem64CMOVNE reg16, reg/mem16CMOVNE reg32, reg/mem32CMOVNE reg64, reg/mem64CMOVBE reg16, reg/mem16CMOVBE reg32, reg/mem32CMOVBE reg64, reg/mem64CMOVNA reg16, reg/mem16CMOVNA reg32, reg/mem32CMOVNA reg64, reg/mem64CMOVNBE reg 16, reg/mem16CMOVNBE reg32,reg/mem32CMOVNBE reg64,reg/mem64CMOVA reg16, reg/mem16CMOVA reg32, reg/mem32CMOVA reg64, reg/mem64CMOVS reg16, reg/mem16CMOVS reg32, reg/mem32CMOVS reg64, reg/mem64CMOVNS reg16, reg/mem16CMOVNS reg32, reg/mem32CMOVNS reg64, reg/mem64CMOVP reg16, reg/mem16CMOVP reg32, reg/mem32CMOVP reg64, reg/mem640F 43 /r Move if not carry (CF = 0).0F 43 /r Move if above or equal (CF = 0).0F 44 /r Move if zero (ZF = 1).0F 44 /r Move if equal (ZF =1).0F 45 /r Move if not zero (ZF = 0).0F 45 /r Move if not equal (ZF = 0).0F 46 /r Move if below or equal (CF = 1 or ZF = 1).0F 46 /r Move if not above (CF = 1 or ZF = 1).0F 47 /r Move if not below or equal (CF = 0 <strong>and</strong> ZF = 0).0F 47 /r Move if above (CF = 1 <strong>and</strong> ZF = 0).0F 48 /r Move if sign (SF =1).0F 49 /r Move if not sign (SF = 0).0F 4A /r Move if parity (PF = 1).104 CMOVcc


24594 Rev. 3.10 February 2005 AMD64 TechnologyMnemonic Opcode DescriptionCMOVPE reg16, reg/mem16CMOVPE reg32, reg/mem32CMOVPE reg64, reg/mem64CMOVNP reg16, reg/mem16CMOVNP reg32, reg/mem32CMOVNP reg64, reg/mem64CMOVPO reg16, reg/mem16CMOVPO reg32, reg/mem32CMOVPO reg64, reg/mem640F 4A /r Move if parity even (PF = 1).0F 4B /r Move if not parity (PF = 0).0F 4B /r Move if parity odd (PF = 0).CMOVL reg16, reg/mem16CMOVL reg32, reg/mem32CMOVL reg64, reg/mem64CMOVNGE reg16, reg/mem16CMOVNGE reg32, reg/mem32CMOVNGE reg64, reg/mem64CMOVNL reg16, reg/mem16CMOVNL reg32, reg/mem32CMOVNL reg64, reg/mem64CMOVGE reg16, reg/mem16CMOVGE reg32, reg/mem32CMOVGE reg64, reg/mem64CMOVLE reg16, reg/mem16CMOVLE reg32, reg/mem32CMOVLE reg64, reg/mem64CMOVNG reg16, reg/mem16CMOVNG reg32, reg/mem32CMOVNG reg64, reg/mem64CMOVNLE reg16, reg/mem16CMOVNLE reg32, reg/mem32CMOVNLE reg64, reg/mem64CMOVG reg16, reg/mem16CMOVG reg32, reg/mem32CMOVG reg64, reg/mem64Related <strong>Instructions</strong>MOVrFLAGS AffectedNone0F 4C /r0F 4C /r0F 4D /r0F 4D /r0F 4E /r0F 4E /r0F 4F /r0F 4F /rMove if less (SF OF).Move if not greater or equal (SF OF).Move if not less (SF = OF).Move if greater or equal (SF = OF).Move if less or equal (ZF = 1 or SF OF).Move if not greater (ZF = 1 or SF OF).Move if not less or equal (ZF = 0 <strong>and</strong> SF = OF).Move if greater (ZF = 0 <strong>and</strong> SF = OF).CMOVcc 105


AMD64 Technology 24594 Rev. 3.10 February 2005ExceptionsException RealVirtual8086 Protected Cause of ExceptionInvalid opcode, #UD X X X The CMOVcc instruction is not supported, as indicated by EDX bit 15of CPUID st<strong>and</strong>ard function 1 or extended function 8000_0001h.Stack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded a data segment limit or was 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.Alignment check, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.106 CMOVcc


24594 Rev. 3.10 February 2005 AMD64 TechnologyCMPCompareCompares the contents of a register or memory location (first oper<strong>and</strong>) with animmediate value or the contents of a register or memory location (second oper<strong>and</strong>),<strong>and</strong> sets or clears the status flags in the rFLAGS register to reflect the results. Toperform the comparison, the instruction subtracts the second oper<strong>and</strong> from the firstoper<strong>and</strong> <strong>and</strong> sets the status flags in the same manner as the SUB instruction, but doesnot alter the first oper<strong>and</strong>. If the second oper<strong>and</strong> is an immediate value, theinstruction sign-extends the value to the length of the first oper<strong>and</strong>.Use the CMP instruction to set the condition codes for a subsequent conditional jump(Jcc), conditional move (CMOVcc), or conditional SETcc instruction. Appendix E,“Instruction Effects on RFLAGS,” shows how instructions affect the rFLAGS statusflags..Mnemonic Opcode DescriptionCMP AL, imm8CMP AX, imm16CMP EAX, imm32CMP RAX, imm32CMP reg/mem8, imm8CMP reg/mem16, imm16CMP reg/mem32, imm32CMP reg/mem64, imm32CMP reg/mem16, imm8CMP reg/mem32, imm83C ib3D iw3D id3D id80 /7 ib81 /7 iw81 /7 id81 /7 id83 /7 ib83 /7 ibCompare an 8-bit immediate value with the contents of the ALregister.Compare a 16-bit immediate value with the contents of the AXregister.Compare a 32-bit immediate value with the contents of the EAXregister.Compare a 32-bit immediate value with the contents of the RAXregister.Compare an 8-bit immediate value with the contents of an 8-bitregister or memory oper<strong>and</strong>.Compare a 16-bit immediate value with the contents of a 16-bitregister or memory oper<strong>and</strong>.Compare a 32-bit immediate value with the contents of a 32-bitregister or memory oper<strong>and</strong>.Compare a 32-bit signed immediate value with the contents of a64-bit register or memory oper<strong>and</strong>.Compare an 8-bit signed immediate value with the contents of a16-bit register or memory oper<strong>and</strong>.Compare an 8-bit signed immediate value with the contents of a32-bit register or memory oper<strong>and</strong>.CMP 107


AMD64 Technology 24594 Rev. 3.10 February 2005Mnemonic Opcode DescriptionCMP reg/mem64, imm883 /7 ibCMP reg/mem8, reg8 38 /rCMP reg/mem16, reg16 39 /rCMP reg/mem32, reg32 39 /rCMP reg/mem64, reg64 39 /rCMP reg8, reg/mem8 3A /rCMP reg16, reg/mem16 3B /rCMP reg32, reg/mem32 3B /rCMP reg64, reg/mem64 3B /rCompare an 8-bit signed immediate value with the contents of a64-bit register or memory oper<strong>and</strong>.Compare the contents of an 8-bit register or memory oper<strong>and</strong>with the contents of an 8-bit register.Compare the contents of a 16-bit register or memory oper<strong>and</strong>with the contents of a 16-bit register.Compare the contents of a 32-bit register or memory oper<strong>and</strong>with the contents of a 32-bit register.Compare the contents of a 64-bit register or memory oper<strong>and</strong>with the contents of a 64-bit register.Compare the contents of an 8-bit register with the contents of an8-bit register or memory oper<strong>and</strong>.Compare the contents of a 16-bit register with the contents of a16-bit register or memory oper<strong>and</strong>.Compare the contents of a 32-bit register with the contents of a32-bit register or memory oper<strong>and</strong>.Compare the contents of a 64-bit register with the contents of a64-bit register or memory oper<strong>and</strong>.When interpreting oper<strong>and</strong>s as unsigned, flag settings are as follows:Oper<strong>and</strong>s CF ZFdest > source 0 0dest = source 0 1dest < source 1 0When interpreting oper<strong>and</strong>s as signed, flag settings are as follows:Oper<strong>and</strong>s OF ZFdest > source SF 0dest = source 0 1dest < source NOT SF 0108 CMP


24594 Rev. 3.10 February 2005 AMD64 TechnologyRelated <strong>Instructions</strong>SUB, CMPSx, SCASxrFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFExceptionsM M M M M M21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.Exception RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded a data segment limit or was 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.Alignment check, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.CMP 109


AMD64 Technology 24594 Rev. 3.10 February 2005CMPSCMPSBCMPSWCMPSDCMPSQCompare StringsCompares the bytes, words, doublewords, or quadwords pointed to by the rSI <strong>and</strong> rDIregisters, sets or clears the status flags of the rFLAGS register to reflect the results,<strong>and</strong> then increments or decrements the rSI <strong>and</strong> rDI registers according to the state ofthe DF flag in the rFLAGS register. To perform the comparison, the instructionsubtracts the second oper<strong>and</strong> from the first oper<strong>and</strong> <strong>and</strong> sets the status flags in thesame manner as the SUB instruction, but does not alter the first oper<strong>and</strong>. The twooper<strong>and</strong>s must be the same size.If the DF flag is 0, the instruction increments rSI <strong>and</strong> rDI; otherwise, it decrements thepointers. It increments or decrements the pointers by 1, 2, 4, or 8, depending on thesize of the oper<strong>and</strong>s.The forms of the CMPSx instruction with explicit oper<strong>and</strong>s address the first oper<strong>and</strong>at seg:[rSI]. The value of seg defaults to the DS segment, but may be overridden by asegment prefix. These instructions always address the second oper<strong>and</strong> at ES:[rDI]. ESmay not be overridden. The explicit oper<strong>and</strong>s serve only to specify the type (size) ofthe values being compared <strong>and</strong> the segment used by the first oper<strong>and</strong>.The no-oper<strong>and</strong>s forms of the instruction use the DS:[rSI] <strong>and</strong> ES:[rDI] registers topoint to the values to be compared. The mnemonic determines the size of theoper<strong>and</strong>s.Do not confuse this CMPSD instruction with the same-mnemonic CMPSD (comparescalar double-precision floating-point) instruction in the 128-bit media instruction set.Assemblers can distinguish the instructions by the number <strong>and</strong> type of oper<strong>and</strong>s.For block comparisons, the CMPS instruction supports the REPE or REPZ prefixes(they are synonyms) <strong>and</strong> the REPNE or REPNZ prefixes (they are synonyms). Fordetails about the REP prefixes, see “Repeat Prefixes” on page 10. If a conditionaljump instruction like JL follows a CMPSx instruction, the jump occurs if the value ofthe seg:[rSI] oper<strong>and</strong> is less than the ES:[rDI] oper<strong>and</strong>. This action allowslexicographical comparisons of string or array elements. A CMPSx instruction canalso operate inside a loop controlled by the LOOPcc instruction.110 CMPS


24594 Rev. 3.10 February 2005 AMD64 TechnologyMnemonic Opcode DescriptionCMPS mem8, mem8CMPS mem16, mem16CMPS mem32, mem32CMPS mem64, mem64CMPSBCMPSWCMPSDCMPSQRelated <strong>Instructions</strong>CMP, SCASxA6A7A7A7A6A7A7A7Compare the byte at DS:rSI with the byte at ES:rDI <strong>and</strong> thenincrement or decrement rSI <strong>and</strong> rDI.Compare the word at DS:rSI with the word at ES:rDI <strong>and</strong> thenincrement or decrement rSI <strong>and</strong> rDI.Compare the doubleword at DS:rSI with the doubleword atES:rDI <strong>and</strong> then increment or decrement rSI <strong>and</strong> rDI.Compare the quadword at DS:rSI with the quadword at ES:rDI<strong>and</strong> then increment or decrement rSI <strong>and</strong> rDI.Compare the byte at DS:rSI with the byte at ES:rDI <strong>and</strong> thenincrement or decrement rSI <strong>and</strong> rDI.Compare the word at DS:rSI with the word at ES:rDI <strong>and</strong> thenincrement or decrement rSI <strong>and</strong> rDI.Compare the doubleword at DS:rSI with the doubleword atES:rDI <strong>and</strong> then increment or decrement rSI <strong>and</strong> rDI.Compare the quadword at DS:rSI with the quadword at ES:rDI<strong>and</strong> then increment or decrement rSI <strong>and</strong> rDI.CMPSQ 111


AMD64 Technology 24594 Rev. 3.10 February 2005rFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFExceptionsM M M M M M21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.Exception RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded a data segment limit or was 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.Alignment check, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.112 CMPSQ


24594 Rev. 3.10 February 2005 AMD64 TechnologyCMPXCHGCompare <strong>and</strong> ExchangeCompares the value in the AL, AX, EAX, or RAX register with the value in a registeror a memory location (first oper<strong>and</strong>). If the two values are equal, the instructioncopies the value in the second oper<strong>and</strong> to the first oper<strong>and</strong> <strong>and</strong> sets the ZF flag in therFLAGS register to 1. Otherwise, it copies the value in the first oper<strong>and</strong> to the AL, AX,EAX, or RAX register <strong>and</strong> clears the ZF flag to 0.The OF, SF, AF, PF, <strong>and</strong> CF flags are set to reflect the results of the compare.The forms of the CMPXCHG instruction that write to memory support the LOCKprefix. For details about the LOCK prefix, see “Lock Prefix” on page 10.Mnemonic Opcode DescriptionCMPXCHG reg/mem8, reg8 0F B0 /rCMPXCHG reg/mem16, reg16 0F B1 /rCMPXCHG reg/mem32, reg32 0F B1 /rCMPXCHG reg/mem64, reg64 0F B1 /rCompare AL register with an 8-bit register or memory location. Ifequal, copy the second oper<strong>and</strong> to the first oper<strong>and</strong>. Otherwise,copy the first oper<strong>and</strong> to AL.Compare AX register with a 16-bit register or memory location. Ifequal, copy the second oper<strong>and</strong> to the first oper<strong>and</strong>. Otherwise,copy the first oper<strong>and</strong> to AX.Compare EAX register with a 32-bit register or memory location.If equal, copy the second oper<strong>and</strong> to the first oper<strong>and</strong>.Otherwise, copy the first oper<strong>and</strong> to EAX.Compare RAX register with a 64-bit register or memory location.If equal, copy the second oper<strong>and</strong> to the first oper<strong>and</strong>.Otherwise, copy the first oper<strong>and</strong> to RAX.Related <strong>Instructions</strong>CMPXCHG8B, CMPXCHG16BCMPXCHG 113


AMD64 Technology 24594 Rev. 3.10 February 2005rFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFExceptionsM M M M M M21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.Exception RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded a data segment limit or was non-canonical.XThe destination oper<strong>and</strong> 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, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.114 CMPXCHG


24594 Rev. 3.10 February 2005 AMD64 TechnologyCMPXCHG8BCMPXCHG16BCompare <strong>and</strong> Exchange Eight BytesCompare <strong>and</strong> Exchange Sixteen BytesCompares the value in the rDX:rAX registers with a 64-bit or 128-bit value in thespecified memory location. If the values are equal, the instruction copies the value inthe rCX:rBX registers to the memory location <strong>and</strong> sets the zero flag (ZF) of therFLAGS register to 1. Otherwise, it copies the value in memory to the rDX:rAXregisters <strong>and</strong> clears ZF to 0.If the effective oper<strong>and</strong> size is 16-bit or 32-bit, the CMPXCHG8B instruction is used.This instruction uses the EDX:EAX <strong>and</strong> ECX:EBX register oper<strong>and</strong>s <strong>and</strong> a 64-bitmemory oper<strong>and</strong>. If the effective oper<strong>and</strong> size is 64-bit, the CMPXCHG16Binstruction is used; this instruction uses RDX:RAX <strong>and</strong> RCX:RBX register oper<strong>and</strong>s<strong>and</strong> a 128-bit memory oper<strong>and</strong>.The CMPXCHG8B <strong>and</strong> CMPXCHG16B instructions support the LOCK prefix. Fordetails about the LOCK prefix, see “Lock Prefix” on page 10.Support for the CMPXCHG8B <strong>and</strong> CMPXCHG16B instructions depends on theprocessor implementation. To find out if a processor can execute the CMPXCHG8Binstruction, use the CPUID instruction to determine whether EDX bit 8 of CPUIDst<strong>and</strong>ard function 1 or extended function 8000_0001h is set to 1. To find out if aprocessor can execute the CMPXCHG16B instruction, use the CPUID instruction todetermine whether ECX bit 13 of CPUID st<strong>and</strong>ard function 1 is set to 1.The memory oper<strong>and</strong> used by CMPXCHG16B must be 16-byte aligned or else ageneral-protection exception is generated.Mnemonic Opcode DescriptionCMPXCHG8B mem64CMPXCHG16B mem128Related <strong>Instructions</strong>CMPXCHG0F C7 /1 m640F C7 /1 m128Compare EDX:EAX register to 64-bit memory location. If equal,set the zero flag (ZF) to 1 <strong>and</strong> copy the ECX:EBX register to thememory location. Otherwise, copy the memory location toEDX:EAX <strong>and</strong> clear the zero flag.Compare RDX:RAX register to 128-bit memory location. If equal,set the zero flag (ZF) to 1 <strong>and</strong> copy the RCX:RBX register to thememory location. Otherwise, copy the memory location toRDX:RAX <strong>and</strong> clear the zero flag.CMPXCHG8/16B 115


AMD64 Technology 24594 Rev. 3.10 February 2005rFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.ExceptionsMExceptionInvalid opcode, #UDRealXVirtual8086 Protected Cause of ExceptionXXThe CMPXCHG8B instruction is not supported, as indicated by EDXbit 8 of CPUID st<strong>and</strong>ard function 1 or extended function 8000_0001h.XThe CMPXCHG16B instruction is not supported, as indicated by ECXbit 13 of CPUID st<strong>and</strong>ard function 1.X X X The oper<strong>and</strong> was a register.Stack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded a data segment limit or was non-canonical.XXThe destination oper<strong>and</strong> was in a non-writable segment.A null data segment was used to reference memory.X The memory oper<strong>and</strong> for CMPXCHG16B was not aligned on a 16-byteboundaryPage fault, #PF X X A page fault resulted from the execution of the instruction.Alignment check, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.116 CMPXCHG8/16B


24594 Rev. 3.10 February 2005 AMD64 TechnologyCPUIDProcessor IdentificationProvides information about the processor <strong>and</strong> its capabilities through a number ofdifferent functions. Software should load the number of the CPUID function toexecute into the EAX register before executing the CPUID instruction. The processorreturns information in the EAX, EBX, ECX, <strong>and</strong> EDX registers; the contents <strong>and</strong>format of these registers depend on the function.The architecture supports CPUID information about st<strong>and</strong>ard functions <strong>and</strong> extendedfunctions. The st<strong>and</strong>ard functions have numbers in the 0000_xxxxh series (forexample, st<strong>and</strong>ard function 1). To determine the largest st<strong>and</strong>ard function numberthat a processor supports, execute CPUID function 0.The extended functions have numbers in the 8000_xxxxh series (for example,extended function 8000_0001h). To determine the largest extended function numberthat a processor supports, execute CPUID extended function 8000_0000h. If the valuereturned in EAX is greater than 8000_0000h, the processor supports extendedfunctions.Software operating at any privilege level can execute the CPUID instruction to collectthis information. In 64-bit mode, this instruction works the same as in legacy modeexcept that it zero-extends 32-bit register results to 64 bits.CPUID is a serializing instruction.Mnemonic Opcode DescriptionCPUID0F A2Returns information about the processor <strong>and</strong> its capabilities. EAXspecifies the function number, <strong>and</strong> the data is returned in EAX,EBX, ECX, EDX.Testing for the CPUIDInstructionTo avoid an invalid-opcode exception (#UD) on those processor implementations thatdo not support the CPUID instruction, software must first test to determine if theCPUID instruction is supported. Support for the CPUID instruction is indicated by theability to write the ID bit in the rFLAGS register. Normally, 32-bit software uses thePUSHFD <strong>and</strong> POPFD instructions in an attempt to write rFLAGS.ID. After readingthe updated rFLAGS.ID bit, a comparison determines if the operation changed itsvalue. If the value changed, the processor executing the code supports the CPUIDCPUID 117


AMD64 Technology 24594 Rev. 3.10 February 2005instruction. If the value did not change, rFLAGS.ID is not writable, <strong>and</strong> the processordoes not support the CPUID instruction.The following code sample shows how to test for the presence of the CPUIDinstruction using 32-bit code.pushfd; save EFLAGSpop eax ; store EFLAGS in EAXmov ebx, eax ; save in EBX for later testingxor eax, 00200000h ; toggle bit 21push eax ; push to stackpopfd; save changed EAX to EFLAGSpushfd; push EFLAGS to TOSpop eax ; store EFLAGS in EAXcmp eax, ebx ; see if bit 21 has changedjz NO_CPUID ; if no change, no CPUIDSt<strong>and</strong>ard Function 0:Processor Vendor <strong>and</strong>Largest St<strong>and</strong>ardFunction NumberAll software using the CPUID instruction must execute st<strong>and</strong>ard function 0. Thisfunction returns the largest st<strong>and</strong>ard function number <strong>and</strong> the processor vendor.St<strong>and</strong>ard Function 0 EAX: Largest St<strong>and</strong>ard Function Number. St<strong>and</strong>ard function 0 loads EAXwith the largest CPUID st<strong>and</strong>ard function number supported by the processorimplementation.St<strong>and</strong>ard Function 0 EBX, EDX, <strong>and</strong> ECX: Processor Vendor. St<strong>and</strong>ard function 0 loads a12-character string into the EBX, EDX, <strong>and</strong> ECX registers identifying the processorvendor. For AMD processors, the string is AuthenticAMD. This string informs softwarethat it should follow the AMD CPUID definition for subsequent CPUID function calls.If the function returns a another vendor’s string, software must use that vendor’sCPUID definition when interpreting the results of subsequent CPUID function calls.Table 3-1 shows the contents of the EBX, EDX, <strong>and</strong> ECX registers after executingfunction 0 on an AMD processor.Table 3-1.Processor Vendor Return ValuesRegister Return Value ASCII CharactersEBX 6874_7541h “h t u A”EDX 6974_6E65h “i t n e”ECX 444D_4163h “D M A c”118 CPUID


24594 Rev. 3.10 February 2005 AMD64 TechnologySt<strong>and</strong>ard Function 1:Processor Signature<strong>and</strong> St<strong>and</strong>ardFeaturesSt<strong>and</strong>ard Function 1 returns the processor signature <strong>and</strong> st<strong>and</strong>ard-feature bits.0000_0001h EAX: Processor Signature. Function 1 returns the processor signature in theEAX register; the signature provides information on the processor revision (stepping)level <strong>and</strong> processor model, as well as the instruction family that the processorsupports.Figure 3-1 shows the format of the EAX register following execution of CPUIDst<strong>and</strong>ard function 1.31 28 27 20 19 16 15 12 11 8 7 4 3 0Reserved Extended Family Extended Model Reserved Family Model SteppingBits Mnemonic Description31–28 Reserved27–20 Extended Family19–16 Extended Model15–12 Reserved11–8 Family7–4 Model3–0 SteppingFigure 3-1.St<strong>and</strong>ard Function 1 EAX : Processor Signature (EAX Register)The extended family <strong>and</strong> extended model fields extend the family <strong>and</strong> model fields,respectively, to accommodate larger family <strong>and</strong> model values. The method forcomputing the actual—or effective—family <strong>and</strong> model depends on the value of thefamily field. The method for computing the effective family is shown in Table 3-2.CPUID 119


AMD64 Technology 24594 Rev. 3.10 February 2005Table 3-2.Effective Family ComputationFamily Field How to Compute the Effective Family ExampleExtended FamilyFhAdd the extended family field <strong>and</strong> the zeroextendedfamily field.+07000Effective Family0Family13011100100700100010513-329.epsFamilyLess than FhUse the family field as the effective family.031100Effective Family031100513-330.epsThe method for computing the effective model is shown in Table 3-3 on page 121.120 CPUID


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable 3-3.Effective Model ComputationFamily Field How to Compute the Effective Model ExampleExtended ModelFhShift the extended model field four bits to theleft <strong>and</strong> add it to the model field.+031000Effective ModelModel0031000710000100513-331.epsModelLess than FhUse the model field as the effective model.130100Effective Model130100513-332.epsSt<strong>and</strong>ard Function 1 EBX: Initial APIC ID, Logical Processor Count, CLFLUSH Size, <strong>and</strong> 8-Bit Br<strong>and</strong> ID.CPUID st<strong>and</strong>ard function 1 returns information on the initial value of the physical IDregister associated with the advanced programmable interrupt controller (APIC), thelogical processor count, the size of the cache line flushed by the CLFLUSHinstruction, <strong>and</strong> the processor br<strong>and</strong>.Figure 3-2 shows the format of the EBX register following execution of CPUIDst<strong>and</strong>ard function 1.31 24 23 16 15 8 7 0Initial APIC ID Logical Processor Count CLFLUSH Size 8-Bit Br<strong>and</strong> IDBits Mnemonic Description31–24 Initial APIC ID23–16 Logical Processor Count15–8 CLFLUSH Size7–0 8-Bit Br<strong>and</strong> IDFigure 3-2.St<strong>and</strong>ard Function 1 EBX: Initial APIC ID, Logical Processor Count, CLFLUSH Size,<strong>and</strong> 8-Bit Br<strong>and</strong> ID (EBX Register)CPUID 121


AMD64 Technology 24594 Rev. 3.10 February 2005Initial APIC ID. This field contains the initial value of the processor’s local APICphysical ID register. This value is composed of the Northbridge NodeID (bits 26–24)<strong>and</strong> the CPU number within the node (bits 31–27). Subsequent writes by software tothe local APIC physical ID register do not change the value of the initial APIC IDfield.Logical Processor Count. The interpretation of the value in the logical processor countfield depends on the value of the core multiprocessing legacy (CMP legacy) bit (ECXbit 1) returned by CPUID extended function 8000_0001h (See Table 3-6). If the valueof the CMP legacy bit is 0, then the value returned for the HTT bit (st<strong>and</strong>ard function1, EDX bit 28) (see Table 3-5) indicates the presence of hyperthreading <strong>and</strong> the valueof the logical processor count field indicates the number of threads for each core on apackage. If the value of the CMP legacy bit is 1, then the value of the HTT bitindicates the presence of multiple cores per package <strong>and</strong> the value of the logicalprocessor count field indicates the number of cores per package.The logical processor count field is reserved (RAZ) if the HTT bit is 0.The CMP legacy bit can be set for multiple core processors that do not supporthyperthreading. This allows software to detect multiple cores as if they were multiplethreads. This method of detecting multiple cores is discouraged; where possible, newsoftware should use should use extended function 8000_0008h to return the number ofcores per package in ECX[7:0].CLFLUSH Size. This field specifies the size (in quadwords) of the cache line that isflushed by the CLFLUSH instruction. This field is implemented only if the CLFLUSHinstruction is supported. To determine if the CLFLUSH instruction is supported, testthe CLFLUSH instruction bit provided by function 1 feature flags.8-bit Br<strong>and</strong> ID. The 8-bit br<strong>and</strong> ID field identifies some AMD64 processors with aunique set of features as a specific br<strong>and</strong>. The BIOS uses the 8-bit br<strong>and</strong> ID field toprogram the processor name string that is returned byfunctions 8000_0002h–8000_0004h. If the br<strong>and</strong> ID field is 0, then the 12-bit br<strong>and</strong> IDfield (returned in EBX by extended function 8000_0001h) is used to determine theprocessor name string. For more information on the 12-bit br<strong>and</strong> ID, see “ExtendedFunction 8000_0001h EBX: 12-bit Br<strong>and</strong> ID” on page 125.For information on using the 8-bit br<strong>and</strong> ID to program the processor name string, seethe AMD Processor Recognition Application Note, order# 20734.0000_0001h ECX: St<strong>and</strong>ard Feature Support. St<strong>and</strong>ard function 1 returns st<strong>and</strong>ard-featurebits in the ECX register. The value of each bit indicates whether support for a specificfeature is present on the processor implementation. If the value of a bit is 1, thefeature is supported. If the value is 0, the feature is not supported. The ECX register is122 CPUID


24594 Rev. 3.10 February 2005 AMD64 Technologyan extension of the EDX register to represent newly introduced st<strong>and</strong>ard processorfeatures.Table 3-4 summarizes the st<strong>and</strong>ard-feature bits returned in the ECX register forst<strong>and</strong>ard function 1.Table 3-4.ECX Bit0CPUID St<strong>and</strong>ard Feature Support (St<strong>and</strong>ard Function 1—ECX)Feature(feature is supported if bit is set to 1)SSE3 <strong>Instructions</strong>. Indicates support for the SSE3 instructions. For details, see Appendix D, “InstructionSubsets <strong>and</strong> CPUID Feature Sets.”1–12 Reserved.13 CMPXCHG16B Instruction.14–31 Reserved.0000_0001h EDX: St<strong>and</strong>ard Feature Support. St<strong>and</strong>ard function 1 returns st<strong>and</strong>ard-featurebits in the EDX register. The value of each bit indicates whether support for a specificfeature is present on the processor implementation. If the value of a bit is 1, thefeature is supported. If the value is 0, the feature is not supported.Table 3-5 summarizes the st<strong>and</strong>ard-feature bits returned in the EDX register forst<strong>and</strong>ard function 1.Table 3-5.EDX BitCPUID St<strong>and</strong>ard Feature Support (St<strong>and</strong>ard Function 1—EDX)Feature(feature is supported if bit is set to 1)0 On-Chip x87-Instruction Unit.1 Virtual-Mode Extensions. See “Virtual Interrupts” in <strong>Volume</strong> 2.2 Debugging Extensions. See “Software-Debug Resources” in <strong>Volume</strong> 2.3 Page-Size Extensions (PSE). See “Page-Size Extensions (PSE) Bit” in <strong>Volume</strong> 2.4 Time-Stamp Counter. See “Time-Stamp Counter” in <strong>Volume</strong> 2.5AMD K86 Model-Specific Registers (MSRs), with RDMSR <strong>and</strong> WRMSR <strong>Instructions</strong>. See “Model-Specific Registers (MSRs)” in <strong>Volume</strong> 2.6 Physical-Address Extensions (PAE). See “Physical-Address Extensions (PAE) Bit” in <strong>Volume</strong> 2.7 Machine Check Exception. See “H<strong>and</strong>ling Machine Check Exceptions” in <strong>Volume</strong> 2.CPUID 123


AMD64 Technology 24594 Rev. 3.10 February 2005Table 3-5.EDX BitCPUID St<strong>and</strong>ard Feature Support (St<strong>and</strong>ard Function 1—EDX) (continued)Feature(feature is supported if bit is set to 1)8 CMPXCHG8B Instruction.9Advanced Programmable Interrupt Controller (APIC). BIOS must enable the local APIC. See thedocumentation for particular implementations of the architecture.10 Reserved.11SYSENTER <strong>and</strong> SYSEXIT <strong>Instructions</strong>. These instructions have different implementations than theSYSCALL <strong>and</strong> SYSRET instructions indicated by bit 11 of extended function 8000_0001h. See “SYSENTER<strong>and</strong> SYSEXIT (Legacy Mode Only)” in <strong>Volume</strong> 2.12 Memory-Type Range Registers (MTRRs). See “Memory-Type Range Registers” in <strong>Volume</strong> 2.13 Page Global Extension. See “Global Pages” in <strong>Volume</strong> 2.14 Machine Check Architecture. See “Machine Check Mechanism” in <strong>Volume</strong> 2.15Conditional Move <strong>Instructions</strong>. Indicates support for conditional move (CMOVcc) general-purposeinstructions, <strong>and</strong>—if the on-chip x87-instruction-unit bit (bit 0) is also set—for the x87 floating-pointconditional move (FCMOVcc) instructions.16 Page Attribute Table (PAT). See “Memory-Type Range Registers” in <strong>Volume</strong> 2.17 Page-Size Extensions (PSE). See“Page-Size Extensions (PSE) Bit” in <strong>Volume</strong> 2.18 Reserved.19CLFLUSH Instruction. Indicates support for the CLFLUSH (writeback, if modified, <strong>and</strong> invalidate) generalpurposeinstruction.20–22 Reserved.23MMX <strong>Instructions</strong>. Indicates support for the integer (MMX) 64-bit media instructions. For details, seeAppendix D, “Instruction Subsets <strong>and</strong> CPUID Feature Sets.”24 FXSAVE <strong>and</strong> FXRSTOR <strong>Instructions</strong>. See “FXSAVE <strong>and</strong> FXRSTOR <strong>Instructions</strong>” in <strong>Volume</strong> 2.2526SSE <strong>Instructions</strong>. Indicates support for the SSE instructions, except that the SSE instructions indicated forthe AMD Extensions to MMX <strong>Instructions</strong> feature (bit 22 of extended function 8000_0001h; see Table 3-7on page 127) are implemented if bit 25 is cleared <strong>and</strong> bit 22 of extended function 8000_0001h is set. Fordetails, see Appendix D, “Instruction Subsets <strong>and</strong> CPUID Feature Sets.”SSE2 Instruction Extensions. Indicates support for the SSE2 instructions. For details, see Appendix D,“Instruction Subsets <strong>and</strong> CPUID Feature Sets.”27 Reserved.28 Hyper-Threading Technology (HTT). (See “Logical Processor Count” on page 122.)29–31 Reserved.124 CPUID


24594 Rev. 3.10 February 2005 AMD64 TechnologyExtended Function8000_0000h:Processor Vendor <strong>and</strong>Largest ExtendedFunction NumberExtended function 8000_0000h mimics the behavior of st<strong>and</strong>ard function 0, exceptthat extended function 8000_0000h returns the largest extended function numberinstead of the largest st<strong>and</strong>ard function number.Extended Function 8000_0000h EAX: Largest Extended Function Number. Extendedfunction 8000_0000h loads EAX with the largest CPUID extended function numbersupported by the processor implementation.Extended Function 8000_0000h EBX, EDX, <strong>and</strong> ECX: Processor Vendor. Extendedfunction 8000_0000h loads a 12-character string into the EBX, EDX, <strong>and</strong> ECXregisters identifying the processor vendor. For AMD processors, the string isAuthenticAMD. This string informs software that it should follow the AMD CPUIDdefinition for subsequent CPUID function calls. If the function returns a anothervendor’s string, software must use that vendor’s CPUID definition when interpretingthe results of subsequent CPUID function calls. Table 3-1 on page 118 shows thecontents of the EBX, EDX, <strong>and</strong> ECX registers after executing extendedfunction 8000_0000h on an AMD processor.Extended Function8000_0001h:Processor Signature<strong>and</strong> AMD FeaturesLike st<strong>and</strong>ard function 1, extended function 8000_0001h returns the processorsignature <strong>and</strong> feature bits. However, the feature bits returned by this function includea subset of the bits reported by st<strong>and</strong>ard function 1, along with additional bits forAMD features.Extended Function 8000_0001h EAX: Processor Signature. Extended function 8000_0001hreturns the processor signature in the EAX register; the signature providesinformation on the processor revision (stepping) level <strong>and</strong> processor model, as well asthe instruction family that the processor supports.Figure 3-1 on page 119 shows the format of the EAX register following execution ofCPUID extended function 8000_0001h. (The value returned in the EAX register forfunction 8000_0001h is the same as the value returned by st<strong>and</strong>ard function 1.)Extended Function 8000_0001h EBX: 12-bit Br<strong>and</strong> ID. Extended function 8000_0001h returnsa 12-bit br<strong>and</strong> ID for certain AMD64 processors. As is the case with the 8-bit br<strong>and</strong> IDCPUID 125


AMD64 Technology 24594 Rev. 3.10 February 2005field, the BIOS uses the 12-bit br<strong>and</strong> ID field to program the processor name stringthat is returned by extended functions 8000_0002h–8000_0004h. If the 8-bit br<strong>and</strong> IDfield is 0 (the value in EBX returned by st<strong>and</strong>ard function 1), then the 12-bit br<strong>and</strong> IDis used to program the processor name string. For more information on the 8-bit br<strong>and</strong>ID, see “St<strong>and</strong>ard Function 1 EBX: Initial APIC ID, Logical Processor Count,CLFLUSH Size, <strong>and</strong> 8-Bit Br<strong>and</strong> ID” on page 121.Figure 3-3 shows the format of the EBX register following execution of CPUIDextended function 8000_0001h.31 12 11 0Reserved12-Bit Br<strong>and</strong> IDBits Mnemonic Description31–12 Reserved11–0 12-Bit Br<strong>and</strong> IDFigure 3-3.Extended Function 8000_0001h EBX: 12-bit Br<strong>and</strong> IDFor information on using the 12-bit br<strong>and</strong> ID to program the processor name string,see the AMD Processor Recognition Application Note, order# 20734.Extended Function 8000_0001h ECX: AMD Feature Support. Extended function 8000_0001hreturns information about AMD features—those features that were originallyimplemented by AMD—in the ECX <strong>and</strong> EDX registers. The value of each bit returnedindicates whether support for a specific feature is present on the processorimplementation. If the value of a bit is 1, the feature is supported. If the value is 0, thefeature is not supported.Table 3-6 summarizes the feature bits returned in the ECX register by CPUIDextended function 8000_0001h.Table 3-6.ECX BitCPUID AMD Feature Support (Extended Function 8000_0001h—ECX)Feature(feature is supported if bit is set to 1)0 LAHF/SAHF Supported in 64-Bit Mode.1CMP Legacy. The HTT (Hyperthreading Technology) feature bit <strong>and</strong> the logical processor count field(returned in EBX by st<strong>and</strong>ard function 1) indicate multiple cores in the package instead of hyperthreading.(See “Logical Processor Count” on page 122.)126 CPUID


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable 3-6.ECX BitCPUID AMD Feature Support (Extended Function 8000_0001h—ECX) (continued)Feature(feature is supported if bit is set to 1)2–3 Reserved.4 CR8 Available in Legacy Mode. (See “MOV(CRn)” on page 329.)5–31 Reserved.Extended Function 8000_0001h EDX: AMD Feature Support. Extended function 8000_0001hreturns information about AMD features in the EDX register. Extended function8000_0001h also duplicates some of the st<strong>and</strong>ard-feature bits from st<strong>and</strong>ardfunction 1 in the EDX register, but this practice is outdated. Any new feature that isfirst implemented by a given vendor is now reported only by a function assigned tothat vendor.Table 3-7 on page 127 summarizes the feature bits returned in the EDX register forextended function 8000_0001h. The right-most column of this table indicates whethera given bit has the same meaning when returned by st<strong>and</strong>ard function 1. If the bit hasthe same meaning, use CPUID st<strong>and</strong>ard function 1 to test whether the feature issupported. For a list of the feature bits returned by st<strong>and</strong>ard function 1, see Table 3-5on page 123.Table 3-7.EDXBitCPUID AMD Feature Support (Extended Function 8000_0001h—EDX)Feature(feature is supported if bit is set to 1)Same asFunction 1(Table 3-5) 10 On-Chip x87-Instruction Unit. yes1 Virtual-Mode Extensions. See “Virtual Interrupts” in <strong>Volume</strong> 2. yes2 Debugging Extensions. See “Software-Debug Resources” in <strong>Volume</strong> 2. yes3 Page-Size Extensions (PSE). See “Page-Size Extensions (PSE) Bit” in <strong>Volume</strong> 2. yes4 Time-Stamp Counter. See “Time-Stamp Counter” in <strong>Volume</strong> 2. yes56AMD K86 Model-Specific Registers (MSRs), with RDMSR <strong>and</strong> WRMSR <strong>Instructions</strong>. See“Model-Specific Registers (MSRs)” in <strong>Volume</strong> 2.Physical-Address Extensions (PAE). See “Physical-Address Extensions (PAE) Bit” in<strong>Volume</strong> 2.yesyesNote:1. If a bit has the same meaning for function 1 as it does for function 8000_0001h, the processor sets or clears the bit identicallyfor both functions.CPUID 127


AMD64 Technology 24594 Rev. 3.10 February 2005Table 3-7.CPUID AMD Feature Support (Extended Function 8000_0001h—EDX) (continued)EDXBitFeature(feature is supported if bit is set to 1)Same asFunction 1(Table 3-5) 17 Machine Check Exception. See “H<strong>and</strong>ling Machine Check Exceptions” in <strong>Volume</strong> 2. yes8 CMPXCHG8B Instruction. yes9Advanced Programmable Interrupt Controller (APIC). BIOS must enable the local APIC.See the documentation for particular implementations of the architecture.yes10 Reserved. no1112SYSCALL <strong>and</strong> SYSRET <strong>Instructions</strong>. These instructions have different implementationsthan the SYSENTER <strong>and</strong> SYSEXIT instructions indicated by bit 11 of st<strong>and</strong>ard function 1. Foradditional information, see “Fast <strong>System</strong> Call <strong>and</strong> Return” in <strong>Volume</strong> 2.Memory-Type Range Registers (MTRRs). See “Memory-Type Range Registers” in<strong>Volume</strong> 2.noyes13 Page Global Extension. See “Global Pages” in <strong>Volume</strong> 2. yes14 Machine Check Architecture. See “Machine Check Mechanism” in <strong>Volume</strong> 2. yes15Conditional Move <strong>Instructions</strong>. Indicates support for conditional move (CMOVcc) generalpurposeinstructions, <strong>and</strong>—if the on-chip x87-instruction-unit bit (bit 0) is also set—for thex87 floating-point conditional move (FCMOVcc) instructions.yes16 Page Attribute Table (PAT). See “Memory-Type Range Registers” in <strong>Volume</strong> 2. yes17 Page-Size Extensions (PSE). See “Page-Size Extensions (PSE) Bit” in <strong>Volume</strong> 2. yes18–19 Reserved. no20 No-Execute Page Protection. See “No Execute (NX) Bit” in <strong>Volume</strong> 2. no21 Reserved. no2223AMD Extensions to MMX <strong>Instructions</strong>. Indicates support for the AMD extensions to theinteger (MMX) 64-bit media instructions, including support for certain SSE <strong>and</strong> SSE2instructions. See Appendix D, “Instruction Subsets <strong>and</strong> CPUID Feature Sets,” for details.MMX <strong>Instructions</strong>. Indicates support for the integer (MMX) 64-bit media instructions. Fordetails, see Appendix D, “Instruction Subsets <strong>and</strong> CPUID Feature Sets.”noyes24 FXSAVE <strong>and</strong> FXRSTOR <strong>Instructions</strong>. See “FXSAVE <strong>and</strong> FXRSTOR <strong>Instructions</strong>” in <strong>Volume</strong> 2. yes25 Fast FXSAVE/FXRSTOR. See "FXSAVE <strong>and</strong> FXRSTOR <strong>Instructions</strong>" in <strong>Volume</strong> 2. noNote:1. If a bit has the same meaning for function 1 as it does for function 8000_0001h, the processor sets or clears the bit identicallyfor both functions.128 CPUID


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable 3-7.CPUID AMD Feature Support (Extended Function 8000_0001h—EDX) (continued)EDXBit26 Reserved.Feature(feature is supported if bit is set to 1)Same asFunction 1(Table 3-5) 127 RDTSCP Instruction. no28 Reserved.29 Long Mode. See “Long Mode” in <strong>Volume</strong> 2. no3031AMD Extensions to 3DNow! <strong>Instructions</strong>. Indicates support for the AMD extensions tothe floating-point (3DNow!) 64-bit media instructions. For details, see Appendix D,“Instruction Subsets <strong>and</strong> CPUID Feature Sets.”AMD 3DNow! <strong>Instructions</strong>. Indicates support for the floating-point (3DNow!) 64-bitmedia instructions. For details, see Appendix D, “Instruction Subsets <strong>and</strong> CPUID FeatureSets.”nonoNote:1. If a bit has the same meaning for function 1 as it does for function 8000_0001h, the processor sets or clears the bit identicallyfor both functions.Extended Functions8000_0002h–8000_0004h:Processor NameExtended functions 8000_0002h, 8000_0003h, <strong>and</strong> 8000_0004h together return anASCII string containing the name of the processor implementation. Software cansimply call these three functions in numerical order to obtain a 48-character ASCIIname string. Although the name string can be up to 48 characters in length, shorternames have unused byte locations filled with the ASCII null character (00h).Note: The BIOS must program the name string before these functions are executed;otherwise, these functions return the default processor name string (48 ASCIInull characters).The name string returned by these functions is in little-endian format. Extendedfunction 8000_0002h returns the first 16 characters of the name <strong>and</strong> extendedfunction 8000_0004h returns the last 16 characters. For each of the three groups of 16characters, the functions return the name (in order of least-significant to mostsignificantbyte) in the EAX, EBX, ECX, <strong>and</strong> EDX registers. The first character residesin the least-significant byte of EAX, <strong>and</strong> the last character resides in the mostsignificantbyte of EDX.CPUID 129


AMD64 Technology 24594 Rev. 3.10 February 2005Table 3-8 on page 130 gives an example of the return values <strong>and</strong> their equivalentASCII characters for a processor with the following name string:AMD Athlon(tm) processorTable 3-8.Processor Name String ExampleFunction Register Return Value ASCII CharactersEAX 2044_4D41h “space D M A”8000_0002hEBX 6C68_7441h “l h t A”ECX 7428_6E6Fh “t ( n o”EDX 7020_296Dh “p space ) m”EAX 6563_6F72h “e c o r”8000_0003h8000_0004hEBX 726F_7373h “r o s s”ECX0000_0000hEDX0000_0000hEAX0000_0000hEBX0000_0000hECX0000_0000hEDX0000_0000hExtended Function8000_0005h: L1Cache <strong>and</strong> TLBInformationCPUID extended functions 8000_0005h <strong>and</strong> 8000_0006h provide cache <strong>and</strong> TLBinformation. These functions are useful to diagnostic software that displaysinformation about the system <strong>and</strong> the configuration of the processor implementation,including cache size <strong>and</strong> organization. For more information about the TLB <strong>and</strong> onchipcaches, see “Translation-Lookaside Buffer (TLB)” in <strong>Volume</strong> 2 <strong>and</strong> “MemoryCaches” in <strong>Volume</strong> 2.Extended function 8000_0005h returns information about the TLBs <strong>and</strong> L1 cachesintegrated on the processor. Tables 3-9, 3-10, 3-11, <strong>and</strong> 3-12, all on page 131, show theregister formats for the information returned by function 8000_0005h.In these tables, the associativity field is encoded as follows:• 00h—Reserved.130 CPUID


24594 Rev. 3.10 February 2005 AMD64 Technology• 01h—Direct mapped.• 02h through FEh—The value represents the actual associativity. For example, avalue of 04h indicates 4-way associativity.• FFh—Fully associative.Table 3-9.RegisterCPUID TLB Bits for 2-Mbyte <strong>and</strong> 4-Mbyte Pages (Extended Function 8000_0005—EAX)Data TLBInstruction TLBAssociativity Number of Entries 1 Associativity Number of Entries 1EAX Bits 31–24 Bits 23–16 Bits 15–8 Bits 7–0Note:1. The number of entries returned is the number of entries available for the 2-Mbyte page size. The 4-Mbyte pages may require two2-Mbyte entries, depending on the implementation, so the number of entries available for the 4-Mbyte page size would be onehalfthe returned value.Table 3-10.RegisterCPUID TLB Bits for 4-Kbyte Pages (Extended Function 8000_0005—EBX)Data TLBInstruction TLBAssociativity Number of Entries Associativity Number of EntriesEBX Bits 31–24 Bits 23–16 Bits 15–8 Bits 7–0Table 3-11.RegisterCPUID L1 Data Cache Bits (Extended Function 8000_0005—ECX)L1 Data CacheSize (Kbytes) Associativity Lines Per Tag Line Size (Bytes)ECX Bits 31–24 Bits 23–16 Bits 15–8 Bits 7–0Table 3-12.RegisterCPUID L1 Instruction Cache Bits (Extended Function 8000_0005—EDX)L1 Instruction CacheSize (Kbytes) Associativity Lines Per Tag Line Size (Bytes)EDX Bits 31–24 Bits 23–16 Bits 15–8 Bits 7–0CPUID 131


AMD64 Technology 24594 Rev. 3.10 February 2005Extended Function8000_0006h: L2Cache <strong>and</strong> TLBInformationExtended function 8000_0006h returns information about the L2 cache integrated onthe processor. Tables 3-13, 3-14, <strong>and</strong> 3-15 on page 133 show the register-contentformats for the information returned by extended function 8000_0006h.In these tables, the associativity field is encoded as follows:• 00h—The L2 cache is off (disabled).• 01h—Direct mapped.• 02h—2-way associative.• 04h—4-way associative.• 06h—8-way associative.• 08h—16-way associative.• 0Fh—Fully associative.• All other encodings are reserved.Table 3-13.RegisterCPUID L2 TLB Bits for 2-Mbyte <strong>and</strong> 4-Mbyte Pages (Extended Function 8000_0006—EAX)L2 Data TLB L2 Instruction or Unified L2 TLB 1Associativity Number of Entries 2 Associativity Number of Entries 2EAX Bits 31–28 Bits 27–16 Bits 15–12 Bits 11–0Notes:1. The presence of a unified L2 TLB is indicated by a value of 0000h in the upper 16 bits of the EAX register. The unified L2 TLBinformation is contained in the lower 16 bits of the EAX register.2. The number of entries returned is the number of entries available for the 2-Mbyte page size. The 4-Mbyte pages may require two2-Mbyte entries, depending on the implementation, so the number of entries available for the 4-Mbyte page size would be onehalfthe returned value.Table 3-14.RegisterCPUID L2 TLB Bits for 4-Kbyte Pages (Extended Function 8000_0006—EBX)L2 Data TLB L2 Instruction or Unified L2 TLB 1Associativity Number of Entries Associativity Number of EntriesEBX Bits 31–28 Bits 27–16 Bits 15–12 Bits 11–0Note:1. The presence of a unified L2 TLB is indicated by a value of 0000h in the upper 16 bits of the EBX register. The unified L2 TLBinformation is contained in the lower 16 bits of the EBX register.132 CPUID


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable 3-15.CPUID L2 Cache Bits(Extended Function 8000_0006—ECX)RegisterExtended Function 8000_0006h EDX. For extended function 8000_0006h, the EDX registeris reserved.Extended Function8000_0007h:Advanced PowerManagementFeaturesL2 CacheSize (Kbytes) Associativity Lines Per Tag Line Size (Bytes)ECX Bits 31–16 Bits 15–12 Bits 11–8 Bits 7–0Extended Function 8000_0007h returns information about the advanced-powermanagementfeatures supported by the processor.Extended Function 8000_0007h EAX, EBX, <strong>and</strong> ECX. For extended function 8000_0007h, theEAX, EBX, <strong>and</strong> ECX registers are reserved.Extended Function 8000_0007h EDX. Extended function 8000_0007h returns informationabout advanced-power-management features in the EDX register. Figure 3-4 shows theformat of the EDX register following execution of CPUID extended extendedfunction 8000_0007h. Each bit indicates whether support for a specific feature ispresent on the processor implementation. If the value of a power-management-featurebit is 1, the feature is supported. If the value is 0, the feature is not supported.31 6 5 4 3 2 1 0ReservedSTCTMTTPVIDFIDTSBits Mnemonic Description31–6 Reserved5 STC Software Thermal Control4 TM Thermal Monitoring3 TTP Thermal Trip2 VID Voltage ID Control1 FID Frequency ID Control0 TS Temperature SensorFigure 3-4.Register)Extended Function 8000_0007h EDX: Advanced Power Management Features (EDXCPUID 133


AMD64 Technology 24594 Rev. 3.10 February 2005Extended Function8000_0008h:Maximum AddressSizes <strong>and</strong> Number ofCPU CoresExtended function 8000_0008h reports the maximum supported virtual-address <strong>and</strong>physical-address sizes <strong>and</strong> the number of CPUID cores on the CPU.Extended Function 8000_0008h EAX. Extended function 8000_0008h reports address-sizeinformation in the EAX register. Figure 3-5 on page 134 shows the format of the EAXregister during execution of CPUID extended function 8000_0008h. The virtualaddress<strong>and</strong> physical-address sizes that are returned indicate the address widths, inbits, supported by the processor implementation. The values returned by this functionare not influenced by enabling or disabling either long mode or physical-addressextensions (CR4.PAE).31 16 15 8 7 0Reserved, RAZ Max Virtual Address Width Max Physical Address WidthBits Definition Value31–16 Reserved RAZ15–8 Maximum Virtual Address Width 30h (48 bits)7–0 Maximum Physical Address Width 28h (40 bits)Figure 3-5.Extended Function 8000_0008h EAX: Virtual <strong>and</strong> Physical Address WidthsExtended Function 8000_0008h ECX. For extended function 8000_0008h, the ECX registerbits 7–0 indicate the number of physical cores on the CPU package being tested.31 7 0Reserved (RAZ)Physical Core CountBits Definition Value31–8 Reserved RAZ7–0 Physical Core Count Number of physical cores in thepackage, minus one.Figure 3-6.Extended Function 8000_0008h ECX: Physical Core CountExtended Function 8000_0008h EBX <strong>and</strong> EDX. For extended function 8000_0008h, the EBX<strong>and</strong> EDX registers are reserved.134 CPUID


24594 Rev. 3.10 February 2005 AMD64 TechnologyRelated <strong>Instructions</strong>NonerFLAGS AffectedNoneExceptionsNoneCPUID 135


AMD64 Technology 24594 Rev. 3.10 February 2005DAADecimal Adjust after AdditionAdjusts the value in the AL register into a packed BCD result <strong>and</strong> sets the CF <strong>and</strong> AFflags in the rFLAGS register to indicate a decimal carry out of either nibble of AL.Use this instruction to adjust the result of a byte ADD instruction that performed thebinary addition of one 2-digit packed BCD values to another.The instruction performs the adjustment by adding 06h to AL if the lower nibble isgreater than 9 or if AF = 1. Then 60h is added to AL if the original AL was greater than99h or if CF = 1.If the lower nibble of AL was adjusted, the AF flag is set to 1. Otherwise AF is notmodified. If the upper nibble of AL was adjusted, the CF flag is set to 1. Otherwise, CFis not modified. SF, ZF, <strong>and</strong> PF are set according to the final value of AL.Using this instruction in 64-bit mode generates an invalid-opcode (#UD) exception.Mnemonic Opcode DescriptionDAA 27Decimal adjust AL.(Invalid in 64-bit mode.)rFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFExceptionsU M M M M M21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.VirtualException Real 8086 Protected Cause of ExceptionInvalid opcode, #UD X This instruction was executed in 64-bit mode.136 DAA


24594 Rev. 3.10 February 2005 AMD64 TechnologyDASDecimal Adjust after SubtractionAdjusts the value in the AL register into a packed BCD result <strong>and</strong> sets the CF <strong>and</strong> AFflags in the rFLAGS register to indicate a decimal borrow.Use this instruction adjust the result of a byte SUB instruction that performed abinary subtraction of one 2-digit, packed BCD value from another.This instruction performs the adjustment by subtracting 06h from AL if the lowernibble is greater than 9 or if AF = 1. Then 60h is subtracted from AL if the original ALwas greater than 99h or if CF = 1.If the adjustment changes the lower nibble of AL, the AF flag is set to 1; otherwise AFis not modified. If the adjustment results in a borrow for either nibble of AL, the CFflag is set to 1; otherwise CF is not modified. The SF, ZF, <strong>and</strong> PF flags are set accordingto the final value of AL.Using this instruction in 64-bit mode generates an invalid-opcode (#UD) exception.Mnemonic Opcode DescriptionDASRelated <strong>Instructions</strong>DAArFLAGS Affected2FDecimal adjusts AL after subtraction.(Invalid in 64-bit mode.)ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFExceptionsU M M M M M21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.VirtualException Real 8086 Protected Cause of ExceptionInvalid opcode, #UD X This instruction was executed in 64-bit mode.DAS 137


AMD64 Technology 24594 Rev. 3.10 February 2005DEC Decrement by 1Subtracts 1 from the specified register or memory location. The CF flag is notaffected.The one-byte forms of this instruction (opcodes 48 through 4F) are used as REXprefixes in 64-bit mode. See “REX Prefixes” on page 14.The forms of the DEC instruction that write to memory support the LOCK prefix. Fordetails about the LOCK prefix, see “Lock Prefix” on page 10.To perform a decrement operation that updates the CF flag, use a SUB instructionwith an immediate oper<strong>and</strong> of 1.Mnemonic Opcode DescriptionDEC reg/mem8 FE /1DEC reg/mem16 FF /1DEC reg/mem32 FF /1DEC reg/mem64 FF /1Decrement the contents of an 8-bit register or memory locationby 1.Decrement the contents of a 16-bit register or memory locationby 1.Decrement the contents of a 32-bit register or memory locationby 1.Decrement the contents of a 64-bit register or memory locationby 1.DEC reg16DEC reg3248 +rw48 +rdDecrement the contents of a 16-bit register by 1.(See “REX Prefixes” on page 14.)Decrement the contents of a 32-bit register by 1.(See “REX Prefixes” on page 14.)Related <strong>Instructions</strong>INC, SUB138 DEC


24594 Rev. 3.10 February 2005 AMD64 TechnologyrFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFExceptionsM M M M M21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.Exception RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded the data segment limit or was noncanonical.XThe destination oper<strong>and</strong> 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, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.DEC 139


AMD64 Technology 24594 Rev. 3.10 February 2005DIVUnsigned DivideDivides the unsigned value in a register by the unsigned value in the specified registeror memory location. The register to be divided depends on the size of the divisor.When dividing a word, the dividend is in the AX register. The instruction stores thequotient in the AL register <strong>and</strong> the remainder in the AH register.When dividing a doubleword, quadword, or double quadword, the most-significantword of the dividend is in the rDX register <strong>and</strong> the least-significant word is in the rAXregister. After the division, the instruction stores the quotient in the rAX register <strong>and</strong>the remainder in the rDX register.The following table summarizes the action of this instruction:Division Size Dividend Divisor Quotient Remainder Maximum QuotientWord/byte AX reg/mem8 AL AH 255Doubleword/word DX:AX reg/mem16 AX DX 65,535Quadword/doubleword EDX:EAX reg/mem32 EAX EDX 2 32 –1Double quadword/quadwordRDX:RAX reg/mem64 RAX RDX 2 64 –1The instruction truncates non-integral results towards 0 <strong>and</strong> the remainder is alwaysless than the divisor. An overflow generates a #DE (divide error) exception, ratherthan setting the CF flag.Division by zero generates a divide-by-zero exception.Mnemonic Opcode DescriptionDIV reg/mem8 F6 /6DIV reg/mem16 F7 /6Perform unsigned division of AX by the contents of an 8-bitregister or memory location <strong>and</strong> store the quotient in AL <strong>and</strong> theremainder in AH.Perform unsigned division of DX:AX by the contents of a 16-bitregister or memory oper<strong>and</strong> store the quotient in AX <strong>and</strong> theremainder in DX.140 DIV


24594 Rev. 3.10 February 2005 AMD64 TechnologyMnemonic Opcode DescriptionDIV reg/mem32 F7 /6DIV reg/mem64 F7 /6Perform unsigned division of EDX:EAX by the contents of a 32-bitregister or memory location <strong>and</strong> store the quotient in EAX <strong>and</strong>the remainder in EDX.Performs unsigned division of RDX:RAX by the contents of a 64-bit register or memory location <strong>and</strong> store the quotient in RAX <strong>and</strong>the remainder in RDX.Related <strong>Instructions</strong>MULrFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFExceptionsU U U U U U21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.ExceptionDivide by zero, #DERealXVirtual8086 Protected Cause of ExceptionXXThe divisor oper<strong>and</strong> was 0.X X X The quotient was too large for the designated register.Stack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded a data segment limit or was 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.Alignment check, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.DIV 141


AMD64 Technology 24594 Rev. 3.10 February 2005ENTERCreate Procedure Stack FrameCreates a stack frame for a procedure.The first oper<strong>and</strong> specifies the size of the stack frame allocated by the instruction.The second oper<strong>and</strong> specifies the nesting level (0 to 31—the value is automaticallymasked to 5 bits). For nesting levels of 1 or greater, the processor copies earlier stackframe pointers before adjusting the stack pointer. This action provides a calledprocedure with access points to other nested stack frames.The 32-bit enter N, 0 (a nesting level of 0) instruction is equivalent to the following32-bit instruction sequence:push ebp ; save current EBPmov ebp, esp ; set stack frame pointer valuesub esp, N ; allocate space for local variablesThe ENTER <strong>and</strong> 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 oper<strong>and</strong> size of ENTER defaults to 64 bits, <strong>and</strong> there is no prefixavailable for encoding a 32-bit oper<strong>and</strong> size.Mnemonic Opcode DescriptionENTER imm16, 0 C8 iw 00 Create a procedure stack frame.ENTER imm16, 1 C8 iw 01 Create a nested stack frame for a procedure.ENTER imm16, imm8 C8 iw ib Create a nested stack frame for a procedure.Action// See “Pseudocode Definitions” on page 49.ENTER_START:temp_ALLOC_SPACE = word-sized immediate specified in the instruction(first oper<strong>and</strong>), zero-extended to 64 bitstemp_LEVEL = byte-sized immediate specified in the instruction(second oper<strong>and</strong>), zero-extended to 64 bitstemp_LEVEL = temp_LEVEL AND 0x1f// only keep 5 bits of level countPUSH.v old_RBP142 ENTER


24594 Rev. 3.10 February 2005 AMD64 Technologytemp_RBP = RSPIF (temp_LEVEL>0){// This value of RSP will eventually be loaded// into RBP.// Push "temp_LEVEL" parameters to the stack.FOR (I=1; I


AMD64 Technology 24594 Rev. 3.10 February 2005IDIVSigned DivideDivides the signed value in a register by the signed value in the specified register ormemory location. The register to be divided depends on the size of the divisor.When dividing a word, the dividend is in the AX register. The instruction stores thequotient in the AL register <strong>and</strong> the remainder in the AH register.When dividing a doubleword, quadword, or double quadword, the most-significantword of the dividend is in the rDX register <strong>and</strong> the least-significant word is in the rAXregister. After the division, the instruction stores the quotient in the rAX register <strong>and</strong>the remainder in the rDX register.The following table summarizes the action of this instruction:Division Size Dividend Divisor Quotient Remainder Quotient RangeWord/byte AX reg/mem8 AL AH –128 to +127Doubleword/word DX:AX reg/mem16 AX DX –32,768 to +32,767Quadword/doubleword EDX:EAX reg/mem32 EAX EDX –2 31 to 2 31 –1Double quadword/quadwordRDX:RAX reg/mem64 RAX RDX –2 63 to 2 63 –1The instruction truncates non-integral results towards 0. The sign of the remainder isalways the same as the sign of the dividend, <strong>and</strong> the absolute value of the remainder isless 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 CQOinstruction to sign-extend the dividend.Mnemonic Opcode DescriptionIDIV reg/mem8 F6 /7IDIV reg/mem16 F7 /7Perform signed division of AX by the contents of an 8-bit registeror memory location <strong>and</strong> store the quotient in AL <strong>and</strong> theremainder in AH.Perform signed division of DX:AX by the contents of a 16-bitregister or memory location <strong>and</strong> store the quotient in AX <strong>and</strong> theremainder in DX.144 IDIV


24594 Rev. 3.10 February 2005 AMD64 TechnologyMnemonic Opcode DescriptionIDIV reg/mem32 F7 /7IDIV reg/mem64 F7 /7Perform signed division of EDX:EAX by the contents of a 32-bitregister or memory location <strong>and</strong> store the quotient in EAX <strong>and</strong>the remainder in EDX.Perform signed division of RDX:RAX by the contents of a 64-bitregister or memory location <strong>and</strong> store the quotient in RAX <strong>and</strong>the remainder in RDX.Related <strong>Instructions</strong>IMULrFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFExceptionsU U U U U U21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.ExceptionDivide by zero, #DERealXVirtual8086 Protected Cause of ExceptionXXThe divisor oper<strong>and</strong> was 0.X X X The quotient was too large for the designated register.Stack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded a data segment limit or was 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.Alignment check, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.IDIV 145


AMD64 Technology 24594 Rev. 3.10 February 2005IMULSigned MultiplyMultiplies two signed oper<strong>and</strong>s. The number of oper<strong>and</strong>s determines the form of theinstruction.If a single oper<strong>and</strong> is specified, the instruction multiplies the value in the specifiedgeneral-purpose register or memory location by the value in the AL, AX, EAX, or RAXregister (depending on the oper<strong>and</strong> size) <strong>and</strong> stores the product in AX, DX:AX,EDX:EAX, or RDX:RAX, respectively.If two oper<strong>and</strong>s are specified, the instruction multiplies the value in a generalpurposeregister (first oper<strong>and</strong>) by an immediate value or the value in a generalpurposeregister or memory location (second oper<strong>and</strong>) <strong>and</strong> stores the product in thefirst oper<strong>and</strong> location.If three oper<strong>and</strong>s are specified, the instruction multiplies the value in a generalpurposeregister or memory location (second oper<strong>and</strong>), by an immediate value (thirdoper<strong>and</strong>) <strong>and</strong> stores the product in a register (first oper<strong>and</strong>).The IMUL instruction sign-extends an immediate oper<strong>and</strong> to the length of the otherregister/memory oper<strong>and</strong>.The CF <strong>and</strong> OF flags are set if, due to integer overflow, the double-widthmultiplication result cannot be represented in the half-width destination register.Otherwise the CF <strong>and</strong> OF flags are cleared.Mnemonic Opcode DescriptionIMUL reg/mem8 F6 /5IMUL reg/mem16 F7 /5IMUL reg/mem32 F7 /5IMUL reg/mem64 F7 /5IMUL reg16, reg/mem16 0F AF /rMultiply the contents of AL by the contents of an 8-bit memoryor register oper<strong>and</strong> <strong>and</strong> put the signed result in AX.Multiply the contents of AX by the contents of a 16-bit memory orregister oper<strong>and</strong> <strong>and</strong> put the signed result in DX:AX.Multiply the contents of EAX by the contents of a 32-bit memoryor register oper<strong>and</strong> <strong>and</strong> put the signed result in EDX:EAX.Multiply the contents of RAX by the contents of a 64-bit memoryor register oper<strong>and</strong> <strong>and</strong> put the signed result in RDX:RAX.Multiply the contents of a 16-bit destination register by thecontents of a 16-bit register or memory oper<strong>and</strong> <strong>and</strong> put thesigned result in the 16-bit destination register.146 IMUL


24594 Rev. 3.10 February 2005 AMD64 TechnologyMnemonic Opcode DescriptionIMUL reg32, reg/mem32 0F AF /rIMUL reg64, reg/mem64 0F AF /rMultiply the contents of a 32-bit destination register by thecontents of a 32-bit register or memory oper<strong>and</strong> <strong>and</strong> put thesigned result in the 32-bit destination register.Multiply the contents of a 64-bit destination register by thecontents of a 64-bit register or memory oper<strong>and</strong> <strong>and</strong> put thesigned result in the 64-bit destination register.IMUL reg16, reg/mem16, imm8IMUL reg32, reg/mem32, imm8IMUL reg64, reg/mem64, imm8IMUL reg16, reg/mem16, imm16IMUL reg32, reg/mem32, imm32IMUL reg64, reg/mem64, imm32Related <strong>Instructions</strong>IDIV6B /r ib6B /r ib6B /r ib69 /r iw69 /r id69 /r idMultiply the contents of a 16-bit register or memory oper<strong>and</strong> by asign-extended immediate byte <strong>and</strong> put the signed result in the16-bit destination register.Multiply the contents of a 32-bit register or memory oper<strong>and</strong> bya sign-extended immediate byte <strong>and</strong> put the signed result in the32-bit destination register.Multiply the contents of a 64-bit register or memory oper<strong>and</strong> bya sign-extended immediate byte <strong>and</strong> put the signed result in the64-bit destination register.Multiply the contents of a 16-bit register or memory oper<strong>and</strong> by asign-extended immediate word <strong>and</strong> put the signed result in the16-bit destination register.Multiply the contents of a 32-bit register or memory oper<strong>and</strong> bya sign-extended immediate double <strong>and</strong> put the signed result inthe 32-bit destination register.Multiply the contents of a 64-bit register or memory oper<strong>and</strong> bya sign-extended immediate double <strong>and</strong> put the signed result inthe 64-bit destination register.IMUL 147


AMD64 Technology 24594 Rev. 3.10 February 2005rFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFExceptionsM U U U U M21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.Exception RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded a data segment limit or was 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.Alignment check, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.148 IMUL


24594 Rev. 3.10 February 2005 AMD64 TechnologyINInput from PortTransfers a byte, word, or doubleword from an I/O port (second oper<strong>and</strong>) to the AL,AX or EAX register (first oper<strong>and</strong>). The port address can be an 8-bit immediate value(00h to FFh) or contained in the DX register (0000h to FFFFh).The port is in the processor’s I/O address space. For 8-bit I/O port accesses, the opcodedetermines the port size. For 16-bit <strong>and</strong> 32-bit accesses, the oper<strong>and</strong>-size attributedetermines the port size. If the oper<strong>and</strong> size is 64-bits, IN reads only 32 bits from theI/O port.If the CPL is higher than IOPL, or the mode is virtual mode, IN checks the I/Opermission bitmap in the TSS before allowing access to the I/O port. (See <strong>Volume</strong> 2 fordetails on the TSS I/O permission bitmap.)Mnemonic Opcode DescriptionIN AL, imm8IN AX, imm8IN EAX, imm8IN AL, DXIN AX, DXIN EAX, DXRelated <strong>Instructions</strong>INSx, OUT, OUTSxrFLAGS AffectedNoneE4 ibE5 ibE5 ibECEDEDInput a byte from the port at the address specified by imm8 <strong>and</strong>put it into the AL register.Input a word from the port at the address specified by imm8 <strong>and</strong>put it into the AX register.Input a doubleword from the port at the address specified byimm8 <strong>and</strong> put it into the EAX register.Input a byte from the port at the address specified by the DXregister <strong>and</strong> put it into the AL register.Input a word from the port at the address specified by the DXregister <strong>and</strong> put it into the AX register.Input a doubleword from the port at the address specified by theDX register <strong>and</strong> put it into the EAX register.IN 149


AMD64 Technology 24594 Rev. 3.10 February 2005ExceptionsException<strong>General</strong> protection,#GPRealVirtual8086 Protected Cause of ExceptionXOne or more I/O permission bits were set in the TSS for the accessedport.X The CPL was greater than the IOPL <strong>and</strong> one or more I/O permissionbits were set in the TSS for the accessed port.Page fault, #PF X X A page fault resulted from the execution of the instruction.150 IN


24594 Rev. 3.10 February 2005 AMD64 TechnologyINC Increment by 1Adds 1 to the specified register or memory location. The CF flag is not affected, evenif the oper<strong>and</strong> is incremented to 0000.The one-byte forms of this instruction (opcodes 40 through 47) are used as REXprefixes in 64-bit mode. See “REX Prefixes” on page 14.The forms of the INC instruction that write to memory support the LOCK prefix. Fordetails about the LOCK prefix, see “Lock Prefix” on page 10.To perform an increment operation that updates the CF flag, use an ADD instructionwith an immediate oper<strong>and</strong> of 1.Mnemonic Opcode DescriptionINC reg/mem8 FE /0INC reg/mem16 FF /0INC reg/mem32 FF /0INC reg/mem64 FF /0Increment the contents of an 8-bit register or memory locationby 1.Increment the contents of a 16-bit register or memory location by1.Increment the contents of a 32-bit register or memory location by1.Increment the contents of a 64-bit register or memory locationby 1.INC reg16INC reg3240 +rw40 +rdIncrement the contents of a 16-bit register by 1.(These opcodes are used as REX prefixes in 64-bit mode. See“REX Prefixes” on page 14.)Increment the contents of a 32-bit register by 1.(These opcodes are used as REX prefixes in 64-bit mode.See“REX Prefixes” on page 14.)Related <strong>Instructions</strong>ADD, DECINC 151


AMD64 Technology 24594 Rev. 3.10 February 2005rFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFExceptionsM M M M M21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.Exception RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded a data segment limit or was non-canonical.XThe destination oper<strong>and</strong> 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, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.152 INC


24594 Rev. 3.10 February 2005 AMD64 TechnologyINSINSBINSWINSDInput StringTransfers data from the I/O port specified in the DX register to an input bufferspecified in the rDI register <strong>and</strong> increments or decrements the rDI register accordingto the setting of the DF flag in the rFLAGS register.If the DF flag is 0, the instruction increments rDI by 1, 2, or 4, depending on thenumber of bytes read. If the DF flag is 1, it decrements the pointer by 1, 2, or 4.In 16-bit <strong>and</strong> 32-bit mode, the INS instruction always uses ES as the data segment. TheES segment cannot be overridden with a segment override prefix. In 64-bit mode, INSalways uses the unsegmented memory space.The INS instructions use the explicit memory oper<strong>and</strong> (first oper<strong>and</strong>) to determinethe size of the I/O port, but always use ES:[rDI] for the location of the input buffer. Theexplicit register oper<strong>and</strong> (second oper<strong>and</strong>) specifies the I/O port address <strong>and</strong> mustalways be DX.The INSB, INSW, <strong>and</strong> INSD instructions copy byte, word, <strong>and</strong> doubleword data,respectively, from the I/O port (0000h to FFFFh) specified in the DX register to theinput buffer specified in the ES:rDI registers.If the oper<strong>and</strong> size is 64-bits, the instruction behaves as if the oper<strong>and</strong> size were 32-bits.If the CPL is higher than the IOPL or the mode is virtual mode, INSx checks the I/Opermission bitmap in the TSS before allowing access to the I/O port. (See volume 2 fordetails on the TSS I/O permission bitmap.)The INSx instructions support the REP prefix for block input of rCX bytes, words, ordoublewords. For details about the REP prefix, see “Repeat Prefixes” on page 10.INSx 153


AMD64 Technology 24594 Rev. 3.10 February 2005Mnemonic Opcode DescriptionINS mem8, DXINS mem16, DXINS mem32, DXINSBINSWINSDRelated <strong>Instructions</strong>IN, OUT, OUTSxrFLAGS AffectedNone6C6D6D6C6D6DInput a byte from the port specified by DX, put it into thememory location specified in ES:rDI, <strong>and</strong> then increment ordecrement rDI.Input a word from the port specified by DX register, put it into thememory location specified in ES:rDI, <strong>and</strong> then increment ordecrement rDI.Input a doubleword from the port specified by DX, put it into thememory location specified in ES:rDI, <strong>and</strong> then increment ordecrement rDI.Input a byte from the port specified by DX, put it into thememory location specified in ES:rDI, <strong>and</strong> then increment ordecrement rDI.Input a word from the port specified by DX, put it into thememory location specified in ES:rDI, <strong>and</strong> then increment ordecrement rDI.Input a doubleword from the port specified by DX, put it into thememory location specified in ES:rDI, <strong>and</strong> then increment ordecrement rDI.154 INSx


24594 Rev. 3.10 February 2005 AMD64 TechnologyExceptionsException<strong>General</strong> protection,#GPRealXVirtual8086 Protected Cause of ExceptionXXA memory address exceeded a data segment limit or was non-canonical.XOne or more I/O permission bits were set in the TSS for the accessedport.XXThe CPL was greater than the IOPL <strong>and</strong> one or more I/O permissionbits were set in the TSS for the accessed port.A null data segment was used to reference memory.X The destination oper<strong>and</strong> was in a non-writable segment.Page fault, #PF X X A page fault resulted from the execution of the instruction.Alignment check, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.INSx 155


AMD64 Technology 24594 Rev. 3.10 February 2005INTInterrupt to VectorTransfers execution to the interrupt h<strong>and</strong>ler specified by an 8-bit unsigned immediatevalue. This value is an interrupt vector number (00h to FFh), which the processor usesas an index into the interrupt-descriptor table (IDT).For detailed descriptions of the steps performed by INTn instructions, see thefollowing:• Legacy-Mode Interrupts: “Legacy Protected-Mode Interrupt Control Transfers” in<strong>Volume</strong> 2.• Long-Mode Interrupts: “Long-Mode Interrupt Control Transfers” in <strong>Volume</strong> 2.See also the descriptions of the INT3 instruction on page 304 <strong>and</strong> the INTOinstruction on page 164.Mnemonic Opcode DescriptionINT imm8 CD ib Call interrupt service routine specified by interrupt vector imm8.Action// See “Pseudocode Definitions” on page 49.INT_N_START:IF (REAL_MODE)INT_N_REALELSIF (PROTECTED_MODE)INT_N_PROTECTEDELSE // (VIRTUAL_MODE)INT_N_VIRTUALINT_N_REAL:temp_int_n_vector = byte-sized interrupt vector specified in the instruction,zero-extended to 64 bitstemp_RIP = READ_MEM.w [idt:temp_int_n_vector*4]// read target CS:RIP from the real-mode idttemp_CS = READ_MEM.w [idt:temp_int_n_vector*4+2]PUSH.w old_RFLAGSPUSH.w old_CSPUSH.w next_RIP156 INT


24594 Rev. 3.10 February 2005 AMD64 TechnologyIF (temp_RIP>CS.limit)EXCEPTION [#GP]CS.sel = temp_CSCS.base = temp_CS SHL 4RFLAGS.AC,TF,IF,RF clearedRIP = temp_RIPEXITINT_N_PROTECTED:temp_int_n_vector = byte-sized interrupt vector specified in the instruction,zero-extended to 64 bitstemp_idt_desc = READ_IDT (temp_int_n_vector)IF (temp_idt_desc.attr.type = ’taskgate’)TASK_SWITCH // using tss selector in the task gate as the target tssIF (LONG_MODE) // The size of the gate controls the size of the// stack pushes.V=8-byte // Long mode only uses 64-bit gates.ELSIF ((temp_idt_desc.attr.type = ’intgate32’)|| (temp_idt_desc.attr.type = ’trapgate32’))V=4-byte // Legacy mode, using a 32-bit gateELSE // gate is intgate16 or trapgate16V=2-byte // Legacy mode, using a 16-bit gatetemp_RIP = temp_idt_desc.offsetIF (LONG_MODE){// In long mode, we need to read the 2nd half of a// 16-byte interrupt-gate from the IDT, to get the// upper 32 bits of the target RIPtemp_upper = READ_MEM.q [idt:temp_int_n_vector*16+8]}temp_RIP = tempRIP + (temp_upper SHL 32) // concatenate both halves of RIPCS = READ_DESCRIPTOR (temp_idt_desc.segment, intcs_chk)IF (CS.attr.conforming=1)temp_CPL = CPLELSEtemp_CPL = CS.attr.dplIF (CPL=temp_CPL){IF (LONG_MODE)// no privilege-level changeINT 157


AMD64 Technology 24594 Rev. 3.10 February 2005{IF (temp_idt_desc.ist!=0)// In long mode, if the IDT gate specifies an IST pointer,// a stack-switch is always doneRSP = READ_MEM.q [tss:ist_index*8+28]RSP = RSP AND 0xFFFFFFFFFFFFFFF0// In long mode, interrupts/exceptions align RSP to a// 16-byte boundary}PUSH.q old_SSPUSH.q old_RSP// In long mode, SS:RSP is always pushed to the stackPUSH.v old_RFLAGSPUSH.v old_CSPUSH.v next_RIPIF ((64BIT_MODE) && (temp_RIP is non-canonical)|| (!64BIT_MODE) && (temp_RIP > CS.limit))EXCEPTION [#GP(0)]RFLAGS.VM,NT,TF,RF clearedRFLAGS.IF cleared if interrupt gateRIP = temp_RIPEXIT}ELSE // (CPL > temp_CPL), changing privilege level{CPL = temp_CPLtemp_SS_desc:temp_RSP = READ_INNER_LEVEL_STACK_POINTER(CPL, temp_idt_desc.ist)IF (LONG_MODE)temp_RSP = temp_RSP AND 0xFFFFFFFFFFFFFFF0// in long mode, interrupts/exceptions align rsp// to a 16-byte boundaryRSP.q = temp_RSPSS = temp_SS_descPUSH.v old_SS // #SS on the following pushes uses SS.sel as error codePUSH.v old_RSPPUSH.v old_RFLAGSPUSH.v old_CSPUSH.v next_RIPIF ((64BIT_MODE) && (temp_RIP is non-canonical)|| (!64BIT_MODE) && (temp_RIP > CS.limit))158 INT


24594 Rev. 3.10 February 2005 AMD64 TechnologyEXCEPTION [#GP(0)]}RFLAGS.VM,NT,TF,RF clearedRFLAGS.IF cleared if interrupt gateRIP = temp_RIPEXITINT_N_VIRTUAL:temp_int_n_vector = byte-sized interrupt vector specified in the instruction,zero-extended to 64 bitsIF (CR4.VME=0)// vme isn’t enabled{IF (RFLAGS.IOPL=3)INT_N_VIRTUAL_TO_PROTECTEDELSEEXCEPTION [#GP(0)]}temp_IRB_BASE = READ_MEM.w [tss:102] - 32// check the vme Int-n Redirection Bitmap (IRB), to see// if we should redirect this interrupt to a virtual-mode// h<strong>and</strong>lertemp_VME_REDIRECTION_BIT = READ_BIT_ARRAY ([tss:temp_IRB_BASE],temp_int_n_vector)IF (temp_VME_REDIRECTION_BIT=1){ // the virtual-mode int-n bitmap bit is set, so don’t// redirect this interruptIF (RFLAGS.IOPL=3)INT_N_VIRTUAL_TO_PROTECTEDELSEEXCEPTION [#GP(0)]}ELSE// redirect interrupt through virtual-mode idt{temp_RIP = READ_MEM.w [0:temp_int_n_vector*4]// read target CS:RIP from the virtual-mode idt at// linear address 0temp_CS = READ_MEM.w [0:temp_int_n_vector*4+2]IF (RFLAGS.IOPL < 3)old_RFLAGS = old_RFLAGS with VIF bit shifted into IF bit, <strong>and</strong> IOPL = 3PUSH.w old_RFLAGSPUSH.w old_CSPUSH.w next_RIPINT 159


AMD64 Technology 24594 Rev. 3.10 February 2005CS.sel = temp_CSCS.base = temp_CS SHL 4}RFLAGS.TF,RF clearedRIP = temp_RIP // RFLAGS.IF cleared if IOPL = 3// RFLAGS.VIF cleared if IOPL < 3EXITINT_N_VIRTUAL_TO_PROTECTED:temp_idt_desc = READ_IDT (temp_int_n_vector)IF (temp_idt_desc.attr.type = ’taskgate’)TASK_SWITCH // using tss selector in the task gate as the target tssIF ((temp_idt_desc.attr.type = ’intgate32’)|| (temp_idt_desc.attr.type = ’trapgate32’))// the size of the gate controls the size of the stack pushesV=4-byte // legacy mode, using a 32-bit gateELSE // gate is intgate16 or trapgate16V=2-byte// legacy mode, using a 16-bit gatetemp_RIP = temp_idt_desc.offsetCS = READ_DESCRIPTOR (temp_idt_desc.segment, intcs_chk)IF (CS.attr.dpl!=0) // H<strong>and</strong>ler must run at CPL 0.EXCEPTION [#GP(CS.sel)]CPL = 0temp_ist = 0// Legacy mode doesn’t use ist pointerstemp_SS_desc:temp_RSP = READ_INNER_LEVEL_STACK_POINTER (CPL, temp_ist)RSP.q = temp_RSPSS = temp_SS_descPUSH.v old_GS // #SS on the following pushes use SS.sel as error code.PUSH.v old_FSPUSH.v old_DSPUSH.v old_ESPUSH.v old_SSPUSH.v old_RSPPUSH.v old_RFLAGS // Pushed with RF clear.PUSH.v old_CSPUSH.v next_RIPIF (temp_RIP > CS.limit)EXCEPTION [#GP(0)]DS = NULL// can’t use virtual-mode selectors in protected mode160 INT


24594 Rev. 3.10 February 2005 AMD64 TechnologyES = NULLFS = NULLGS = NULL// can’t use virtual-mode selectors in protected mode// can’t use virtual-mode selectors in protected mode// can’t use virtual-mode selectors in protected modeRFLAGS.VM,NT,TF,RF clearedRFLAGS.IF cleared if interrupt gateRIP = temp_RIPEXITRelated <strong>Instructions</strong>INT 3, INTO, BOUNDrFLAGS AffectedIf 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 CFM M M 0 M M 021 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.INT 161


AMD64 Technology 24594 Rev. 3.10 February 2005ExceptionsExceptionInvalid TSS, #TS(selector)RealVirtual8086 Protected Cause of ExceptionXXAs part of a stack switch, the target stack segment selector or rSP inthe TSS was beyond the TSS limit.XXXXXXXXXXAs part of a stack switch, the target stack segment selector in the TSSwas a null selector.As part of a stack switch, the target stack segment selector’s TI bit wasset, but the LDT selector was a null selector.As part of a stack switch, the target stack segment selector in the TSSwas beyond the limit of the GDT or LDT descriptor table.As part of a stack switch, the target stack segment selector in the TSScontained a RPL that was not equal to its DPL.As part of a stack switch, the target stack segment selector in the TSScontained a DPL that was not equal to the CPL of the code segmentselector.Segment not present,#NP (selector)XXAs part of a stack switch, the target stack segment selector in the TSSwas not a writable segment.X X The accessed code segment, interrupt gate, trap gate, task gate, orTSS was not present.Stack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical,<strong>and</strong> no stack switch occurred.Stack, #SS(selector)XXAfter a stack switch, a memory address exceeded the stack segmentlimit or was non-canonical.<strong>General</strong> protection,#GPXXXXXAs part of a stack switch, the SS register was loaded with a non-nullsegment selector <strong>and</strong> the segment was marked not present.A memory address exceeded a data segment limit or was non-canonical.XXXThe target offset exceeded the code segment limit or was non-canonical.XThe IOPL was less than 3 <strong>and</strong> CR4.VME was 0.XIOPL was less than 3, CR4.VME was 1, <strong>and</strong> the corresponding bit inthe VME interrupt redirection bitmap was 1.162 INT


24594 Rev. 3.10 February 2005 AMD64 TechnologyException<strong>General</strong> protection,#GP(selector)RealXVirtual8086 Protected Cause of ExceptionXXXXThe interrupt vector was beyond the limit of IDT.The descriptor in the IDT was not an interrupt, trap, or task gate inlegacy mode or not a 64-bit interrupt or trap gate in long mode.XXXXXXXXXThe DPL of the interrupt, trap, or task gate descriptor was less thanthe CPL.The segment selector specified by the interrupt or trap gate had its TIbit set, but the LDT selector was a null selector.The segment descriptor specified by the interrupt or trap gateexceeded the descriptor table limit or was a null selector.The segment descriptor specified by the interrupt or trap gate wasnot a code segment in legacy mode, or not a 64-bit code segment inlong mode.The DPL of the segment specified by the interrupt or trap gate wasgreater than the CPL.XThe DPL of the segment specified by the interrupt or trap gatepointed 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, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.INT 163


AMD64 Technology 24594 Rev. 3.10 February 2005INTOInterrupt to Overflow VectorChecks the overflow flag (OF) in the rFLAGS register <strong>and</strong> calls the overflow exception(#OF) h<strong>and</strong>ler if the OF flag is set to 1. This instruction has no effect if the OF flag iscleared to 0. The INTO instruction detects overflow in signed number addition. SeeAMD64 Architecture Programmer’s Manual <strong>Volume</strong> 1: Application Programming for moreinformation on the OF flag.Using this instruction in 64-bit mode generates an invalid-opcode exception.For detailed descriptions of the steps performed by INT instructions, see thefollowing:• Legacy-Mode Interrupts: “Legacy Protected-Mode Interrupt Control Transfers” in<strong>Volume</strong> 2.• Long-Mode Interrupts: “Long-Mode Interrupt Control Transfers” in <strong>Volume</strong> 2.Mnemonic Opcode DescriptionINTOCECall overflow exception if the overflow flag is set.(Invalid in 64-bit mode.)ActionIF (64BIT_MODE)EXCEPTION[#UD]IF (RFLAGS.OF = 1)EXCEPTION [#OF]EXIT// #OF is a trap, <strong>and</strong> pushes the rIP of the instruction// following INTO.Related <strong>Instructions</strong>INT, INT 3, BOUNDrFLAGS AffectedNone.ExceptionsException RealVirtual8086 Protected Cause of ExceptionOverflow, #OF X X X The INTO instruction was executed with 0F set to 1.Invalid opcode, #UD X Instruction was executed in 64-bit mode.164 INTO


24594 Rev. 3.10 February 2005 AMD64 TechnologyJccJump on ConditionChecks the status flags in the rFLAGS register <strong>and</strong>, if the flags meet the conditionspecified by the condition code in the mnemonic (cc), jumps to the target instructionlocated at the specified relative offset. Otherwise, execution continues with theinstruction following the Jcc instruction.Unlike the unconditional jump (JMP), conditional jump instructions have only twoforms—short <strong>and</strong> near conditional jumps. Different opcodes correspond to differentforms of one instruction. For example, the JO instruction (jump if overflow) hasopcode 0Fh 80h for its near form <strong>and</strong> 70h for its short form, but the mnemonic is thesame for both forms. The only difference is that the near form has a 16- or 32-bitrelative displacement, while the short form always has an 8-bit relative displacement.Mnemonics are provided to deal with the programming semantics of both signed <strong>and</strong>unsigned numbers. <strong>Instructions</strong> tagged A (above) <strong>and</strong> B (below) are intended for usein unsigned integer code; those tagged G (greater) <strong>and</strong> L (less) are intended for use insigned integer code.If the jump is taken, the signed displacement is added to the rIP (of the followinginstruction) <strong>and</strong> the result is truncated to 16, 32, or 64 bits, depending on oper<strong>and</strong>size.In 64-bit mode, the oper<strong>and</strong> size defaults to 64 bits. The processor sign-extends the8-bit or 32-bit displacement value to 64 bits before adding it to the RIP.These instructions cannot perform far jumps (to other code segments). To create a farconditional-jumpcode sequence corresponding to a high-level language statementlike:IF A = B THEN GOTO FarLabelwhere FarLabel is located in another code segment, use the opposite condition in aconditional short jump before an unconditional far jump. Such a code sequence mightlook like:cmp A,B ; compare oper<strong>and</strong>sjne NextInstr ; continue program if not equaljmp far FarLabel ; far jump if oper<strong>and</strong>s are equalNextInstr:; continue programFor details about control-flow instructions, see “Control Transfers” in <strong>Volume</strong> 1, <strong>and</strong>“Control-Transfer Privilege Checks” in <strong>Volume</strong> 2.Jcc 165


AMD64 Technology 24594 Rev. 3.10 February 2005Mnemonic Opcode DescriptionJO rel8offJO rel16offJO rel32offJNO rel8offJNO rel16offJNO rel32offJB rel8offJB rel16offJB rel32offJC rel8offJC rel16offJC rel32offJNAE rel8offJNAE rel16offJNAE rel32offJNB rel8offJNB rel16offJNB rel32offJNC rel8offJNC rel16offJNC rel32offJAE rel8offJAE rel16offJAE rel32offJZ rel8offJZ rel16offJZ rel32offJE rel8offJE rel16offJE rel32offJNZ rel8offJNZ rel16offJNZ rel32offJNE rel8offJNE rel16offJNE rel32off70 cb0F 80 cw0F 80 cd71 cb0F 81 cw0F 81 cd72 cb0F 82 cw0F 82 cd72 cb0F 82 cw0F 82 cd72 cb0F 82 cw0F 82 cd73 cb0F 83 cw0F 83 cd73 cb0F 83 cw0F 83 cd73 cb0F 83 cw0F 83 cd74 cb0F 84 cw0F 84 cd74 cb0F 84 cw0F 84 cd75 cb0F 85 cw0F 85 cd75 cb0F 85 cw0F 85 cdJump if overflow (OF = 1).Jump if not overflow (OF = 0).Jump if below (CF = 1).Jump if carry (CF = 1).Jump if not above or equal (CF = 1).Jump if not below (CF = 0).Jump if not carry (CF = 0).Jump if above or equal (CF = 0).Jump if zero (ZF = 1).Jump if equal (ZF = 1).Jump if not zero (ZF = 0).Jump if not equal (ZF = 0).166 Jcc


24594 Rev. 3.10 February 2005 AMD64 TechnologyMnemonic Opcode DescriptionJBE rel8offJBE rel16offJBE rel32offJNA rel8offJNA rel16offJNA rel32offJNBE rel8offJNBE rel16offJNBE rel32offJA rel8offJA rel16offJA rel32offJS rel8offJS rel16offJS rel32offJNS rel8offJNS rel16offJNS rel32offJP rel8offJP rel16offJP rel32offJPE rel8offJPE rel16offJPE rel32offJNP rel8offJNP rel16offJNP rel32offJPO rel8offJPO rel16offJPO rel32offJL rel8offJL rel16offJL rel32offJNGE rel8offJNGE rel16offJNGE rel32offJNL rel8offJNL rel16offJNL rel32off76 cb0F 86 cw0F 86 cd76 cb0F 86 cw0F 86 cd77 cb0F 87 cw0F 87 cd77 cb0F 87 cw0F 87 cd78 cb0F 88 cw0F 88 cd79 cb0F 89 cw0F 89 cd7A cb0F 8A cw0F 8A cd7A cb0F 8A cw0F 8A cd7B cb0F 8B cw0F 8B cd7B cb0F 8B cw0F 8B cd7C cb0F 8C cw0F 8C cd7C cb0F 8C cw0F 8C cd7D cb0F 8D cw0F 8D cdJump if below or equal (CF = 1 or ZF = 1).Jump if not above (CF = 1 or ZF = 1).Jump if not below or equal (CF = 0 <strong>and</strong> ZF = 0).Jump if above (CF = 0 <strong>and</strong> ZF = 0).Jump if sign (SF = 1).Jump if not sign (SF = 0).Jump if parity (PF = 1).Jump if parity even (PF = 1).Jump if not parity (PF = 0).Jump if parity odd (PF = 0).Jump if less (SF OF).Jump if not greater or equal (SF OF).Jump if not less (SF = OF).Jcc 167


AMD64 Technology 24594 Rev. 3.10 February 2005Mnemonic Opcode DescriptionJGE rel8offJGE rel16offJGE rel32offJLE rel8offJLE rel16offJLE rel32offJNG rel8offJNG rel16offJNG rel32offJNLE rel8offJNLE rel16offJNLE rel32offJG rel8offJG rel16offJG rel32offRelated <strong>Instructions</strong>7D cb0F 8D cw0F 8D cd7E cb0F 8E cw0F 8E cd7E cb0F 8E cw0F 8E cd7F cb0F 8F cw0F 8F cd7F cb0F 8F cw0F 8F cdJump if greater or equal (SF = OF).Jump if less or equal (ZF = 1 or SF OF).Jump if not greater (ZF = 1 or SF OF).Jump if not less or equal (ZF = 0 <strong>and</strong> SF = OF).Jump if greater (ZF = 0 <strong>and</strong> SF = OF).JMP (Near), JMP (Far), JrCXZrFLAGS AffectedNoneExceptionsException<strong>General</strong> protection,#GPRealVirtual8086 Protected Cause of ExceptionX X X The target offset exceeded the code segment limit or was non-canonical.168 Jcc


24594 Rev. 3.10 February 2005 AMD64 TechnologyJCXZJECXZJRCXZJump if rCX ZeroChecks the contents of the count register (rCX) <strong>and</strong>, if 0, jumps to the targetinstruction located at the specified 8-bit relative offset. Otherwise, executioncontinues with the instruction following the JrCXZ instruction.The size of the count register (CX, ECX, or RCX) depends on the address-sizeattribute of the JrCXZ instruction. Therefore, JRCXZ can only be executed in 64-bitmode <strong>and</strong> JCXZ cannot be executed in 64-bit mode.If the jump is taken, the signed displacement is added to the rIP (of the followinginstruction) <strong>and</strong> the result is truncated to 16, 32, or 64 bits, depending on oper<strong>and</strong>size.In 64-bit mode, the oper<strong>and</strong> size defaults to 64 bits. The processor sign-extends the 8-bit displacement value to 64 bits before adding it to the RIP.For details about control-flow instructions, see “Control Transfers” in <strong>Volume</strong> 1, <strong>and</strong>“Control-Transfer Privilege Checks” in <strong>Volume</strong> 2.Mnemonic Opcode DescriptionJCXZ rel8off E3 cb Jump short if the 16-bit count register (CX) is zero.JECXZ rel8off E3 cb Jump short if the 32-bit count register (ECX) is zero.JRCXZ rel8off E3 cb Jump short if the 64-bit count register (RCX) is zero.Related <strong>Instructions</strong>Jcc, JMP (Near), JMP (Far)rFLAGS AffectedNoneJrCXZ 169


AMD64 Technology 24594 Rev. 3.10 February 2005ExceptionsException<strong>General</strong> protection,#GPRealVirtual8086 Protected Cause of ExceptionX X X The target offset exceeded the code segment limit or was non-canonical170 JrCXZ


24594 Rev. 3.10 February 2005 AMD64 TechnologyJMP (Near)Near JumpUnconditionally transfers control to a new address without saving the current rIPvalue. This form of the instruction jumps to an address in the current code segment<strong>and</strong> is called a near jump. The target oper<strong>and</strong> can specify a register, a memorylocation, or a label.If the JMP target is specified in a register or memory location, then a 16-, 32-, or 64-bitrIP is read from the oper<strong>and</strong>, depending on oper<strong>and</strong> size. This rIP is zero-extended to64 bits.If the JMP target is specified by a displacement in the instruction, the signeddisplacement is added to the rIP (of the following instruction), <strong>and</strong> the result istruncated to 16, 32, or 64 bits depending on oper<strong>and</strong> size. The signed displacementcan be 8 bits, 16 bits, or 32 bits, depending on the opcode <strong>and</strong> the oper<strong>and</strong> size.For near jumps in 64-bit mode, the oper<strong>and</strong> size defaults to 64 bits. The E9 opcoderesults in RIP = RIP + 32-bit signed displacement, <strong>and</strong> the FF /4 opcode results in RIP= 64-bit offset from register or memory. No prefix is available to encode a 32-bitoper<strong>and</strong> size in 64-bit mode.See JMP (Far) for information on far jumps—jumps to procedures located outside ofthe current code segment. For details about control-flow instructions, see “ControlTransfers” in <strong>Volume</strong> 1, <strong>and</strong> “Control-Transfer Privilege Checks” in <strong>Volume</strong> 2.Mnemonic Opcode DescriptionJMP rel8offJMP rel16offJMP rel32offEB cbE9 cwE9 cdShort jump with the target specified by an 8-bit signeddisplacement.Near jump with the target specified by a 16-bit signeddisplacement.Near jump with the target specified by a 32-bit signeddisplacement.JMP reg/mem16 FF /4 Near jump with the target specified reg/mem16.JMP reg/mem32 FF /4Near jump with the target specified reg/mem32.(No prefix for encoding in 64-bit mode.)JMP reg/mem64 FF /4 Near jump with the target specified reg/mem64.JMP (Near) 171


AMD64 Technology 24594 Rev. 3.10 February 2005Related <strong>Instructions</strong>JMP (Far), Jcc, JrCXrFLAGS AffectedNone.ExceptionsException RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPXXXA memory address exceeded a data segment limit or was non-canonical.XXXThe target offset exceeded the code segment limit or was 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.Alignment check, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.172 JMP (Near)


24594 Rev. 3.10 February 2005 AMD64 TechnologyJMP (Far)Far JumpUnconditionally transfers control to a new address without saving the current CS:rIPvalues. This form of the instruction jumps to an address outside the current codesegment <strong>and</strong> is called a far jump. The oper<strong>and</strong> specifies a target selector <strong>and</strong> offset.The target oper<strong>and</strong> can be specified by the instruction directly, by containing the farpointer in the jmp far opcode itself, or indirectly, by referencing a far pointer inmemory. In 64-bit mode, only indirect far jumps are allowed, executing a direct farjmp (opcode EA) will generate an undefined opcode exception.In all modes, the target selector used by the instruction can be a code selector.Additionally, the target selector can also be a call gate in protected mode, or a taskgate or TSS selector in legacy protected mode.• Target is a code segment—Control is transferred to the target CS:rIP. In this case,the target offset can only be a 16 or 32 bit value, depending on oper<strong>and</strong>-size, <strong>and</strong>is zero-extended to 64 bits. No CPL change is allowed.• Target is a call gate—The call gate specifies the actual target code segment <strong>and</strong> offset,<strong>and</strong> control is transferred to the target CS:rIP. When jumping through a callgate, the size of the target rIP is 16, 32, or 64 bits, depending on the size of the callgate. If the target rIP is less than 64 bits, it's zero-extended to 64 bits. In longmode, only 64-bit call gates are allowed, <strong>and</strong> they must point to 64-bit code segments.No CPL change is allowed.• Target is a task gate or a TSS—If the mode is legacy protected mode, then a taskswitch occurs. See “Hardware Task-Management in Legacy Mode” in volume 2 fordetails about task switches. Hardware task switches are not supported in longmode.See JMP (Near) for information on near jumps—jumps to procedures located insidethe current code segment. For details about control-flow instructions, see “ControlTransfers” in <strong>Volume</strong> 1, <strong>and</strong> “Control-Transfer Privilege Checks” in <strong>Volume</strong> 2.Mnemonic Opcode DescriptionJMP FAR pntr16:16JMP FAR pntr16:32EA cdEA cpFar jump direct, with the target specified by a far pointercontained in the instruction. (Invalid in 64-bit mode.)Far jump direct, with the target specified by a far pointercontained in the instruction. (Invalid in 64-bit mode.)JMP (Far) 173


AMD64 Technology 24594 Rev. 3.10 February 2005Mnemonic Opcode DescriptionJMP FAR mem16:16 FF /5JMP FAR mem16:32 FF /5Far jump indirect, with the target specified by a far pointer inmemory.Far jump indirect, with the target specified by a far pointer inmemory.Action// Far jumps (JMPF)// See “Pseudocode Definitions” on page 49.JMPF_START:IF (REAL_MODE)JMPF_REAL_OR_VIRTUALELSIF (PROTECTED_MODE)JMPF_PROTECTEDELSE // (VIRTUAL_MODE)JMPF_REAL_OR_VIRTUALJMPF_REAL_OR_VIRTUAL:IF (OPCODE = jmpf [mem]) //JMPF Indirect{temp_RIP = READ_MEM.z [mem]temp_CS = READ_MEM.w [mem+Z]}ELSE // (OPCODE = jmpf direct){temp_RIP = z-sized offset specified in the instruction,zero-extended to 64 bitstemp_CS = selector specified in the instruction}IF (temp_RIP>CS.limit)EXCEPTION [#GP(0)]CS.sel = temp_CSCS.base = temp_CS SHL 4RIP = temp_RIPEXITJMPF_PROTECTED:IF (OPCODE = jmpf [mem]) // JMPF Indirect{temp_offset = READ_MEM.z [mem]temp_sel = READ_MEM.w [mem+Z]174 JMP (Far)


24594 Rev. 3.10 February 2005 AMD64 Technology}ELSE // (OPCODE = jmpf direct){IF (64BIT_MODE)EXCEPTION [#UD]// ’jmpf direct’ is illegal in 64-bit mode}temp_offset = z-sized offset specified in the instruction,zero-extended to 64 bitstemp_sel = selector specified in the instructiontemp_desc = READ_DESCRIPTOR (temp_sel, cs_chk)// read descriptor, perform protection <strong>and</strong> type checksIF (temp_desc.attr.type = ’available_tss’)TASK_SWITCH // using temp_sel as the target tss selectorELSIF (temp_desc.attr.type = ’taskgate’)TASK_SWITCH // using the tss selector in the task gate as the// target tssELSIF (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_offsetCS = temp_descIF ((!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_RIPEXIT}ELSE{// (temp_desc.attr.type = ’callgate’)// if the selector refers to a call gate, then// the target CS <strong>and</strong> RIP both come from the call gatetemp_RIP = temp_desc.offsetIF (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 RIPtemp_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.temp_RIP = tempRIP + (temp_upper SHL 32)JMP (Far) 175


AMD64 Technology 24594 Rev. 3.10 February 2005}// concatenate both halves of RIP}CS = READ_DESCRIPTOR (temp_desc.segment, clg_chk)// set up new CS base, attr, limitsIF ((64BIT_MODE) && (temp_RIP is non-canonical)|| (!64BIT_MODE) && (temp_RIP > CS.limit))EXCEPTION [#GP(0)]RIP = temp_RIPEXITRelated <strong>Instructions</strong>JMP (Near), Jcc, JrCXrFLAGS AffectedNone, unless a task switch occurs, in which case all flags are modified.ExceptionsVirtualException Real 8086 Protected Cause of ExceptionInvalid opcode, #UD X X X The far JUMP indirect opcode (FF /5) had a register oper<strong>and</strong>.Segment not present,#NP (selector)XXThe far JUMP direct opcode (EA) was executed in 64-bit mode.The accessed code segment, call gate, task gate, or TSS was notpresent.Stack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPXXXA memory address exceeded a data segment limit or was non-canonical.XXXThe target offset exceeded the code segment limit or was non-canonical.XA null data segment was used to reference memory.176 JMP (Far)


24594 Rev. 3.10 February 2005 AMD64 TechnologyException<strong>General</strong> protection,#GP(selector)RealVirtual8086 Protected Cause of ExceptionXXThe target code segment selector was a null selector.A code, call gate, task gate, or TSS descriptor exceeded the descriptortable limit.XXXXXXXXXXA segment selector’s TI bit was set, but the LDT selector was a nullselector.The segment descriptor specified by the instruction was not a codesegment, task gate, call gate or available TSS in legacy mode, or nota 64-bit code segment or a 64-bit call gate in long mode.The RPL of the non-conforming code segment selector specified bythe instruction was greater than the CPL, or its DPL was not equal tothe CPL.The DPL of the conforming code segment descriptor specified by theinstruction was greater than the CPL.The DPL of the callgate, taskgate, or TSS descriptor specified by theinstruction was less than the CPL or less than its own RPL.The segment selector specified by the call gate or task gate was a nullselector.The segment descriptor specified by the call gate was not a code segmentin legacy mode or not a 64-bit code segment in long mode.The DPL of the segment descriptor specified the call gate was greaterthan the CPL <strong>and</strong> it is a conforming segment.The DPL of the segment descriptor specified by the callgate was notequal to the CPL <strong>and</strong> it is a non-conforming segment.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, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.JMP (Far) 177


AMD64 Technology 24594 Rev. 3.10 February 2005LAHFLoad Status Flags into AH RegisterLoads the lower 8 bits of the rFLAGS register, including sign flag (SF), zero flag (ZF),auxiliary carry flag (AF), parity flag (PF), <strong>and</strong> carry flag (CF), into the AH register.The instruction sets the reserved bits 1, 3, <strong>and</strong> 5 of the rFLAGS register to 1, 0, <strong>and</strong> 0,respectively, in the AH register.The LAHF instruction can only be executed in 64-bit mode if supported by theprocessor implementation. Check the status of ECX bit 0 returned by CPUIDextended function 8000_0001h to verify that the processor supports LAHF in 64-bitmode.Mnemonic Opcode DescriptionLAHF 9F Load the SF, ZF, AF, PF, <strong>and</strong> CF flags into the AH register.Related <strong>Instructions</strong>SAHFrFLAGS AffectedExceptionsException RealVirtual8086 Protected Cause of ExceptionInvalid opcode, #UD X This instruction is not supported in 64-bit mode, as indicated by ECXbit 0 returned by CPUID st<strong>and</strong>ard function 8000_0001h.178 LAHF


24594 Rev. 3.10 February 2005 AMD64 TechnologyLDSLESLFSLGSLSSLoad Far PointerLoads a far pointer from a memory location (second oper<strong>and</strong>) into a segment register(mnemonic) <strong>and</strong> general-purpose register (first oper<strong>and</strong>). The instruction stores the16-bit segment selector of the pointer into the segment register <strong>and</strong> the 16-bit or 32-bit offset portion into the general-purpose register. The oper<strong>and</strong>-size attributedetermines whether the pointer is 32-bit or 48-bit.These instructions load associated segment-descriptor information into the hiddenportion of the specified segment register.Using LDS or LES in 64-bit mode generates an invalid-opcode exception.Executing LFS, LGS, or LSS with a 64-bit oper<strong>and</strong> size only loads a 32-bit generalpurpose register <strong>and</strong> the specified segment register.Mnemonic Opcode DescriptionLDS reg16, mem16:16 C5 /rLDS reg32, mem16:32 C5 /rLES reg16, mem16:16 C4 /rLES reg32, mem16:32 C4 /rLoad DS:reg16 with a far pointer from memory.(Invalid in 64-bit mode.)Load DS:reg32 with a far pointer from memory.(Invalid in 64-bit mode.)Load ES:reg16 with a far pointer from memory.(Invalid in 64-bit mode.)Load ES:reg32 with a far pointer from memory.(Invalid in 64-bit mode.)LFS reg16, mem16:16 0F B4 /r Load FS:reg16 with a far pointer from memory.LFS reg32, mem16:32 0F B4 /r Load FS:reg32 with a far pointer from memory.LGS reg16, mem16:16 0F B5 /r Load GS:reg16 with a far pointer from memory.LGS reg32, mem16:32 0F B5 /r Load GS:reg32 with a far pointer from memory.LSS reg16, mem16:16 0F B2 /r Load SS:reg16 with a far pointer from memory.LSS reg32, mem16:32 0F B2 /r Load SS:reg32 with a far pointer from memory.LxS 179


AMD64 Technology 24594 Rev. 3.10 February 2005Related <strong>Instructions</strong>NonerFLAGS AffectedNoneExceptionsVirtualException Real 8086 Protected Cause of ExceptionInvalid opcode, #UD X X X The source oper<strong>and</strong> was a register.Segment not present,#NP (selector)XXLDS or LES was executed in 64-bit mode.The DS, ES, FS, or GS register was loaded with a non-null segmentselector <strong>and</strong> the segment was marked not present.Stack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.Stack, #SS(selector)<strong>General</strong> protection,#GPXX X XThe SS register was loaded with a non-null segment selector <strong>and</strong> thesegment was marked not present.A memory address exceeded a data segment limit or was non-canonical.<strong>General</strong> protection,#GP(selector)XXXXXXXXA null data segment was used to reference memory.A segment register was loaded, but the segment descriptor exceededthe descriptor table limit.A segment register was loaded <strong>and</strong> the segment selector’s TI bit wasset, but the LDT selector was a null selector.The SS register was loaded with a null segment selector in non-64-bitmode or while CPL = 3.The SS register was loaded <strong>and</strong> the segment selector RPL <strong>and</strong> thesegment descriptor DPL were not equal to the CPL.The SS register was loaded <strong>and</strong> the segment pointed to was not awritable data segment.The DS, ES, FS, or GS register was loaded <strong>and</strong> the segment pointedto was a data or non-conforming code segment, but the RPL or CPLwas greater than the DPL.The DS, ES, FS, or GS register was loaded <strong>and</strong> the segment pointedto was not a data segment or readable code segment.180 LxS


24594 Rev. 3.10 February 2005 AMD64 TechnologyExceptionRealVirtual8086 Protected Cause of ExceptionPage fault, #PF X X A page fault resulted from the execution of the instruction.Alignment check, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.LxS 181


AMD64 Technology 24594 Rev. 3.10 February 2005LEALoad Effective AddressComputes the effective address of a memory location (second oper<strong>and</strong>) <strong>and</strong> stores it ina general-purpose register (first oper<strong>and</strong>).The address size of the memory location <strong>and</strong> the size of the register determine thespecific action taken by the instruction, as follows:• If the address size <strong>and</strong> the register size are the same, the instruction stores theeffective address as computed.• If the address size is longer than the register size, the instruction truncates theeffective address to the size of the register.• If the address size is shorter than the register size, the instruction zero-extendsthe effective address to the size of the register.If the second oper<strong>and</strong> is a register, an undefined-opcode exception occurs.The LEA instruction is related to the MOV instruction, which copies data from amemory location to a register, but LEA takes the address of the source oper<strong>and</strong>,whereas MOV takes the contents of the memory location specified by the sourceoper<strong>and</strong>. In the simplest cases, LEA can be replaced with MOV. For example:lea eax, [ebx]has the same effect as:mov eax, ebxHowever, LEA allows software to use any valid ModRM <strong>and</strong> SIB addressing mode forthe source oper<strong>and</strong>. For example:lea eax, [ebx+edi]loads the sum of the EBX <strong>and</strong> EDI registers into the EAX register. This could not beaccomplished by a single MOV instruction.The LEA instruction has a limited capability to perform multiplication of oper<strong>and</strong>s ingeneral-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. Possiblevalues of multipliers are 2, 4, 8, 3, 5, <strong>and</strong> 9.The LEA instruction is widely used in string-processing <strong>and</strong> array-processing toinitialize an index register (rSI or rDI) before performing string instructions such as182 LEA


24594 Rev. 3.10 February 2005 AMD64 TechnologyMOVSx. It is also used to initialize the rBX register before performing the XLATinstruction in programs that perform character translations. In data structures, theLEA instruction can calculate addresses of oper<strong>and</strong>s stored in memory, <strong>and</strong> inparticular, addresses of array or string elements.Mnemonic Opcode DescriptionLEA reg16, mem 8D /r Store effective address in a 16-bit register.LEA reg32, mem 8D /r Store effective address in a 32-bit register.LEA reg64, mem 8D /r Store effective address in a 64-bit register.Related <strong>Instructions</strong>MOVrFLAGS AffectedNoneExceptionsVirtualException Real 8086 Protected Cause of ExceptionInvalid opcode, #UD X X X The source oper<strong>and</strong> was a register.LEA 183


AMD64 Technology 24594 Rev. 3.10 February 2005LEAVEDelete Procedure Stack FrameReleases a stack frame created by a previous ENTER instruction. To release theframe, it copies the frame pointer (in the rBP register) to the stack pointer register(rSP), <strong>and</strong> then pops the old frame pointer from the stack into the rBP register, thusrestoring the stack frame of the calling procedure.The 32-bit LEAVE instruction is equivalent to the following 32-bit operation:MOV ESP,EBPPOP EBPTo return program control to the calling procedure, execute a RET instruction afterthe LEAVE instruction.In 64-bit mode, the LEAVE oper<strong>and</strong> size defaults to 64 bits, <strong>and</strong> there is no prefixavailable for encoding a 32-bit oper<strong>and</strong> size.Mnemonic Opcode DescriptionLEAVELEAVELEAVERelated <strong>Instructions</strong>ENTERrFLAGS AffectedNoneC9C9C9Set the stack pointer register SP to the value in the BP register<strong>and</strong> pop BP.Set the stack pointer register ESP to the value in the EBP register<strong>and</strong> pop EBP.(No prefix for encoding this in 64-bit mode.)Set the stack pointer register RSP to the value in the RBP register<strong>and</strong> pop RBP.184 LEAVE


24594 Rev. 3.10 February 2005 AMD64 TechnologyExceptionsException RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.Page fault, #PF X X A page fault resulted from the execution of the instruction.Alignment check, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.LEAVE 185


AMD64 Technology 24594 Rev. 3.10 February 2005LFENCELoad FenceActs as a barrier to force strong memory ordering (serialization) between loadinstructions preceding the LFENCE <strong>and</strong> load instructions that follow the LFENCE. Aweakly-ordered memory system allows hardware to reorder reads <strong>and</strong> writes betweenthe processor <strong>and</strong> memory. The LFENCE instruction guarantees that the systemcompletes all previous loads before executing subsequent loads.The LFENCE instruction is weakly-ordered with respect to store instructions, data<strong>and</strong> instruction prefetches, <strong>and</strong> the SFENCE instruction. Speculative loads initiatedby the processor, or specified explicitly using cache-prefetch instructions, can bereordered around an LFENCE.In addition to load instructions, the LFENCE instruction is strongly ordered withrespect to other LFENCE instructions, MFENCE instructions, <strong>and</strong> serializinginstructions.Support for the LFENCE instruction is indicated when the SSE2 bit (bit 26) is set to 1in EDX after executing CPUID st<strong>and</strong>ard function 1.Mnemonic Opcode DescriptionLFENCE 0F AE E8 Force strong ordering of (serialize) load operations.Related <strong>Instructions</strong>MFENCE, SFENCErFLAGS AffectedNoneExceptionsException RealVirtual8086 Protected Cause of ExceptionInvalid opcode, #UD X X X The LFENCE instruction is not supported as indicated by EDX bit 26of CPUID st<strong>and</strong>ard function 1.186 LFENCE


24594 Rev. 3.10 February 2005 AMD64 TechnologyLODSLODSBLODSWLODSDLODSQLoad StringCopies the byte, word, doubleword, or quadword in the memory location pointed to bythe DS:rSI registers to the AL, AX, EAX, or RAX register, depending on the size of theoper<strong>and</strong>, <strong>and</strong> then increments or decrements the rSI register according to the state ofthe DF flag in the rFLAGS register.If the DF flag is 0, the instruction increments rSI; otherwise, it decrements rSI. Itincrements or decrements rSI by 1, 2, 4, or 8, depending on the number of bytes beingloaded.The forms of the LODS instruction with an explicit oper<strong>and</strong> address the oper<strong>and</strong> atseg:[rSI]. The value of seg defaults to the DS segment, but may be overridden by asegment prefix. The explicit oper<strong>and</strong> serves only to specify the type (size) of the valuebeing copied <strong>and</strong> the specific registers used.The no-oper<strong>and</strong>s forms of the instruction always use the DS:[rSI] registers to point tothe value to be copied (they do not allow a segment prefix). The mnemonic determinesthe size of the oper<strong>and</strong> <strong>and</strong> the specific registers used.The LODSx instructions support the REP prefixes. For details about the REP prefixes,see “Repeat Prefixes” on page 10. More often, software uses the LODSx instructioninside a loop controlled by a LOOPcc instruction as a more efficient replacement forinstructions like:mov eax, dword ptr ds:[esi]add esi, 4The LODSQ instruction can only be used in 64-bit mode.Mnemonic Opcode DescriptionLODS mem8 AC Load byte at DS:rSI into AL <strong>and</strong> then increment or decrement rSI.LODS mem16LODS mem32ADADLoad word at DS:rSI into AX <strong>and</strong> then increment or decrementrSI.Load doubleword at DS:rSI into EAX <strong>and</strong> then increment ordecrement rSI.LODSx 187


AMD64 Technology 24594 Rev. 3.10 February 2005Mnemonic Opcode DescriptionLODS mem64ADLoad quadword at DS:rSI into RAX <strong>and</strong> then increment ordecrement rSI.LODSB AC Load byte at DS:rSI into AL <strong>and</strong> then increment or decrement rSI.LODSWLODSDLODSQRelated <strong>Instructions</strong>MOVSx, STOSxrFLAGS AffectedNoneExceptionsADADADLoad the word at DS:rSI into AX <strong>and</strong> then increment ordecrement rSI.Load doubleword at DS:rSI into EAX <strong>and</strong> then increment ordecrement rSI.Load quadword at DS:rSI into RAX <strong>and</strong> then increment ordecrement rSI.Exception RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded a data segment limit or was 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.Alignment check, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.188 LODSx


24594 Rev. 3.10 February 2005 AMD64 TechnologyLOOPccLOOPELOOPNELOOPNZLOOPZLoopDecrements the count register (rCX) by 1, then, if rCX is not 0 <strong>and</strong> the ZF flag meetsthe condition specified by the mnemonic, it jumps to the target instruction specifiedby the signed 8-bit relative offset. Otherwise, it continues with the next instructionafter the LOOPcc instruction.The size of the count register used (CX, ECX, or RCX) depends on the address-sizeattribute of the LOOPcc instruction.The LOOP instruction ignores the state of the ZF flag.The LOOPE <strong>and</strong> LOOPZ instructions jump if rCX is not 0 <strong>and</strong> the ZF flag is set to 1. Inother words, the instruction exits the loop (falls through to the next instruction) if rCXbecomes 0 or ZF = 0.The LOOPNE <strong>and</strong> LOOPNZ instructions jump if rCX is not 0 <strong>and</strong> ZF flag is cleared to0. 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 loopcontains 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 followinginstruction) <strong>and</strong> the result is truncated to 16, 32, or 64 bits, depending on oper<strong>and</strong>size.In 64-bit mode, the oper<strong>and</strong> size defaults to 64 bits without the need for a REX prefix,<strong>and</strong> the processor sign-extends the 8-bit offset before adding it to the RIP.Mnemonic Opcode DescriptionLOOP rel8off E2 cb Decrement rCX, then jump short if rCX is not 0.LOOPE rel8off E1 cb Decrement rCX, then jump short if rCX is not 0 <strong>and</strong> ZF is 1.LOOPNE rel8off E0 cb Decrement rCX, then Jump short if rCX is not 0 <strong>and</strong> ZF is 0.LOOPcc 189


AMD64 Technology 24594 Rev. 3.10 February 2005Mnemonic Opcode DescriptionLOOPNZ rel8off E0 cb Decrement rCX, then Jump short if rCX is not 0 <strong>and</strong> ZF is 0.LOOPZ rel8off E1 cb Decrement rCX, then Jump short if rCX is not 0 <strong>and</strong> ZF is 1.Related <strong>Instructions</strong>NonerFLAGS AffectedNoneExceptionsException<strong>General</strong> protection,#GPRealVirtual8086 Protected Cause of ExceptionX X X The target offset exceeded the code segment limit or was non-canonical.190 LOOPcc


24594 Rev. 3.10 February 2005 AMD64 TechnologyMFENCEMemory FenceActs as a barrier to force strong memory ordering (serialization) between load <strong>and</strong>store instructions preceding the MFENCE, <strong>and</strong> load <strong>and</strong> store instructions that followthe MFENCE. A weakly-ordered memory system allows the hardware to reorder reads<strong>and</strong> writes between the processor <strong>and</strong> memory. The MFENCE instruction guaranteesthat the system completes all previous memory accesses before executing subsequentaccesses.The MFENCE instruction is weakly-ordered with respect to data <strong>and</strong> instructionprefetches. Speculative loads initiated by the processor, or specified explicitly usingcache-prefetch instructions, can be reordered around an MFENCE.In addition to load <strong>and</strong> store instructions, the MFENCE instruction is strongly orderedwith respect to other MFENCE instructions, LFENCE instructions, SFENCEinstructions, serializing instructions, <strong>and</strong> CLFLUSH instructions.Support for the MFENCE instruction is indicated when the SSE2 bit (bit 26) is set to 1in EDX after executing CPUID with st<strong>and</strong>ard function 1.Mnemonic Opcode DescriptionMFENCE 0F AE F0 Force strong ordering of (serialized) load <strong>and</strong> store operations.Related <strong>Instructions</strong>LFENCE, SFENCErFLAGS AffectedNoneExceptionsException RealVirtual8086 Protected Cause of ExceptionInvalid opcode, #UD X X X The MFENCE instruction is not supported as indicated by bit 26 ofCPUID st<strong>and</strong>ard function 1.MFENCE 191


AMD64 Technology 24594 Rev. 3.10 February 2005MOVMoveCopies an immediate value or the value in a general-purpose register, segmentregister, or memory location (second oper<strong>and</strong>) to a general-purpose register, segmentregister, or memory location. The source <strong>and</strong> destination must be the same size (byte,word, doubleword, or quadword) <strong>and</strong> cannot both be memory locations.In opcodes A0 through A3, the memory offsets (called moffsets) are address sized. In64-bit mode, memory offsets default to 64 bits. Opcodes A0–A3, in 64-bit mode, are theonly cases that support a 64-bit offset value. (In all other cases, offsets <strong>and</strong>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 oper<strong>and</strong> size, the processor zero-extendsthe 16-bit selector results to 32 bits. When reading segment-registers with a 64-bitoper<strong>and</strong> size, the processor zero-extends the 16-bit selector to 64 bits. If thedestination oper<strong>and</strong> specifies a segment register (DS, ES, FS, GS, or SS), the sourceoper<strong>and</strong> 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 subsequentreference to such a segment does cause a #GP exception. For more information aboutsegment selectors, see “Segment Selectors <strong>and</strong> Registers” on page 82.When the MOV instruction is used to load the SS register, the processor blocksexternal interrupts until after the execution of the following instruction. This actionallows the following instruction to be a MOV instruction to load a stack pointer intothe ESP register (MOV ESP,val) before an interrupt occurs. However, the LSSinstruction provides a more efficient method of loading SS <strong>and</strong> ESP.Attempting to use the MOV instruction to load the CS register generates an invalidopcode exception (#UD). Use the far JMP, CALL, or RET instructions to load the CSregister.To initialize a register to 0, rather than using a MOV instruction, it may be moreefficient to use the XOR instruction with identical destination <strong>and</strong> source oper<strong>and</strong>s.192 MOV


24594 Rev. 3.10 February 2005 AMD64 TechnologyMnemonic Opcode DescriptionMOV reg/mem8, reg8 88 /rMOV reg/mem16, reg16 89 /rMOV reg/mem32, reg32 89 /rMOV reg/mem64, reg64 89 /rMOV reg8, reg/mem8 8A /rMOV reg16, reg/mem16 8B /rMOV reg32, reg/mem32 8B /rMOV reg64, reg/mem64 8B /rMOV reg16/32/64/mem16, segReg 8C /rMOV segReg, reg/mem16 8E /rMove the contents of an 8-bit register to an 8-bit destinationregister or memory oper<strong>and</strong>.Move the contents of a 16-bit register to a 16-bit destinationregister or memory oper<strong>and</strong>.Move the contents of a 32-bit register to a 32-bit destinationregister or memory oper<strong>and</strong>.Move the contents of a 64-bit register to a 64-bit destinationregister or memory oper<strong>and</strong>.Move the contents of an 8-bit register or memory oper<strong>and</strong> to an8-bit destination register.Move the contents of a 16-bit register or memory oper<strong>and</strong> to a16-bit destination register.Move the contents of a 32-bit register or memory oper<strong>and</strong> to a32-bit destination register.Move the contents of a 64-bit register or memory oper<strong>and</strong> to a64-bit destination register.Move the contents of a segment register to a 16-bit, 32-bit, or 64-bit destination register or to a 16-bit memory oper<strong>and</strong>.Move the contents of a 16-bit register or memory oper<strong>and</strong> to asegment register.MOV AL, moffset8 A0 Move 8-bit data at a specified memory offset to the AL register.MOV AX, moffset16 A1 Move 16-bit data at a specified memory offset to the AX register.MOV EAX, moffset32 A1 Move 32-bit data at a specified memory offset to the EAX register.MOV RAX, moffset64A1Move 64-bit data at a specified memory offset to the RAXregister.MOV moffset8, AL A2 Move the contents of the AL register to an 8-bit memory offset.MOV moffset16, AX A3 Move the contents of the AX register to a 16-bit memory offset.MOV moffset32, EAX A3 Move the contents of the EAX register to a 32-bit memory offset.MOV moffset64, RAX A3 Move the contents of the RAX register to a 64-bit memory offset.MOV reg8, imm8 B0 +rb Move an 8-bit immediate value into an 8-bit register.MOV reg16, imm16 B8 +rw Move a 16-bit immediate value into a 16-bit register.MOV reg32, imm32 B8 +rd Move an 32-bit immediate value into a 32-bit register.MOV 193


AMD64 Technology 24594 Rev. 3.10 February 2005Mnemonic Opcode DescriptionMOV reg64, imm64 B8 +rq Move an 64-bit immediate value into a 64-bit register.MOV reg/mem8, imm8 C6 /0MOV reg/mem16, imm16 C7 /0MOV reg/mem32, imm32 C7 /0MOV reg/mem64, imm32 C7 /0Move an 8-bit immediate value to an 8-bit register or memoryoper<strong>and</strong>.Move a 16-bit immediate value to a 16-bit register or memoryoper<strong>and</strong>.Move a 32-bit immediate value to a 32-bit register or memoryoper<strong>and</strong>.Move a 32-bit signed immediate value to a 64-bit register ormemory oper<strong>and</strong>.Related <strong>Instructions</strong>MOV(CRn), MOV(DRn), MOVD, MOVSX, MOVZX, MOVSXD, MOVSxrFLAGS AffectedNoneExceptionsVirtualException Real 8086 Protected Cause of ExceptionInvalid opcode, #UD X X X An attempt was made to load the CS register.Segment not present,#NP (selector)XThe DS, ES, FS, or GS register was loaded with a non-null segmentselector <strong>and</strong> the segment was marked not present.Stack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.Stack, #SS(selector)<strong>General</strong> protection,#GPXX X XThe SS register was loaded with a non-null segment selector, <strong>and</strong> thesegment was marked not present.A memory address exceeded a data segment limit or was noncanonical.XXThe destination oper<strong>and</strong> was in a non-writable segment.A null data segment was used to reference memory.194 MOV


24594 Rev. 3.10 February 2005 AMD64 TechnologyException<strong>General</strong> protection,#GP(selector)RealVirtual8086 Protected Cause of ExceptionXXA segment register was loaded, but the segment descriptor exceededthe descriptor table limit.A segment register was loaded <strong>and</strong> the segment selector’s TI bit wasset, but the LDT selector was a null selector.XXXXThe SS register was loaded with a null segment selector in non-64-bitmode or while CPL = 3.The SS register was loaded <strong>and</strong> the segment selector RPL <strong>and</strong> thesegment descriptor DPL were not equal to the CPL.The SS register was loaded <strong>and</strong> the segment pointed to was not awritable data segment.The DS, ES, FS, or GS register was loaded <strong>and</strong> the segment pointedto was a data or non-conforming code segment, but the RPL or CPLwas greater than the DPL.X The DS, ES, FS, or GS register was loaded <strong>and</strong> the segment pointedto 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, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.MOV 195


AMD64 Technology 24594 Rev. 3.10 February 2005MOVDMove Doubleword or QuadwordMoves a 32-bit or 64-bit value in one of the following ways:• from a 32-bit or 64-bit general-purpose register or memory location to the loworder32 or 64 bits of an XMM register, with zero-extension to 128 bits• from the low-order 32 or 64 bits of an XMM to a 32-bit or 64-bit general-purposeregister or memory location• from a 32-bit or 64-bit general-purpose register or memory location to the loworder32 bits (with zero-extension to 64 bits) or the full 64 bits of an MMX register• from the low-order 32 or the full 64 bits of an MMX register to a 32-bit or 64-bitgeneral-purpose register or memory locationMnemonic Opcode DescriptionMOVD xmm, reg/mem32 66 0F 6E /rMOVD xmm, reg/mem64 66 0F 6E /rMOVD reg/mem32, xmm 66 0F 7E /rMOVD reg/mem64, xmm 66 0F 7E /rMOVD mmx, reg/mem32 0F 6E /rMOVD mmx, reg/mem64 0F 6E /rMOVD reg/mem32, mmx 0F 7E /rMOVD reg/mem64, mmx 0F 7E /rMove 32-bit value from a general-purpose register or 32-bitmemory location to an XMM register.Move 64-bit value from a general-purpose register or 64-bitmemory location to an XMM register.Move 32-bit value from an XMM register to a 32-bit generalpurposeregister or memory location.Move 64-bit value from an XMM register to a 64-bit generalpurposeregister or memory location.Move 32-bit value from a general-purpose register or 32-bitmemory location to an MMX register.Move 64-bit value from a general-purpose register or 64-bitmemory location to an MMX register.Move 32-bit value from an MMX register to a 32-bit generalpurposeregister or memory location.Move 64-bit value from an MMX register to a 64-bit generalpurposeregister or memory location.The diagrams in Figure 3-7 on page 197 illustrate the operation of the MOVDinstruction.196 MOVD


24594 Rev. 3.10 February 2005 AMD64 Technologyxmm127 32 31 00reg/mem32310xmm127 64 63 00reg/mem6463 0All operationsare "copy"reg/mem3231 0with REX prefixxmm127 32 310reg/mem6463 0xmm127 64 63 0mmx63 32 3100with REX prefixreg/mem32310mmx63 0reg/mem6463 0reg/mem3231 0with REX prefixmmx63 32 31 0reg/mem6463 0mmx63 0with REX prefixmovd.epsFigure 3-7.MOVD Instruction OperationMOVD 197


AMD64 Technology 24594 Rev. 3.10 February 2005Related <strong>Instructions</strong>MOVDQA, MOVDQU, MOVDQ2Q, MOVQ, MOVQ2DQrFLAGS AffectedNoneMXCSR Flags AffectedNoneExceptions (All Modes)ExceptionInvalid opcode, #UDRealXVirtual8086 Protected DescriptionXXThe MMX instructions are not supported, as indicated byEDX bit 23 of CPUID st<strong>and</strong>ard function 1.XXXThe SSE2 instructions are not supported, as indicated by EDXbit 26 of CPUID st<strong>and</strong>ard function 1.XXXThe emulate bit (EM) of CR0 was set to 1.X X X The instruction used XMM registers while CR4.OSFXSR=0.Device not available, X X X The task-switch bit (TS) of CR0 was set to 1.#NMStack, #SS X X X A memory address exceeded the stack segment limit or wasnon-canonical.<strong>General</strong> protection, #GP X X X A memory address exceeded a data segment limit or wasnon-canonical.Page fault, #PF X X A page fault resulted from the execution of the instruction.x87 floating-point exceptionpending, #MFX X X An x87 floating-point exception was pending <strong>and</strong> theinstruction referenced an MMX register.Alignment check, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.198 MOVD


24594 Rev. 3.10 February 2005 AMD64 TechnologyMOVMSKPDExtract Packed Double-Precision Floating-PointSign MaskMoves the sign bits of two packed double-precision floating-point values in an XMMregister (second oper<strong>and</strong>) to the two low-order bits of a general-purpose register (firstoper<strong>and</strong>) with zero-extension.The MOVMSKPD instruction is an SSE2 instruction; Check the status of EDX bit 26 ofCPUID st<strong>and</strong>ard function 1 to verify that the processor supports this function.Mnemonic Opcode DescriptionMOVMSKPD reg32, xmm 66 0F 50 /rMove sign bits 127 <strong>and</strong> 63 in an XMM register to a 32-bit generalpurposeregister.reg32xmm3110127 63 00copy signcopy signmovmskpd.epsRelated <strong>Instructions</strong>MOVMSKPS, PMOVMSKBrFLAGS AffectedNoneMXCSR Flags AffectedNoneMOVMSKPD 199


AMD64 Technology 24594 Rev. 3.10 February 2005ExceptionsException (vector)Invalid opcode, #UDRealXVirtual8086 Protected Cause of ExceptionXXThe SSE2 instructions are not supported, as indicated by EDXbit 26 of CPUID st<strong>and</strong>ard function 1.XXXThe operating-system FXSAVE/FXRSTOR support bit(OSFXSR) of CR4 was cleared to 0.Device not available,#NMX X X The emulate bit (EM) of CR0 was set to 1.X X X The task-switch bit (TS) of CR0 was set to 1.200 MOVMSKPD


24594 Rev. 3.10 February 2005 AMD64 TechnologyMOVMSKPSExtract Packed Single-Precision Floating-PointSign MaskMoves the sign bits of four packed single-precision floating-point values in an XMMregister (second oper<strong>and</strong>) to the four low-order bits of a general-purpose register (firstoper<strong>and</strong>) with zero-extension.The MOVMSKPD instruction is an SSE2 instruction; Check the status of EDX bit 26 ofCPUID st<strong>and</strong>ard function 1 to verify that the processor supports this function.Mnemonic Opcode DescriptionMOVMSKPS reg32, xmm 0F 50 /rMove sign bits 127, 95, 63, 31 in an XMM register to a 32-bitgeneral-purpose register.reg32xmm3103 0 127 95 63 310copy signcopy signcopy signcopy signmovmskps.epsRelated <strong>Instructions</strong>MOVMSKPD, PMOVMSKBrFLAGS AffectedNoneMXCSR Flags AffectedNoneMOVMSKPS 201


AMD64 Technology 24594 Rev. 3.10 February 2005ExceptionsExceptionInvalid opcode, #UDRealXVirtual8086 Protected Cause of ExceptionXXThe SSE2 instructions are not supported, as indicated by EDXbit 26 of CPUID extended function 1.XXXThe operating-system FXSAVE/FXRSTOR support bit (OSFXSR)of CR4 was cleared to 0.Device not available,#NMX X X The emulate bit (EM) of CR0 was set to 1.X X X The task-switch bit (TS) of CR0 was set to 1.202 MOVMSKPS


24594 Rev. 3.10 February 2005 AMD64 TechnologyMOVNTIMove Non-Temporal Doubleword or QuadwordStores a value in a 32-bit or 64-bit general-purpose register (second oper<strong>and</strong>) in amemory location (first oper<strong>and</strong>). This instruction indicates to the processor that thedata is non-temporal <strong>and</strong> is unlikely to be used again soon. The processor treats thestore as a write-combining (WC) memory write, which minimizes cache pollution. Theexact method by which cache pollution is minimized depends on the hardwareimplementation of the instruction. For further information, see “MemoryOptimization” in <strong>Volume</strong> 1.The MOVNTI instruction is weakly-ordered with respect to other instructions thatoperate on memory. Software should use an SFENCE instruction to force strongmemory ordering of MOVNTI with respect to other stores.Support for the MOVNTI instruction is indicated when the SSE2 bit (bit 26) is set to 1in EDX after executing CPUID st<strong>and</strong>ard function 1.Mnemonic Opcode DescriptionMOVNTI mem32, reg32 0F C3 /rMOVNTI mem64, reg64 0F C3 /rStores a 32-bit general-purpose register value into a 32-bitmemory location, minimizing cache pollution.Stores a 64-bit general-purpose register value into a 64-bitmemory location, minimizing cache pollution.Related <strong>Instructions</strong>MOVNTDQ, MOVNTPD, MOVNTPS, MOVNTQrFLAGS AffectedNoneExceptionsException (vector) RealVirtual8086 Protected Cause of ExceptionInvalid opcode, #UD X X X The SSE2 instructions are not supported, as indicated by EDXbit 26 of CPUID st<strong>and</strong>ard function 1.Stack, #SS X X X A memory address exceeded the stack segment limit or wasnon-canonical.MOVNTI 203


AMD64 Technology 24594 Rev. 3.10 February 2005Exception (vector)Real<strong>General</strong> protection, #GP X X XVirtual8086 Protected Cause of ExceptionA memory address exceeded a data segment limit or wasnon-canonical.XA null data segment was used to reference memory.X The destination oper<strong>and</strong> was in a non-writable segment.Page fault, #PF X X A page fault resulted from the execution of the instruction.Alignment check, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.204 MOVNTI


24594 Rev. 3.10 February 2005 AMD64 TechnologyMOVSMOVSBMOVSWMOVSDMOVSQMove StringMoves a byte, word, doubleword, or quadword from the memory location pointed to byDS:rSI to the memory location pointed to by ES:rDI, <strong>and</strong> then increments ordecrements the rSI <strong>and</strong> rDI registers according to the state of the DF flag in therFLAGS register.If the DF flag is 0, the instruction increments both pointers; otherwise, it decrementsthem. It increments or decrements the pointers by 1, 2, 4, or 8, depending on the sizeof the oper<strong>and</strong>s.The forms of the MOVSx instruction with explicit oper<strong>and</strong>s address the first oper<strong>and</strong>at seg:[rSI]. The value of seg defaults to the DS segment, but can be overridden by asegment prefix. These instructions always address the second oper<strong>and</strong> at ES:[rDI] (ESmay not be overridden). The explicit oper<strong>and</strong>s serve only to specify the type (size) ofthe value being moved.The no-oper<strong>and</strong>s forms of the instruction use the DS:[rSI] <strong>and</strong> ES:[rDI] registers topoint to the value to be moved (they do not allow a segment prefix). The mnemonicdetermines the size of the oper<strong>and</strong>s.Do not confuse this MOVSD instruction with the same-mnemonic MOVSD (movescalar double-precision floating-point) instruction in the 128-bit media instruction set.Assemblers can distinguish the instructions by the number <strong>and</strong> type of oper<strong>and</strong>s.The MOVSx instructions support the REP prefixes. For details about the REPprefixes, see “Repeat Prefixes” on page 10.Mnemonic Opcode DescriptionMOVS mem8, mem8MOVS mem16, mem16MOVS mem32, mem32A4A5A5Move byte at DS:rSI to ES:rDI, <strong>and</strong> then increment or decrementrSI <strong>and</strong> rDI.Move word at DS:rSI to ES:rDI, <strong>and</strong> then increment or decrementrSI <strong>and</strong> rDI.Move doubleword at DS:rSI to ES:rDI, <strong>and</strong> then increment ordecrement rSI <strong>and</strong> rDI.MOVSx 205


AMD64 Technology 24594 Rev. 3.10 February 2005Mnemonic Opcode DescriptionMOVS mem64, mem64MOVSBMOVSWMOVSDMOVSQRelated <strong>Instructions</strong>MOV, LODSx, STOSxrFLAGS AffectedNoneExceptionsA5A4A5A5A5Move quadword at DS:rSI to ES:rDI, <strong>and</strong> then increment ordecrement rSI <strong>and</strong> rDI.Move byte at DS:rSI to ES:rDI, <strong>and</strong> then increment or decrementrSI <strong>and</strong> rDI.Move word at DS:rSI to ES:rDI, <strong>and</strong> then increment or decrementrSI <strong>and</strong> rDI.Move doubleword at DS:rSI to ES:rDI, <strong>and</strong> then increment ordecrement rSI <strong>and</strong> rDI.Move quadword at DS:rSI to ES:rDI, <strong>and</strong> then increment ordecrement rSI <strong>and</strong> rDI.Exception RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded a data segment limit or was non-canonical.XThe destination oper<strong>and</strong> 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, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.206 MOVSx


24594 Rev. 3.10 February 2005 AMD64 TechnologyMOVSXMove with Sign-ExtensionCopies the value in a register or memory location (second oper<strong>and</strong>) into a register(first oper<strong>and</strong>), extending the most significant bit of an 8-bit or 16-bit value into allhigher bits in a 16-bit, 32-bit, or 64-bit register.Mnemonic Opcode DescriptionMOVSX reg16, reg/mem8 0F BE /rMOVSX reg32, reg/mem8 0F BE /rMOVSX reg64, reg/mem8 0F BE /rMOVSX reg32, reg/mem16 0F BF /rMOVSX reg64, reg/mem16 0F BF /rMove the contents of an 8-bit register or memory location to a16-bit register with sign extension.Move the contents of an 8-bit register or memory location to a32-bit register with sign extension.Move the contents of an 8-bit register or memory location to a64-bit register with sign extension.Move the contents of an 16-bit register or memory location to a32-bit register with sign extension.Move the contents of an 16-bit register or memory location to a64-bit register with sign extension.Related <strong>Instructions</strong>MOVSXD, MOVZXrFLAGS AffectedNoneExceptionsException RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded a data segment limit or was 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.Alignment check, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.MOVSX 207


AMD64 Technology 24594 Rev. 3.10 February 2005MOVSXDMove with Sign-Extend DoublewordCopies the 32-bit value in a register or memory location (second oper<strong>and</strong>) into a 64-bitregister (first oper<strong>and</strong>), extending the most significant bit of the 32-bit value into allhigher bits of the 64-bit register.This instruction requires the REX prefix 64-bit oper<strong>and</strong> size bit (REX.W) to be set to 1to sign-extend a 32-bit source oper<strong>and</strong> to a 64-bit result. Without the REX oper<strong>and</strong>sizeprefix, the oper<strong>and</strong> size will be 32 bits, the default for 64-bit mode, <strong>and</strong> the sourceis zero-extended into a 64-bit register. With a 16-bit oper<strong>and</strong> size, only 16 bits arecopied, without modifying the upper 48 bits in the destination.This instruction is available only in 64-bit mode. In legacy or compatibility mode thisopcode is interpreted as ARPL.Mnemonic Opcode DescriptionMOVSXD reg64, reg/mem32 63 /rMove the contents of a 32-bit register or memory oper<strong>and</strong> to a64-bit register with sign extension.Related <strong>Instructions</strong>MOVSX, MOVZXrFLAGS AffectedNoneExceptionsException RealVirtual8086 Protected Cause of ExceptionStack, #SS X A memory address was non-canonical.<strong>General</strong> protection,X A memory address was non-canonical.#GPPage fault, #PF X A page fault resulted from the execution of the instruction.Alignment check, #AC X An unaligned memory reference was performed while alignmentchecking was enabled.208 MOVSXD


24594 Rev. 3.10 February 2005 AMD64 TechnologyMOVZXMove with Zero-ExtensionCopies the value in a register or memory location (second oper<strong>and</strong>) into a register(first oper<strong>and</strong>), zero-extending the value to fit in the destination register. Theoper<strong>and</strong>-size attribute determines the size of the zero-extended value.Mnemonic Opcode DescriptionMOVZX reg16, reg/mem8 0F B6 /rMOVZX reg32, reg/mem8 0F B6 /rMOVZX reg64, reg/mem8 0F B6 /rMOVZX reg32, reg/mem16 0F B7 /rMOVZX reg64, reg/mem16 0F B7 /rMove the contents of an 8-bit register or memory oper<strong>and</strong> to a16-bit register with zero-extension.Move the contents of an 8-bit register or memory oper<strong>and</strong> to a32-bit register with zero-extension.Move the contents of an 8-bit register or memory oper<strong>and</strong> to a64-bit register with zero-extension.Move the contents of a 16-bit register or memory oper<strong>and</strong> to a32-bit register with zero-extension.Move the contents of a 16-bit register or memory oper<strong>and</strong> to a64-bit register with zero-extension.Related <strong>Instructions</strong>MOVSXD, MOVSXrFLAGS AffectedNoneExceptionsException RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded a data segment limit or was 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.Alignment check, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.MOVZX 209


AMD64 Technology 24594 Rev. 3.10 February 2005MULUnsigned MultiplyMultiplies the unsigned byte, word, doubleword, or quadword value in the specifiedregister or memory location by the value in AL, AX, EAX, or RAX <strong>and</strong> stores the resultin AX, DX:AX, EDX:EAX, or RDX:RAX (depending on the oper<strong>and</strong> size). It puts thehigh-order bits of the product in AH, DX, EDX, or RDX.If the upper half of the product is non-zero, the instruction sets the carry flag (CF) <strong>and</strong>overflow flag (OF) both to 1. Otherwise, it clears CF <strong>and</strong> OF to 0. The other arithmeticflags (SF, ZF, AF, PF) are undefined.Mnemonic Opcode DescriptionMUL reg/mem8 F6 /4MUL reg/mem16 F7 /4MUL reg/mem32 F7 /4MUL reg/mem64 F7 /4Multiplies an 8-bit register or memory oper<strong>and</strong> by the contentsof the AL register <strong>and</strong> stores the result in the AX register.Multiplies a 16-bit register or memory oper<strong>and</strong> by the contents ofthe AX register <strong>and</strong> stores the result in the DX:AX register.Multiplies a 32-bit register or memory oper<strong>and</strong> by the contents ofthe EAX register <strong>and</strong> stores the result in the EDX:EAX register.Multiplies a 64-bit register or memory oper<strong>and</strong> by the contentsof the RAX register <strong>and</strong> stores the result in the RDX:RAX register.Related <strong>Instructions</strong>DIV210 MUL


24594 Rev. 3.10 February 2005 AMD64 TechnologyrFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFExceptionsM U U U U M21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.Exception RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded a data segment limit or was 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.Alignment check, #AC X X An unaligned memory reference is performed while alignmentchecking was enabled.MUL 211


AMD64 Technology 24594 Rev. 3.10 February 2005NEGTwo’s Complement NegationPerforms the two’s complement negation of the value in the specified register ormemory location by subtracting the value from 0. Use this instruction only on signedinteger numbers.If the value is 0, the instruction clears the CF flag to 0; otherwise, it sets CF to 1. TheOF, SF, ZF, AF, <strong>and</strong> PF flag settings depend on the result of the operation.The forms of the NEG instruction that write to memory support the LOCK prefix. Fordetails about the LOCK prefix, see “Lock Prefix” on page 10.Mnemonic Opcode DescriptionNEG reg/mem8 F6 /3NEG reg/mem16 F7 /3NEG reg/mem32 F7 /3NEG reg/mem64 F7 /3Performs a two’s complement negation on an 8-bit register ormemory oper<strong>and</strong>.Performs a two’s complement negation on a 16-bit register ormemory oper<strong>and</strong>.Performs a two’s complement negation on a 32-bit register ormemory oper<strong>and</strong>.Performs a two’s complement negation on a 64-bit register ormemory oper<strong>and</strong>.Related <strong>Instructions</strong>AND, NOT, OR, XOR212 NEG


24594 Rev. 3.10 February 2005 AMD64 TechnologyrFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFExceptionsM M M M M M21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.Exception RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded a data segment limit or was non-canonical.XThe destination oper<strong>and</strong> 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, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.NEG 213


AMD64 Technology 24594 Rev. 3.10 February 2005NOPNo OperationDoes nothing. This one-byte instruction increments the rIP to point to next instructionin the instruction stream, but does not affect the machine state in any other way.The NOP instruction is an alias for XCHG rAX,rAX.Mnemonic Opcode DescriptionNOP 90 Performs no operation.Related <strong>Instructions</strong>NonerFLAGS AffectedNoneExceptionsNone214 NOP


24594 Rev. 3.10 February 2005 AMD64 TechnologyNOTOne’s Complement NegationPerforms the one’s complement negation of the value in the specified register ormemory location by inverting each bit of the value.The memory-oper<strong>and</strong> forms of the NOT instruction support the LOCK prefix. Fordetails about the LOCK prefix, see “Lock Prefix” on page 10.Mnemonic Opcode DescriptionNOT reg/mem8 F6 /2 Complements the bits in an 8-bit register or memory oper<strong>and</strong>.NOT reg/mem16 F7 /2 Complements the bits in a 16-bit register or memory oper<strong>and</strong>.NOT reg/mem32 F7 /2 Complements the bits in a 32-bit register or memory oper<strong>and</strong>.NOT reg/mem64 F7 /2 Compliments the bits in a 64-bit register or memory oper<strong>and</strong>.Related <strong>Instructions</strong>AND, NEG, OR, XORrFLAGS AffectedNoneExceptionsException RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded a data segment limit or was non-canonical.XThe destination oper<strong>and</strong> 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, #AC X X An unaligned memory reference is performed while alignmentchecking was enabled.NOT 215


AMD64 Technology 24594 Rev. 3.10 February 2005ORLogical ORPerforms a logical OR on the bits in a register, memory location, or immediate value(second oper<strong>and</strong>) <strong>and</strong> a register or memory location (first oper<strong>and</strong>) <strong>and</strong> stores theresult in the first oper<strong>and</strong> location. The two oper<strong>and</strong>s cannot both be memorylocations.If both corresponding bits are 0, the corresponding bit of the result is 0; otherwise, thecorresponding result bit is 1.The forms of the OR instruction that write to memory support the LOCK prefix. Fordetails about the LOCK prefix, see “Lock Prefix” on page 10.Mnemonic Opcode DescriptionOR AL, imm8 0C ib OR the contents of AL with an immediate 8-bit value.OR AX, imm16 0D iw OR the contents of AX with an immediate 16-bit value.OR EAX, imm32 0D id OR the contents of EAX with an immediate 32-bit value.OR RAX, imm320D idOR reg/mem8, imm880 /1 ibOR reg/mem16, imm1681 /1 iwOR reg/mem32, imm3281 /1 idOR reg/mem64, imm3281 /1 idOR reg/mem16, imm883 /1 ibOR reg/mem32, imm883 /1 ibOR reg/mem64, imm883 /1 ibOR reg/mem8, reg8 08 /rOR the contents of RAX with a sign-extended immediate 32-bitvalue.OR the contents of an 8-bit register or memory oper<strong>and</strong> <strong>and</strong> animmediate 8-bit value.OR the contents of a 16-bit register or memory oper<strong>and</strong> <strong>and</strong> animmediate 16-bit value.OR the contents of a 32-bit register or memory oper<strong>and</strong> <strong>and</strong> animmediate 32-bit value.OR the contents of a 64-bit register or memory oper<strong>and</strong> <strong>and</strong>sign-extended immediate 32-bit value.OR the contents of a 16-bit register or memory oper<strong>and</strong> <strong>and</strong> asign-extended immediate 8-bit value.OR the contents of a 32-bit register or memory oper<strong>and</strong> <strong>and</strong> asign-extended immediate 8-bit value.OR the contents of a 64-bit register or memory oper<strong>and</strong> <strong>and</strong> asign-extended immediate 8-bit value.OR the contents of an 8-bit register or memory oper<strong>and</strong> with thecontents of an 8-bit register.216 OR


24594 Rev. 3.10 February 2005 AMD64 TechnologyMnemonic Opcode DescriptionOR reg/mem16, reg16 09 /rOR reg/mem32, reg32 09 /rOR reg/mem64, reg64 09 /rOR reg8, reg/mem8 0A /rOR reg16, reg/mem16 0B /rOR reg32, reg/mem32 0B /rOR reg64, reg/mem64 0B /rOR the contents of a 16-bit register or memory oper<strong>and</strong> with thecontents of a 16-bit register.OR the contents of a 32-bit register or memory oper<strong>and</strong> with thecontents of a 32-bit register.OR the contents of a 64-bit register or memory oper<strong>and</strong> with thecontents of a 64-bit register.OR the contents of an 8-bit register with the contents of an 8-bitregister or memory oper<strong>and</strong>.OR the contents of a 16-bit register with the contents of a 16-bitregister or memory oper<strong>and</strong>.OR the contents of a 32-bit register with the contents of a 32-bitregister or memory oper<strong>and</strong>.OR the contents of a 64-bit register with the contents of a 64-bitregister or memory oper<strong>and</strong>.The following chart summarizes the effect of this instruction:X Y X OR Y0 0 00 1 11 0 11 1 1Related <strong>Instructions</strong>AND, NEG, NOT, XOROR 217


AMD64 Technology 24594 Rev. 3.10 February 2005rFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFExceptions0 M M U M 021 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.Exception RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded a data segment limit or was non-canonical.XThe destination oper<strong>and</strong> 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, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.218 OR


24594 Rev. 3.10 February 2005 AMD64 TechnologyOUTOutput to PortCopies the value from the AL, AX, or EAX register (second oper<strong>and</strong>) to an I/O port(first oper<strong>and</strong>). The port address can be a byte-immediate value (00h to FFh) or thevalue in the DX register (0000h to FFFFh). The source register used determines thesize of the port (8, 16, or 32 bits).If the oper<strong>and</strong> size is 64 bits, OUT only writes to a 32-bit I/O port.If the CPL is higher than the IOPL or the mode is virtual mode, OUT checks the I/Opermission bitmap in the TSS before allowing access to the I/O port. See <strong>Volume</strong> 2 fordetails on the TSS I/O permission bitmap.Mnemonic Opcode DescriptionOUT imm8, ALOUT imm8, AXOUT imm8, EAXRelated <strong>Instructions</strong>IN, INSx, OUTSxrFLAGS AffectedNoneE6 ibE7 ibE7 ibOutput the byte in the AL register to the port specified by an 8-bitimmediate value.Output the word in the AX register to the port specified by an 8-bit immediate value.Output the doubleword in the EAX register to the port specifiedby an 8-bit immediate value.OUT DX, AL EE Output byte in AL to the output port specified in DX.OUT DX, AX EF Output word in AX to the output port specified in DX.OUT DX, EAX EF Output doubleword in EAX to the output port specified in DX.OUT 219


AMD64 Technology 24594 Rev. 3.10 February 2005ExceptionsException<strong>General</strong> protection,#GPRealVirtual8086 Protected Cause of ExceptionXOne or more I/O permission bits were set in the TSS for the accessedport.X The CPL was greater than the IOPL <strong>and</strong> one or more I/O permissionbits were set in the TSS for the accessed port.Page fault (#PF) X X A page fault resulted from the execution of the instruction.220 OUT


24594 Rev. 3.10 February 2005 AMD64 TechnologyOUTSOUTSBOUTSWOUTSDOutput StringCopies data from the memory location pointed to by DS:rSI to the I/O port address(0000h to FFFFh) specified in the DX register, <strong>and</strong> then increments or decrements therSI register according to the setting of the DF flag in the rFLAGS register.If the DF flag is 0, the instruction increments rSI; otherwise, it decrements rSI. Itincrements or decrements the pointer by 1, 2, or 4, depending on the size of the valuebeing copied.The OUTSx instruction uses an explicit memory oper<strong>and</strong> (second oper<strong>and</strong>) todetermine the type (size) of the value being copied, but always uses DS:rSI for thelocation of the value to copy. The explicit register oper<strong>and</strong> specifies the I/O portaddress <strong>and</strong> must always be DX.The no-oper<strong>and</strong>s forms of the instruction use the DS:[rSI] register pair to point to thedata to be copied <strong>and</strong> the DX register as the destination. The mnemonic specifies thesize of the I/O port <strong>and</strong> the type (size) of the value being copied.The OUTSx instruction supports the REP prefix. For details about the REP prefix, see“Repeat Prefixes” on page 10.If the oper<strong>and</strong> size is 64-bits, OUTS only writes to a 32-bit I/O port.If the CPL is higher than the IOPL or the mode is virtual mode, OUTSx checks the I/Opermission bitmap in the TSS before allowing access to the I/O port. See <strong>Volume</strong> 2 fordetails on the TSS I/O permission bitmap.Mnemonic Opcode DescriptionOUTS DX, mem8OUTS DX, mem16OUTS DX, mem326E6F6FOutput the byte in DS:rSI to the port specified in DX, thenincrement or decrement rSI.Output the word in DS:rSI to the port specified in DX, thenincrement or decrement rSI.Output the doubleword in DS:rSI to the port specified in DX, thenincrement or decrement rSI.OUTSx 221


AMD64 Technology 24594 Rev. 3.10 February 2005Mnemonic Opcode DescriptionOUTSBOUTSWOUTSDRelated <strong>Instructions</strong>IN, INSx, OUTrFLAGS AffectedNoneExceptions6E6F6FOutput the byte in DS:rSI to the port specified in DX, thenincrement or decrement rSI.Output the word in DS:rSI to the port specified in DX, thenincrement or decrement rSI.Output the doubleword in DS:rSI to the port specified in DX, thenincrement or decrement rSI.Exception RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPXXXA memory address exceeded a data segment limit or was non-canonical.XA null data segment was used to reference memory.XOne or more I/O permission bits were set in the TSS for the accessedport.X The CPL was greater than the IOPL <strong>and</strong> one or more I/O permissionbits 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, #AC X X An unaligned memory reference is performed while alignmentchecking was enabled.222 OUTSx


24594 Rev. 3.10 February 2005 AMD64 TechnologyPOPPop StackCopies the value pointed to by the stack pointer (SS:rSP) to the specified register ormemory location <strong>and</strong> then increments the rSP by 2 for a 16-bit pop, 4 for a 32-bit pop,or 8 for a 64-bit pop.The oper<strong>and</strong>-size attribute determines the amount by which the stack pointer isincremented (2,4 or 8 bytes). The stack-size attribute determines whether SP, ESP, orRSP is incremented.For forms of the instruction that load a segment register (POP DS, POP ES, POP FS,POP GS, POP SS), the source oper<strong>and</strong> must be a valid segment selector. When asegment selector is popped into a segment register, the processor also loads allassociated descriptor information into the hidden part of the register <strong>and</strong> validates it.It is possible to pop a null segment selector value (0000–0003h) into the DS, ES, FS, orGS register. This action does not cause a general protection fault, but a subsequentreference to such a segment does cause a #GP exception. For more information aboutsegment selectors, see “Segment Selectors <strong>and</strong> Registers” on page 82.In 64-bit mode, the POP oper<strong>and</strong> size defaults to 64 bits <strong>and</strong> there is no prefixavailable to encode a 32-bit oper<strong>and</strong> size. Using POP DS, POP ES, or POP SSinstruction in 64-bit mode generates an invalid-opcode exception.This instruction cannot pop a value into the CS register. The RET (Far) instructionperforms this function.Mnemonic Opcode DescriptionPOP reg/mem16 8F /0 Pop the top of the stack into a 16-bit register or memory location.POP reg/mem32 8F /0Pop the top of the stack into a 32-bit register or memory location.(No prefix for encoding this in 64-bit mode.)POP reg/mem64 8F /0 Pop the top of the stack into a 64-bit register or memory location.POP reg16 58 +rw Pop the top of the stack into a 16-bit register.POP reg3258 +rdPop the top of the stack into a 32-bit register.(No prefix for encoding this in 64-bit mode.)POP reg64 58 +rq Pop the top of the stack into a 64-bit register.POP DS1FPop the top of the stack into the DS register.(Invalid in 64-bit mode.)POP 223


AMD64 Technology 24594 Rev. 3.10 February 2005Mnemonic Opcode DescriptionPOP ES 07POP SS 17Pop the top of the stack into the ES register.(Invalid in 64-bit mode.)Pop the top of the stack into the SS register.(Invalid in 64-bit mode.)POP FS 0F A1 Pop the top of the stack into the FS register.POP GS 0F A9 Pop the top of the stack into the GS register.Related <strong>Instructions</strong>PUSHrFLAGS AffectedNoneExceptionsVirtualException Real 8086 Protected Cause of ExceptionInvalid opcode, #UD X POP DS, POP ES, or POP SS was executed in 64-bit mode.Segment not present,#NP (selector)XThe DS, ES, FS, or GS register was loaded with a non-null segmentselector <strong>and</strong> the segment was marked not present.Stack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.Stack, #SS(selector)<strong>General</strong> protection,#GPXX X XThe SS register was loaded with a non-null segment selector <strong>and</strong> thesegment was marked not present.A memory address exceeded a data segment limit or was non-canonical.XXThe destination oper<strong>and</strong> was in a non-writable segment.A null data segment was used to reference memory.224 POP


24594 Rev. 3.10 February 2005 AMD64 TechnologyException<strong>General</strong> protection,#GP(selector)RealVirtual8086 Protected Cause of ExceptionXXA segment register was loaded <strong>and</strong> the segment descriptor exceededthe descriptor table limit.A segment register was loaded <strong>and</strong> the segment selector’s TI bit wasset, but the LDT selector was a null selector.XXXXThe SS register was loaded with a null segment selector in non-64-bitmode or while CPL = 3.The SS register was loaded <strong>and</strong> the segment selector RPL <strong>and</strong> thesegment descriptor DPL were not equal to the CPL.The SS register was loaded <strong>and</strong> the segment pointed to was a not awritable data segment.The DS, ES, FS, or GS register was loaded <strong>and</strong> the segment pointedto was a data or non-conforming code segment, but the RPL or theCPL was greater than the DPL.X The DS, ES, FS, or GS register was loaded <strong>and</strong> the segment pointedto 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, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.POP 225


AMD64 Technology 24594 Rev. 3.10 February 2005POPAxPOPADPOP All GPRsPops words or doublewords from the stack into the general-purpose registers in thefollowing order: eDI, eSI, eBP, eSP (image is popped <strong>and</strong> discarded), eBX, eDX, eCX,<strong>and</strong> eAX. The instruction increments the stack pointer by 16 or 32, depending on theoper<strong>and</strong> size.Using the POPA or POPAD instructions in 64-bit mode generates an invalid-opcodeexception.Mnemonic Opcode DescriptionPOPA 61POPAD 61Pop the DI, SI, BP, SP, BX, DX, CX, <strong>and</strong> AX registers.(Invalid in 64-bit mode.)Pop the EDI, ESI, EBP, ESP, EBX, EDX, ECX, <strong>and</strong> EAX registers.(Invalid in 64-bit mode.)Related <strong>Instructions</strong>PUSHA, PUSHADrFLAGS AffectedNoneExceptionsException RealVirtual8086 Protected Cause of ExceptionInvalid opcode (#UD) X This instruction was executed in 64-bit mode.Stack, #SS X X X A memory address exceeded the stack segment limit.Page fault, #PF X X A page fault resulted from the execution of the instruction.Alignment check, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.226 POPAx


24594 Rev. 3.10 February 2005 AMD64 TechnologyPOPFxPOPFDPOPFQPOP to rFLAGSPops a word, doubleword, or quadword from the stack into the rfLAGS register <strong>and</strong>then increments the stack pointer by 2, 4, or 8, depending on the oper<strong>and</strong> size.In protected or real mode, all the non-reserved flags in the rFLAGS register can bemodified, except the VIP, VIF, <strong>and</strong> VM flags, which are unchanged. In protected mode,at a privilege level greater than 0 the IOPL is also unchanged. The instruction altersthe interrupt flag (IF) only when the CPL is less than or equal to the IOPL.In virtual-8086 mode, if IOPL field is less than 3, attempting to execute a POPFx orPUSHFx instruction while VME is not enabled, or the oper<strong>and</strong> size is not 16-bit,generates a #GP exception.In 64-bit mode, this instruction defaults to a 64-bit oper<strong>and</strong> size; there is no prefixavailable to encode a 32-bit oper<strong>and</strong> size.Mnemonic Opcode DescriptionPOPF 9D Pop a word from the stack into the FLAGS register.POPFDAction// See “Pseudocode Definitions” on page 49.POPF_START:IF (REAL_MODE)POPF_REALELSIF (PROTECTED_MODE)POPF_PROTECTEDELSE // (VIRTUAL_MODE)POPF_VIRTUAL9DPop a double word from the stack into the EFLAGS register. (Noprefix for encoding this in 64-bit mode.)POPFQ 9D Pop a quadword from the stack to the RFLAGS register.POPF_REAL:POP.v temp_RFLAGSPOPFx 227


AMD64 Technology 24594 Rev. 3.10 February 2005RFLAGS.v = temp_RFLAGSEXIT// VIF,VIP,VM unchanged// RF clearedPOPF_PROTECTED:POP.v temp_RFLAGSRFLAGS.v = temp_RFLAGSEXIT// VIF,VIP,VM unchanged// IOPL changed only if (CPL=0)// IF changed only if (CPL


24594 Rev. 3.10 February 2005 AMD64 TechnologyExceptionsException RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPXThe I/O privilege level was less than 3 <strong>and</strong> one of the following conditionswas true:• CR4.VME was 0.• The effective oper<strong>and</strong> size was 32-bit.• Both the original EFLAGS.VIP <strong>and</strong> the new EFLAGS.IF bits wereset.• The new EFLAGS.TF bit was set.Page fault, #PF X X A page fault resulted from the execution of the instruction.Alignment check, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.POPFx 229


AMD64 Technology 24594 Rev. 3.10 February 2005PREFETCHxPREFETCHWPrefetch L1 Data-Cache LinePREFETCH <strong>and</strong> PREFETCHW are 3DNow! instructions. They load a cache line intothe L1 data cache from the specified memory address. The PREFETCH instructionloads a cache line even if the mem8 address is not aligned with the start of the line. Ifa cache hit occurs, or if a memory fault is detected, no bus cycle is initiated, <strong>and</strong> theinstruction is treated as a NOP.The PREFETCHW instruction loads the prefetched line <strong>and</strong> sets the cache-line stateto Modified, in anticipation of subsequent data writes to the line. The PREFETCHinstruction, by contrast, typically (depending on hardware implementation) sets thecache-line state to Exclusive.The opcodes for the instructions include the ModRM byte, <strong>and</strong> only the memory formof ModRM is valid. The register form of ModRM causes an invalid-opcode exception.Because there is no destination register, the three destination register field bits of theModRM byte define the type of prefetch to be performed. The bit patterns 000b <strong>and</strong>001b define the PREFETCH <strong>and</strong> PREFETCHW instructions, respectively. All otherbit patterns are reserved for future use.The reserved PREFETCH types do not result in an invalid-opcode exception ifexecuted. Instead, for forward compatibility with future processors that mayimplement additional forms of the PREFETCH instruction, all reserved PREFETCHtypes are implemented as synonyms of the basic PREFETCH type (the PREFETCHinstruction with type 000b).The operation of these instructions is implementation-dependent. The processorimplementation can ignore or change these instructions. The size of the cache linealso depends on the implementation, with a minimum size of 32 bytes. For details onthe use of this instruction, see the data sheet or other software-optimizationdocumentation relating to particular hardware implementations.These instructions are 3DNow! instructions; check the status of EDX bit 31 of CPUIDextended function 8000_0001h; check EDX bit 25 of CPUID extended function8000_0001h to verify that the processor supports long mode.230 PREFETCHx


24594 Rev. 3.10 February 2005 AMD64 TechnologyMnemonic Opcode DescriptionPREFETCH mem8 0F 0D /0 Prefetch processor cache line into L1 data cache.PREFETCHW mem8 0F 0D /1Prefetch processor cache line into L1 data cache <strong>and</strong> mark itmodified.Related <strong>Instructions</strong>PREFETCHlevelrFLAGS AffectedNoneExceptionsException (vector)Invalid opcode, #UDRealXVirtual8086 Protected Cause of ExceptionXXThe AMD 3DNow! instructions are not supported, as indicatedby EDX bit 31 of CPUID extended function8000_0001h; <strong>and</strong> Long Mode is not supported, as indicatedby EDX bit 29 of CPUID extended function 8000_0001h.XXXThe oper<strong>and</strong> was a register.PREFETCHx 231


AMD64 Technology 24594 Rev. 3.10 February 2005PREFETCHlevelPrefetch Data to Cache Level levelLoads a cache line from the specified memory address into the data-cache levelspecified by the locality reference bits 5–3 of the ModRM byte. Table 3-16 on page 233lists the locality reference options for the instruction.This instruction loads a cache line even if the mem8 address is not aligned with thestart of the line. If the cache line is already contained in a cache level that is lowerthan the specified locality reference, or if a memory fault is detected, a bus cycle isnot initiated <strong>and</strong> the instruction is treated as a NOP.The operation of this instruction is implementation-dependent. The processorimplementation can ignore or change this instruction. The size of the cache line alsodepends on the implementation, with a minimum size of 32 bytes. AMD processorsalias PREFETCH1 <strong>and</strong> PREFETCH2 to PREFETCH0. For details on the use of thisinstruction, see the software-optimization documentation relating to particularhardware implementations.Mnemonic Opcode DescriptionPREFETCHNTA mem8 0F 18 /0 Move data closer to the processor using the NTA reference.PREFETCHT0 mem8 0F 18 /1 Move data closer to the processor using the T0 reference.PREFETCHT1 mem8 0F 18 /2 Move data closer to the processor using the T1 reference.PREFETCHT2 mem8 0F 18 /3 Move data closer to the processor using the T2 reference.232 PREFETCHlevel


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable 3-16.Locality References for the Prefetch <strong>Instructions</strong>LocalityReferenceNTAT0T1T2DescriptionNon-Temporal Access—Move the specified data into the processor with minimumcache pollution. This is intended for data that will be used only once, rather thanrepeatedly. The specific technique for minimizing cache pollution isimplementation-dependent <strong>and</strong> may include such techniques as allocating spacein a software-invisible buffer, allocating a cache line in only a single way, etc. Fordetails, see the software-optimization documentation for a particular hardwareimplementation.All Cache Levels—Move the specified data into all cache levels.Level 2 <strong>and</strong> Higher—Move the specified data into all cache levels except 0th level(L1) cache.Level 3 <strong>and</strong> Higher—Move the specified data into all cache levels except 0th level(L1) <strong>and</strong> 1st level (L2) caches.Related <strong>Instructions</strong>PREFETCH, PREFETCHWrFLAGS AffectedNoneExceptionsNonePREFETCHlevel 233


AMD64 Technology 24594 Rev. 3.10 February 2005PUSHPush onto StackDecrements the stack pointer <strong>and</strong> then copies the specified immediate value or thevalue in the specified register or memory location to the top of the stack (the memorylocation pointed to by SS:rSP).The oper<strong>and</strong>-size attribute determines the number of bytes pushed to the stack. Thestack-size attribute determines whether SP, ESP, or RSP is the stack pointer. Theaddress-size attribute is used only to locate the memory oper<strong>and</strong> when pushing amemory oper<strong>and</strong> to the stack.If the instruction pushes the stack pointer (rSP), the resulting value on the stack isthat of rSP before execution of the instruction.There is a PUSH CS instruction but no corresponding POP CS. The RET (Far)instruction pops a value from the top of stack into the CS register as part of itsoperation.In 64-bit mode, the oper<strong>and</strong> size of all PUSH instructions defaults to 64 bits, <strong>and</strong> thereis no prefix available to encode a 32-bit oper<strong>and</strong> size. Using the PUSH CS, PUSH DS,PUSH ES, or PUSH SS instructions in 64-bit mode generates an invalid-opcodeexception.Pushing an odd number of 16-bit oper<strong>and</strong>s when the stack address-size attribute is 32results in a misaligned stack pointer.Mnemonic Opcode DescriptionPUSH reg/mem16 FF /6PUSH reg/mem32 FF /6PUSH reg/mem64 FF /6Push the contents of a 16-bit register or memory oper<strong>and</strong> ontothe stack.Push the contents of a 32-bit register or memory oper<strong>and</strong> ontothe stack. (No prefix for encoding this in 64-bit mode.)Push the contents of a 64-bit register or memory oper<strong>and</strong> ontothe stack.PUSH reg16 50 +rw Push the contents of a 16-bit register onto the stack.PUSH reg3250 +rdPush the contents of a 32-bit register onto the stack. (No prefixfor encoding this in 64-bit mode.)PUSH reg64 50 +rq Push the contents of a 64-bit register onto the stack.PUSH imm86APush an 8-bit immediate value (sign-extended to 16, 32, or 64bits) onto the stack.234 PUSH


24594 Rev. 3.10 February 2005 AMD64 TechnologyMnemonic Opcode DescriptionPUSH imm16 68 Push a 16-bit immediate value onto the stack.PUSH imm32 68Push a 32-bit immediate value onto the stack. (No prefix forencoding this in 64-bit mode.)PUSH imm64 68 Push a sign-extended 32-bit immediate value onto the stack.PUSH CS 0E Push the CS selector onto the stack. (Invalid in 64-bit mode.)PUSH SS 16 Push the SS selector onto the stack. (Invalid in 64-bit mode.)PUSH DS 1E Push the DS selector onto the stack. (Invalid in 64-bit mode.)PUSH ES 06 Push the ES selector onto the stack. (Invalid in 64-bit mode.)PUSH FS 0F A0 Push the FS selector onto the stack.PUSH GS 0F A8 Push the GS selector onto the stack.Related <strong>Instructions</strong>POPrFLAGS AffectedNoneExceptionsException RealVirtual8086 Protected Cause of ExceptionInvalid opcode, #UD X PUSH CS, PUSH DS, PUSH ES, or PUSH SS was executed in 64-bitmode.Stack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded a data segment limit or was 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.Alignment check, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.PUSH 235


AMD64 Technology 24594 Rev. 3.10 February 2005PUSHAxPUSHADPush All GPRs onto StackPushes the contents of the eAX, eCX, eDX, eBX, eSP (original value), eBP, eSI, <strong>and</strong>eDI general-purpose registers onto the stack in that order. This instruction decrementsthe stack pointer by 16 or 32 depending on oper<strong>and</strong> size.Using the PUSHA or PUSHAD instruction in 64-bit mode generates an invalid-opcodeexception.Mnemonic Opcode DescriptionPUSHA 60PUSHAD 60Push the contents of the AX, CX, DX, BX, original SP, BP, SI, <strong>and</strong>DI registers onto the stack.(Invalid in 64-bit mode.)Push the contents of the EAX, ECX, EDX, EBX, original ESP, EBP,ESI, <strong>and</strong> EDI registers onto the stack.(Invalid in 64-bit mode.)Related <strong>Instructions</strong>POPA, POPADrFLAGS AffectedNoneExceptionsException RealVirtual8086 Protected Cause of ExceptionInvalid opcode, #UD X This instruction was executed in 64-bit mode.Stack, #SS X X X A memory address exceeded the stack segment limit.Page fault, #PF X X A page fault resulted from the execution of the instruction.Alignment check, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.236 PUSHAx


24594 Rev. 3.10 February 2005 AMD64 TechnologyPUSHFxPUSHFDPUSHFQPush rFLAGS onto StackDecrements the rSP register <strong>and</strong> copies the rFLAGS register (except for the VM <strong>and</strong>RF flags) onto the stack. The instruction clears the VM <strong>and</strong> RF flags in the rFLAGSimage before putting it on the stack.The instruction pushes 2, 4, or 8 bytes, depending on the oper<strong>and</strong> size.In 64-bit mode, this instruction defaults to a 64-bit oper<strong>and</strong> size <strong>and</strong> there is no prefixavailable to encode a 32-bit oper<strong>and</strong> size.In virtual-8086 mode, if system software has set the IOPL field to a value less than 3, ageneral-protection exception occurs if application software attempts to executePUSHFx or POPFx while VME is not enabled or the oper<strong>and</strong> size is not 16-bit.Mnemonic Opcode DescriptionPUSHF 9C Push the FLAGS word onto the stack.PUSHFDAction// See “Pseudocode Definitions” on page 49.PUSHF_START:IF (REAL_MODE)PUSHF_REALELSIF (PROTECTED_MODE)PUSHF_PROTECTEDELSE // (VIRTUAL_MODE)PUSHF_VIRTUAL9CPush the EFLAGS doubleword onto stack. (No prefix encodingthis in 64-bit mode.)PUSHFQ 9C Push the RFLAGS quadword onto stack.PUSHF_REAL:PUSH.v old_RFLAGSEXITPUSHF_PROTECTED:PUSH.v old_RFLAGSEXIT// Pushed with RF <strong>and</strong> VM cleared.// Pushed with RF cleared.PUSHFx 237


AMD64 Technology 24594 Rev. 3.10 February 2005PUSHF_VIRTUAL:IF (RFLAGS.IOPL=3){PUSH.v old_RFLAGS // Pushed with RF,VM cleared.EXIT}ELSIF ((CR4.VME=1) && (OPERAND_SIZE=16)){PUSH.v old_RFLAGS // Pushed with VIF in the IF position.// Pushed with IOPL=3.EXIT}ELSE // ((RFLAGS.IOPL


24594 Rev. 3.10 February 2005 AMD64 TechnologyRCLRotate Through Carry LeftRotates the bits of a register or memory location (first oper<strong>and</strong>) to the left (moresignificant bit positions) <strong>and</strong> through the carry flag by the number of bit positions inan unsigned immediate value or the CL register (second oper<strong>and</strong>). The bits rotatedthrough the carry flag are rotated back in at the right end (lsb) of the first oper<strong>and</strong>location.The processor masks the upper three bits of the count oper<strong>and</strong>, thus restricting thecount to a number between 0 <strong>and</strong> 31. When the destination is 64 bits wide, theprocessor masks the upper two bits of the count, providing a count in the range of 0 to63.For 1-bit rotates, the instruction sets the OF flag to the exclusive OR of the CF bit(after the rotate) <strong>and</strong> the most significant bit of the result. When the rotate count isgreater than 1, the OF flag is undefined. When the rotate count is 0, no flags areaffected.Mnemonic Opcode DescriptionRCL reg/mem8,1 D0 /2RCL reg/mem8, CL D2 /2RCL reg/mem8, imm8C0 /2 ibRCL reg/mem16, 1 D1 /2RCL reg/mem16, CL D3 /2RCL reg/mem16, imm8C1 /2 ibRCL reg/mem32, 1 D1 /2Rotate the 9 bits consisting of the carry flag <strong>and</strong> an 8-bit registeror memory location left 1 bit.Rotate the 9 bits consisting of the carry flag <strong>and</strong> an 8-bit registeror memory location left the number of bits specified in the CLregister.Rotate the 9 bits consisting of the carry flag <strong>and</strong> an 8-bit registeror memory location left the number of bits specified by an 8-bitimmediate value.Rotate the 17 bits consisting of the carry flag <strong>and</strong> a 16-bit registeror memory location left 1 bit.Rotate the17 bits consisting of the carry flag <strong>and</strong> a 16-bit registeror memory location left the number of bits specified in the CLregister.Rotate the 17 bits consisting of the carry flag <strong>and</strong> a 16-bit registeror memory location left the number of bits specified by an 8-bitimmediate value.Rotate the 33 bits consisting of the carry flag <strong>and</strong> a 32-bit registeror memory location left 1 bit.RCL 239


AMD64 Technology 24594 Rev. 3.10 February 2005Mnemonic Opcode DescriptionRCL reg/mem32, CL D3 /2Rotate 33 bits consisting of the carry flag <strong>and</strong> a 32-bit register ormemory location left the number of bits specified in the CLregister.RCL reg/mem32, imm8C1 /2 ibRotate the 33 bits consisting of the carry flag <strong>and</strong> a 32-bit registeror memory location left the number of bits specified by an 8-bitimmediate value.RCL reg/mem64, 1 D1 /2RCL reg/mem64, CL D3 /2Rotate the 65 bits consisting of the carry flag <strong>and</strong> a 64-bit registeror memory location left 1 bit.Rotate the 65 bits consisting of the carry flag <strong>and</strong> a 64-bit registeror memory location left the number of bits specified in the CLregister.RCL reg/mem64, imm8Related <strong>Instructions</strong>RCR, ROL, RORrFLAGS AffectedC1 /2 ibRotates the 65 bits consisting of the carry flag <strong>and</strong> a 64-bitregister or memory location left the number of bits specified byan 8-bit immediate value.ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFMM21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.ExceptionsException RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded a data segment limit or was non-canonical.XXThe destination oper<strong>and</strong> was in a non-writable segment.A null data segment was used to reference memory.240 RCL


24594 Rev. 3.10 February 2005 AMD64 TechnologyExceptionRealVirtual8086 Protected Cause of ExceptionPage fault, #PF X X A page fault resulted from the execution of the instruction.Alignment check, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.RCL 241


AMD64 Technology 24594 Rev. 3.10 February 2005RCRRotate Through Carry RightRotates the bits of a register or memory location (first oper<strong>and</strong>) to the right (towardthe less significant bit positions) <strong>and</strong> through the carry flag by the number of bitpositions in an unsigned immediate value or the CL register (second oper<strong>and</strong>). Thebits rotated through the carry flag are rotated back in at the left end (msb) of the firstoper<strong>and</strong> location.The processor masks the upper three bits in the count oper<strong>and</strong>, thus restricting thecount to a number between 0 <strong>and</strong> 31. When the destination is 64 bits wide, theprocessor masks the upper two bits of the count, providing a count in the range of 0 to63.For 1-bit rotates, the instruction sets the OF flag to the exclusive OR of the CF flag(before the rotate) <strong>and</strong> the most significant bit of the original value. When the rotatecount is greater than 1, the OF flag is undefined. When the rotate count is 0, no flagsare affected.Mnemonic Opcode DescriptionRCR reg/mem8, 1 D0 /3RCR reg/mem8,CL D2 /3RCR reg/mem8,imm8C0 /3 ibRCR reg/mem16,1 D1 /3RCR reg/mem16,CL D3 /3RCR reg/mem16, imm8C1 /3 ibRCR reg/mem32,1 D1 /3Rotate the 9 bits consisting of the carry flag <strong>and</strong> an 8-bit registeror memory location right 1 bit.Rotate the 9 bits consisting of the carry flag <strong>and</strong> an 8-bit registeror memory location right the number of bits specified in the CLregister.Rotate the 9 bits consisting of the carry flag <strong>and</strong> an 8-bit registeror memory location right the number of bits specified by an 8-bitimmediate value.Rotate the 17 bits consisting of the carry flag <strong>and</strong> a 16-bit registeror memory location right 1 bit.Rotate the17 bits consisting of the carry flag <strong>and</strong> a 16-bit registeror memory location right the number of bits specified in the CLregister.Rotate the 17 bits consisting of the carry flag <strong>and</strong> a 16-bit registeror memory location right the number of bits specified by an 8-bitimmediate value.Rotate the 33 bits consisting of the carry flag <strong>and</strong> a 32-bit registeror memory location right 1 bit.242 RCR


24594 Rev. 3.10 February 2005 AMD64 TechnologyMnemonic Opcode DescriptionRCR reg/mem32,CL D3 /3Rotate 33 bits consisting of the carry flag <strong>and</strong> a 32-bit register ormemory location right the number of bits specified in the CLregister.RCR reg/mem32, imm8C1 /3 ibRotate the 33 bits consisting of the carry flag <strong>and</strong> a 32-bit registeror memory location right the number of bits specified by an 8-bitimmediate value.RCR reg/mem64,1 D1 /3RCR reg/mem64,CL D3 /3Rotate the 65 bits consisting of the carry flag <strong>and</strong> a 64-bit registeror memory location right 1 bit.Rotate 65 bits consisting of the carry flag <strong>and</strong> a 64-bit register ormemory location right the number of bits specified in the CLregister.RCR reg/mem64, imm8Related <strong>Instructions</strong>RCL, ROR, ROLrFLAGS AffectedC1 /3 ibRotate the 65 bits consisting of the carry flag <strong>and</strong> a 64-bit registeror memory location right the number of bits specified by an 8-bitimmediate value.ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFMM21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.ExceptionsException RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded a data segment limit or was non-canonical.XXThe destination oper<strong>and</strong> was in a non-writable segment.A null data segment was used to reference memory.RCR 243


AMD64 Technology 24594 Rev. 3.10 February 2005ExceptionRealVirtual8086 Protected Cause of ExceptionPage fault, #PF X X A page fault resulted from the execution of the instruction.Alignment check, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.244 RCR


24594 Rev. 3.10 February 2005 AMD64 TechnologyRET (Near)Near Return from Called ProcedureReturns from a procedure previously entered by a CALL near instruction. This form ofthe RET instruction returns to a calling procedure within the current code segment.This instruction pops the rIP from the stack, with the size of the pop determined bythe oper<strong>and</strong> size. The new rIP is then zero-extended to 64 bits. The RET instructioncan accept an immediate value oper<strong>and</strong> that it adds to the rSP after it pops the targetrIP. This action skips over any parameters previously passed back to the subroutinethat are no longer needed.In 64-bit mode, the oper<strong>and</strong> size defaults to 64 bits (eight bytes) without the need for aREX prefix. No prefix is available to encode a 32-bit oper<strong>and</strong> size in 64-bit mode.See RET (Far) for information on far returns—returns to procedures located outsideof the current code segment. For details about control-flow instructions, see “ControlTransfers” in <strong>Volume</strong> 1, <strong>and</strong> “Control-Transfer Privilege Checks” in <strong>Volume</strong> 2.Mnemonic Opcode DescriptionRET C3 Near return to the calling procedure.RET imm16Related <strong>Instructions</strong>C2 iwNear return to the calling procedure then pop of the specifiednumber of bytes from the stack.CALL (Near), CALL (Far), RET (Far)rFLAGS AffectedNoneExceptionsException RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X X The target offset exceeded the code segment limit or was non-canonical.RET (Near) 245


AMD64 Technology 24594 Rev. 3.10 February 2005ExceptionRealVirtual8086 Protected Cause of ExceptionPage fault, #PF X X A page fault resulted from the execution of the instruction.Alignment check, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.246 RET (Near)


24594 Rev. 3.10 February 2005 AMD64 TechnologyRET (Far)Far Return from Called ProcedureReturns from a procedure previously entered by a CALL Far instruction. This form ofthe RET instruction returns to a calling procedure in a different segment than thecurrent code segment. It can return to the same CPL or to a less privileged CPL.RET Far pops a target CS <strong>and</strong> rIP from the stack. If the new code segment is lessprivileged than the current code segment, the stack pointer is incremented by thenumber of bytes indicated by the immediate oper<strong>and</strong>, if present; then a new SS <strong>and</strong>rSP are also popped from the stack.The final value of rSP is incremented by the number of bytes indicated by theimmediate oper<strong>and</strong>, if present. This action skips over the parameters (previouslypassed to the subroutine) that are no longer needed.All stack pops are determined by the oper<strong>and</strong> size. If necessary, the target rIP is zeroextendedto 64 bits before assuming program control.If the CPL changes, the data segment selectors are set to NULL for any of the datasegments (DS, ES, FS, GS) not accessible at the new CPL.See RET (Near) for information on near returns—returns to procedures located insidethe current code segment. For details about control-flow instructions, see “ControlTransfers” in <strong>Volume</strong> 1, <strong>and</strong> “Control-Transfer Privilege Checks” in <strong>Volume</strong> 2.Mnemonic Opcode DescriptionRETF CB Far return to the calling procedure.RETF imm16CA iwFar return to the calling procedure, then pop of the specifiednumber of bytes from the stack.Action// Far returns (RETF)// See “Pseudocode Definitions” on page 49.RETF_START:IF (REAL_MODE)RETF_REAL_OR_VIRTUALELSIF (PROTECTED_MODE)RETF_PROTECTEDELSE // (VIRTUAL_MODE)RETF_REAL_OR_VIRTUALRET (Far) 247


AMD64 Technology 24594 Rev. 3.10 February 2005RETF_REAL_OR_VIRTUAL:IF (OPCODE = retf imm16)temp_IMM = word-sized immediate specified in the instruction,zero-extended to 64 bitsELSE // (OPCODE = retf)temp_IMM = 0POP.v temp_RIPPOP.v temp_CSIF (temp_RIP > CS.limit)EXCEPTION [#GP(0)]CS.sel = temp_CSCS.base = temp_CS SHL 4RSP.s = RSP + temp_IMMRIP = temp_RIPEXITRETF_PROTECTED:IF (OPCODE = retf imm16)temp_IMM = word-sized immediate specified in the instruction,zero-extended to 64 bitsELSE // (OPCODE = retf)temp_IMM = 0POP.v temp_RIPPOP.v temp_CStemp_CPL = temp_CS.rplIF (CPL=temp_CPL){CS = READ_DESCRIPTOR (temp_CS, iret_chk)RSP.s = RSP + temp_IMMIF ((64BIT_MODE) && (temp_RIP is non-canonical)|| (!64BIT_MODE) && (temp_RIP > CS.limit))EXCEPTION [#GP(0)]RIP = temp_RIPEXIT}ELSE // (CPL!=temp_CPL)248 RET (Far)


24594 Rev. 3.10 February 2005 AMD64 Technology{RSP.s = RSP + temp_IMMPOP.v temp_RSPPOP.v temp_SSCS = READ_DESCRIPTOR (temp_CS, iret_chk)CPL = temp_CPLIF ((64BIT_MODE) && (temp_RIP is non-canonical)|| (!64BIT_MODE) && (temp_RIP > CS.limit))EXCEPTION [#GP(0)]SS = READ_DESCRIPTOR (temp_SS, ss_chk)RSP.s = temp_RSP + temp_IMMIF (changing CPL){FOR (seg = ES, DS, FS, GS)IF ((seg.attr.dpl < CPL) && ((seg.attr.type = ’data’)|| (seg.attr.type = ’non-conforming-code’))){seg = NULL // can’t use lower dpl data segment at higher cpl}}}RIP = temp_RIPEXITRelated <strong>Instructions</strong>CALL (Near), CALL (Far), RET (Near)rFLAGS AffectedNoneExceptionsExceptionSegment not present,#NP (selector)RealVirtual8086 Protected Cause of ExceptionXThe return code segment was marked not present.Stack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.Stack, #SS (selector) X The return stack segment was marked not present.RET (Far) 249


AMD64 Technology 24594 Rev. 3.10 February 2005Exception<strong>General</strong> protection,#GP<strong>General</strong> protection,#GP(selector)RealVirtual8086 Protected Cause of ExceptionX X X The target offset exceeded the code segment limit or was non-canonical.XXThe return code selector was a null selector.The return stack selector was a null selector <strong>and</strong> the return mode wasnon-64-bit mode or CPL was 3.XXXXXXXXThe return code or stack descriptor exceeded the descriptor tablelimit.The return code or stack selector’s TI bit was set but the LDT selectorwas a null selector.The segment descriptor for the return code was not a code segment.The RPL of the return code segment selector was less than the CPL.The return code segment was non-conforming <strong>and</strong> the segmentselector’s DPL was not equal to the RPL of the code segment’s segmentselector.The return code segment was conforming <strong>and</strong> the segment selector’sDPL was greater than the RPL of the code segment’s segment selectorThe segment descriptor for the return stack was not a writable datasegment.The stack segment descriptor DPL was not equal to the RPL of thereturn code segment selector.X The stack segment selector RPL was not equal to the RPL of the returncode segment selector.Page fault, #PF X X A page fault resulted from the execution of the instruction.Alignment check, #AC X X An unaligned-memory reference was performed while alignmentchecking was enabled.250 RET (Far)


24594 Rev. 3.10 February 2005 AMD64 TechnologyROLRotate LeftRotates the bits of a register or memory location (first oper<strong>and</strong>) to the left (toward themore significant bit positions) by the number of bit positions in an unsignedimmediate value or the CL register (second oper<strong>and</strong>). The bits rotated out left arerotated back in at the right end (lsb) of the first oper<strong>and</strong> location.The processor masks the upper three bits of the count oper<strong>and</strong>, thus restricting thecount to a number between 0 <strong>and</strong> 31. When the destination is 64 bits wide, it masksthe upper two bits of the count, providing a count in the range of 0 to 63.After completing the rotation, the instruction sets the CF flag to the last bit rotatedout (the lsb of the result). For 1-bit rotates, the instruction sets the OF flag to theexclusive OR of the CF bit (after the rotate) <strong>and</strong> the most significant bit of the result.When the rotate count is greater than 1, the OF flag is undefined. When the rotatecount is 0, no flags are affected.Mnemonic Opcode DescriptionROL reg/mem8, 1 D0 /0 Rotate an 8-bit register or memory oper<strong>and</strong> left 1 bit.ROL reg/mem8, CL D2 /0ROL reg/mem8, imm8C0 /0 ibRotate an 8-bit register or memory oper<strong>and</strong> left the number ofbits specified in the CL register.Rotate an 8-bit register or memory oper<strong>and</strong> left the number ofbits specified by an 8-bit immediate value.ROL reg/mem16, 1 D1 /0 Rotate a 16-bit register or memory oper<strong>and</strong> left 1 bit.ROL reg/mem16, CL D3 /0ROL reg/mem16, imm8C1 /0 ibRotate a 16-bit register or memory oper<strong>and</strong> left the number ofbits specified in the CL register.Rotate a 16-bit register or memory oper<strong>and</strong> left the number ofbits specified by an 8-bit immediate value.ROL reg/mem32, 1 D1 /0 Rotate a 32-bit register or memory oper<strong>and</strong> left 1 bit.ROL reg/mem32, CL D3 /0ROL reg/mem32, imm8C1 /0 ibRotate a 32-bit register or memory oper<strong>and</strong> left the number ofbits specified in the CL register.Rotate a 32-bit register or memory oper<strong>and</strong> left the number ofbits specified by an 8-bit immediate value.ROL reg/mem64, 1 D1 /0 Rotate a 64-bit register or memory oper<strong>and</strong> left 1 bit.ROL 251


AMD64 Technology 24594 Rev. 3.10 February 2005Mnemonic Opcode DescriptionROL reg/mem64, CL D3 /0Rotate a 64-bit register or memory oper<strong>and</strong> left the number ofbits specified in the CL register.ROL reg/mem64, imm8Related <strong>Instructions</strong>RCL, RCR, RORrFLAGS AffectedC1 /0 ibRotate a 64-bit register or memory oper<strong>and</strong> left the number ofbits specified by an 8-bit immediate value.ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFMM21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.ExceptionsException RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded a data segment limit or was non-canonical.XThe destination oper<strong>and</strong> 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, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.252 ROL


24594 Rev. 3.10 February 2005 AMD64 TechnologyRORRotate RightRotates the bits of a register or memory location (first oper<strong>and</strong>) to the right (towardthe less significant bit positions) by the number of bit positions in an unsignedimmediate value or the CL register (second oper<strong>and</strong>). The bits rotated out right arerotated back in at the left end (the most significant bit) of the first oper<strong>and</strong> location.The processor masks the upper three bits of the count oper<strong>and</strong>, thus restricting thecount to a number between 0 <strong>and</strong> 31. When the destination is 64 bits wide, theprocessor masks the upper two bits of the count, providing a count in the range of 0 to63.After completing the rotation, the instruction sets the CF flag to the last bit rotatedout (the most significant bit of the result). For 1-bit rotates, the instruction sets the OFflag to the exclusive OR of the two most significant bits of the result. When the rotatecount is greater than 1, the OF flag is undefined. When the rotate count is 0, no flagsare affected.Mnemonic Opcode DescriptionROR reg/mem8, 1 D0 /1 Rotate an 8-bit register or memory location right 1 bit.ROR reg/mem8, CL D2 /1ROR reg/mem8, imm8C0 /1 ibRotate an 8-bit register or memory location right the number ofbits specified in the CL register.Rotate an 8-bit register or memory location right the number ofbits specified by an 8-bit immediate value.ROR reg/mem16, 1 D1 /1 Rotate a 16-bit register or memory location right 1 bit.ROR reg/mem16, CL D3 /1ROR reg/mem16, imm8C1 /1 ibRotate a 16-bit register or memory location right the number ofbits specified in the CL register.Rotate a 16-bit register or memory location right the number ofbits specified by an 8-bit immediate value.ROR reg/mem32, 1 D1 /1 Rotate a 32-bit register or memory location right 1 bit.ROR reg/mem32, CL D3 /1ROR reg/mem32, imm8C1 /1 ibRotate a 32-bit register or memory location right the number ofbits specified in the CL register.Rotate a 32-bit register or memory location right the number ofbits specified by an 8-bit immediate value.ROR reg/mem64, 1 D1 /1 Rotate a 64-bit register or memory location right 1 bit.ROR 253


AMD64 Technology 24594 Rev. 3.10 February 2005Mnemonic Opcode DescriptionROR reg/mem64, CL D3 /1Rotate a 64-bit register or memory oper<strong>and</strong> right the number ofbits specified in the CL register.ROR reg/mem64, imm8Related <strong>Instructions</strong>RCL, RCR, ROLrFLAGS AffectedC1 /1 ibRotate a 64-bit register or memory oper<strong>and</strong> right the number ofbits specified by an 8-bit immediate value.ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFMM21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.ExceptionsException RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded a data segment limit or was non-canonical.XThe destination oper<strong>and</strong> 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, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.254 ROR


24594 Rev. 3.10 February 2005 AMD64 TechnologySAHFStore AH into FlagsLoads the SF, ZF, AF, PF, <strong>and</strong> CF flags of the EFLAGS register with values from thecorresponding bits in the AH register (bits 7, 6, 4, 2, <strong>and</strong> 0, respectively). Theinstruction ignores bits 1, 3, <strong>and</strong> 5 of register AH; it sets those bits in the EFLAGSregister to 1, 0, <strong>and</strong> 0, respectively.The SAHF instruction can only be executed in 64-bit mode if supported by theprocessor implementation. Check the status of ECX bit 0 returned by CPUIDextended function 8000_0001h to verify that the processor supports SAHF in 64-bitmode.Mnemonic Opcode DescriptionSAHFRelated <strong>Instructions</strong>LAHFrFLAGS Affected9ELoads the sign flag, the zero flag, the auxiliary flag, the parity flag,<strong>and</strong> the carry flag from the AH register into the lower 8 bits of theEFLAGS register.ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFExceptionsM M M M M21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.Exception RealVirtual8086 Protected Cause of ExceptionInvalid opcode, #UD X This instruction is not supported in 64-bit mode, as indicated by ECXbit 0 returned by CPUID st<strong>and</strong>ard function 8000_0001h.SAHF 255


AMD64 Technology 24594 Rev. 3.10 February 2005SALSHLShift LeftShifts the bits of a register or memory location (first oper<strong>and</strong>) to the left through theCF bit by the number of bit positions in an unsigned immediate value or the CLregister (second oper<strong>and</strong>). The instruction discards bits shifted out of the CF flag. Foreach bit shift, the SAL instruction clears the least-significant bit to 0. At the end of theshift operation, the CF flag contains the last bit shifted out of the first oper<strong>and</strong>.The processor masks the upper three bits of the count oper<strong>and</strong>, thus restricting thecount to a number between 0 <strong>and</strong> 31. When the destination is 64 bits wide, theprocessor masks the upper two bits of the count, providing a count in the range of 0 to63.The effect of this instruction is multiplication by powers of two.For 1-bit shifts, the instruction sets the OF flag to the exclusive OR of the CF bit (afterthe shift) <strong>and</strong> the most significant bit of the result. When the shift count is greaterthan 1, the OF flag is undefined.If the shift count is 0, no flags are modified.SHL is an alias to the SAL instruction.Mnemonic Opcode DescriptionSAL reg/mem8, 1 D0 /4 Shift an 8-bit register or memory location left 1 bit.SAL reg/mem8, CL D2 /4SAL reg/mem8, imm8C0 /4 ibShift an 8-bit register or memory location left the number of bitsspecified in the CL register.Shift an 8-bit register or memory location left the number of bitsspecified by an 8-bit immediate value.SAL reg/mem16, 1 D1 /4 Shift a 16-bit register or memory location left 1 bit.SAL reg/mem16, CL D3 /4SAL reg/mem16, imm8C1 /4 ibShift a 16-bit register or memory location left the number of bitsspecified in the CL register.Shift a 16-bit register or memory location left the number of bitsspecified by an 8-bit immediate value.SAL reg/mem32, 1 D1 /4 Shift a 32-bit register or memory location left 1 bit.SAL reg/mem32, CL D3 /4Shift a 32-bit register or memory location left the number of bitsspecified in the CL register.256 SAL, SHL


24594 Rev. 3.10 February 2005 AMD64 TechnologyMnemonic Opcode DescriptionSAL reg/mem32, imm8Related <strong>Instructions</strong>SAR, SHR, SHLD, SHRDC1 /4 ibShift a 32-bit register or memory location left the number of bitsspecified by an 8-bit immediate value.SAL reg/mem64, 1 D1 /4 Shift a 64-bit register or memory location left 1 bit.SAL reg/mem64, CL D3 /4SAL reg/mem64, imm8C1 /4 ibShift a 64-bit register or memory location left the number of bitsspecified in the CL register.Shift a 64-bit register or memory location left the number of bitsspecified by an 8-bit immediate value.SHL reg/mem8, 1 D0 /4 Shift an 8-bit register or memory location by 1 bit.SHL reg/mem8, CL D2 /4SHL reg/mem8, imm8C0 /4 ibShift an 8-bit register or memory location left the number of bitsspecified in the CL register.Shift an 8-bit register or memory location left the number of bitsspecified by an 8-bit immediate value.SHL reg/mem16, 1 D1 /4 Shift a 16-bit register or memory location left 1 bit.SHL reg/mem16, CL D3 /4SHL reg/mem16, imm8C1 /4 ibShift a 16-bit register or memory location left the number of bitsspecified in the CL register.Shift a 16-bit register or memory location left the number of bitsspecified by an 8-bit immediate value.SHL reg/mem32, 1 D1 /4 Shift a 32-bit register or memory location left 1 bit.SHL reg/mem32, CL D3 /4SHL reg/mem32, imm8C1 /4 ibShift a 32-bit register or memory location left the number of bitsspecified in the CL register.Shift a 32-bit register or memory location left the number of bitsspecified by an 8-bit immediate value.SHL reg/mem64, 1 D1 /4 Shift a 64-bit register or memory location left 1 bit.SHL reg/mem64, CL D3 /4SHL reg/mem64, imm8C1 /4 ibShift a 64-bit register or memory location left the number of bitsspecified in the CL register.Shift a 64-bit register or memory location left the number of bitsspecified by an 8-bit immediate value.SAL, SHL 257


AMD64 Technology 24594 Rev. 3.10 February 2005rFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFExceptionsM M M U M M21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.Exception RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded a data segment limit or was non-canonical.XThe destination oper<strong>and</strong> 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, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.258 SAL, SHL


24594 Rev. 3.10 February 2005 AMD64 TechnologySARShift Arithmetic RightShifts the bits of a register or memory location (first oper<strong>and</strong>) to the right through theCF bit by the number of bit positions in an unsigned immediate value or the CLregister (second oper<strong>and</strong>). The instruction discards bits shifted out of the CF flag. Atthe end of the shift operation, the CF flag contains the last bit shifted out of the firstoper<strong>and</strong>.The SAR instruction does not change the sign bit of the target oper<strong>and</strong>. For each bitshift, it copies the sign bit to the next bit, preserving the sign of the result.The processor masks the upper three bits of the count oper<strong>and</strong>, thus restricting thecount to a number between 0 <strong>and</strong> 31. When the destination is 64 bits wide, theprocessor masks the upper two bits of the count, providing a count in the range of 0 to63.For 1-bit shifts, the instruction clears the OF flag to 0. When the shift count is greaterthan 1, the OF flag is undefined.If the shift count is 0, no flags are modified.Although the SAR instruction effectively divides the oper<strong>and</strong> by a power of 2, thebehavior is different from the IDIV instruction. For example, shifting –11(FFFFFFF5h) by two bits to the right (that is, divide –11 by 4), gives a result ofFFFFFFFDh, or –3, whereas the IDIV instruction for dividing –11 by 4 gives a result of–2. This is because the IDIV instruction rounds off the quotient to zero, whereas theSAR instruction rounds off the remainder to zero for positive dividends <strong>and</strong> tonegative infinity for negative dividends. So, for positive oper<strong>and</strong>s, SAR behaves likethe corresponding IDIV instruction. For negative oper<strong>and</strong>s, it gives the same result if<strong>and</strong> only if all the shifted-out bits are zeroes; otherwise, the result is smaller by 1.Mnemonic Opcode DescriptionSAR reg/mem8, 1 D0 /7 Shift a signed 8-bit register or memory oper<strong>and</strong> right 1 bit.SAR reg/mem8, CL D2 /7SAR reg/mem8, imm8C0 /7 ibShift a signed 8-bit register or memory oper<strong>and</strong> right the numberof bits specified in the CL register.Shift a signed 8-bit register or memory oper<strong>and</strong> right the numberof bits specified by an 8-bit immediate value.SAR reg/mem16, 1 D1 /7 Shift a signed 16-bit register or memory oper<strong>and</strong> right 1 bit.SAR 259


AMD64 Technology 24594 Rev. 3.10 February 2005Mnemonic Opcode DescriptionSAR reg/mem16, CL D3 /7Shift a signed 16-bit register or memory oper<strong>and</strong> right thenumber of bits specified in the CL register.SAR reg/mem16, imm8C1 /7 ibShift a signed 16-bit register or memory oper<strong>and</strong> right thenumber of bits specified by an 8-bit immediate value.SAR reg/mem32, 1 D1 /7 Shift a signed 32-bit register or memory location 1 bit.SAR reg/mem32, CL D3 /7Shift a signed 32-bit register or memory location right thenumber of bits specified in the CL register.SAR reg/mem32, imm8C1 /7 ibShift a signed 32-bit register or memory location right thenumber of bits specified by an 8-bit immediate value.SAR reg/mem64, 1 D1 /7 Shift a signed 64-bit register or memory location right 1 bit.SAR reg/mem64, CL D3 /7Shift a signed 64-bit register or memory location right thenumber of bits specified in the CL register.SAR reg/mem64, imm8Related <strong>Instructions</strong>C1 /7 ibShift a signed 64-bit register or memory location right thenumber of bits specified by an 8-bit immediate value.SAL, SHL, SHR, SHLD, SHRDrFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFExceptionsM M M U M M21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.Exception RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded a data segment limit or was non-canonical.XXThe destination oper<strong>and</strong> was in a non-writable segment.A null data segment was used to reference memory.260 SAR


24594 Rev. 3.10 February 2005 AMD64 TechnologyExceptionRealVirtual8086 Protected Cause of ExceptionPage fault, #PF X X A page fault resulted from the execution of the instruction.Alignment check, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.SAR 261


AMD64 Technology 24594 Rev. 3.10 February 2005SBBSubtract with BorrowSubtracts an immediate value or the value in a register or a memory location (secondoper<strong>and</strong>) from a register or a memory location (first oper<strong>and</strong>), <strong>and</strong> stores the result inthe first oper<strong>and</strong> location. If the carry flag (CF) is 1, the instruction subtracts 1 fromthe result. Otherwise, it operates like SUB.The SBB instruction sign-extends immediate value oper<strong>and</strong>s to the length of the firstoper<strong>and</strong> size.This instruction evaluates the result for both signed <strong>and</strong> unsigned data types <strong>and</strong> setsthe OF <strong>and</strong> CF flags to indicate a borrow in a signed or unsigned result, respectively. Itsets the SF flag to indicate the sign of a signed result.This instruction is useful for multibyte (multiword) numbers because it takes intoaccount the borrow from a previous SUB instruction.The forms of the SBB instruction that write to memory support the LOCK prefix. Fordetails about the LOCK prefix, see “Lock Prefix” on page 10.Mnemonic Opcode DescriptionSBB AL, imm8SBB AX, imm16SBB EAX, imm32SBB RAX, imm32SBB reg/mem8, imm8SBB reg/mem16, imm16SBB reg/mem32, imm32SBB reg/mem64, imm321C ib1D iw1D id1D id80 /3 ib81 /3 iw81 /3 id81 /3 idSubtract an immediate 8-bit value from the AL register withborrow.Subtract an immediate 16-bit value from the AX register withborrow.Subtract an immediate 32-bit value from the EAX register withborrow.Subtract a sign-extended immediate 32-bit value from the RAXregister with borrow.Subtract an immediate 8-bit value from an 8-bit register ormemory location with borrow.Subtract an immediate 16-bit value from a 16-bit register ormemory location with borrow.Subtract an immediate 32-bit value from a 32-bit register ormemory location with borrow.Subtract a sign-extended immediate 32-bit value from a 64-bitregister or memory location with borrow.262 SBB


24594 Rev. 3.10 February 2005 AMD64 TechnologyMnemonic Opcode DescriptionSBB reg/mem16, imm883 /3 ibSBB reg/mem32, imm883 /3 ibSBB reg/mem64, imm883 /3 ibSBB reg/mem8, reg8 18 /rSBB reg/mem16, reg16 19 /rSBB reg/mem32, reg32 19 /rSBB reg/mem64, reg64 19 /rSBB reg8, reg/mem8 1A /rSBB reg16, reg/mem16 1B /rSBB reg32, reg/mem32 1B /rSBB reg64, reg/mem64 1B /rSubtract a sign-extended 8-bit immediate value from a 16-bitregister or memory location with borrow.Subtract a sign-extended 8-bit immediate value from a 32-bitregister or memory location with borrow.Subtract a sign-extended 8-bit immediate value from a 64-bitregister or memory location with borrow.Subtract the contents of an 8-bit register from an 8-bit register ormemory location with borrow.Subtract the contents of a 16-bit register from a 16-bit register ormemory location with borrow.Subtract the contents of a 32-bit register from a 32-bit register ormemory location with borrow.Subtract the contents of a 64-bit register from a 64-bit register ormemory location with borrow.Subtract the contents of an 8-bit register or memory locationfrom the contents of an 8-bit register with borrow.Subtract the contents of a 16-bit register or memory locationfrom the contents of a 16-bit register with borrow.Subtract the contents of a 32-bit register or memory locationfrom the contents of a 32-bit register with borrow.Subtract the contents of a 64-bit register or memory locationfrom the contents of a 64-bit register with borrow.Related <strong>Instructions</strong>SUB, ADD, ADCSBB 263


AMD64 Technology 24594 Rev. 3.10 February 2005rFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFExceptionsM M M M M M21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.Exception RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded a data segment limit or was non-canonical.XThe destination oper<strong>and</strong> 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, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.264 SBB


24594 Rev. 3.10 February 2005 AMD64 TechnologySCASSCASBSCASWSCASDSCASQScan StringCompares the AL, AX, EAX, or RAX register with the byte, word, doubleword, orquadword pointed to by ES:rDI, sets the status flags in the rFLAGS register accordingto the results, <strong>and</strong> then increments or decrements the rDI register according to thestate of the DF flag in the rFLAGS register.If the DF flag is 0, the instruction increments the rDI register; otherwise, itdecrements it. The instruction increments or decrements the rDI register by 1, 2, 4, or8, depending on the size of the oper<strong>and</strong>s.The forms of the SCASx instruction with an explicit oper<strong>and</strong> address the oper<strong>and</strong> atES:rDI. The explicit oper<strong>and</strong> serves only to specify the size of the values beingcompared.The no-oper<strong>and</strong>s forms of the instruction use the ES:rDI registers to point to the valueto be compared. The mnemonic determines the size of the oper<strong>and</strong>s <strong>and</strong> the specificregister containing the other comparison value.For block comparisons, the SCASx instructions support the REPE or REPZ prefixes(they are synonyms) <strong>and</strong> the REPNE or REPNZ prefixes (they are synonyms). Fordetails about the REP prefixes, see “Repeat Prefixes” on page 10. A SCASxinstruction can also operate inside a loop controlled by the LOOPcc instruction.Mnemonic Opcode DescriptionSCAS mem8SCAS mem16SCAS mem32SCAS mem64AEAFAFAFCompare the contents of the AL register with the byte at ES:rDI,<strong>and</strong> then increment or decrement rDI.Compare the contents of the AX register with the word at ES:rDI,<strong>and</strong> then increment or decrement rDI.Compare the contents of the EAX register with the doubleword atES:rDI, <strong>and</strong> then increment or decrement rDI.Compare the contents of the RAX register with the quadword atES:rDI, <strong>and</strong> then increment or decrement rDI.SCASx 265


AMD64 Technology 24594 Rev. 3.10 February 2005Mnemonic Opcode DescriptionSCASBSCASWSCASDSCASQRelated <strong>Instructions</strong>CMP, CMPSxrFLAGS AffectedAEAFAFAFCompare the contents of the AL register with the byte at ES:rDI,<strong>and</strong> then increment or decrement rDI.Compare the contents of the AX register with the word at ES:rDI,<strong>and</strong> then increment or decrement rDI.Compare the contents of the EAX register with the doubleword atES:rDI, <strong>and</strong> then increment or decrement rDI.Compare the contents of the RAX register with the quadword atES:rDI, <strong>and</strong> then increment or decrement rDI.ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFExceptionsM M M M M M21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.Exception<strong>General</strong> protection,#GPRealXVirtual8086 Protected Cause of ExceptionXXXA null ES segment was used to reference memory.A memory address exceeded the ES segment limit or was non-canonical.Page fault, #PF X X A page fault resulted from the execution of the instruction.Alignment check, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.266 SCASx


24594 Rev. 3.10 February 2005 AMD64 TechnologySETccSet Byte on ConditionChecks the status flags in the rFLAGS register <strong>and</strong>, if the flags meet the conditionspecified in the mnemonic (cc), sets the value in the specified 8-bit memory location orregister to 1. If the flags do not meet the specified condition, SETcc clears the memorylocation or register to 0.Mnemonics with the A (above) <strong>and</strong> B (below) tags are intended for use whenperforming unsigned integer comparisons; those with G (greater) <strong>and</strong> L (less) tags areintended for use with signed integer comparisons.Software typically uses the SETcc instructions to set logical indicators. Like theCMOVcc instructions (page 103), the SETcc instructions can replace twoinstructions—a conditional jump <strong>and</strong> a move. Replacing conditional jumps withconditional sets can help avoid branch-prediction penalties that may result fromconditional jumps.If the logical value “true” (logical one) is represented in a high-level language as aninteger with all bits set to 1, software can accomplish such representation by firstexecuting the opposite SETcc instruction—for example, the opposite of SETZ isSETNZ—<strong>and</strong> then decrementing the result.A ModR/M byte is used to identify the oper<strong>and</strong>. The reg field in the ModR/M byte isunused.Mnemonic Opcode DescriptionSETO reg/mem8 0F 90 /0 Set byte if overflow (OF = 1).SETNO reg/mem8 0F 91 /0 Set byte if not overflow (OF = 0).SETB reg/mem8SETC reg/mem8SETNAE reg/mem8SETNB reg/mem8SETNC reg/mem8SETAE reg/mem8SETZ reg/mem8SETE reg/mem8SETNZ reg/mem8SETNE reg/mem80F 92 /00F 93 /00F 94 /00F 95 /0Set byte if below (CF = 1).Set byte if carry (CF = 1).Set byte if not above or equal (CF = 1).Set byte if not below (CF = 0).Set byte if not carry (CF = 0).Set byte if above or equal (CF = 0).Set byte if zero (ZF = 1).Set byte if equal (ZF = 1).Set byte if not zero (ZF = 0).Set byte if not equal (ZF = 0).SETcc 267


AMD64 Technology 24594 Rev. 3.10 February 2005Mnemonic Opcode DescriptionSETBE reg/mem8SETNA reg/mem8SETNBE reg/mem8SETA reg/mem8Related <strong>Instructions</strong>NonerFLAGS AffectedNone0F 96 /00F 97 /0Set byte if below or equal (CF = 1 or ZF = 1).Set byte if not above (CF = 1 or ZF = 1).SETS reg/mem8 0F 98 /0 Set byte if sign (SF = 1).Set byte if not below or equal (CF = 0 <strong>and</strong> ZF = 0).Set byte if above (CF = 0 <strong>and</strong> ZF = 0).SETNS reg/mem8 0F 99 /0 Set byte if not sign (SF = 0).SETP reg/mem8SETPE reg/mem8SETNP reg/mem8SETPO reg/mem8SETL reg/mem8SETNGE reg/mem8SETNL reg/mem8SETGE reg/mem8SETLE reg/mem8SETNG reg/mem8SETNLE reg/mem8SETG reg/mem80F 9A /00F 9B /00F 9C /00F 9D /00F 9E /00F 9F /0Set byte if parity (PF = 1).Set byte if parity even (PF = 1).Set byte if not parity (PF = 0).Set byte if parity odd (PF = 0).Set byte if less (SF OF).Set byte if not greater or equal (SF OF).Set byte if not less (SF = OF).Set byte if greater or equal (SF = OF).Set byte if less or equal (ZF = 1 or SF OF).Set byte if not greater (ZF = 1 or SF OF).Set byte if not less or equal (ZF = 0 <strong>and</strong> SF = OF).Set byte if greater (ZF = 0 <strong>and</strong> SF = OF).268 SETcc


24594 Rev. 3.10 February 2005 AMD64 TechnologyExceptionsException RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded a data segment limit or was non-canonical.XThe destination oper<strong>and</strong> 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.SETcc 269


AMD64 Technology 24594 Rev. 3.10 February 2005SFENCEStore FenceActs as a barrier to force strong memory ordering (serialization) between storeinstructions preceding the SFENCE <strong>and</strong> store instructions that follow the SFENCE. Aweakly-ordered memory system allows hardware to reorder reads <strong>and</strong> writes betweenthe processor <strong>and</strong> memory. The SFENCE instruction guarantees that the systemcompletes all previous stores before executing subsequent stores.The SFENCE instruction is weakly-ordered with respect to load instructions, data <strong>and</strong>instruction prefetches, <strong>and</strong> the LFENCE instruction. Speculative loads initiated bythe processor, or specified explicitly using cache-prefetch instructions, can bereordered around an SFENCE.In addition to store instructions, SFENCE is strongly ordered with respect to otherSFENCE instructions, MFENCE instructions, <strong>and</strong> serializing instructions.Support for the SFENCE instruction is indicated when the SSE bit (bit 25) is set to 1 inEDX after executing CPUID st<strong>and</strong>ard function 1.Mnemonic Opcode DescriptionSFENCE 0F AE F8 Force strong ordering of (serialized) store operations.Related <strong>Instructions</strong>LFENCE, MFENCErFLAGS AffectedNoneExceptionsException RealVirtual8086 Protected Cause of ExceptionInvalid Opcode, #UD X X X The SSE instructions are not supported, as indicated by EDX bit 25 ofCPUID st<strong>and</strong>ard function 1; <strong>and</strong> the AMD extensions to MMX are notsupported, as indicated by EDX bit 22 of CPUID extended function8000_0001h.270 SFENCE


24594 Rev. 3.10 February 2005 AMD64 TechnologySHLShift LeftThis instruction is synonymous with the SAL instruction. For information, see “SALSHL” on page 256.SHL 271


AMD64 Technology 24594 Rev. 3.10 February 2005SHLDShift Left DoubleShifts the bits of a register or memory location (first oper<strong>and</strong>) to the left by thenumber of bit positions in an unsigned immediate value or the CL register (thirdoper<strong>and</strong>), <strong>and</strong> shifts in a bit pattern (second oper<strong>and</strong>) from the right. At the end of theshift operation, the CF flag contains the last bit shifted out of the first oper<strong>and</strong>.The processor masks the upper three bits of the count oper<strong>and</strong>, thus restricting thecount to a number between 0 <strong>and</strong> 31. When the destination is 64 bits wide, theprocessor masks the upper two bits of the count, providing a count in the range of 0 to63. If the masked count is greater than the oper<strong>and</strong> size, the result in the destinationregister is undefined.If the shift count is 0, no flags are modified.If the count is 1 <strong>and</strong> the sign of the oper<strong>and</strong> being shifted changes, the instruction setsthe OF flag to 1. If the count is greater than 1, OF is undefined.Mnemonic Opcode DescriptionSHLD reg/mem16, reg16, imm80F A4 /r ibShift bits of a 16-bit destination register or memory oper<strong>and</strong> tothe left the number of bits specified in an 8-bit immediate value,while shifting in bits from the second oper<strong>and</strong>.SHLD reg/mem16, reg16, CL 0F A5 /rShift bits of a 16-bit destination register or memory oper<strong>and</strong> tothe left the number of bits specified in the CL register, whileshifting in bits from the second oper<strong>and</strong>.SHLD reg/mem32, reg32, imm80F A4 /r ibShift bits of a 32-bit destination register or memory oper<strong>and</strong> tothe left the number of bits specified in an 8-bit immediate value,while shifting in bits from the second oper<strong>and</strong>.SHLD reg/mem32, reg32, CL 0F A5 /rShift bits of a 32-bit destination register or memory oper<strong>and</strong> tothe left the number of bits specified in the CL register, whileshifting in bits from the second oper<strong>and</strong>.SHLD reg/mem64, reg64, imm80F A4 /r ibShift bits of a 64-bit destination register or memory oper<strong>and</strong> tothe left the number of bits specified in an 8-bit immediate value,while shifting in bits from the second oper<strong>and</strong>.SHLD reg/mem64, reg64, CL 0F A5 /rShift bits of a 64-bit destination register or memory oper<strong>and</strong> tothe left the number of bits specified in the CL register, whileshifting in bits from the second oper<strong>and</strong>.272 SHLD


24594 Rev. 3.10 February 2005 AMD64 TechnologyRelated <strong>Instructions</strong>SHRD, SAL, SAR, SHR, SHLrFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFExceptionsM M M U M M21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.Exception RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded a data segment limit or was non-canonical.XThe destination oper<strong>and</strong> 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, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.SHLD 273


AMD64 Technology 24594 Rev. 3.10 February 2005SHRShift RightShifts the bits of a register or memory location (first oper<strong>and</strong>) to the right through theCF bit by the number of bit positions in an unsigned immediate value or the CLregister (second oper<strong>and</strong>). The instruction discards bits shifted out of the CF flag. Atthe end of the shift operation, the CF flag contains the last bit shifted out of the firstoper<strong>and</strong>.For each bit shift, the instruction clears the most-significant bit to 0.The effect of this instruction is unsigned division by powers of two.The processor masks the upper three bits of the count oper<strong>and</strong>, thus restricting thecount to a number between 0 <strong>and</strong> 31. When the destination is 64 bits wide, theprocessor masks the upper two bits of the count, providing a count in the range of 0 to63.For 1-bit shifts, the instruction sets the OF flag to the most-significant bit of theoriginal value. If the count is greater than 1, the OF flag is undefined.If the shift count is 0, no flags are modified.Mnemonic Opcode DescriptionSHR reg/mem8, 1 D0 /5 Shift an 8-bit register or memory oper<strong>and</strong> right 1 bit.SHR reg/mem8, CL D2 /5SHR reg/mem8, imm8C0 /5 ibShift an 8-bit register or memory oper<strong>and</strong> right the number ofbits specified in the CL register.Shift an 8-bit register or memory oper<strong>and</strong> right the number ofbits specified by an 8-bit immediate value.SHR reg/mem16, 1 D1 /5 Shift a 16-bit register or memory oper<strong>and</strong> right 1 bit.SHR reg/mem16, CL D3 /5SHR reg/mem16, imm8C1 /5 ibShift a 16-bit register or memory oper<strong>and</strong> right the number ofbits specified in the CL register.Shift a 16-bit register or memory oper<strong>and</strong> right the number ofbits specified by an 8-bit immediate value.SHR reg/mem32, 1 D1 /5 Shift a 32-bit register or memory oper<strong>and</strong> right 1 bit.SHR reg/mem32, CL D3 /5SHR reg/mem32, imm8C1 /5 ibShift a 32-bit register or memory oper<strong>and</strong> right the number ofbits specified in the CL register.Shift a 32-bit register or memory oper<strong>and</strong> right the number ofbits specified by an 8-bit immediate value.274 SHR


24594 Rev. 3.10 February 2005 AMD64 TechnologySHR reg/mem64, 1 D1 /5 Shift a 64-bit register or memory oper<strong>and</strong> right 1 bit.SHR reg/mem64, CL D3 /5Shift a 64-bit register or memory oper<strong>and</strong> right the number ofbits specified in the CL register.SHR reg/mem64, imm8Related <strong>Instructions</strong>C1 /5 ibShift a 64-bit register or memory oper<strong>and</strong> right the number ofbits specified by an 8-bit immediate value.SHL, SAL, SAR, SHLD, SHRDrFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFExceptionsM M M U M M21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.Exception RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded a data segment limit or was non-canonical.XThe destination oper<strong>and</strong> 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, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.SHR 275


AMD64 Technology 24594 Rev. 3.10 February 2005SHRDShift Right DoubleShifts the bits of a register or memory location (first oper<strong>and</strong>) to the right by thenumber of bit positions in an unsigned immediate value or the CL register (thirdoper<strong>and</strong>), <strong>and</strong> shifts in a bit pattern (second oper<strong>and</strong>) from the left. At the end of theshift operation, the CF flag contains the last bit shifted out of the first oper<strong>and</strong>.The processor masks the upper three bits of the count oper<strong>and</strong>, thus restricting thecount to a number between 0 <strong>and</strong> 31. When the destination is 64 bits wide, theprocessor masks the upper two bits of the count, providing a count in the range of 0 to63. If the masked count is greater than the oper<strong>and</strong> size, the result in the destinationregister is undefined.If the shift count is 0, no flags are modified.If the count is 1 <strong>and</strong> the sign of the value being shifted changes, the instruction setsthe OF flag to 1. If the count is greater than 1, the OF flag is undefined.Mnemonic Opcode DescriptionSHRD reg/mem16, reg16, imm80F AC /r ibShift bits of a 16-bit destination register or memory oper<strong>and</strong> tothe right the number of bits specified in an 8-bit immediatevalue, while shifting in bits from the second oper<strong>and</strong>.SHRD reg/mem16, reg16, CL 0F AD /rShift bits of a 16-bit destination register or memory oper<strong>and</strong> tothe right the number of bits specified in the CL register, whileshifting in bits from the second oper<strong>and</strong>.SHRD reg/mem32, reg32, imm80F AC /r ibShift bits of a 32-bit destination register or memory oper<strong>and</strong> tothe right the number of bits specified in an 8-bit immediatevalue, while shifting in bits from the second oper<strong>and</strong>.SHRD reg/mem32, reg32, CL 0F AD /rShift bits of a 32-bit destination register or memory oper<strong>and</strong> tothe right the number of bits specified in the CL register, whileshifting in bits from the second oper<strong>and</strong>.SHRD reg/mem64, reg64, imm80F AC /r ibShift bits of a 64-bit destination register or memory oper<strong>and</strong> tothe right the number of bits specified in an 8-bit immediatevalue, while shifting in bits from the second oper<strong>and</strong>.SHRD reg/mem64, reg64, CL 0F AD /rShift bits of a 64-bit destination register or memory oper<strong>and</strong> tothe right the number of bits specified in the CL register, whileshifting in bits from the second oper<strong>and</strong>.276 SHRD


24594 Rev. 3.10 February 2005 AMD64 TechnologyRelated <strong>Instructions</strong>SHLD, SHR, SHL, SAR, SALrFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFExceptionsM M M U M M21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.Exception RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded a data segment limit or was non-canonical.XThe destination oper<strong>and</strong> 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, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.SHRD 277


AMD64 Technology 24594 Rev. 3.10 February 2005STCSet Carry FlagSets the carry flag (CF) in the rFLAGS register to one.Mnemonic Opcode DescriptionSTC F9 Set the carry flag (CF) to one.Related <strong>Instructions</strong>CLC, CMCrFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0ExceptionsNoneNote: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.1278 STC


24594 Rev. 3.10 February 2005 AMD64 TechnologySTDSet Direction FlagSet the direction flag (DF) in the rFLAGS register to 1. If the DF flag is 0, eachiteration of a string instruction increments the data pointer (index registers rSI orrDI). If the DF flag is 1, the string instruction decrements the pointer. Use the CLDinstruction before a string instruction to make the data pointer increment.Mnemonic Opcode DescriptionSTD FD Set the direction flag (DF) to one.Related <strong>Instructions</strong>CLD, INSx, LODSx, MOVSx, OUTSx, SCASx, STOSx, CMPSxrFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0ExceptionsNoneNote: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.1STD 279


AMD64 Technology 24594 Rev. 3.10 February 2005STOSSTOSBSTOSWSTOSDSTOSQStore StringCopies a byte, word, doubleword, or quadword from the AL, AX, EAX, or RAXregisters to the memory location pointed to by ES:rDI <strong>and</strong> increments or decrementsthe rDI register according to the state of the DF flag in the rFLAGS register.If the DF flag is 0, the instruction increments the pointer; otherwise, it decrements thepointer. It increments or decrements the pointer by 1, 2, 4, or 8, depending on the sizeof the value being copied.The forms of the STOSx instruction with an explicit oper<strong>and</strong> use the oper<strong>and</strong> only tospecify the type (size) of the value being copied.The no-oper<strong>and</strong>s forms specify the type (size) of the value being copied with themnemonic.The STOSx instructions support the REP prefixes. For details about the REP prefixes,see “Repeat Prefixes” on page 10. The STOSx instructions can also operate inside aLOOPcc instruction.Mnemonic Opcode DescriptionSTOS mem8STOS mem16STOS mem32STOS mem64STOSBSTOSWAAABABABAAABStore the contents of the AL register to ES:rDI, <strong>and</strong> thenincrement or decrement rDI.Store the contents of the AX register to ES:rDI, <strong>and</strong> thenincrement or decrement rDI.Store the contents of the EAX register to ES:rDI, <strong>and</strong> thenincrement or decrement rDI.Store the contents of the RAX register to ES:rDI, <strong>and</strong> thenincrement or decrement rDI.Store the contents of the AL register to ES:rDI, <strong>and</strong> thenincrement or decrement rDI.Store the contents of the AX register to ES:rDI, <strong>and</strong> thenincrement or decrement rDI.280 STOSx


24594 Rev. 3.10 February 2005 AMD64 TechnologySTOSDSTOSQRelated <strong>Instructions</strong>LODSx, MOVSxrFLAGS AffectedNoneExceptionsABABStore the contents of the EAX register to ES:rDI, <strong>and</strong> thenincrement or decrement rDI.Store the contents of the RAX register to ES:rDI, <strong>and</strong> thenincrement or decrement rDI.Exception<strong>General</strong> protection,#GPRealVirtual8086 Protected Cause of ExceptionX X XA memory address exceeded the ES segment limit or was non-canonical.XThe 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, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.STOSx 281


AMD64 Technology 24594 Rev. 3.10 February 2005SUBSubtractSubtracts an immediate value or the value in a register or memory location (secondoper<strong>and</strong>) from a register or a memory location (first oper<strong>and</strong>) <strong>and</strong> stores the result inthe first oper<strong>and</strong> location. An immediate value is sign-extended to the length of thefirst oper<strong>and</strong>.This instruction evaluates the result for both signed <strong>and</strong> unsigned data types <strong>and</strong> setsthe OF <strong>and</strong> CF flags to indicate a borrow in a signed or unsigned result, respectively. Itsets 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. Fordetails about the LOCK prefix, see “Lock Prefix” on page 10.Mnemonic Opcode DescriptionSUB AL, imm8SUB AX, imm16SUB EAX, imm32SUB RAX, imm32SUB reg/mem8, imm8SUB reg/mem16, imm16SUB reg/mem32, imm32SUB reg/mem64, imm32SUB reg/mem16, imm8SUB reg/mem32, imm8SUB reg/mem64, imm82C ib2D iw2D id2D id80 /5 ib81 /5 iw81 /5 id81 /5 id83 /5 ib83 /5 ib83 /5 ibSubtract an immediate 8-bit value from the AL register <strong>and</strong> storethe result in AL.Subtract an immediate 16-bit value from the AX register <strong>and</strong> storethe result in AX.Subtract an immediate 32-bit value from the EAX register <strong>and</strong>store the result in EAX.Subtract a sign-extended immediate 32-bit value from the RAXregister <strong>and</strong> store the result in RAX.Subtract an immediate 8-bit value from an 8-bit destinationregister or memory location.Subtract an immediate 16-bit value from a 16-bit destinationregister or memory location.Subtract an immediate 32-bit value from a 32-bit destinationregister or memory location.Subtract a sign-extended immediate 32-bit value from a 64-bitdestination register or memory location.Subtract a sign-extended immediate 8-bit value from a 16-bitregister or memory location.Subtract a sign-extended immediate 8-bit value from a 32-bitregister or memory location.Subtract a sign-extended immediate 8-bit value from a 64-bitregister or memory location.282 SUB


24594 Rev. 3.10 February 2005 AMD64 TechnologyMnemonic Opcode DescriptionSUB reg/mem8, reg8 28 /rSUB reg/mem16, reg16 29 /rSUB reg/mem32, reg32 29 /rSUB reg/mem64, reg64 29 /rSUB reg8, reg/mem8 2A /rSUB reg16, reg/mem16 2B /rSUB reg32, reg/mem32 2B /rSUB reg64, reg/mem64 2B /rSubtract the contents of an 8-bit register from an 8-bit destinationregister or memory location.Subtract the contents of a 16-bit register from a 16-bit destinationregister or memory location.Subtract the contents of a 32-bit register from a 32-bit destinationregister or memory location.Subtract the contents of a 64-bit register from a 64-bit destinationregister or memory location.Subtract the contents of an 8-bit register or memory oper<strong>and</strong>from an 8-bit destination register.Subtract the contents of a 16-bit register or memory oper<strong>and</strong>from a 16-bit destination register.Subtract the contents of a 32-bit register or memory oper<strong>and</strong>from a 32-bit destination register.Subtract the contents of a 64-bit register or memory oper<strong>and</strong>from a 64-bit destination register.Related <strong>Instructions</strong>ADC, ADD, SBBSUB 283


AMD64 Technology 24594 Rev. 3.10 February 2005rFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFExceptionsM M M M M M21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.Exception RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded a data segment limit or was non-canonical.XThe destination oper<strong>and</strong> 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, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.284 SUB


24594 Rev. 3.10 February 2005 AMD64 TechnologyTESTTest BitsPerforms a bit-wise logical AND on the value in a register or memory location (firstoper<strong>and</strong>) with an immediate value or the value in a register (second oper<strong>and</strong>) <strong>and</strong> setsthe flags in the rFLAGS register based on the result. While the AND instructionchanges the contents of the destination <strong>and</strong> the flag bits, the TEST instructionchanges only the flag bits.Mnemonic Opcode DescriptionTEST AL, imm8A8 ibTEST AX, imm16A9 iwTEST EAX, imm32A9 idTEST RAX, imm32A9 idTEST reg/mem8, imm8F6 /0 ibTEST reg/mem16, imm16F7 /0 iwTEST reg/mem32, imm32F7 /0 idTEST reg/mem64, imm32F7 /0 idTEST reg/mem8, reg8 84 /rTEST reg/mem16, reg16 85 /rTEST reg/mem32, reg32 85 /rTEST reg/mem64, reg64 85 /rAND an immediate 8-bit value with the contents of the ALregister <strong>and</strong> set rFLAGS to reflect the result.AND an immediate 16-bit value with the contents of the AXregister <strong>and</strong> set rFLAGS to reflect the result.AND an immediate 32-bit value with the contents of the EAXregister <strong>and</strong> set rFLAGS to reflect the result.AND a sign-extended immediate 32-bit value with the contentsof the RAX register <strong>and</strong> set rFLAGS to reflect the result.AND an immediate 8-bit value with the contents of an 8-bitregister or memory oper<strong>and</strong> <strong>and</strong> set rFLAGS to reflect the result.AND an immediate 16-bit value with the contents of a 16-bitregister or memory oper<strong>and</strong> <strong>and</strong> set rFLAGS to reflect the result.AND an immediate 32-bit value with the contents of a 32-bitregister or memory oper<strong>and</strong> <strong>and</strong> set rFLAGS to reflect the result.AND a sign-extended immediate32-bit value with the contents ofa 64-bit register or memory oper<strong>and</strong> <strong>and</strong> set rFLAGS to reflectthe result.AND the contents of an 8-bit register with the contents of an 8-bitregister or memory oper<strong>and</strong> <strong>and</strong> set rFLAGS to reflect the result.AND the contents of a 16-bit register with the contents of a 16-bitregister or memory oper<strong>and</strong> <strong>and</strong> set rFLAGS to reflect the result.AND the contents of a 32-bit register with the contents of a 32-bitregister or memory oper<strong>and</strong> <strong>and</strong> set rFLAGS to reflect the result.AND the contents of a 64-bit register with the contents of a 64-bitregister or memory oper<strong>and</strong> <strong>and</strong> set rFLAGS to reflect the result.TEST 285


AMD64 Technology 24594 Rev. 3.10 February 2005Related <strong>Instructions</strong>AND, CMPrFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFExceptions0 M M U M 021 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.Exception RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded a data segment limit or was non-canonical.XThe destination oper<strong>and</strong> 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, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.286 TEST


24594 Rev. 3.10 February 2005 AMD64 TechnologyXADDExchange <strong>and</strong> AddExchanges the contents of a register (second oper<strong>and</strong>) with the contents of a registeror memory location (first oper<strong>and</strong>), computes the sum of the two values, <strong>and</strong> stores theresult in the first oper<strong>and</strong> location.The forms of the XADD instruction that write to memory support the LOCK prefix.For details about the LOCK prefix, see “Lock Prefix” on page 10.Mnemonic Opcode DescriptionXADD reg/mem8, reg8 0F C0 /rXADD reg/mem16, reg16 0F C1 /rXADD reg/mem32, reg32 0F C1 /rXADD reg/mem64, reg64 0F C1 /rExchange the contents of an 8-bit register with the contents of an8-bit destination register or memory oper<strong>and</strong> <strong>and</strong> load their suminto the destination.Exchange the contents of a 16-bit register with the contents of a16-bit destination register or memory oper<strong>and</strong> <strong>and</strong> load theirsum into the destination.Exchange the contents of a 32-bit register with the contents of a32-bit destination register or memory oper<strong>and</strong> <strong>and</strong> load theirsum into the destination.Exchange the contents of a 64-bit register with the contents of a64-bit destination register or memory oper<strong>and</strong> <strong>and</strong> load theirsum into the destination.Related <strong>Instructions</strong>NoneXADD 287


AMD64 Technology 24594 Rev. 3.10 February 2005rFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFExceptionsM M M M M M21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.Exception RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded a data segment limit or was non-canonical.XThe destination oper<strong>and</strong> 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, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.288 XADD


24594 Rev. 3.10 February 2005 AMD64 TechnologyXCHGExchangeExchanges the contents of the two oper<strong>and</strong>s. The oper<strong>and</strong>s can be two generalpurposeregisters or a register <strong>and</strong> a memory location. If either oper<strong>and</strong> referencesmemory, the processor locks automatically, whether or not the LOCK prefix is used<strong>and</strong> independently of the value of IOPL. For details about the LOCK prefix, see “LockPrefix” on page 10.The x86 architecture commonly uses the XCHG EAX, EAX instruction (opcode 90h) asa one-byte NOP. In 64-bit mode, the processor treats opcode 90h as a true NOP only ifit would exchange rAX with itself. Without this special h<strong>and</strong>ling, the instructionwould zero-extend the upper 32 bits of RAX, <strong>and</strong> thus it would not be a true nooperation.Opcode 90h can still be used to exchange rAX <strong>and</strong> r8 if the appropriateREX prefix is used.This special h<strong>and</strong>ling does not apply to the two-byte ModRM form of the XCHGinstruction.Mnemonic Opcode DescriptionXCHG AX, reg1690 +rwXCHG reg16, AX90 +rwXCHG EAX, reg3290 +rdXCHG reg32, EAX90 +rdXCHG RAX, reg6490 +rqXCHG reg64, RAX90 +rqXCHG reg/mem8, reg8 86 /rXCHG reg8, reg/mem8 86 /rXCHG reg/mem16, reg16 87 /rExchange the contents of the AX register with the contents of a16-bit register.Exchange the contents of a 16-bit register with the contents of theAX register.Exchange the contents of the EAX register with the contents of a32-bit register.Exchange the contents of a 32-bit register with the contents of theEAX register.Exchange the contents of the RAX register with the contents of a64-bit register.Exchange the contents of a 64-bit register with the contents ofthe RAX register.Exchange the contents of an 8-bit register with the contents of an8-bit register or memory oper<strong>and</strong>.Exchange the contents of an 8-bit register or memory oper<strong>and</strong>with the contents of an 8-bit register.Exchange the contents of a 16-bit register with the contents of a16-bit register or memory oper<strong>and</strong>.XCHG 289


AMD64 Technology 24594 Rev. 3.10 February 2005Mnemonic Opcode DescriptionXCHG reg16, reg/mem16 87 /rXCHG reg/mem32, reg32 87 /rXCHG reg32, reg/mem32 87 /rXCHG reg/mem64, reg64 87 /rXCHG reg64, reg/mem64 87 /rExchange the contents of a 16-bit register or memory oper<strong>and</strong>with the contents of a 16-bit register.Exchange the contents of a 32-bit register with the contents of a32-bit register or memory oper<strong>and</strong>.Exchange the contents of a 32-bit register or memory oper<strong>and</strong>with the contents of a 32-bit register.Exchange the contents of a 64-bit register with the contents of a64-bit register or memory oper<strong>and</strong>.Exchange the contents of a 64-bit register or memory oper<strong>and</strong>with the contents of a 64-bit register.Related <strong>Instructions</strong>BSWAP, XADDrFLAGS AffectedNoneExceptionsException RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded a data segment limit or was non-canonical.XThe source or destination oper<strong>and</strong> 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, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.290 XCHG


24594 Rev. 3.10 February 2005 AMD64 TechnologyXLATxXLATBTranslate Table IndexUses the unsigned integer in the AL register as an offset into a table <strong>and</strong> copies thecontents of the table entry at that location to the AL register.The instruction uses seg:[rBX] as the base address of the table. The value of segdefaults to the DS segment, but may be overridden by a segment prefix.This instruction writes AL without changing RAX[63:8]. This instruction ignoresoper<strong>and</strong> size.The single-oper<strong>and</strong> form of the XLAT instruction uses the oper<strong>and</strong> to document thesegment <strong>and</strong> address size attribute, but it uses the base address specified by the rBXregister.This instruction is often used to translate data from one format (such as ASCII) toanother (such as EBCDIC).Mnemonic Opcode DescriptionXLAT mem8 D7 Set AL to the contents of DS:[rBX + unsigned AL].XLATB D7 Set AL to the contents of DS:[rBX + unsigned AL].Related <strong>Instructions</strong>NonerFLAGS AffectedNoneExceptionsException RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.XLATx 291


AMD64 Technology 24594 Rev. 3.10 February 2005Exception<strong>General</strong> protection,#GPRealVirtual8086 Protected Cause of ExceptionX X XA memory address exceeded a data segment limit or was 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.292 XLATx


24594 Rev. 3.10 February 2005 AMD64 TechnologyXORLogical Exclusive ORPerforms a bitwise exclusive OR operation on both oper<strong>and</strong>s <strong>and</strong> stores the result inthe first oper<strong>and</strong> location. The first oper<strong>and</strong> can be a register or memory location. Thesecond oper<strong>and</strong> can be an immediate value, a register, or a memory location. XOR-inga register with itself clears the register.The forms of the XOR instruction that write to memory support the LOCK prefix. Fordetails about the LOCK prefix, see “Lock Prefix” on page 10.The instruction performs the following operation for each bit:X Y X XOR Y0 0 00 1 11 0 11 1 0Mnemonic Opcode DescriptionXOR AL, imm8XOR AX, imm16XOR EAX, imm32XOR RAX, imm32XOR reg/mem8, imm8XOR reg/mem16, imm1634 ib35 iw35 id35 id80 /6 ib81 /6 iwXOR the contents of AL with an immediate 8-bit oper<strong>and</strong> <strong>and</strong>store the result in AL.XOR the contents of AX with an immediate 16-bit oper<strong>and</strong> <strong>and</strong>store the result in AX.XOR the contents of EAX with an immediate 32-bit oper<strong>and</strong> <strong>and</strong>store the result in EAX.XOR the contents of RAX with a sign-extended immediate 32-bitoper<strong>and</strong> <strong>and</strong> store the result in RAX.XOR the contents of an 8-bit destination register or memoryoper<strong>and</strong> with an 8-bit immediate value <strong>and</strong> store the result in thedestination.XOR the contents of a 16-bit destination register or memoryoper<strong>and</strong> with a 16-bit immediate value <strong>and</strong> store the result in thedestination.XOR 293


AMD64 Technology 24594 Rev. 3.10 February 2005Mnemonic Opcode DescriptionXOR reg/mem32, imm32XOR reg/mem64, imm32XOR reg/mem16, imm8XOR reg/mem32, imm8XOR reg/mem64, imm881 /6 id81 /6 id83 /6 ib83 /6 ib83 /6 ibXOR the contents of a 32-bit destination register or memoryoper<strong>and</strong> with a 32-bit immediate value <strong>and</strong> store the result in thedestination.XOR the contents of a 64-bit destination register or memoryoper<strong>and</strong> with a sign-extended 32-bit immediate value <strong>and</strong> storethe result in the destination.XOR the contents of a 16-bit destination register or memoryoper<strong>and</strong> with a sign-extended 8-bit immediate value <strong>and</strong> storethe result in the destination.XOR the contents of a 32-bit destination register or memoryoper<strong>and</strong> with a sign-extended 8-bit immediate value <strong>and</strong> storethe result in the destination.XOR the contents of a 64-bit destination register or memoryoper<strong>and</strong> with a sign-extended 8-bit immediate value <strong>and</strong> storethe result in the destination.XOR reg/mem8, reg8 30 /rXOR reg/mem16, reg16 31 /rXOR reg/mem32, reg32 31 /rXOR reg/mem64, reg64 31 /rXOR reg8, reg/mem8 32 /rXOR reg16, reg/mem16 33 /rXOR reg32, reg/mem32 33 /rXOR reg64, reg/mem64 33 /rXOR the contents of an 8-bit destination register or memoryoper<strong>and</strong> with the contents of an 8-bit register <strong>and</strong> store the resultin the destination.XOR the contents of a 16-bit destination register or memoryoper<strong>and</strong> with the contents of a 16-bit register <strong>and</strong> store the resultin the destination.XOR the contents of a 32-bit destination register or memoryoper<strong>and</strong> with the contents of a 32-bit register <strong>and</strong> store the resultin the destination.XOR the contents of a 64-bit destination register or memoryoper<strong>and</strong> with the contents of a 64-bit register <strong>and</strong> store the resultin the destination.XOR the contents of an 8-bit destination register with thecontents of an 8-bit register or memory oper<strong>and</strong> <strong>and</strong> store theresults in the destination.XOR the contents of a 16-bit destination register with the contentsof a 16-bit register or memory oper<strong>and</strong> <strong>and</strong> store the results inthe destination.XOR the contents of a 32-bit destination register with thecontents of a 32-bit register or memory oper<strong>and</strong> <strong>and</strong> store theresults in the destination.XOR the contents of a 64-bit destination register with thecontents of a 64-bit register or memory oper<strong>and</strong> <strong>and</strong> store theresults in the destination.294 XOR


24594 Rev. 3.10 February 2005 AMD64 TechnologyRelated <strong>Instructions</strong>OR, AND, NOT, NEGrFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFExceptions0 M M U M 021 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.Exception RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded a data segment limit or was non-canonical.XThe destination oper<strong>and</strong> 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, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.XOR 295


AMD64 Technology 24594 Rev. 3.10 February 2005296 XOR


24594 Rev. 3.10 February 2005 AMD64 Technology4 <strong>System</strong> Instruction ReferenceThis chapter describes the function, mnemonic syntax, opcodes,affected flags, <strong>and</strong> possible exceptions generated by the systeminstructions. The system instructions are used to establish theoperating mode, access processor resources, h<strong>and</strong>le program<strong>and</strong> system errors, <strong>and</strong> manage memory. Many of theseinstructions can only be executed by privileged software, suchas the operating system kernel <strong>and</strong> interrupt h<strong>and</strong>lers, that runat the highest privilege level. Only system instructions canaccess certain processor resources, such as the control registers,model-specific registers, <strong>and</strong> debug registers.<strong>System</strong> instructions are supported in all hardwareimplementations of the AMD64 architecture, except that thefollowing system instructions are implemented only if theirassociated CPUID function bits are set:• RDMSR <strong>and</strong> WRMSR, indicated by bit 5 of CPUID st<strong>and</strong>ardfunction 1 or extended function 8000_0001h.• SYSENTER <strong>and</strong> SYSEXIT, indicated by bit 11 of CPUIDst<strong>and</strong>ard function 1.• SYSCALL <strong>and</strong> SYSRET, indicated by bit 11 of CPUIDextended function 8000_0001h.• Long Mode instructions, indicated by bit 29 of CPUIDextended function 8000_0001h.There are also several other CPUID function bits that controlthe use of system resources <strong>and</strong> functions, such as pagingfunctions, virtual-mode extensions, machine-check exceptions,advanced programmable interrupt control (APIC), memorytyperange registers (MTRRs), etc. For details, see “ProcessorFeature Identification” in <strong>Volume</strong> 2.For further information about the system instructions <strong>and</strong>register resources, see:• “<strong>System</strong>-Management <strong>Instructions</strong>” in <strong>Volume</strong> 2.• “Summary of Registers <strong>and</strong> Data Types” on page 30.• “Notation” on page 43.• “Instruction Prefixes” on page 3.297


AMD64 Technology 24594 Rev. 3.10 February 2005ARPLAdjust Requestor Privilege LevelCompares the requestor privilege level (RPL) fields of two segment selectors in thesource <strong>and</strong> destination oper<strong>and</strong>s of the instruction. If the RPL field of the destinationoper<strong>and</strong> is less than the RPL field of the segment selector in the source register, thenthe zero flag is set <strong>and</strong> the RPL field of the destination oper<strong>and</strong> is increased to matchthat of the source oper<strong>and</strong>. Otherwise, the destination oper<strong>and</strong> remains unchanged<strong>and</strong> the zero flag is cleared.The destination oper<strong>and</strong> can be either a 16-bit register or memory location; the sourceoper<strong>and</strong> must be a 16-bit register.The ARPL instruction is intended for use by operating-system procedures to adjustthe RPL of a segment selector that has been passed to the operating system by anapplication program to match the privilege level of the application program. Thesegment selector passed to the operating system is placed in the destination oper<strong>and</strong><strong>and</strong> the segment selector for the code segment of the application program is placed inthe source oper<strong>and</strong>. The RPL field in the source oper<strong>and</strong> represents the privilege levelof the application program. The ARPL instruction then insures that the RPL of thesegment selector received by the operating system is no lower than the privilege levelof the application program.See “Adjusting Access Rights” in <strong>Volume</strong> 2, for more information on access rights.In 64-bit mode, this opcode (63H) is used for the MOVSXD instruction.Mnemonic Opcode DescriptionARPL reg/mem16, reg16 63 /r Adjust the RPL of a destination segment selector to a levelnot less than the RPL of the segment selector specified inthe 16-bit source register.(Invalid in 64-bit mode.)Related <strong>Instructions</strong>LAR, LSL, VERR, VERW298 ARPL


24594 Rev. 3.10 February 2005 AMD64 TechnologyrFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to one or cleared to zero is M (modified). Unaffected flags are blank. Undefinedflags are U.ExceptionsException RealVirtual8086 Protected Cause of ExceptionInvalid opcode, #UD X X This instruction is only recognized in protected legacy <strong>and</strong>compatibility mode.Stack, #SS X A memory address exceeded the stack segment limit.<strong>General</strong> protection, #GPX A memory address exceeded a data segment limit.MXThe destination oper<strong>and</strong> was in a non-writable segment.X A null segment selector was used to reference memory.Page fault, #PF X A page fault resulted from the execution of the instruction.Alignment check, #AC X An unaligned memory reference was performed while alignmentchecking was enabled.ARPL 299


AMD64 Technology 24594 Rev. 3.10 February 2005CLIClear Interrupt FlagClears the interrupt flag (IF) in the rFLAGS register to zero, thereby masking externalinterrupts received on the INTR input. Interrupts received on the non-maskableinterrupt (NMI) input are not affected by this instruction.In real mode, this instruction clears IF to 0.In protected mode <strong>and</strong> virtual-8086-mode, this instruction is IOPL-sensitive. If theCPL is less than or equal to the rFLAGS.IOPL field, the instruction clears IF to 0.In protected mode, if IOPL < 3, CPL = 3, <strong>and</strong> protected mode virtual interrupts areenabled (CR4.PVI = 1), then the instruction instead clears rFLAGS.VIF to 0. If none ofthese conditions apply, the processor raises a general-purpose exception (#GP). Formore information, see “Protected Mode Virtual Interrupts” in <strong>Volume</strong> 2.In virtual-8086 mode, if IOPL < 3 <strong>and</strong> the virtual-8086-mode extensions are enabled(CR4.VME = 1), the CLI instruction clears the virtual interrupt flag (rFLAGS.VIF) to0 instead.See “Virtual-8086 Mode Extensions” in <strong>Volume</strong> 2 for more information about IOPLsensitiveinstructions.Mnemonic Opcode DescriptionCLI FA Clear the interrupt flag (IF) to zero.ActionIF (CPL


24594 Rev. 3.10 February 2005 AMD64 TechnologyrFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFMM21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to one or cleared to zero is M (modified). Unaffected flags are blank. Undefinedflags are U.ExceptionsException<strong>General</strong> protection,#GPRealVirtual8086 Protected Cause of ExceptionXThe CPL was greater than the IOPL <strong>and</strong> virtual mode extensions arenot enabled (CR4.VME = 0).XThe CPL was greater than the IOPL <strong>and</strong> either the CPL was not 3 orprotected mode virtual interrupts were not enabled (CR4.PVI = 0).CLI 301


AMD64 Technology 24594 Rev. 3.10 February 2005CLTSClear Task-Switched Flag in CR0Clears the task-switched (TS) flag in the CR0 register to 0. The processor sets the TSflag on each task switch. The CLTS instruction is intended to facilitate thesynchronization of FPU context saves during multitasking operations.This instruction can only be used if the current privilege level is 0.See “<strong>System</strong>-Control Registers” in <strong>Volume</strong> 2 for more information on FPUsynchronization <strong>and</strong> the TS flag.Mnemonic Opcode DescriptionCLTS 0F 06 Clear the task-switched (TS) flag in CR0 to 0.Related <strong>Instructions</strong>LMSW, MOV (CRn)rFLAGS AffectedNoneExceptionsException<strong>General</strong> protection,#GPRealVirtual8086 Protected Cause of ExceptionX X CPL was not 0.302 CLTS


24594 Rev. 3.10 February 2005 AMD64 TechnologyHLTHaltCauses the microprocessor to halt instruction execution <strong>and</strong> enter the HALT state.Entering the HALT state puts the processor in low-power mode. Execution resumeswhen an unmasked hardware interrupt (INTR), non-maskable interrupt (NMI), systemmanagement interrupt (SMI), RESET, or INIT occurs.If an INTR, NMI, or SMI is used to resume execution after a HLT instruction, the savedinstruction pointer points to the instruction following the HLT instruction.Before executing a HLT instruction, hardware interrupts should be enabled. IfrFLAGS.IF = 0, the system will remain in a HALT state until an NMI, SMI, RESET, orINIT occurs.If an SMI brings the processor out of the HALT state, the SMI h<strong>and</strong>ler can decidewhether to return to the HALT state or not. See <strong>Volume</strong> 2, <strong>System</strong> Programming, forinformation on SMIs.Current privilege level must be 0 to execute this instruction.Mnemonic Opcode DescriptionHLT F4 Halt instruction execution.Related <strong>Instructions</strong>STI, CLIrFLAGS AffectedNoneExceptionsException<strong>General</strong> protection,#GPRealVirtual8086 Protected Cause of ExceptionX X CPL was not 0.HLT 303


AMD64 Technology 24594 Rev. 3.10 February 2005INT 3Interrupt to Debug VectorCalls the debug exception h<strong>and</strong>ler. This instruction maps to a 1-byte opcode (CC) thatraises a #BP exception. The INT 3 instruction is normally used by debug software toset instruction breakpoints by replacing the first byte of the instruction opcode byteswith the INT 3 opcode.This one-byte INT 3 instruction behaves differently from the two-byte INT 3instruction (opcode CD 03) (see “INT” in Chapter 3 “<strong>General</strong> <strong>Purpose</strong> <strong>Instructions</strong>”for further information) in two ways:• The #BP exception is h<strong>and</strong>led without any IOPL checking in virtual x86 mode.(IOPL mismatches will not trigger an exception.)• In VME mode, the #BP exception is not redirected via the interrupt redirectiontable. (Instead, it is h<strong>and</strong>led by a protected mode h<strong>and</strong>ler.)Mnemonic Opcode DescriptionINT 3 CC Trap to debugger at Interrupt 3.For complete descriptions of the steps performed by INT instructions, see thefollowing:• Legacy-Mode Interrupts: “Legacy Protected-Mode Interrupt Control Transfers” in<strong>Volume</strong> 2.• Long-Mode Interrupts: “Long-Mode Interrupt Control Transfers” in <strong>Volume</strong> 2.Action// Refer to INT instruction’s Action section for the details on INT_N_REAL,// INT_N_PROTECTED, <strong>and</strong> INT_N_VIRTUAL_TO_PROTECTED.INT3_START:If (REAL_MODE)INT_N_REAL //N = 3ELSEIF (PROTECTED_MODE)INT_N_PROTECTED //N = 3ELSE // VIRTUAL_MODEINT_N_VIRTUAL_TO_PROTECTED //N = 3Related <strong>Instructions</strong>INT, INTO, IRET304 INT 3


24594 Rev. 3.10 February 2005 AMD64 TechnologyrFLAGS AffectedIf 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 CFExceptionsM 0 0 M M 021 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to one or cleared to zero is M (modified). Unaffected flags are blank. Undefinedflags are U.VirtualException Real 8086 Protected Cause of ExceptionBreakpoint, #BP X X X INT 3 instruction was executed.Invalid TSS, #TS(selector)XXAs part of a stack switch, the target stack segment selector or rSP inthe TSS was that was beyond the TSS limit.XXXXXXXXXXAs part of a stack switch, the target stack segment selector in the TSSwas beyond the limit of the GDT or LDT descriptor table.As part of a stack switch, the target stack segment selector in the TSSwas a null selector.As part of a stack switch, the target stack segment selector’s TI bit wasset, but the LDT selector was a null selector.As part of a stack switch, the target stack segment selector in the TSScontained a RPL that was not equal to its DPL.As part of a stack switch, the target stack segment selector in the TSScontained a DPL that was not equal to the CPL of the code segmentselector.Segment not present,#NP (selector)XXAs part of a stack switch, the target stack segment selector in the TSSwas not a writable segment.X X The accessed code segment, interrupt gate, trap gate, task gate, orTSS was not present.Stack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.INT 3 305


AMD64 Technology 24594 Rev. 3.10 February 2005Stack, #SS(selector)ExceptionRealVirtual8086 Protected Cause of ExceptionXXAfter a stack switch, a memory address exceeded the stack segmentlimit or was non-canonical <strong>and</strong> a stack switch occurred.XXAs part of a stack switch, the SS register was loaded with a non-nullsegment selector <strong>and</strong> the segment was marked not present.<strong>General</strong> protection,#GPXXXA memory address exceeded the data segment limit or was noncanonical.XXXThe target offset exceeded the code segment limit or was noncanonical.<strong>General</strong> protection,#GP(selector)XXXXXThe interrupt vector was beyond the limit of IDT.The descriptor in the IDT was not an interrupt, trap, or task gate inlegacy mode or not a 64-bit interrupt or trap gate in long mode.XXThe DPL of the interrupt, trap, or task gate descriptor was less thanthe CPL.XXThe segment selector specified by the interrupt or trap gate had its TIbit set, but the LDT selector was a null selector.XXThe segment descriptor specified by the interrupt or trap gateexceeded the descriptor table limit or was a null selector.XXThe segment descriptor specified by the interrupt or trap gate wasnot a code segment in legacy mode, or not a 64-bit code segment inlong mode.XThe DPL of the segment specified by the interrupt or trap gate wasgreater than the CPL.XThe DPL of the segment specified by the interrupt or trap gatepointed 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, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.306 INT 3


24594 Rev. 3.10 February 2005 AMD64 TechnologyINVDInvalidate CachesInvalidates internal caches (data cache, instruction cache, <strong>and</strong> on-chip L2 cache) <strong>and</strong>triggers a bus cycle that causes external caches to invalidate themselves as well.No data is written back to main memory from invalidating internal caches. Afterinvalidating internal caches, the processor proceeds immediately with the executionof the next instruction without waiting for external hardware to invalidate its caches.This is a privileged instruction. The current privilege level (CPL) of a procedureinvalidating the processor’s internal caches must be 0.To insure that data is written back to memory prior to invalidating caches, use theWBINVD instruction.This instruction does not invalidate TLB caches.INVD is a serializing instruction.Mnemonic Opcode DescriptionINVD 0F 08 Flush internal caches <strong>and</strong> trigger external cache flushes.Related <strong>Instructions</strong>WBINVD, CLFLUSHrFLAGS AffectedNoneExceptionsException<strong>General</strong> protection,#GPRealVirtual8086 Protected Cause of ExceptionX X CPL was not 0.INVD 307


AMD64 Technology 24594 Rev. 3.10 February 2005INVLPGInvalidate TLB EntryInvalidates the TLB entry that would be used for the 1-byte memory oper<strong>and</strong>.This instruction invalidates the TLB entry, regardless of the G (Global) bit setting inthe associated PDE or PTE entry <strong>and</strong> regardless of the page size (4 Kbytes, 2 Mbytes,or 4 Mbytes). It may invalidate any number of additional TLB entries, in addition tothe targeted entry.INVLPG is a serializing instruction <strong>and</strong> a privileged instruction. The current privilegelevel must be 0 to execute this instruction.See “Page Translation <strong>and</strong> Protection” in <strong>Volume</strong> 2 for more information on pagetranslation.Mnemonic Opcode DescriptionINVLPG mem8 0F 01 /7 Invalidate the TLB entry for the page containing a specified memorylocation.Related <strong>Instructions</strong>MOV CRn (CR3 <strong>and</strong> CR4)rFLAGS AffectedNoneExceptionsException<strong>General</strong> protection,#GPRealVirtual8086 Protected Cause of ExceptionX X CPL was not 0.308 INVLPG


24594 Rev. 3.10 February 2005 AMD64 TechnologyIRETxIRETDIRETQReturn from InterruptReturns program control from an exception or interrupt h<strong>and</strong>ler to a program orprocedure previously interrupted by an exception, an external interrupt, or asoftware-generated interrupt. These instructions also perform a return from a nestedtask. All flags, CS, <strong>and</strong> rIP are restored to the values they had before the interrupt sothat execution may continue at the next instruction following the interrupt orexception. In 64-bit mode or if the CPL changes, SS <strong>and</strong> RSP are also restored.IRET, IRETD, <strong>and</strong> IRETQ are synonyms mapping to the same opcode. They areintended to provide semantically distinct forms for various opcode sizes. The IRETinstruction is used for 16-bit oper<strong>and</strong> size; IRETD is used for 32-bit oper<strong>and</strong> sizes;IRETQ is used for 64-bit oper<strong>and</strong>s. The latter form is only meaningful in 64-bit mode.IRET, IRETD, or IRETQ must be used to terminate the exception or interrupt h<strong>and</strong>lerassociated with the exception, external interrupt, or software-generated interrupt.IRETx is a serializing instruction.For detailed descriptions of the steps performed by IRETx instructions, see thefollowing:• Legacy-Mode Interrupts: “Legacy Protected-Mode Interrupt Control Transfers” in<strong>Volume</strong> 2.• Long-Mode Interrupts: “Long-Mode Interrupt Control Transfers” in <strong>Volume</strong> 2.Mnemonic Opcode DescriptionIRET CF Return from interrupt (16-bit oper<strong>and</strong> size).IRETD CF Return from interrupt (32-bit oper<strong>and</strong> size).IRETQ CF Return from interrupt (64-bit oper<strong>and</strong> size).ActionIRET_START:IF (REAL_MODE)IRET_REALELSIF (PROTECTED_MODE)IRETx 309


AMD64 Technology 24594 Rev. 3.10 February 2005IRET_PROTECTEDELSE // (VIRTUAL_MODE)IRET_VIRTUALIRET_REAL:POP.v temp_RIPPOP.v temp_CSPOP.v temp_RFLAGSIF (temp_RIP > CS.limit)EXCEPTION [#GP(0)]CS.sel = temp_CSCS.base = temp_CS SHL 4RFLAGS.v = temp_RFLAGS // VIF,VIP,VM unchangedRIP = temp_RIPEXITIRET_PROTECTED:IF (RFLAGS.NT=1)// iret does a task-switch to a previous taskIF (LEGACY_MODE)TASK_SWITCH// using the ’back link’ field in the tssELSE// (LONG_MODE)EXCEPTION [#GP(0)] // task switches aren’t supported in long modePOP.v temp_RIPPOP.v temp_CSPOP.v temp_RFLAGSIF ((temp_RFLAGS.VM=1) && (CPL=0) && (LEGACY_MODE))IRET_FROM_PROTECTED_TO_VIRTUALtemp_CPL = temp_CS.rplIF ((64BIT_MODE) || (temp_CPL!=CPL)){POP.v temp_RSP// in 64-bit mode, iret always pops ss:rspPOP.v temp_SS}CS = READ_DESCRIPTOR (temp_CS, iret_chk)IF ((64BIT_MODE) && (temp_RIP is non-canonical)|| (!64BIT_MODE) && (temp_RIP > CS.limit)){EXCEPTION [#GP(0)]310 IRETx


24594 Rev. 3.10 February 2005 AMD64 Technology}CPL = temp_CPLIF ((started in 64-bit mode) || (changing CPL))// ss:rsp were popped, so load them into the registers{SS = READ_DESCRIPTOR (temp_SS, ss_chk)RSP.s = temp_RSP}IF (changing CPL){FOR (seg = ES, DS, FS, GS)IF ((seg.attr.dpl < CPL) && ((seg.attr.type = ’data’)|| (seg.attr.type = ’non-conforming-code’))){seg = NULL // can’t use lower dpl data segment at higher cpl}}RFLAGS.v = temp_RFLAGSRIP = temp_RIPEXIT// VIF,VIP,IOPL only changed if (old_CPL=0)// IF only changed if (old_CPL


AMD64 Technology 24594 Rev. 3.10 February 2005// now ((IOPL


24594 Rev. 3.10 February 2005 AMD64 TechnologyES.attr = 16-bit dpl3 dataFS.sel = temp_FSFS.base = temp_FS SHL 4FS.limit= 0x0000FFFFFS.attr = 16-bit dpl3 dataGS.sel = temp_GSGS.base = temp_GS SHL 4GS.limit= 0x0000FFFFGS.attr = 16-bit dpl3 dataRSP.d = temp_RSPRFLAGS.d = temp_RFLAGSCPL = 3RIP = temp_RIP AND 0x0000FFFFEXITRelated <strong>Instructions</strong>INT, INTO, INT3rFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFM M M M M M M M M M M M M M M M M21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to one or cleared to zero is M (modified). Unaffected flags are blank. Undefinedflags are U.ExceptionsExceptionSegment not present,#NP (selector)RealVirtual8086 Protected Cause of ExceptionXThe return code segment was marked not present.Stack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.Stack, #SS (selector) X The SS register was loaded with a non-null segment selector <strong>and</strong> thesegment was marked not present.IRETx 313


AMD64 Technology 24594 Rev. 3.10 February 2005Exception<strong>General</strong> protection,#GPRealXVirtual8086 Protected Cause of ExceptionXThe target offset exceeded the code segment limit or was noncanonical.XIOPL was less than 3 <strong>and</strong> one of the following conditions was true:• CR4.VME was 0.• The effective oper<strong>and</strong> size was 32-bit.• Both the original EFLAGS.VIP <strong>and</strong> the new EFLAGS.IF were set.• The new EFLAGS.TF was set.<strong>General</strong> protection,#GP(selector)XXXXXXXXXXXIRETx was executed in long mode while EFLAGS.NT=1.The return code selector was a null selector.The return stack selector was a null selector <strong>and</strong> the return mode wasnon-64-bit mode or CPL was 3.The return code or stack descriptor exceeded the descriptor tablelimit.The return code or stack selector’s TI bit was set but the LDT selectorwas a null selector.The segment descriptor for the return code was not a code segment.The RPL of the return code segment selector was less than the CPL.The return code segment was non-conforming <strong>and</strong> the segmentselector’s DPL was not equal to the RPL of the code segment’ssegment selector.The return code segment was conforming <strong>and</strong> the segment selector’sDPL was greater than the RPL of the code segment’s segment selectorThe segment descriptor for the return stack was not a writable datasegment.The stack segment descriptor DPL was not equal to the RPL of thereturn code segment selector.X The stack segment selector RPL was not equal to the RPL of the returncode segment selector.Page fault, #PF X X A page fault resulted from the execution of the instruction.Alignment check, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.314 IRETx


24594 Rev. 3.10 February 2005 AMD64 TechnologyLARLoad Access Rights ByteLoads the access rights from the segment descriptor specified by a 16-bit sourceregister or memory oper<strong>and</strong> into a specified 16-bit, 32-bit, or 64-bit general-purposeregister <strong>and</strong> sets the zero (ZF) flag in the rFLAGS register if successful. LAR clearsthe zero flag if the descriptor is invalid for any reason.The LAR instruction checks that:• the segment selector is not a null selector.• the descriptor is within the GDT or LDT limit.• the descriptor DPL is greater than or equal to both the CPL <strong>and</strong> RPL, or the segmentis a conforming code segment.• the descriptor type is valid for the LAR instruction. Valid descriptor types areshown in the following table. LDT <strong>and</strong> TSS descriptors in 64-bit mode, <strong>and</strong> callgatedescriptors in long mode, are only valid if bits 12–8 of doubleword +12 arezero, as shown on page 111 of vol. 2 in Figure 4-22.Valid Descriptor TypeDescriptionLegacy ModeLong Mode— — All code <strong>and</strong> data descriptors1 — Available 16-bit TSS2 2 LDT3 — Busy 16-bit TSS4 — 16-bit call gate5 — Task gate9 9 Available 32-bit or 64-bit TSSB B Busy 32-bit or 64-bit TSSC C 32-bit or 64-bit call gateIf the segment descriptor passes these checks, the attributes are loaded into thedestination general-purpose register. If it does not, then the zero flag is cleared <strong>and</strong>the destination register is not modified.When the oper<strong>and</strong> size is 16 bits, access rights include the DPL <strong>and</strong> Type fields locatedin bytes 4 <strong>and</strong> 5 of the descriptor table entry. Before loading the access rights into thedestination oper<strong>and</strong>, the low order word is masked with FF00H.LAR 315


AMD64 Technology 24594 Rev. 3.10 February 2005When the oper<strong>and</strong> size is 32 or 64 bits, access rights include the DPL <strong>and</strong> type as wellas the descriptor type (S field), segment present (P flag), available to system (AVLflag), default operation size (D/B flag), <strong>and</strong> granularity flags located in bytes 4–7 of thedescriptor. Before being loaded into the destination oper<strong>and</strong>, the doubleword ismasked with 00FF_FF00H.In 64-bit mode, for both 32-bit <strong>and</strong> 64-bit oper<strong>and</strong> sizes, 32-bit register results are zeroextendedto 64 bits.This instruction can only be executed in protected mode.Mnemonic Opcode DescriptionLAR reg16, reg/mem16 0F 02 /r Reads the GDT/LDT descriptor referenced by the 16-bit sourceoper<strong>and</strong>, masks the attributes with FF00h <strong>and</strong> saves the result in the16-bit destination register.LAR reg32, reg/mem16 0F 02 /r Reads the GDT/LDT descriptor referenced by the 16-bit sourceoper<strong>and</strong>, masks the attributes with 00FFFF00h <strong>and</strong> saves the result inthe 32-bit destination register.LAR reg64, reg/mem16 0F 02 /r Reads the GDT/LDT descriptor referenced by the 16-bit sourceoper<strong>and</strong>, masks the attributes with 00FFFF00h <strong>and</strong> saves the result inthe 64-bit destination register.Related <strong>Instructions</strong>ARPL, LSL, VERR, VERWrFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to one or zero is M (modified). Unaffected flags are blank. Undefined flagsare U.M316 LAR


24594 Rev. 3.10 February 2005 AMD64 TechnologyExceptionsException RealVirtual8086 Protected Cause of ExceptionInvalid opcode, #UD X X This instruction is only recognized in protected mode.Stack, #SS X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection, #GPX A memory address exceeded the data segment limit or was noncanonical.XA null data segment was used to reference memory.X The extended attribute bits of a system descriptor was not zero in64-bit mode.Page fault, #PF X A page fault resulted from the execution of the instruction.Alignment check, #AC X An unaligned memory reference was performed while alignmentchecking was enabled.LAR 317


AMD64 Technology 24594 Rev. 3.10 February 2005LGDTLoad Global Descriptor Table RegisterLoads the pseudo-descriptor specified by the source oper<strong>and</strong> into the globaldescriptor table register (GDTR). The pseudo-descriptor is a memory locationcontaining the GDTR base <strong>and</strong> limit. In legacy <strong>and</strong> compatibility mode, the pseudodescriptoris 6 bytes; in 64-bit mode, it is 10 bytes.If the oper<strong>and</strong> size is 16 bits, the high-order byte of the 6-byte pseudo-descriptor is notused. The lower two bytes specify the 16-bit limit <strong>and</strong> the third, fourth, <strong>and</strong> fifth bytesspecify the 24-bit base address. The high-order byte of the GDTR is filled with zeros.If the oper<strong>and</strong> size is 32 bits, the lower two bytes specify the 16-bit limit <strong>and</strong> the upperfour bytes specify a 32-bit base address.In 64-bit mode, the lower two bytes specify the 16-bit limit <strong>and</strong> the upper eight bytesspecify a 64-bit base address. In 64-bit mode, oper<strong>and</strong>-size prefixes are ignored <strong>and</strong>the oper<strong>and</strong> size is forced to 64-bits; therefore, the pseudo-descriptor is always 10bytes.This instruction is only used in operating system software <strong>and</strong> must be executed atCPL 0. It is typically executed once in real mode to initialize the processor beforeswitching to protected mode.LGDT is a serializing instruction.Mnemonic Opcode DescriptionLGDT mem16:32 0F 01 /2 Loads mem16:32 into the global descriptor table register.LGDT mem16:64 0F 01 /2 Loads mem16:64 into the global descriptor table register.Related <strong>Instructions</strong>LIDT, LLDT, LTR, SGDT, SIDT, SLDT, STRrFLAGS AffectedNone318 LGDT


24594 Rev. 3.10 February 2005 AMD64 TechnologyExceptionsException RealVirtual8086 Protected Cause of ExceptionInvalid opcode, #UD X X X The oper<strong>and</strong> was a register.Stack, #SS X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection, #GP XX A memory address exceeded the data segment limit or was noncanonical.XXXCPL was not 0.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.LGDT 319


AMD64 Technology 24594 Rev. 3.10 February 2005LIDTLoad Interrupt Descriptor Table RegisterLoads the pseudo-descriptor specified by the source oper<strong>and</strong> into the interruptdescriptor table register (IDTR). The pseudo-descriptor is a memory locationcontaining the IDTR base <strong>and</strong> limit. In legacy <strong>and</strong> compatibility mode, the pseudodescriptoris six bytes; in 64-bit mode, it is 10 bytes.If the oper<strong>and</strong> size is 16 bits, the high-order byte of the 6-byte pseudo-descriptor is notused. The lower two bytes specify the 16-bit limit <strong>and</strong> the third, fourth, <strong>and</strong> fifth bytesspecify the 24-bit base address. The high-order byte of the IDTR is filled with zeros.If the oper<strong>and</strong> size is 32 bits, the lower two bytes specify the 16-bit limit <strong>and</strong> the upperfour bytes specify a 32-bit base address.In 64-bit mode, the lower two bytes specify the 16-bit limit, <strong>and</strong> the upper eight bytesspecify a 64-bit base address. In 64-bit mode, oper<strong>and</strong>-size prefixes are ignored <strong>and</strong>the oper<strong>and</strong> size is forced to 64-bits; therefore, the pseudo-descriptor is always 10bytes.This instruction is only used in operating system software <strong>and</strong> must be executed atCPL 0. It is normally executed once in real mode to initialize the processor beforeswitching to protected mode.LIDT is a serializing instruction.Mnemonic Opcode DescriptionLIDT mem16:32 0F 01 /3 Loads mem16:32 into the interrupt descriptor table register.LIDT mem16:64 0F 01 /3 Loads mem16:64 into the interrupt descriptor table register.Related <strong>Instructions</strong>LGDT, LLDT, LTR, SGDT, SIDT, SLDT, STRrFLAGS AffectedNone320 LIDT


24594 Rev. 3.10 February 2005 AMD64 TechnologyExceptionsException RealVirtual8086 Protected Cause of ExceptionInvalid opcode, #UD X X X The oper<strong>and</strong> was a register.Stack, #SS X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection, #GP XX A memory address exceeded the data segment limit or was noncanonical.XXXCPL was not 0.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.LIDT 321


AMD64 Technology 24594 Rev. 3.10 February 2005LLDTLoad Local Descriptor Table RegisterLoads the specified segment selector into the visible portion of the local descriptortable (LDT). The processor uses the selector to locate the descriptor for the LDT in theglobal descriptor table. It then loads this descriptor into the hidden portion of theLDTR.If the source oper<strong>and</strong> is a null selector, the LDTR is marked invalid <strong>and</strong> all referencesto descriptors in the LDT will generate a general protection exception (#GP), exceptfor the LAR, VERR, VERW or LSL instructions.In legacy <strong>and</strong> compatibility modes, the LDT descriptor is 8 bytes long <strong>and</strong> contains a32-bit base address.In 64-bit mode, the LDT descriptor is 16-bytes long <strong>and</strong> contains a 64-bit base address.The LDT descriptor type (02h) is redefined in 64-bit mode for use as the 16-byte LDTdescriptor.This instruction must be executed in protected mode. It is only provided for use byoperating system software at CPL 0.LLDT is a serializing instruction.Mnemonic Opcode DescriptionLLDT reg/mem16 0F 00 /2 Load the 16-bit segment selector into the local descriptor table register<strong>and</strong> load the LDT descriptor from the GDT.Related <strong>Instructions</strong>LGDT, LIDT, LTR, SGDT, SIDT, SLDT, STRrFLAGS AffectedNone322 LLDT


24594 Rev. 3.10 February 2005 AMD64 TechnologyExceptionsException RealVirtual8086 Protected Cause of ExceptionInvalid 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)Stack, #SS X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection, #GPX A memory address exceeded a data segment limit or was noncanonical.<strong>General</strong> protection, #GP(selector)XXXXXXCPL was not 0.A null data segment was used to reference memory.The source selector did not point into the GDT.The descriptor was beyond the GDT limit.The descriptor was not an LDT descriptor.The descriptor's extended attribute bits were not zero in 64-bitmode.X The new LDT base address was non-canonical.Page fault, #PF X A page fault resulted from the execution of the instruction.LLDT 323


AMD64 Technology 24594 Rev. 3.10 February 2005LMSWLoad Machine Status WordLoads the lower four bits of the 16-bit register or memory oper<strong>and</strong> into bits 3–0 of themachine status word in register CR0. Only the protection enabled (PE), monitorcoprocessor (MP), emulation (EM), <strong>and</strong> task switched (TS) bits of CR0 are modified.Additionally, LMSW can set CR0.PE, but cannot clear it.The LMSW instruction can be used only when the current privilege level is 0. It is onlyprovided for compatibility with early processors.Use the MOV CR0 instruction to load all 32 or 64 bits of CR0.Mnemonic Opcode DescriptionLMSW reg/mem16 0F 01 /6 Load the lower 4 bits of the source into the lower 4 bits of CR0.Related <strong>Instructions</strong>MOV (CRn), SMSWrFLAGS AffectedNoneExceptionsException RealVirtual8086 Protected Cause of ExceptionStack, #SS X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPXXA memory address exceeded a data segment limit or was noncanonical.XXCPL 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.324 LMSW


24594 Rev. 3.10 February 2005 AMD64 TechnologyLSLLoad Segment LimitLoads the segment limit from the segment descriptor specified by a 16-bit sourceregister or memory oper<strong>and</strong> into a specified 16-bit, 32-bit, or 64-bit general-purposeregister <strong>and</strong> sets the zero (ZF) flag in the rFLAGS register if successful. LSL clears thezero flag if the descriptor is invalid for any reason.In 64-bit mode, for both 32-bit <strong>and</strong> 64-bit oper<strong>and</strong> sizes, 32-bit register results are zeroextendedto 64 bits.The LSL instruction checks that:• the segment selector is not a null selector.• the descriptor is within the GDT or LDT limit.• the descriptor DPL is greater than or equal to both the CPL <strong>and</strong> RPL, or the segmentis a conforming code segment.• the descriptor type is valid for the LAR instruction. Valid descriptor types areshown in the following table. LDT <strong>and</strong> TSS descriptors in 64-bit mode are onlyvalid if bits 12–8 of doubleword +12 are zero, as shown on page 111 of vol. 2 in Figure4-22.Valid Descriptor TypeDescriptionLegacy ModeLong Mode— — All code <strong>and</strong> data descriptors1 — Available 16-bit TSS2 2 LDT3 — Busy 16-bit TSS9 9 Available 32-bit or 64-bit TSSB B Busy 32-bit or 64-bit TSSIf the segment selector passes these checks <strong>and</strong> the segment limit is loaded into thedestination general-purpose register, the instruction sets the zero flag of the rFLAGSregister to 1. If the selector does not pass the checks, then LSL clears the zero flag to 0<strong>and</strong> does not modify the destination.The instruction calculates the segment limit to 32 bits, taking the 20-bit limit <strong>and</strong> thegranularity bit into account. When the oper<strong>and</strong> size is 16 bits, it truncates the upperLSL 325


AMD64 Technology 24594 Rev. 3.10 February 200516 bits of the 32-bit adjusted segment limit <strong>and</strong> loads the lower 16-bits into the targetregister.Mnemonic Opcode DescriptionLSL reg16, reg/mem16 0F 03 /r Loads a 16-bit general-purpose register with the segment limit for aselector specified in a 16-bit memory or register oper<strong>and</strong>.LSL reg32, reg/mem16 0F 03 /r Loads a 32-bit general-purpose register with the segment limit for aselector specified in a 16-bit memory or register oper<strong>and</strong>.LSL reg64, reg/mem16 0F 03 /r Loads a 64-bit general-purpose register with the segment limit for aselector specified in a 16-bit memory or register oper<strong>and</strong>.Related <strong>Instructions</strong>ARPL, LAR, VERR, VERWrFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.ExceptionsException RealVirtual8086 Protected Cause of ExceptionInvalid opcode, #UD X X This instruction is only recognized in protected mode.Stack, #SS X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPXA memory address exceeded a data segment limit or was noncanonical.MXA null data segment was used to reference memory.X The extended attribute bits of a system descriptor was not zero in 64-bit modePage fault, #PF X A page fault resulted from the execution of the instruction.Alignment check, #AC X An unaligned memory reference was performed while alignmentchecking was enabled.326 LSL


24594 Rev. 3.10 February 2005 AMD64 TechnologyLTRLoad Task RegisterLoads the specified segment selector into the visible portion of the task register (TR).The processor uses the selector to locate the descriptor for the TSS in the globaldescriptor table. It then loads this descriptor into the hidden portion of TR. The TSSdescriptor in the GDT is marked busy, but no task switch is made.If the source oper<strong>and</strong> is null, a general protection exception (#GP) is generated.In legacy <strong>and</strong> compatibility modes, the TSS descriptor is 8 bytes long <strong>and</strong> contains a32-bit base address.In 64-bit mode, the instruction references a 64-bit descriptor to load a 64-bit baseaddress. The TSS type (09H) is redefined in 64-bit mode for use as the 16-byte TSSdescriptor.This instruction must be executed in protected mode when the current privilege levelis 0. It is only provided for use by operating system software.The oper<strong>and</strong> size attribute has no effect on this instruction.LTR is a serializing instruction.Mnemonic Opcode DescriptionLTR reg/mem16 0F 00 /3 Load the 16-bit segment selector into the task register <strong>and</strong> load the TSSdescriptor from the GDT.Related <strong>Instructions</strong>LGDT, LIDT, LLDT, STR, SGDT, SIDT, SLDTrFLAGS AffectedNoneLTR 327


AMD64 Technology 24594 Rev. 3.10 February 2005ExceptionsException RealVirtual8086 Protected Cause of ExceptionInvalid 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)Stack, #SS X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection, #GPX A memory address exceeded a data segment limit or was noncanonical.<strong>General</strong> protection, #GP(selector)XXXXXXXCPL was not 0.A null data segment was used to reference memory.The new TSS selector was a null selector.The source selector did not point into the GDT.The descriptor was beyond the GDT limit.The descriptor was not an available TSS descriptor.The descriptor's extended attribute bits were not zero in 64-bitmode.X The new TSS base address was non-canonical.Page fault, #PF X A page fault resulted from the execution of the instruction.328 LTR


24594 Rev. 3.10 February 2005 AMD64 TechnologyMOV(CRn)Move to/from Control RegistersMoves the contents of a 32-bit or 64-bit general-purpose register to a control registeror vice versa.In 64-bit mode, the oper<strong>and</strong> size is fixed at 64 bits without the need for a REX prefix.In non-64-bit mode, the oper<strong>and</strong> size is fixed at 32 bits <strong>and</strong> the upper 32 bits of thedestination are forced to 0.CR0 maintains the state of various control bits. CR2 <strong>and</strong> CR3 are used for pagetranslation. CR4 holds various feature enable bits. CR8 is used to prioritize externalinterrupts. CR1, CR5, CR6, CR7, <strong>and</strong> CR9 through CR15 are all reserved <strong>and</strong> raise anundefined opcode exception (#UD) if referenced.CR8 can also be read <strong>and</strong> modified using the task priority register described in“<strong>System</strong>-Control Registers” in <strong>Volume</strong> 2.CR8 can be read <strong>and</strong> written in 64-bit mode, using a REX prefix. CR8 can be read <strong>and</strong>written in legacy mode using the MOV (CRn) opcode, using a LOCK prefix instead of aREX prefix to specify the additional opcode bit. To verify whether the LOCK prefixcan be used in this way, check the status of ECX bit 4 returned by CPUID st<strong>and</strong>ardfunction 80000001h.This instruction is always treated as a register-to-register (MOD = 11) instruction,regardless of the encoding of the MOD field in the MODR/M byte.MOV(CRn) is a privileged instruction <strong>and</strong> must always be executed at CPL = 0.MOV (CRn) is a serializing instruction.Mnemonic Opcode DescriptionMOV CRn, reg32 0F 22 /r Move the contents of a 32-bit register to CRnMOV CRn, reg64 0F 22 /r Move the contents of a 64-bit register to CRnMOV reg32,CRn 0F 20 /r Move the contents of CRn to a 32-bit register.MOV reg64,CRn 0F 20 /r Move the contents of CRn to a 64-bit register.Note:CR0, CR2, CR3, CR4, <strong>and</strong> CR8 are the only registers to which this instruction applies. See text for details.MOV(CRn) 329


AMD64 Technology 24594 Rev. 3.10 February 2005Related <strong>Instructions</strong>CLTS, LMSW, SMSWrFLAGS AffectedNoneExceptionsExceptionInvalid Instruction,#UD<strong>General</strong> protection,#GPRealVirtual8086 Protected Cause of ExceptionX X X An illegal control register was referenced (CR1, CR5–CR7,CR9–CR15).XXXXCPL was not 0.An attempt was made to set CR0.PG = 1 <strong>and</strong> CR0.PE = 0.XXXXXXXXXAn attempt was made to set CR0.CD = 0 <strong>and</strong> CR0.NW = 1.Reserved bits were set in the page-directory pointers table (used inthe legacy extended physical addressing mode) <strong>and</strong> the instructionmodified CR0, CR3, or CR4.An attempt was made to write 1 to any reserved bit in CR0, CR3, CR4or CR8.An attempt was made to set CR0.PG while long mode was 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 active(EFER.LMA = 1).330 MOV(CRn)


24594 Rev. 3.10 February 2005 AMD64 TechnologyMOV(DRn)Move to/from Debug RegistersMoves the contents of a debug register into a 32-bit or 64-bit general-purpose registeror vice versa.In 64-bit mode, the oper<strong>and</strong> size is fixed at 64 bits without the need for a REX prefix.In non-64-bit mode, the oper<strong>and</strong> size is fixed at 32-bits <strong>and</strong> the upper 32 bits of thedestination are forced to 0.DR0 through DR3 are linear breakpoint address registers. DR6 is the debug statusregister <strong>and</strong> DR7 is the debug control register. DR4 <strong>and</strong> DR5 are aliased to DR6 <strong>and</strong>DR7 if CR4.DE = 0, <strong>and</strong> are reserved if CR4.DE = 1.DR8 through DR15 are reserved <strong>and</strong> generate an undefined opcode exception ifreferenced.These instructions are privileged <strong>and</strong> must be executed at CPL 0.The MOV DRn,reg32 <strong>and</strong> MOV DRn,reg64 instructions are serializing instructions.The MOV(DR) instruction is always treated as a register-to-register (MOD = 11)instruction, regardless of the encoding of the MOD field in the MODR/M byte.See “Debug <strong>and</strong> Performance Resources” in <strong>Volume</strong> 2 for details.Mnemonic Opcode DescriptionMOV reg32, DRn 0F 21 /r Move the contents of DRn to a 32-bit register.MOV reg64, DRn 0F 21 /r Move the contents of DRn to a 64-bit register.MOV DRn, reg32 0F 23 /r Move the contents of a 32-bit register to DRn.MOV DRn, reg64 0F 23 /r Move the contents of a 64-bit register to DRn.Related <strong>Instructions</strong>NonerFLAGS AffectedNoneMOV(DRn) 331


AMD64 Technology 24594 Rev. 3.10 February 2005ExceptionsException RealVirtual8086 Protected Cause of ExceptionDebug, #DB X X A debug register was referenced while the general detect (GD) bitin DR7 was set.Invalid opcode, #UD X XDR4 or DR5 was referenced while the debug extensions (DE) bit inCR4 was set.X<strong>General</strong> protection, #GP X XXAn illegal debug register (DR8-DR15) was referenced.CPL was not 0.A 1 was written to any of the upper 32 bits of DR6 or DR7 in 64-bitmode.332 MOV(DRn)


24594 Rev. 3.10 February 2005 AMD64 TechnologyRDMSRRead Model-Specific RegisterLoads the contents of a 64-bit model-specific register (MSR) specified in the ECXregister into registers EDX:EAX. The EDX register receives the high-order 32 bits <strong>and</strong>the EAX register receives the low order bits. The RDMSR instruction ignores oper<strong>and</strong>size; ECX always holds the MSR number, <strong>and</strong> EDX:EAX holds the data. If a modelspecificregister has fewer than 64 bits, the unimplemented bit positions loaded intothe destination registers are undefined.This instruction must be executed at a privilege level of 0 or a general protectionexception (#GP) will be raised. This exception is also generated if a reserved orunimplemented model-specific register is specified in ECX.Use the CPUID instruction to determine if this instruction is supported.RDMSR is a serializing instruction.For more information about model-specific registers, see the documentation forvarious hardware implementations <strong>and</strong> <strong>Volume</strong> 2, <strong>System</strong> Programming.Mnemonic Opcode DescriptionRDMSR 0F 32 Copy MSR specified by ECX into EDX:EAX.Related <strong>Instructions</strong>WRMSR, RDTSC, RDPMCrFLAGS AffectedNoneExceptionsException RealVirtual8086 Protected Cause of ExceptionInvalid opcode, #UD X X X The RDMSR instruction is not supported, as indicated by EDX bit 5returned by CPUID st<strong>and</strong>ard function 1 or extended function8000_0001h.<strong>General</strong> protection,#GPXX XXCPL was not 0.The value in ECX specifies a reserved or unimplemented MSRaddress.RDMSR 333


AMD64 Technology 24594 Rev. 3.10 February 2005RDPMCRead Performance-Monitoring CounterLoads the contents of a 64-bit performance counter register (PerfCtrn) specified inthe ECX register into registers EDX:EAX. The EDX register receives the high-order32 bits <strong>and</strong> the EAX register receives the low order 32 bits. The RDPMC instructionignores oper<strong>and</strong> size; ECX always holds the number of the PerfCtr, <strong>and</strong> EDX:EAXholds the data.The AMD64 architecture currently supports four performance counters: PerfCtr0through PerfCtr3. To specify the performance counter number in ECX, specify thecounter number (0000_0000h–0000_0003h), rather than the performance counterMSR address (C001_0004h–C001_0007h).Programs running at any privilege level can read performance monitor counters if thePCE flag in CR4 is set to 1; otherwise this instruction must be executed at a privilegelevel of 0.This instruction is not serializing. Therefore, there is no guarantee that all instructionshave completed at the time the performance counter is read.For more information about performance-counter registers, see the documentation forvarious hardware implementations <strong>and</strong> “Performance Counters” in <strong>Volume</strong> 2.Mnemonic Opcode DescriptionRDPMC 0F 33 Copy the performance monitor counter specified by ECXinto EDX:EAX.Related <strong>Instructions</strong>RDMSR, WRMSRrFLAGS AffectedNone334 RDPMC


24594 Rev. 3.10 February 2005 AMD64 TechnologyExceptionsException<strong>General</strong> Protection,#GPRealXVirtual8086 Protected Cause of ExceptionXXThe value in ECX specified an unimplemented performance counternumber.XXCPL was not 0 <strong>and</strong> CR4.PCE = 0.RDPMC 335


AMD64 Technology 24594 Rev. 3.10 February 2005RDTSCRead Time-Stamp CounterLoads the value of the processor’s 64-bit time-stamp counter into registers EDX:EAX.The time-stamp counter is contained in a 64-bit model-specific register (MSR). Theprocessor sets the counter to 0 upon reset <strong>and</strong> increments the counter every clockcycle. INIT does not modify the TSC.The high-order 32 bits are loaded into EDX, <strong>and</strong> the low-order 32 bits are loaded intothe EAX register. This instruction ignores oper<strong>and</strong> size.When the time-stamp disable flag (TSD) in CR4 is set to 1, the RDTSC instruction canonly be used at privilege level 0. If the TSD flag is 0, this instruction can be used at anyprivilege level.This instruction is not serializing. Therefore, there is no guarantee that all instructionshave completed at the time the time-stamp counter is read.Mnemonic Opcode DescriptionRDTSC 0F 31 Copy the time-stamp counter into EDX:EAX.Related <strong>Instructions</strong>RDTSCP, RDMSR, WRMSRrFLAGS AffectedNoneExceptionsException RealVirtual8086 Protected Cause of ExceptionInvalid opcode, #UD X X X The RDTSC instruction is not supported, as indicated by EDX bit 4returned by CPUID st<strong>and</strong>ard function 1 or extended function8000_0001h.<strong>General</strong> protection, #GP X X CPL was not 0 <strong>and</strong> CR4.TSD = 1.336 RDTSC


24594 Rev. 3.10 February 2005 AMD64 TechnologyRDTSCPRead Time-Stamp Counter <strong>and</strong> Processor IDLoads the value of the processor’s 64-bit time-stamp counter into registers EDX:EAX,<strong>and</strong> loads the value of TSC_AUX into ECX. This instruction ignores oper<strong>and</strong> size.The time-stamp counter is contained in a 64-bit model-specific register (MSR). Theprocessor sets the counter to 0 upon reset <strong>and</strong> increments the counter every clockcycle. INIT does not modify the TSC.The high-order 32 bits are loaded into EDX, <strong>and</strong> the low-order 32 bits are loaded intothe EAX register.The TSC_AUX value is contained in the low-order 32 bits of the TSC_AUX register(MSR address C000_0103h). This MSR is initialized by privileged software to anymeaningful value, such as a processor ID, that software wants to associate with thereturned TSC value.When the time-stamp disable flag (TSD) in CR4 is set to 1, the RDTSCP instructioncan only be used at privilege level 0. If the TSD flag is 0, this instruction can be used atany privilege level.Unlike the RDTSC instruction, RDTSCP is a serializing instruction.Use the CPUID instruction to verify support for this instruction.Mnemonic Opcode DescriptionRDTSC P 0F 01 F9 Copy the time-stamp counter into EDX:EAX. <strong>and</strong> theTSC_AUX register into ECX.Related <strong>Instructions</strong>RDTSCrFLAGS AffectedNoneRDTSCP 337


AMD64 Technology 24594 Rev. 3.10 February 2005ExceptionsException RealVirtual8086 Protected Cause of ExceptionInvalid opcode, #UD X X X The RDTSCP instruction is not supported, as indicated by EDX bit 27returned by CPUID extended function 8000_0001h.<strong>General</strong> protection, #GP X X CPL was not 0 <strong>and</strong> CR4.TSD = 1.338 RDTSCP


24594 Rev. 3.10 February 2005 AMD64 TechnologyRSMResume from <strong>System</strong> Management ModeResumes an operating system or application procedure previously interrupted by asystem management interrupt (SMI). The processor state is restored from theinformation saved when the SMI was taken. If the processor detects invalid stateinformation in the system management mode (SMM) save area during RSM, it goesinto a shutdown state.RSM will shutdown if any of the following conditions are found in the save map (SSM):• An illegal combination of flags in CR0 (CR0.PG = 1 <strong>and</strong> CR0.PE = 0, or CR0.NW =1 <strong>and</strong> CR0.CD = 0).• A reserved bit in CR0, CR3, CR4, DR6, DR7, or the extended feature enable register(EFER) is set to 1.• The following bit combination occurs: EFER.LME = 1, CR0.PG = 1, CR4.PAE = 0.• The following bit combination occurs: EFER.LME = 1, CR0.PG = 1, CR4.PAE = 1,CS.D = 1, CS.L = 1.• SMM revision field has been modified.The AMD64 architecture uses a new 64-bit SMM state-save memory image. This 64-bitsave-state map is used in all modes, regardless of mode. See “<strong>System</strong>-ManagementMode” in <strong>Volume</strong> 2 for details.Mnemonic Opcode DescriptionRSM 0F AA Resume operation of an interrupted program.Related <strong>Instructions</strong>NoneRSM 339


AMD64 Technology 24594 Rev. 3.10 February 2005rFLAGS AffectedAll 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 CFM M M M M M M M M M M M M M M M M21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to 1 or cleared to 0 is M (modified). Unaffected flags are blank. Undefinedflags are U.ExceptionsVirtualException Real 8086 Protected Cause of ExceptionInvalid opcode, #UD X X X The processor was not in <strong>System</strong> Management Mode (SMM).340 RSM


24594 Rev. 3.10 February 2005 AMD64 TechnologySGDTStore Global Descriptor Table RegisterStores the global descriptor table register (GDTR) into the destination oper<strong>and</strong>. Inlegacy <strong>and</strong> compatibility mode, the destination oper<strong>and</strong> is six bytes; in 64-bit mode, itis 10 bytes. In all modes, oper<strong>and</strong>-size prefixes are ignored.In non-64-bit mode, the lower two bytes of the oper<strong>and</strong> specify the 16-bit limit <strong>and</strong> theupper 4 bytes specify the 32-bit base address.In 64-bit mode, the lower two bytes of the oper<strong>and</strong> specify the 16-bit limit <strong>and</strong> theupper 8 bytes specify the 64-bit base address.This instruction is intended for use in operating system software, but it can be used atany privilege level.Mnemonic Opcode DescriptionSGDT mem16:32 0F 01 /0 Store global descriptor table register to memory.SGDT mem16:64 0F 01 /0 Store global descriptor table register to memory.Related <strong>Instructions</strong>SIDT, SLDT, STR, LGDT, LIDT, LLDT, LTRrFLAGS AffectedNoneExceptionsException RealVirtual8086 Protected Cause of ExceptionInvalid opcode, #UD X X X The oper<strong>and</strong> was a register.Stack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.SGDT 341


AMD64 Technology 24594 Rev. 3.10 February 2005Exception<strong>General</strong> protection,#GPRealVirtual8086 Protected Cause of ExceptionX X XA memory address exceeded a data segment limit or was noncanonical.XThe destination oper<strong>and</strong> 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, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.342 SGDT


24594 Rev. 3.10 February 2005 AMD64 TechnologySIDTStore Interrupt Descriptor Table RegisterStores the interrupt descriptor table register (IDTR) in the destination oper<strong>and</strong>. Inlegacy <strong>and</strong> compatibility mode, the destination oper<strong>and</strong> is 6 bytes; in 64-bit mode it is10 bytes. In all modes, oper<strong>and</strong>-size prefixes are ignored.In non-64-bit mode, the lower two bytes of the oper<strong>and</strong> specify the 16-bit limit <strong>and</strong> theupper 4 bytes specify the 32-bit base address.In 64-bit mode, the lower two bytes of the oper<strong>and</strong> specify the 16-bit limit <strong>and</strong> theupper 8 bytes specify the 64-bit base address.This instruction is intended for use in operating system software, but it can be used atany privilege level.Mnemonic Opcode DescriptionSIDT mem16:32 0F 01 /1 Store interrupt descriptor table register to memory.SIDT mem16:64 0F 01 /1 Store interrupt descriptor table register to memory.Related <strong>Instructions</strong>SGDT, SLDT, STR, LGDT, LIDT, LLDT, LTRrFLAGS AffectedNoneExceptionsException RealVirtual8086 Protected Cause of ExceptionInvalid opcode, #UD X X X The oper<strong>and</strong> was a register.Stack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.SIDT 343


AMD64 Technology 24594 Rev. 3.10 February 2005Exception<strong>General</strong> protection,#GPRealVirtual8086 Protected Cause of ExceptionX X XA memory address exceeded a data segment limit or was noncanonical.XThe destination oper<strong>and</strong> 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, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.344 SIDT


24594 Rev. 3.10 February 2005 AMD64 TechnologySLDTStore Local Descriptor Table RegisterStores the local descriptor table (LDT) selector to a register or memory destinationoper<strong>and</strong>.If the destination is a register, the selector is zero-extended into a 16-, 32-, or 64-bitgeneral purpose register, depending on oper<strong>and</strong> size.If the destination oper<strong>and</strong> is a memory location, the segment selector is written tomemory as a 16-bit value, regardless of oper<strong>and</strong> size.This SLDT instruction can only be used in protected mode, but it can be executed atany privilege level.Mnemonic Opcode DescriptionSLDT reg16 0F 00 /0 Store the segment selector from the local descriptor tableregister to a 16-bit register.SLDT reg32 0F 00 /0 Store the segment selector from the local descriptor tableregister to a 32-bit register.SLDT reg64 0F 00 /0 Store the segment selector from the local descriptor tableregister to a 64-bit register.SLDT mem16 0F 00 /0 Store the segment selector from the local descriptor tableregister to a 16-bit memory location.Related <strong>Instructions</strong>SIDT, SGDT, STR, LIDT, LGDT, LLDT, LTRrFLAGS AffectedNoneSLDT 345


AMD64 Technology 24594 Rev. 3.10 February 2005ExceptionsException RealVirtual8086 Protected Cause of ExceptionInvalid opcode, #UD X X This instruction is only recognized in protected mode.Stack, #SS X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPXA memory address exceeded a data segment limit or was noncanonical.XThe destination oper<strong>and</strong> 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, #AC X An unaligned memory reference was performed while alignmentchecking was enabled.346 SLDT


24594 Rev. 3.10 February 2005 AMD64 TechnologySMSWStore Machine Status WordStores the lower bits of the machine status word (CR0). The target can be a 16-, 32-, or64-bit register or a 16-bit memory oper<strong>and</strong>.This instruction is provided for compatibility with early processors.This instruction can be used at any privilege level (CPL).Mnemonic Opcode DescriptionSMSW reg16 0F 01 /4 Store the low 16 bits of CR0 to a 16-bit register.SMSW reg32 0F 01 /4 Store the low 32 bits of CR0 to a 32-bit register.SMSW reg64 0F 01 /4 Store the entire 64-bit CR0 to a 64-bit register.SMSW mem16 0F 01 /4 Store the low 16 bits of CR0 to memory.Related <strong>Instructions</strong>LMSW, MOV(CRn)rFLAGS AffectedNoneExceptionsException RealVirtual8086 Protected Cause of ExceptionStack, #SS X X X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPX X XA memory address exceeded a data segment limit or was noncanonical.XThe destination oper<strong>and</strong> 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, #AC X X An unaligned memory reference was performed while alignmentchecking was enabled.SMSW 347


AMD64 Technology 24594 Rev. 3.10 February 2005STISet Interrupt FlagSets the interrupt flag (IF) in the rFLAGS register to 1, thereby allowing externalinterrupts received on the INTR input. Interrupts received on the non-maskableinterrupt (NMI) input are not affected by this instruction.In real mode, this instruction sets IF to 1.In protected mode <strong>and</strong> virtual-8086-mode, this instruction is IOPL-sensitive. If theCPL is less than or equal to the rFLAGS.IOPL field, the instruction sets IF to 1.In protected mode, if IOPL < 3, CPL = 3, <strong>and</strong> protected mode virtual interrupts areenabled (CR4.PVI = 1), then the instruction instead sets rFLAGS.VIF to 1. If none ofthese conditions apply, the processor raises a general protection exception (#GP). Formore information, see “Protected Mode Virtual Interrupts” in <strong>Volume</strong> 2.In virtual-8086 mode, if IOPL < 3 <strong>and</strong> the virtual-8086-mode extensions are enabled(CR4.VME = 1), the STI instruction instead sets the virtual interrupt flag(rFLAGS.VIF) to 1.If STI sets the IF flag <strong>and</strong> IF was initially clear, then interrupts are not enabled untilafter the instruction following STI. Thus, if IF is 0, this code will not allow an INTR tohappen:STICLIIn the following sequence, INTR will be allowed to happen only after the NOP.STINOPCLIIf STI sets the VIF flag <strong>and</strong> VIP is already set, a #GP fault will be generated.See “Virtual-8086 Mode Extensions” in <strong>Volume</strong> 2 for more information about IOPLsensitiveinstructions.Mnemonic Opcode DescriptionSTI FB Set interrupt flag (IF) to 1.348 STI


24594 Rev. 3.10 February 2005 AMD64 TechnologyActionIF (CPL


AMD64 Technology 24594 Rev. 3.10 February 2005STRStore Task RegisterStores the task register (TR) selector to a register or memory destination oper<strong>and</strong>.If the destination is a register, the selector is zero-extended into a 16-, 32-, or 64-bitgeneral purpose register, depending on the oper<strong>and</strong> size.If the destination is a memory location, the segment selector is written to memory as a16-bit value, regardless of oper<strong>and</strong> size.The STR instruction can only be used in protected mode, but it can be used at anyprivilege level.Mnemonic Opcode DescriptionSTR reg16 0F 00 /1 Store the segment selector from the task register to a 16-bit generalpurposeregister.STR reg32 0F 00 /1 Store the segment selector from the task register to a 32-bit generalpurposeregister.STR reg64 0F 00 /1 Store the segment selector from the task register to a 64-bit generalpurposeregister.STR mem16 0F 00 /1 Store the segment selector from the task register to a 16-bit memorylocation.Related <strong>Instructions</strong>LGDT, LIDT, LLDT, LTR, SIDT, SGDT, SLDTrFLAGS AffectedNone350 STR


24594 Rev. 3.10 February 2005 AMD64 TechnologyExceptionsException RealVirtual8086 Protected Cause of ExceptionInvalid opcode, #UD X X This instruction is only recognized in protected mode.Stack, #SS X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection, #GPX A memory address exceeded a data segment limit or was noncanonical.XThe destination oper<strong>and</strong> 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, #AC X An unaligned memory reference was performed while alignmentchecking was enabled.STR 351


AMD64 Technology 24594 Rev. 3.10 February 2005SWAPGSSwap GS Register with KernelGSbase MSRProvides a fast method for system software to load a pointer to system data structures.SWAPGS can be used upon entering system-software routines as a result of aSYSCALL instruction, an interrupt or an exception. Prior to returning to applicationsoftware, SWAPGS can be used to restore the application data pointer that wasreplaced by the system data-structure pointer.This instruction can only be executed in 64-bit mode. Executing SWAPGS in any othermode generates an undefined opcode exception.The SWAPGS instruction only exchanges the base-address value located in theKernelGSbase model-specific register (MSR address C000_0102h) with the baseaddressvalue located in the hidden-portion of the GS selector register (GS.base). Thisallows the system-kernel software to access kernel data structures by using the GSsegment-override prefix during memory references.The address stored in the KernelGSbase MSR must be in canonical form. The WRMSRinstruction used to load the KernelGSbase MSR causes a general-protection exceptionif the address loaded is not in canonical form. The SWAPGS instruction itself does notperform a canonical check.This instruction is only valid in 64-bit mode at CPL 0. A general protection exception(#GP) is generated if this instruction is executed at any other privilege level.For additional information about this instruction, refer to “<strong>System</strong>-Management<strong>Instructions</strong>” in <strong>Volume</strong> 2.ExamplesAt a kernel entry point, the OS uses SwapGS to obtain a pointer to kernel datastructures <strong>and</strong> simultaneously save the user's GS base. Upon exit, it uses SwapGS torestore the user's GS base:<strong>System</strong>CallEntryPoint:SwapGS; get kernel pointer, save user GSbasemov gs:[SavedUserRSP], rsp ; save user's stack pointermov rsp, gs:[KernelStackPtr] ; set up kernel stackpush rax; now save user GPRs on kernel stack. ; perform system service.SwapGS; restore user GS, save kernel pointer352 SWAPGS


24594 Rev. 3.10 February 2005 AMD64 TechnologyMnemonic Opcode DescriptionSWAPGS 0F 01 F8 Exchange GS base with KernelGSBase MSR.(Invalid in legacy <strong>and</strong> compatibility modes.)Related <strong>Instructions</strong>NonerFLAGS AffectedNoneExceptionsException RealVirtual8086 Protected Cause of ExceptionInvalid opcode, #UD X X X This instruction was executed in legacy or compatibilitymode.<strong>General</strong> protection, #GP X CPL was not 0.SWAPGS 353


AMD64 Technology 24594 Rev. 3.10 February 2005SYSCALLFast <strong>System</strong> CallTransfers control to a fixed entry point in an operating system. It is designed for useby system <strong>and</strong> application software implementing a flat-segment memory model.The SYSCALL <strong>and</strong> SYSRET instructions are low-latency system call <strong>and</strong> returncontrol-transfer instructions, which assume that the operating system implements aflat-segment memory model. By eliminating unneeded checks, <strong>and</strong> by loading predeterminedvalues into the CS <strong>and</strong> SS segment registers (both visible <strong>and</strong> hiddenportions), calls to <strong>and</strong> returns from the operating system are greatly simplified. Theseinstructions can be used in protected mode <strong>and</strong> are particularly well-suited for use in64-bit mode, which requires implementation of a paged, flat-segment memory model.This instruction has been optimized by reducing the number of checks <strong>and</strong> memoryreferences that are normally made so that a call or return takes considerably fewerclock cycles than the CALL FAR /RET FAR instruction method.It is assumed that the base, limit, <strong>and</strong> attributes of the Code Segment will remain flatfor all processes <strong>and</strong> for the operating system, <strong>and</strong> that only the current privilege levelfor the selector of the calling process should be changed from a current privilege levelof 3 to a new privilege level of 0. It is also assumed (but not checked) that the RPL ofthe SYSCALL <strong>and</strong> SYSRET target selectors are set to 0 <strong>and</strong> 3, respectively.SYSCALL sets the CPL to 0, regardless of the values of bits 33–32 of the STARregister. There are no permission checks based on the CPL, real mode, or virtual-8086mode. SYSCALL <strong>and</strong> SYSRET must be enabled by setting EFER.SCE to 1.It is the responsibility of the operating system to keep the descriptors in memory thatcorrespond to the CS <strong>and</strong> SS selectors loaded by the SYSCALL <strong>and</strong> SYSRETinstructions consistent with the segment base, limit, <strong>and</strong> attribute values forced bythese instructions.Legacy x86 Mode. In legacy x86 mode, when SYSCALL is executed, the EIP register iscopied into the ECX register. Bits 31–0 of the SYSCALL/SYSRET target addressregister (STAR) are copied into the EIP register. (The STAR register is model-specificregister 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 SSregister.354 SYSCALL


24594 Rev. 3.10 February 2005 AMD64 Technology• The CS_base <strong>and</strong> the SS_base are both forced to zero.• The CS_limit <strong>and</strong> 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 <strong>and</strong> exp<strong>and</strong>-up with a 32-bit stackreferenced by ESP.Long Mode. When long mode is activated, the behavior of the SYSCALL instructiondepends on whether the calling software is in 64-bit mode or compatibility mode. In64-bit mode, SYSCALL saves the RIP of the instruction following the SYSCALL intoRCX <strong>and</strong> loads the new RIP from LSTAR bits 63–0. (The LSTAR register is modelspecificregister C000_0082h.) In compatibility mode, SYSCALL saves the RIP of theinstruction following the SYSCALL into RCX <strong>and</strong> loads the new RIP from CSTAR bits63–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 SSregister.• The CS_base <strong>and</strong> the SS_base are both forced to zero.• The CS_limit <strong>and</strong> 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 <strong>and</strong> exp<strong>and</strong>-up with a 64-bit stackreferenced by RSP.The WRMSR instruction loads the target RIP into the LSTAR <strong>and</strong> CSTAR registers. Ifan RIP written by WRMSR is not in canonical form, a general-protection exception(#GP) occurs.How SYSCALL <strong>and</strong> SYSRET h<strong>and</strong>le rFLAGS, depends on the processor’s operatingmode.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.SYSCALL 355


AMD64 Technology 24594 Rev. 3.10 February 2005• RFLAGS.RF is cleared to 0.For further details on the SYSCALL <strong>and</strong> SYSRET instructions <strong>and</strong> their associatedMSR registers (STAR, LSTAR, CSTAR, <strong>and</strong> SYSCALL_FLAG_MASK), see “Fast<strong>System</strong> Call <strong>and</strong> Return” in <strong>Volume</strong> 2.Mnemonic Opcode DescriptionSYSCALL 0F 05 Call operating system.Action// See “Pseudocode Definitions” on page 49.SYSCALL_START:IF (MSR_EFER.SCE = 0)EXCEPTION [#UD]// Check if syscall/sysret are enabled.IF (LONG_MODE)SYSCALL_LONG_MODEELSE // (LEGACY_MODE)SYSCALL_LEGACY_MODESYSCALL_LONG_MODE:RCX.q = next_RIPR11.q = RFLAGS// with rf clearedIF (64BIT_MODE)temp_RIP.q = MSR_LSTARELSE // (COMPATIBILITY_MODE)temp_RIP.q = MSR_CSTARCS.sel = MSR_STAR.SYSCALL_CS AND 0xFFFCCS.attr = 64-bit code,dpl0 // Always switch to 64-bit mode in long mode.CS.base = 0x00000000CS.limit = 0xFFFFFFFFSS.sel = MSR_STAR.SYSCALL_CS + 8SS.attr = 64-bit stack,dpl0SS.base = 0x00000000SS.limit = 0xFFFFFFFFRFLAGS = RFLAGS AND ~MSR_SFMASKRFLAGS.RF = 0CPL = 0356 SYSCALL


24594 Rev. 3.10 February 2005 AMD64 TechnologyRIP = temp_RIPEXITSYSCALL_LEGACY_MODE:RCX.d = next_RIPtemp_RIP.d = MSR_STAR.EIPCS.sel = MSR_STAR.SYSCALL_CS AND 0xFFFCCS.attr = 32-bit code,dpl0 // Always switch to 32-bit mode in legacy mode.CS.base = 0x00000000CS.limit = 0xFFFFFFFFSS.sel = MSR_STAR.SYSCALL_CS + 8SS.attr = 32-bit stack,dpl0SS.base = 0x00000000SS.limit = 0xFFFFFFFFRFLAGS.VM,IF,RF=0CPL = 0RIP = temp_RIPEXITRelated <strong>Instructions</strong>SYSRET, SYSENTER, SYSEXITrFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFM M M M 0 0 M M M M M M M M M M M21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to one or cleared to zero is M (modified). Unaffected flags are blank. Undefinedflags are U.SYSCALL 357


AMD64 Technology 24594 Rev. 3.10 February 2005ExceptionsExceptionInvalid opcode, #UDRealXVirtual8086 Protected Cause of ExceptionXXThe SYSCALL <strong>and</strong> SYSRET instructions are not supported,as indicated by EDX bit 11 returned by CPUID extendedfunction 8000_0001h.XXXThe system call extension bit (SCE) of the extendedfeature enable register (EFER) is set to 0. (The EFERregister is MSR C000_0080h.)358 SYSCALL


24594 Rev. 3.10 February 2005 AMD64 TechnologySYSENTER<strong>System</strong> CallTransfers control to a fixed entry point in an operating system. It is designed for useby system <strong>and</strong> application software implementing a flat-segment memory model. Thisinstruction is valid only in legacy mode.Three model-specific registers (MSRs) are used to specify the target address <strong>and</strong> stackpointers for the SYSENTER instruction, as well as the CS <strong>and</strong> SS selectors of thecalled <strong>and</strong> returned procedures:• MSR_SYSENTER_CS: Contains the CS selector of the called procedure. The SSselector is set to MSR_SYSENTER_CS + 8.• MSR_SYSENTER_ESP: Contains the called procedure’s stack pointer.• MSR_SYSENTER_EIP: Contains the offset into the CS of the called procedure.The hidden portions of the CS <strong>and</strong> SS segment registers are not loaded from thedescriptor table as they would be using a legacy x86 CALL instruction. Instead, thehidden portions are forced by the processor to the following values:• The CS <strong>and</strong> SS base values are forced to 0.• The CS <strong>and</strong> SS limit values are forced to 4 Gbytes.• 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 <strong>and</strong> exp<strong>and</strong>-up with a 32-bit stackreferenced by ESP.<strong>System</strong> software must create corresponding descriptor-table entries referenced by thenew CS <strong>and</strong> SS selectors that match the values described above.The return EIP <strong>and</strong> application stack are not saved by this instruction. <strong>System</strong>software must explicitly save that information.An invalid-opcode exception occurs if this instruction is used in long mode. Softwareshould use the SYSCALL (<strong>and</strong> SYSRET) instructions in long mode. If SYSENTER isused in real mode, a #GP is raised.For additional information on this instruction, see “SYSENTER <strong>and</strong> SYSEXIT(Legacy Mode Only)” in <strong>Volume</strong> 2.Mnemonic Opcode DescriptionSYSENTER 0F 34 Call operating system.SYSENTER 359


AMD64 Technology 24594 Rev. 3.10 February 2005Related <strong>Instructions</strong>SYSCALL, SYSEXIT, SYSRETrFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFExceptions0 021 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to one or zero is M (modified). Unaffected flags are blank. Undefined flagsare U.Exception RealInvalid opcode, #UD X X XVirtual8086 Protected Cause of ExceptionThe SYSENTER <strong>and</strong> SYSEXIT instructions are notsupported, as indicated by EDX bit 11 returned by CPUIDst<strong>and</strong>ard function 1.<strong>General</strong> protection, #GPXXThis instruction is not recognized in long mode.This instruction is not recognized in real mode.XXMSR_SYSENTER_CS was cleared to 0.360 SYSENTER


24594 Rev. 3.10 February 2005 AMD64 TechnologySYSEXIT<strong>System</strong> ReturnReturns from the operating system to an application. It is a low-latency system returninstruction designed for use by system <strong>and</strong> application software implementing a flatsegmentmemory model.This is a privileged instruction. The current privilege level must be zero to executethis instruction. An invalid-opcode exception occurs if this instruction is used in longmode. Software should use the SYSRET (<strong>and</strong> SYSCALL) instructions when running inlong mode.When a system procedure performs a SYSEXIT back to application software, the CSselector is updated to point to the second descriptor entry after the SYSENTER CSvalue (MSR SYSENTER_CS+16). The SS selector is updated to point to the thirddescriptor entry after the SYSENTER CS value (MSR SYSENTER_CS+24). The CPLis forced to 3, as are the descriptor privilege levels.The hidden portions of the CS <strong>and</strong> SS segment registers are not loaded from thedescriptor table as they would be using a legacy x86 RET instruction. Instead, thehidden portions are forced by the processor to the following values:• The CS <strong>and</strong> SS base values are forced to 0.• The CS <strong>and</strong> SS limit values are forced to 4 Gbytes.• The CS segment attributes are set to 32-bit read/execute at CPL 3.• The SS segment attributes are set to read/write <strong>and</strong> exp<strong>and</strong>-up with a 32-bit stackreferenced by ESP.<strong>System</strong> software must create corresponding descriptor-table entries referenced by thenew CS <strong>and</strong> SS selectors that match the values described above.The following additional actions result from executing SYSEXIT:• EIP is loaded from EDX.• ESP is loaded from ECX.<strong>System</strong> software must explicitly load the return address <strong>and</strong> application softwarestackpointer into the EDX <strong>and</strong> ECX registers prior to executing SYSEXIT.For additional information on this instruction, see “SYSENTER <strong>and</strong> SYSEXIT(Legacy Mode Only)” in <strong>Volume</strong> 2.SYSEXIT 361


AMD64 Technology 24594 Rev. 3.10 February 2005Mnemonic Opcode DescriptionSYSEXIT 0F 35 Return from operating system to application.Related <strong>Instructions</strong>SYSCALL, SYSENTER, SYSRETrFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFExceptions021 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to one or cleared to zero is M (modified). Unaffected flags are blank.Exception RealInvalid opcode, #UD X X XVirtual8086 Protected Cause of ExceptionThe SYSENTER <strong>and</strong> SYSEXIT instructions are notsupported, as indicated by EDX bit 11 returned by CPUIDst<strong>and</strong>ard function 1.<strong>General</strong> protection, #GP X XXXXThis instruction is not recognized in long mode.This instruction is only recognized in protected mode.CPL was not 0.MSR_SYSENTER_CS was cleared to 0.362 SYSEXIT


24594 Rev. 3.10 February 2005 AMD64 TechnologySYSRETFast <strong>System</strong> ReturnReturns from the operating system to an application. It is a low-latency system returninstruction designed for use by system <strong>and</strong> application software implementing a flatsegmentation memory model.The SYSCALL <strong>and</strong> SYSRET instructions are low-latency system call <strong>and</strong> returncontrol-transfer instructions that assume that the operating system implements a flatsegmentmemory model. By eliminating unneeded checks, <strong>and</strong> by loading predeterminedvalues into the CS <strong>and</strong> SS segment registers (both visible <strong>and</strong> hiddenportions), calls to <strong>and</strong> returns from the operating system are greatly simplified. Theseinstructions can be used in protected mode <strong>and</strong> are particularly well-suited for use in64-bit mode, which requires implementation of a paged, flat-segment memory model.This instruction has been optimized by reducing the number of checks <strong>and</strong> memoryreferences that are normally made so that a call or return takes substantially fewerinternal clock cycles when compared to the CALL/RET instruction method.It is assumed that the base, limit, <strong>and</strong> attributes of the Code Segment will remain flatfor all processes <strong>and</strong> for the operating system, <strong>and</strong> that only the current privilege levelfor the selector of the calling process should be changed from a current privilege levelof 0 to a new privilege level of 3. It is also assumed (but not checked) that the RPL ofthe SYSCALL <strong>and</strong> SYSRET target selectors are set to 0 <strong>and</strong> 3, respectively.SYSRET sets the CPL to 3, regardless of the values of bits 49–48 of the star register.SYSRET can only be executed in protected mode at CPL 0. SYSCALL <strong>and</strong> SYSRETmust be enabled by setting EFER.SCE to 1.It is the responsibility of the operating system to keep the descriptors in memory thatcorrespond to the CS <strong>and</strong> SS selectors loaded by the SYSCALL <strong>and</strong> SYSRETinstructions consistent with the segment base, limit, <strong>and</strong> attribute values forced bythese instructions.When a system procedure performs a SYSRET back to application software, the CSselector is updated from bits 63–50 of the STAR register (STAR.SYSRET_CS) asfollows:• If the return is to 32-bit mode (legacy or compatibility), CS is updated with thevalue of STAR.SYSRET_CS.• If the return is to 64-bit mode, CS is updated with the value of STAR.SYSRET_CS+ 16.SYSRET 363


AMD64 Technology 24594 Rev. 3.10 February 2005In both cases, the CPL is forced to 3, effectively ignoring STAR bits 49–48. The SSselector is updated to point to the next descriptor-table entry after the CS descriptor(STAR.SYSRET_CS + 8), <strong>and</strong> its RPL is not forced to 3.The hidden portions of the CS <strong>and</strong> SS segment registers are not loaded from thedescriptor table as they would be using a legacy x86 RET instruction. Instead, thehidden portions are forced by the processor to the following values:• The CS base value is forced to 0.• The CS limit value is forced to 4 Gbytes.• The CS segment attributes are set to execute-read 32 bits or 64 bits (see below).• The SS segment base, limit, <strong>and</strong> attributes are not modified.When SYSCALLed system software is running in 64-bit mode, it has been enteredfrom either 64-bit mode or compatibility mode. The corresponding SYSRET needs toknow the mode to which it must return. Executing SYSRET in non-64-bit mode or witha 16- or 32-bit oper<strong>and</strong> size, returns to 32-bit mode with a 32-bit stack pointer.Executing SYSRET in 64-bit mode with a 64-bit oper<strong>and</strong> size returns to 64-bit modewith a 64-bit stack pointer.The instruction pointer is updated with the return address based on the operatingmode 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 h<strong>and</strong>les RFLAGS, depends on the processor’s operating mode:• If executed in 64-bit mode, SYSRET loads the lower-32 RFLAGS bits fromR11[31:0] <strong>and</strong> clears the upper 32 RFLAGS bits.• If executed in legacy mode or compatibility mode, SYSRET sets EFLAGS.IF.For further details on the SYSCALL <strong>and</strong> SYSRET instructions <strong>and</strong> their associatedMSR registers (STAR, LSTAR, <strong>and</strong> CSTAR), see “Fast <strong>System</strong> Call <strong>and</strong> Return” in<strong>Volume</strong> 2.Mnemonic Opcode DescriptionSYSRET 0F 07 Return from operating system.Action// See “Pseudocode Definitions” on page 49.SYSRET_START:364 SYSRET


24594 Rev. 3.10 February 2005 AMD64 TechnologyIF (MSR_EFER.SCE = 0)EXCEPTION [#UD]// Check if syscall/sysret are enabled.IF ((!PROTECTED_MODE) || (CPL != 0))EXCEPTION [#GP(0)]// SYSRET requires protected mode, cpl0IF (64BIT_MODE)SYSRET_64BIT_MODEELSE // (!64BIT_MODE)SYSRET_NON_64BIT_MODESYSRET_64BIT_MODE:IF (OPERAND_SIZE = 64)// Return to 64-bit mode.{CS.sel = (MSR_STAR.SYSRET_CS + 16) OR 3CS.base = 0x00000000CS.limit = 0xFFFFFFFFCS.attr = 64-bit code,dpl3temp_RIP.q = RCX}ELSE// Return to 32-bit compatibility mode.{CS.sel = MSR_STAR.SYSRET_CS OR 3CS.base = 0x00000000CS.limit = 0xFFFFFFFFCS.attr = 32-bit code,dpl3}temp_RIP.d = RCXSS.sel = MSR_STAR.SYSRET_CS + 8// SS selector is changed,// SS base, limit, attributes unchanged.RFLAGS.q = R11CPL = 3// RF=0,VM=0RIP = temp_RIPEXITSYSRET_NON_64BIT_MODE:CS.sel = MSR_STAR.SYSRET_CS OR 3 // Return to 32-bit legacy protected mode.CS.base = 0x00000000CS.limit = 0xFFFFFFFFCS.attr = 32-bit code,dpl3temp_RIP.d = RCXSYSRET 365


AMD64 Technology 24594 Rev. 3.10 February 2005SS.sel = MSR_STAR.SYSRET_CS + 8RFLAGS.IF = 1CPL = 3// SS selector is changed.// SS base, limit, attributes unchanged.RIP = temp_RIPEXITRelated <strong>Instructions</strong>SYSCALL, SYSENTER, SYSEXITrFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CFM M M M 0 M M M M M M M M M M M21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to one or cleared to zero is M (modified). Unaffected flags are blank. Undefinedflags are U.ExceptionsExceptionInvalid opcode, #UDRealXVirtual8086 Protected Cause of ExceptionXXThe SYSCALL <strong>and</strong> SYSRET instructions are not supported,as indicated by EDX bit 11 returned by CPUID extendedfunction 8000_0001h.<strong>General</strong> protection, #GP X XXXXXThe system call extension bit (SCE) of the extendedfeature enable register (EFER) is set to 0. (The EFERregister is MSR C000_0080h.)This instruction is only recognized in protected mode.CPL was not 0.366 SYSRET


24594 Rev. 3.10 February 2005 AMD64 TechnologyUD2Undefined OperationGenerates an invalid opcode exception. Unlike other undefined opcodes that may bedefined as legal instructions in the future, UD2 is guaranteed to stay undefined.Mnemonic Opcode DescriptionUD2 0F 0B Raise an invalid opcode exception.Related <strong>Instructions</strong>NonerFLAGS AffectedNoneExceptionsVirtualException Real 8086 Protected Cause of ExceptionInvalid opcode, #UD X X X This instruction is not recognized.UD2 367


AMD64 Technology 24594 Rev. 3.10 February 2005VERRVerify Segment for ReadsVerifies whether a code or data segment specified by the segment selector in the 16-bit register or memory oper<strong>and</strong> is readable from the current privilege level. The zeroflag (ZF) is set to 1 if the specified segment is readable. Otherwise, ZF is cleared.A segment is readable if all of the following apply:• the selector is not a null selector.• the descriptor is within the GDT or LDT limit.• the segment is a data segment or readable code segment.• the descriptor DPL is greater than or equal to both the CPL <strong>and</strong> RPL, or the segmentis a conforming code segment.The processor does not recognize the VERR instruction in real or virtual-8086 mode.Mnemonic Opcode DescriptionVERR reg/mem16 0F 00 /4 Set the zero flag (ZF) to 1 if the segment selected canbe read.Related <strong>Instructions</strong>ARPL, LAR, LSL, VERWrFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to one or cleared to zero is M (modified). Unaffected flags are blank. Undefinedflags are U.M368 VERR


24594 Rev. 3.10 February 2005 AMD64 TechnologyExceptionsException RealVirtual8086 Protected Cause of ExceptionInvalid opcode, #UD X X This instruction is only recognized in protected mode.Stack, #SS X A memory address exceeded the stack segment limit or is noncanonical.<strong>General</strong> protection,#GPXA memory address exceeded a data segment limit or was noncanonical.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, #AC X An unaligned memory reference was performed while alignmentchecking was enabled.VERR 369


AMD64 Technology 24594 Rev. 3.10 February 2005VERWVerify Segment for WritesVerifies whether a data segment specified by the segment selector in the 16-bitregister or memory oper<strong>and</strong> is writable from the current privilege level. The zero flag(ZF) is set to 1 if the specified segment is writable. Otherwise, ZF is cleared.A segment is writable if all of the following apply:• the selector is not a null selector.• the descriptor is within the GDT or LDT limit.• the segment is a writable data segment.• the descriptor DPL is greater than or equal to both the CPL <strong>and</strong> RPL.The processor does not recognize the VERW instruction in real or virtual-8086 mode.Mnemonic Opcode DescriptionVERW reg/mem16 0F 00 /5 Set the zero flag (ZF) to 1 if the segment selected canbe written.Related <strong>Instructions</strong>ARPL, LAR, LSL, VERRrFLAGS AffectedID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF21 20 19 18 17 16 14 13–12 11 10 9 8 7 6 4 2 0Note: Bits 31–22, 15, 5, 3, <strong>and</strong> 1 are reserved. A flag set to one or cleared to zero is M (modified). Unaffected flags are blank. Undefinedflags are U.M370 VERW


24594 Rev. 3.10 February 2005 AMD64 TechnologyExceptionsException RealVirtual8086 Protected Cause of ExceptionInvalid opcode, #UD X X This instruction is only recognized in protected mode.Stack, #SS X A memory address exceeded the stack segment limit or was noncanonical.<strong>General</strong> protection,#GPXA memory address exceeded a data segment limit or was noncanonical.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, #AC X An unaligned memory reference was performed while alignmentchecking was enabled.VERW 371


AMD64 Technology 24594 Rev. 3.10 February 2005WBINVDWriteback <strong>and</strong> Invalidate CachesThe WBINVD instruction writes all modified cache lines in the internal caches back tomain memory <strong>and</strong> invalidates (flushes) internal caches. It then causes external cachesto write back modified data to main memory; the external caches are subsequentlyinvalidated. After invalidating internal caches, the processor proceeds immediatelywith the execution of the next instruction without waiting for external hardware toinvalidate its caches.The INVD instruction can be used when cache coherence with memory is notimportant.This instruction does not invalidate TLB caches.This is a privileged instruction. The current privilege level of a procedure invalidatingthe processor’s internal caches must be zero.WBINVD is a serializing instruction.Mnemonic Opcode DescriptionWBINVD 0F 09 Write modified cache lines to main memory, invalidate internalcaches, <strong>and</strong> trigger external cache flushes.Related <strong>Instructions</strong>CLFLUSH, INVDrFLAGS AffectedNoneExceptionsException<strong>General</strong> protection,#GPRealVirtual8086 Protected Cause of ExceptionX X CPL was not 0.372 WBINVD


24594 Rev. 3.10 February 2005 AMD64 TechnologyWRMSRWrite to Model-Specific RegisterWrites data to 64-bit model-specific registers (MSRs). These registers are widely usedin performance-monitoring <strong>and</strong> debugging applications, as well as testability <strong>and</strong>program execution tracing.This instruction writes the contents of the EDX:EAX register pair into a 64-bit modelspecificregister specified in the ECX register. The 32 bits in the EDX register aremapped into the high-order bits of the model-specific register <strong>and</strong> the 32 bits in EAXform the low-order 32 bits.This instruction must be executed at a privilege level of 0 or a general protection fault#GP(0) will be raised. This exception is also generated if an attempt is made to specifya reserved or unimplemented model-specific register in ECX.WRMSR is a serializing instruction.The CPUID instruction can provide model information useful in determining theexistence of a particular MSR.See <strong>Volume</strong> 2, <strong>System</strong> Programming, for more information about model-specificregisters, machine check architecture, performance monitoring <strong>and</strong> debug registers.Mnemonic Opcode DescriptionWRMSR 0F 30 Write EDX:EAX to the MSR specified by ECX.Related <strong>Instructions</strong>RDMSRrFLAGS AffectedNoneWRMSR 373


AMD64 Technology 24594 Rev. 3.10 February 2005ExceptionsException RealVirtual8086 Protected Cause of ExceptionInvalid Opcode, #UD X X X The WRMSR instruction is not supported, as indicated by EDX bit 5returned by CPUID function 1 or 8000_0001h.<strong>General</strong> protection,#GPXXXXCPL was not 0.The value in ECX specifies a reserved or unimplemented MSRaddress.XXWriting 1 to any bit that must be zero (MBZ) in the MSR.374 WRMSR


24594 Rev. 3.10 February 2005 AMD64 TechnologyAppendix AOpcode <strong>and</strong> Oper<strong>and</strong> EncodingsA.1 Opcode-Syntax NotationThis section specifies the hexadecimal <strong>and</strong>/or binary encodingsfor the opcodes <strong>and</strong> the implicit oper<strong>and</strong> references used in theAMD64 instruction set. For an overview of the instructionformats to which these encodings apply, see Chapter 1,“Instruction Formats.”The following notation is used in this section to specify opcodes<strong>and</strong> their oper<strong>and</strong>s:ACDEFGIJMOPPRQFar pointer is encoded in the instruction.Control register specified by the ModRM reg field.Debug register specified by the ModRM reg field.<strong>General</strong> purpose register or memory oper<strong>and</strong> specified bythe ModRM byte. Memory addresses can be computedfrom a segment register, SIB byte, <strong>and</strong>/or displacement.rFLAGS register.<strong>General</strong> purpose register specified by the ModRM regfield.Immediate value.The instruction includes a relative offset that is added tothe rIP.A memory oper<strong>and</strong> specified by the ModRM byte.The offset of an oper<strong>and</strong> is encoded in the instruction.There is no ModRM byte in the instruction. Complexaddressing using the SIB byte cannot be done.64-bit MMX register specified by the ModRM reg field.64-bit MMX register specified by the ModRM r/m field.The ModRM mod field must be 11b.64-bit MMX-register or memory oper<strong>and</strong> specified by theModRM byte. Memory addresses can be computed from asegment register, SIB byte, <strong>and</strong>/or displacement.Appendix A: Opcode <strong>and</strong> Oper<strong>and</strong> Encodings 375


AMD64 Technology 24594 Rev. 3.10 February 2005RSVVRWXYabddqppdpipsqssd<strong>General</strong> purpose register specified by the ModRM r/mfield. The ModRM mod field must be 11b.Segment register specified by the ModRM reg field.128-bit XMM register specified by the ModRM reg field.128-bit XMM register specified by the ModRM r/m field.The ModRM mod field must be 11b.A 128-bit XMM register or memory oper<strong>and</strong> specified bythe ModRM byte. Memory addresses can be computedfrom a segment register, SIB byte, <strong>and</strong>/or displacement.A memory oper<strong>and</strong> addressed by the DS.rSI registers. Usedin string instructions.A memory oper<strong>and</strong> addressed by the ES.rDI registers.Used in string instructions.Two 16-bit or 32-bit memory oper<strong>and</strong>s, depending on theeffective oper<strong>and</strong> size. Used in the BOUND instruction.A byte, irrespective of the effective oper<strong>and</strong> size.A doubleword (32 bits), irrespective of the effectiveoper<strong>and</strong> size.A double-quadword (128 bits), irrespective of the effectiveoper<strong>and</strong> size.A 32-bit or 48-bit far pointer, depending on the effectiveoper<strong>and</strong> size.A 128-bit double-precision floating-point vector oper<strong>and</strong>(packed double).A 64-bit MMX oper<strong>and</strong> (packed integer).A 128-bit single-precision floating-point vector oper<strong>and</strong>(packed single).A quadword, irrespective of the effective oper<strong>and</strong> size.A 6-byte or 10-byte pseudo-descriptor.A scalar double-precision floating-point oper<strong>and</strong> (scalardouble).376 Appendix A: Opcode <strong>and</strong> Oper<strong>and</strong> Encodings


24594 Rev. 3.10 February 2005 AMD64 TechnologysissvwzA scalar doubleword (32-bit) integer oper<strong>and</strong> (scalarinteger).A scalar single-precision floating-point oper<strong>and</strong> (scalarsingle).A word, doubleword, or quadword, depending on theeffective oper<strong>and</strong> size.A word, irrespective of the effective oper<strong>and</strong> size.A word if the effective oper<strong>and</strong> size is 16 bits, or adoubleword if the effective oper<strong>and</strong> size is 32 or 64 bits.A.2 Opcode Encodings/n A ModRM-byte reg field or SIB-byte base field that containsa value (n) between zero (binary 000) <strong>and</strong> 7 (binary 111).For definitions of the mnemonics used to name registers, see“Summary of Registers <strong>and</strong> Data Types” on page 30.A.2.1 One-ByteOpcodesTable A-1 on page 378 shows the one-byte opcodes in which thelow nibble is in the range 0–7h. Table A-2 on page 379 showsthose opcodes in which the low nibble is in the range 8–Fh. Inboth tables, the rows show the full range (0–Fh) of the highnibble, <strong>and</strong> the columns show the specified range of the lownibble.Appendix A: Opcode <strong>and</strong> Oper<strong>and</strong> Encodings 377


AMD64 Technology 24594 Rev. 3.10 February 2005Table A-1. One-Byte Opcodes, Low Nibble 0–7hNibble 1 0 1 2 3 4 5 6 70ADD PUSH POPEb, Gb Ev, Gv Gb, Eb Gv, Ev AL, Ib rAX, Iz ES 3 ES 31ADC PUSH POPEb, Gb Ev, Gv Gb, Eb Gv, Ev AL, Ib rAX, Iz SS 3 SS 32AND seg ES 6 DAA 3Eb, Gb Ev, Gv Gb, Eb Gv, Ev AL, Ib rAX, Iz3XOR seg SS 6 AAA 3Eb, Gb Ev, Gv Gb, Eb Gv, Ev AL, Ib rAX, Iz4INC 5eAX eCX eDX eBX eSP eBP eSI eDI5PUSHrAX/r8 rCX/r9 rDX/r10 rBX/r11 rSP/r12 rBP/r13 rSI/r14 rDI/r156PUSHA/D 3 POPA/D 3 BOUND 3 ARPL 3addressseg FS seg GS oper<strong>and</strong> sizeGv, Ma Ew, GwsizeMOVSXD 4Gv, Ed7JO JNO JB JNB JZ JNZ JBE JNBEJb Jb Jb Jb Jb Jb Jb Jb8Group 1 2 TEST XCHGEb, Ib Ev, Iz Eb, Ib 3 Ev, Ib Eb, Gb Ev, Gv Eb, Gb Ev, GvXCHG9 r8, rAXNOPrCX/r9, rAX rDX/r10, rAX rBX/r11, rAX rSP/r12, rAX rBP/r13, rAX rSI/r14, rAX rDI/r15, rAXAMOV MOVSB MOVSW/D/Q CMPSB CMPSW/D/QAL, Ob rAX, Ov Ob, AL Ov, rAX Yb, Xb Yv, Xv Xb, Yb Xv, YvMOVBAL, Ibr8b, IbCL, Ibr9b, IbDL, Ibr10b, IbBL, Ibr11b, IbAH, Ibr12b, IbCH, Ibr13b, IbDH, Ibr14b, IbBH, Ibr15b, IbGroup 2C2 RET near LES 3 LDS 3 Group 11 2Eb, Ib Ev, Ib Iw Gz, Mp Gz, Mp Eb, Ib Ev, IzGroup 2D2 AAM 3 AAD 3 SALC 3 XLATEb, 1 Ev, 1 Eb, CL Ev, CLLOOPNE/NZ LOOPE/Z LOOP JrCXZ IN OUTEJb Jb Jb Jb AL, Ib eAX, Ib Ib, AL Ib, eAXLOCK: INT1 REPNE: REP: HLT CMC Group 3F2ICE BkptREPE:Note:1. Rows in this table show the high opcode nibble, columns show the low opcode nibble.2. An opcode extension is specified in bits 5–3 of the ModRM byte. See “ModRM Extensions to One-Byte <strong>and</strong> Two-Byte Opcodes” onpage 387 for details.3. Invalid in 64-bit mode.4. Valid only in 64-bit mode.5. Used as REX prefixes in 64-bit mode.6. This is a null prefix in 64-bit mode.378 Appendix A: Opcode <strong>and</strong> Oper<strong>and</strong> Encodings


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable A-2.One-Byte Opcodes, Low Nibble 8–FhNibble 1 8 9 A B C D E F0OR PUSH 2-byteEb, Gb Ev, Gv Gb, Eb Gv, Ev AL, Ib rAX, Iz CS 3 opcodes1SBB PUSH POPEb, Gb Ev, Gv Gb, Eb Gv, Ev AL, Ib rAX, Iz DS 3 DS 32SUB seg CS 6 DAS 3Eb, Gb Ev, Gv Gb, Eb Gv, Ev AL, Ib rAX, Iz3CMP seg DS 6 AAS 3Eb, Gb Ev, Gv Gb, Eb Gv, Ev AL, Ib rAX, Iz4DEC 5eAX eCX eDX eBX eSP eBP eSI eDI5POPrAX/r8 rCX/r9 rDX/r10 rBX/r11 rSP/r12 rBP/r13 rSI/r14 rDI/r156PUSH IMUL PUSH IMUL INSB INSW/D OUTSB OUTSW/DIz Gv, Ev, Iz Ib Gv, Ev, Ib Yb, DX Yz, DX DX, Xb DX, Xz7JS JNS JP JNP JL JNL JLE JNLEJb Jb Jb Jb Jb Jb Jb Jb8MOV LEA MOV Group 1a 2Eb, Gb Ev, Gv Gb, Eb Gv, Ev Mw/Rv, Sw Gv, M Sw, Ew Ev9CBW, CWDE CWD, CDQ, CALL 3 WAIT PUSHF/D/Q POPF/D/Q SAHF LAHFCDQE CQO Ap FWAIT Fv FvATEST STOSB STOSW/D/Q LODSB LODSW/D/Q SCASB SCASW/D/QAL, Ib rAX, Iz Yb, AL Yv, rAX AL, Xb rAX, Xv AL, Yb rAX, YvMOVB rAX, Ivr8, IvrCX, Ivr9, IvrDX, Ivr10, IvrBX, Ivr11, IvrSP, Ivr12, IvrBP, Ivr13, IvrSI, Ivr14, IvrDI, Ivr15, IvCENTER LEAVE RET far INT3 INT INTO 3 IRET, IRETDIw, Ib Iw Ib IRETQDx87see Table A-10 on page 394ECALL JMP IN OUTJz Jz Ap 3 Jb AL, DX eAX, DX DX, AL DX, eAXFCLC STC CLI STI CLD STD Group 4 2 Group 5 2EbNote:1. Rows in this table show the high opcode nibble, columns show the low opcode nibble.2. An opcode extension is specified in bits 5–3 of the ModRM byte. See “ModRM Extensions to One-Byte <strong>and</strong> Two-Byte Opcodes” onpage 387 for details.3. Invalid in 64-bit mode.4. Valid only in 64-bit mode.5. Used as REX prefixes in 64-bit mode.6. This is a null prefix in 64-bit mode.Appendix A: Opcode <strong>and</strong> Oper<strong>and</strong> Encodings 379


AMD64 Technology 24594 Rev. 3.10 February 2005A.2.2 Two-ByteOpcodesAll two-byte opcodes have 0Fh as their first byte. Table A-3below shows the second byte of the two-byte opcodes in whichthe second byte’s low nibble is in the range 0–7h. Table A-4 onpage 383 shows those opcodes in which the second byte’s lownibble is in the range 8–Fh. In both tables, the rows show thefull range (0–Fh) of the high nibble, <strong>and</strong> the columns show thelow nibble of the opcode. The left-most column shows specialpurposeprefix bytes used in many 128-bit <strong>and</strong> 64-bitinstructions to modify the opcode.Table A-3. Second Byte of Two-Byte Opcodes, Low Nibble 0–7hPrefix Nibble 1 0 1 2 3 4 5 6 7n/a 0noneF3 166F2n/a 2n/a 3Group 6 2 Group 7 2 LAR LSL invalid SYSCALL CLTS SYSRETGv, Ew Gv, EwMOVUPSMOVLPSVps, MqMOVHLPSMOVLPS UNPCKLPS UNPCKHPSMOVHPSVps, MqMOVLHPSMOVHPSVps, Wps Wps, Vps Vps, VRq Mq, Vps Vps, Wq Vps, Wq Vps, VRq Mq, VpsMOVSS MOVSLDUP invalid invalid invalid MOVSHDUP invalidVdq/ss, Wss Wss, Vss Vps, Wps Vps, WpsMOVUPD MOVLPD UNPCKLPD UNPCKHPD MOVHPDVpd, Wpd Wpd, Vpd Vsd, Mq Mq, Vsd Vpd, Wq Vpd, Wq Vsd, Mq Mq, VsdMOVSD MOVDDUP invalid invalid invalid invalid invalidVdq/sd, Wsd Wsd, Vsd Vpd,WsdMOV invalid invalid invalid invalidRd/q, Cd/q Rd/q, Dd/q Cd/q, Rd/q Dd/q, Rd/qWRMSR RDTSC RDMSR RDPMC SYSENTER 3 SYSEXIT 3 invalid invalidn/a 4CMOVO CMOVNO CMOVB CMOVNB CMOVZ CMOVNZ CMOVBE CMOVNBEGv, Ev Gv, Ev Gv, Ev Gv, Ev Gv, Ev Gv, Ev Gv, Ev Gv, EvnoneMOVMSKPS SQRTPS RSQRTPS RCPPS ANDPS ANDNPS ORPS XORPSGd, VRps Vps, Wps Vps, Wps Vps, Wps Vps, Wps Vps, Wps Vps, Wps Vps, Wpsinvalid SQRTSS RSQRTSS RCPSS invalid invalid invalid invalidF3Vss, Wss Vss, Wss Vss, Wss5MOVMSKPD SQRTPD invalid invalid ANDPD ANDNPD ORPD XORPD66Gd, VRpd Vpd, Wpd Vpd, Wpd Vpd, Wpd Vpd, Wpd Vpd, WpdF2invalid SQRTSD invalid invalid invalid invalid invalid invalidVsd, WsdNote:1. All two-byte opcodes begin with an OFh byte. Rows in the table show the high nibble of the second opcode bytes, columns showthe low nibble of this byte.2. An opcode extension is specified in bits 5–3 of the ModRM byte. See “ModRM Extensions to One-Byte <strong>and</strong> Two-Byte Opcodes” onpage 387 for details.3. Invalid in long mode.380 Appendix A: Opcode <strong>and</strong> Oper<strong>and</strong> Encodings


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable A-3.Second Byte of Two-Byte Opcodes, Low Nibble 0–7h (continued)Prefix Nibble 1 0 1 2 3 4 5 6 7nonePUNPCKLBW PUNPCKLWD PUNPCKLDQ PACKSSWB PCMPGTB PCMPGTW PCMPGTD PACKUSWBPq, Qd Pq, Qd Pq, Qd Pq, Qq Pq, Qq Pq, Qq Pq, Qq Pq, QqF3invalid invalid invalid invalid invalid invalid invalid invalid6PUNPCKLBW PUNPCKLWD PUNPCKLDQ PACKSSWB PCMPGTB PCMPGTW PCMPGTD PACKUSWB66 Vdq, Wq Vdq, Wq Vdq, Wq Vdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, WdqF2invalid invalid invalid invalid invalid invalid invalid invalidnonePSHUFW Group 12 2 Group 13 2 Group 14 2 PCMPEQB PCMPEQW PCMPEQD EMMSPq, Qq, Ib Pq, Qq Pq, Qq Pq, QqPSHUFHW invalid invalid invalid invalid invalid invalid invalidF3Vq, Wq, Ib7PSHUFD Group 1266Group 13 2 Group 14 2 PCMPEQB PCMPEQW PCMPEQD invalidVdq, Wdq, Ib Vdq, Wdq Vdq, Wdq Vdq, WdqF2PSHUFLW invalid invalid invalid invalid invalid invalid invalidVq, Wq, Ibn/a 8JO JNO JB JNB JZ JNZ JBE JNBEJz Jz Jz Jz Jz Jz Jz Jzn/a 9SETO SETNO SETB SETNB SETZ SETNZ SETBE SETNBEEb Eb Eb Eb Eb Eb Eb Ebn/a APUSH POP CPUID BT SHLD invalid invalidFS FS Ev, Gv Ev, Gv, Ib Ev, Gv, CLn/a BCMPXCHG LSS BTR LFS LGS MOVZXEb, Gb Ev, Gv Gz, Mp Ev, Gv Gz, Mp Gz, Mp Gv, Eb Gv, EwnoneXADD CMPPS MOVNTI PINSRW PEXTRW SHUFPS Group 9 2Vps, Wps, Ib Md/q, Gd/q Pq, Ew, Ib Gd, PRq, Ib Vps, Wps, IbCMPSS invalid invalid invalid invalidF3Vss, Wss, IbCEb, Gb Ev, Gv CMPPD invalid PINSRW PEXTRW SHUFPD Mq66Vpd, Wpd, Ib Vdq, Ew, Ib Gd, VRdq, Ib Vpd, Wpd, IbF2CMPSD invalid invalid invalid invalidVsd, Wsd, IbNote:1. All two-byte opcodes begin with an OFh byte. Rows in the table show the high nibble of the second opcode bytes, columns showthe low nibble of this byte.2. An opcode extension is specified in bits 5–3 of the ModRM byte. See “ModRM Extensions to One-Byte <strong>and</strong> Two-Byte Opcodes” onpage 387 for details.3. Invalid in long mode.Appendix A: Opcode <strong>and</strong> Oper<strong>and</strong> Encodings 381


AMD64 Technology 24594 Rev. 3.10 February 2005Table A-3.Second Byte of Two-Byte Opcodes, Low Nibble 0–7h (continued)Prefix Nibble 1 0 1 2 3 4 5 6 7noneF366F2noneF366F2noneF3DEinvalid PSRLW PSRLD PSRLQ PADDQ PMULLW invalid PMOVMSKBPq, Qq Pq, Qq Pq, Qq Pq, Qq Pq, Qq Gd, PRqinvalid invalid invalid invalid invalid invalid MOVQ2DQ invalidVdq, PRqADDSUBPD PSRLW PSRLD PSRLQ PADDQ PMULLW MOVQ PMOVMSKBVpd, Wpd Vdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdq Wq, Vq Gd, VRdqADDSUBPS invalid invalid invalid invalid invalid MOVDQ2Q invalidVps, WpsPq, VRqPAVGB PSRAW PSRAD PAVGW PMULHUW PMULHW invalid MOVNTQPq, Qq Pq, Qq Pq, Qq Pq, Qq Pq, Qq Pq, Qq Mq, Pqinvalid invalid invalid invalid invalid invalid CVTDQ2PD invalidVpd, WqPAVGB PSRAW PSRAD PAVGW PMULHUW PMULHW CVTTPD2DQ MOVNTDQVdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdq Vq, Wpd Mdq, Vdqinvalid invalid invalid invalid invalid invalid CVTPD2DQ invalidVq, Wpdinvalid PSLLW PSLLD PSLLQ PMULUDQ PMADDWD PSADBW MASKMOVQPq, Qq Pq, Qq Pq, Qq Pq, Qq Pq, Qq Pq, Qq Pq, PRqinvalid invalid invalid invalid invalid invalid invalid invalidFMASKinvalidPSLLW PSLLD PSLLQ PMULUDQ PMADDWD PSADBW66MOVDQUVdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, VRdqLDDQU invalid invalid invalid invalid invalid invalid invalidF2Vpd,MdqNote:1. All two-byte opcodes begin with an OFh byte. Rows in the table show the high nibble of the second opcode bytes, columns showthe low nibble of this byte.2. An opcode extension is specified in bits 5–3 of the ModRM byte. See “ModRM Extensions to One-Byte <strong>and</strong> Two-Byte Opcodes” onpage 387 for details.3. Invalid in long mode.382 Appendix A: Opcode <strong>and</strong> Oper<strong>and</strong> Encodings


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable A-4.Second Byte of Two-Byte Opcodes, Low Nibble 8–FhPrefix Nibble 1 8 9 A B C D E Fn/a 0n/a 1INVD WBINVD invalid UD2 invalid Group P 2 FEMMS 3DNow!PREFETCHSee“3DNow!Opcodes” onpage 390Group 16 2 NOP 3 NOP 3 NOP 3 NOP 3 NOP 3 NOP 3 NOP 3noneF3266F2n/a 3n/a 4noneF3566F2noneF3666F2MOVAPS CVTPI2PS MOVNTPS CVTTPS2PI CVTPS2PI UCOMISS COMISSVps, Wps Wps, Vps Vps, Qq Mdq, Vps Pq, Wps Pq, Wps Vss, Wss Vps, Wpsinvalid invalid CVTSI2SS invalid CVTTSS2SI CVTSS2SI invalid invalidVss, Ed/q Gd/q, Wss Gd/q, WssMOVAPD CVTPI2PD MOVNTPD CVTTPD2PI CVTPD2PI UCOMISD COMISDVpd, Wpd Wpd, Vpd Vpd, Qq Mdq, Vpd Pq, Wpd Pq, Wpd Vsd, Wsd Vpd, Wsdinvalid invalid CVTSI2SD invalid CVTTSD2SI CVTSD2SI invalid invalidVsd, Ed/q Gd/q, Wsd Gd/q, Wsdinvalid invalid invalid invalid invalid invalid invalid invalidCMOVS CMOVNS CMOVP CMOVNP CMOVL CMOVNL CMOVLE CMOVNLEGv, Ev Gv, Ev Gv, Ev Gv, Ev Gv, Ev Gv, Ev Gv, Ev Gv, EvADDPS MULPS CVTPS2PD CVTDQ2PS SUBPS MINPS DIVPS MAXPSVps, Wps Vps, Wps Vpd, Wps Vps, Wdq Vps, Wps Vps, Wps Vps, Wps Vps, WpsADDSS MULSS CVTSS2SD CVTTPS2DQ SUBSS MINSS DIVSS MAXSSVss, Wss Vss, Wss Vsd, Wss Vdq, Wps Vss, Wss Vss, Wss Vss, Wss Vss, WssADDPD MULPD CVTPD2PS CVTPS2DQ SUBPD MINPD DIVPD MAXPDVpd, Wpd Vpd, Wpd Vps, Wpd Vdq, Wps Vpd, Wpd Vpd, Wpd Vpd, Wpd Vpd, WpdADDSD MULSD CVTSD2SS invalid SUBSD MINSD DIVSD MAXSDVsd, Wsd Vsd, Wsd Vss, Wsd Vsd, Wsd Vsd, Wsd Vsd, Wsd Vsd, WsdPUNPCK-HBWPUNPCK-HWDPUNPCK-HDQPACKSSDW invalid invalid MOVD MOVQPq, Qd Pq, Qd Pq, Qd Pq, Qq Pq, Ed/q Pq, Qqinvalid invalid invalid invalid invalid invalid invalid MOVDQUVdq, WdqPUNPCK-HBWPUNPCK-HWDPUNPCK-HDQPACKSSDWPUNPCK-LQDQPUNPCK-HQDQMOVDMOVDQAVdq, Wq Vdq, Wq Vdq, Wq Vdq, Wdq Vdq, Wq Vdq, Wq Vdq, Ed/q Vdq, Wdqinvalid invalid invalid invalid invalid invalid invalid invalidNote:1. All two-byte opcodes begin with an OFh byte. Rows show high opcode nibble (hex), columns show low opcode nibble in hex.2. An opcode extension is specified in the ModRM reg field (bits 5–3). See “ModRM Extensions to One-Byte <strong>and</strong> Two-Byte Opcodes”on page 387 for details.3. This instruction takes a ModRM byte.Appendix A: Opcode <strong>and</strong> Oper<strong>and</strong> Encodings 383


AMD64 Technology 24594 Rev. 3.10 February 2005Table A-4.Second Byte of Two-Byte Opcodes, Low Nibble 8–Fh (continued)Prefix Nibble 1 8 9 A B C D E Fnoneinvalid invalid invalid invalid invalid invalid MOVD MOVQEd/q, Pd/q Qq, Pqinvalid invalid invalid invalid invalid invalid MOVQ MOVDQUF3Vq, Wq Wdq, Vdq7invalid invalid invalid invalid HADDPD HSUBPD MOVD MOVDQA66 Vpd,Wpd Vpd,Wpd Ed/q, Vd/q Wdq, VdqF2invalid invalid invalid invalid HADDPS HSUBPS invalid invalidVps,Wps Vps,Wpsn/a 8JS JNS JP JNP JL JNL JLE JNLEJz Jz Jz Jz Jz Jz Jz Jzn/a 9SETS SETNS SETP SETNP SETL SETNL SETLE SETNLEEb Eb Eb Eb Eb Eb Eb Ebn/a APUSH POP RSM BTS SHRD Group 15 2 IMULGS GS Ev, Gv Ev, Gv, Ib Ev, Gv, CL Gv, Evn/a Binvalid Group 10 2 Group 8 2 BTC BSF BSR MOVSXEv, Ib Ev, Gv Gv, Ev Gv, Ev Gv, Eb Gv, Ewn/a CBSWAPrAX/r8 rCX/r9 rDX/r10 rBX/r11 rSP/r12 rBP/r13 rSI/r14 rDI/r15nonePSUBUSB PSUBUSW PMINUB PAND PADDUSB PADDUSW PMAXUB PANDNPq, Qq Pq, Qq Pq, Qq Pq, Qq Pq, Qq Pq, Qq Pq, Qq Pq, QqF3invalid invalid invalid invalid invalid invalid invalid invalid66DPSUBUSB PSUBUSW PMINUB PAND PADDUSB PADDUSW PMAXUB PANDNVdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, WdqF2invalid invalid invalid invalid invalid invalid invalid invalidnoneF366F2EPSUBSB PSUBSW PMINSW POR PADDSB PADDSW PMAXSW PXORPq, Qq Pq, Qq Pq, Qq Pq, Qq Pq, Qq Pq, Qq Pq, Qq Pq, Qqinvalid invalid invalid invalid invalid invalid invalid invalidPSUBSB PSUBSW PMINSW POR PADDSB PADDSW PMAXSW PXORVdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdqinvalid invalid invalid invalid invalid invalid invalid invalidNote:1. All two-byte opcodes begin with an OFh byte. Rows show high opcode nibble (hex), columns show low opcode nibble in hex.2. An opcode extension is specified in the ModRM reg field (bits 5–3). See “ModRM Extensions to One-Byte <strong>and</strong> Two-Byte Opcodes”on page 387 for details.3. This instruction takes a ModRM byte.384 Appendix A: Opcode <strong>and</strong> Oper<strong>and</strong> Encodings


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable A-4.Second Byte of Two-Byte Opcodes, Low Nibble 8–Fh (continued)Prefix Nibble 1 8 9 A B C D E FnoneF366F2FPSUBB PSUBW PSUBD PSUBQ PADDB PADDW PADDD invalidPq, Qq Pq, Qq Pq, Qq Pq, Qq Pq, Qq Pq, Qq Pq, Qqinvalid invalid invalid invalid invalid invalid invalid invalidPSUBB PSUBW PSUBD PSUBQ PADDB PADDW PADDD invalidVdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdq Vdq, Wdqinvalid invalid invalid invalid invalid invalid invalid invalidNote:1. All two-byte opcodes begin with an OFh byte. Rows show high opcode nibble (hex), columns show low opcode nibble in hex.2. An opcode extension is specified in the ModRM reg field (bits 5–3). See “ModRM Extensions to One-Byte <strong>and</strong> Two-Byte Opcodes”on page 387 for details.3. This instruction takes a ModRM byte.Appendix A: Opcode <strong>and</strong> Oper<strong>and</strong> Encodings 385


AMD64 Technology 24594 Rev. 3.10 February 2005A.2.3 rFLAGSCondition Codes forTwo-Byte OpcodesTable A-5 shows the rFLAGS condition codes specified by thelow nibble in the second opcode byte of the CMOVcc, Jcc, <strong>and</strong>SETcc instructions.Table A-5.rFLAGS Condition Codes for CMOVcc, Jcc, <strong>and</strong> SETccLow Nibble ofSecond OpcodeByte (hex)rFLAGS Valuecc MnemonicArithmeticTypeCondition(s)0 OF= 1 OOverflowSigned1 OF= 0 NO No Overflow2 CF= 1 B, C, NAEBelow, Carry, Not Above or Equal3 CF = 0 NB, NC, AE Not Below, No Carry, Above or Equal4 ZF = 1 Z, E Zero, EqualUnsigned5 ZF = 0 NZ, NE Not Zero, Not Equal6 CF = 1 or ZF = 1 BE, NA Below or Equal, Not Above7 CF = 0 <strong>and</strong> ZF = 0 NBE, A Not Below or Equal, Above8 SF =1 SSignSigned9 SF = 0 NS Not SignA PF= 1 P, PEParity, Parity Evenn/aB PF = 0 NP, PO Not Parity, Parity OddC (SF xor OF) =1 L, NGESignedLess than, Not Greater than or Equal toD (SF xor OF) = 0 NL, GE Not Less than, Greater than or Equal toEF(SF xor OF) = 1or ZF = 1(SF xor OF) = 0<strong>and</strong> ZF = 0LE, NGNLE, GLess than or Equal to, Not Greater thanNot Less than or Equal to, Greater than386 Appendix A: Opcode <strong>and</strong> Oper<strong>and</strong> Encodings


24594 Rev. 3.10 February 2005 AMD64 TechnologyA.2.4 ModRMExtensions to One-Byte <strong>and</strong> Two-ByteOpcodesThe ModRM byte, which immediately follows the last opcodebyte, is used in certain instruction encodings to provideadditional opcode bits with which to define the function of theinstruction. ModRM bytes have three fields—mod, reg, <strong>and</strong> r/m,as shown in Figure A-1.Bits:7 6 5 4 3 2 1 0mod reg r/m ModRM513-325.epsFigure A-1.ModRM-Byte FieldsIn most cases, the reg field (bits 5–3) provides the additionalbits with which to extend the encodings of the first one or twoopcode bytes. In the case of the x87 floating-point instructions,the entire ModRM byte is used to extend the opcode encodings.Table A-6 on page 388 shows how the ModRM reg field is used toextend the range of one-byte <strong>and</strong> two-byte opcodes. The opcoderanges are organized into groups of opcode extensions. Thegroup number is shown in the left-most column of Table A-6.These groups are referenced in the opcodes shown in Table A-1on page 378 through Table A-4 on page 383. An entry of “n.a.”in the Prefix column means that prefixes are not applicable tothe opcodes in that row. Prefixes only apply to certain 128-bitmedia, 64-bit media, <strong>and</strong> a few other instructions introducedwith the SSE or SSE2 technologies.The /0 through /7 notation for the ModRM reg field (bits 5–3)means that the three-bit field contains a value from zero (binary000) to 7 (binary 111).Appendix A: Opcode <strong>and</strong> Oper<strong>and</strong> Encodings 387


AMD64 Technology 24594 Rev. 3.10 February 2005Table A-6.GroupNumberGroup 1One-Byte <strong>and</strong> Two-Byte Opcode ModRM ExtensionsPrefix Opcoden/a80818283Group 1a n/a 8FGroup 2Group 3n/an/aC0C1D0D1D2D3F6F7ModRM reg Field/0 /1 /2 /3 /4 /5 /6 /7ADD OR ADC SBB AND SUB XOR CMPEb, Ib Eb, Ib Eb, Ib Eb, Ib Eb, Ib Eb, Ib Eb, Ib Eb, IbADD OR ADC SBB AND SUB XOR CMPEv, Iz Ev, Iz Ev, Iz Ev, Iz Ev, Iz Ev, Iz Ev, Iz Ev, IzADD OR ADC SBB AND SUB XOR CMPEb, Ib 2 Eb, Ib 2 Eb, Ib 2 Eb, Ib 2 Eb, Ib 2 Eb, Ib 2 Eb, Ib 2 Eb, Ib 2ADD OR ADC SBB AND SUB XOR CMPEv, Ib Ev, Ib Ev, Ib Ev, Ib Ev, Ib Ev, Ib Ev, Ib Ev, IbPOP invalid invalid invalid invalid invalid invalid invalidEvROL ROR RCL RCR SHL/SAL SHR SHL/SAL SAREb, Ib Eb, Ib Eb, Ib Eb, Ib Eb, Ib Eb, Ib Eb, Ib Eb, IbROL ROR RCL RCR SHL/SAL SHR SHL/SAL SAREv, Ib Ev, Ib Ev, Ib Ev, Ib Ev, Ib Ev, Ib Ev, Ib Ev, IbROL ROR RCL RCR SHL/SAL SHR SHL/SAL SAREb, 1 Eb, 1 Eb, 1 Eb, 1 Eb, 1 Eb, 1 Eb, 1 Eb, 1ROL ROR RCL RCR SHL/SAL SHR SHL/SAL SAREv, 1 Ev, 1 Ev, 1 Ev, 1 Ev, 1 Ev, 1 Ev, 1 Ev, 1ROL ROR RCL RCR SHL/SAL SHR SHL/SAL SAREb, CL Eb, CL Eb, CL Eb, CL Eb, CL Eb, CL Eb, CL Eb, CLROL ROR RCL RCR SHL/SAL SHR SHL/SAL SAREv, CL Ev, CL Ev, CL Ev, CL Ev, CL Ev, CL Ev, CL Ev, CLTESTEb,IbTESTEv,IzNOT NEG MUL IMUL DIV IDIVEb Eb Eb Eb Eb EbNOT NEG MUL IMUL DIV IDIVEv Ev Ev Ev Ev EvGroup 4 n/a FEINC DEC invalid invalid invalid invalid invalid invalidEb EbGroup 5 n/a FFINC DEC CALL CALL JMP JMP PUSH invalidEv Ev Ev Mp Ev Mp EvGroup 6 n/a 0F 00SLDT STR LLDT LTR VERR VERW invalid invalidMw/Rv Mw/Rv Ew Ew Ew EwGroup 7 n/a 0F 01SGDT SIDT LGDT LIDT SMSW invalid LMSW INVLPG MbMs Ms Ms Ms Mw/Rv Ew SWAPGS 1Group 8 n/a 0F BAinvalid invalid invalid invalid BT BTS BTR BTCEv, Ib Ev, Ib Ev, Ib Ev, IbNote:1. See Table A-7 on page 390 for ModRM extensions of this two-byte opcode to encode SWAPGS.2. Invalid in 64-bit mode.3. See Table A-7 on page 390 for ModRM extensions of this two-byte opcode to encode LFENCE, MFENCE, <strong>and</strong> SFENCE.4. This instruction takes a ModRM byte.5. Reserved prefetch encodings are aliased to the /0 encoding (PREFETCH Exclusive) for future compatibility.388 Appendix A: Opcode <strong>and</strong> Oper<strong>and</strong> Encodings


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable A-6.GroupNumberOne-Byte <strong>and</strong> Two-Byte Opcode ModRM Extensions (continued)Prefix OpcodeGroup 9 n/a 0F C7Group 10 n/a 0F B9ModRM reg Field/0 /1 /2 /3 /4 /5 /6 /7invalid CMPXCHG8B invalid invalid invalid invalid invalid invalidMqCMPXCHG16Mdqinvalid invalid invalid invalid invalid invalid invalid invalidGroup 11Group 12n/an/anone66F2, F3C6C70F 71MOV invalid invalid invalid invalid invalid invalid invalidEb,IbMOV invalid invalid invalid invalid invalid invalid invalidEv,Izinvalid invalid PSRLW invalid PSRAW invalid PSLLW invalidPRq, Ib PRq, Ib PRq, Ibinvalid invalid PSRLW invalid PSRAW invalid PSLLW invalidVRdq, Ib VRdq, Ib VRdq, Ibinvalid invalid invalid invalid invalid invalid invalid invalidGroup 13none66F2, F30F 72invalid invalid PSRLD invalid PSRAD invalid PSLLD invalidPRq, Ib PRq, Ib PRq, Ibinvalid invalid PSRLD invalid PSRAD invalid PSLLD invalidVRdq, Ib VRdq, Ib VRdq, Ibinvalid invalid invalid invalid invalid invalid invalid invalidGroup 14none66F2, F30F 73invalid invalid PSRLQ invalid invalid invalid PSLLQ invalidPRq, IbPRq, Ibinvalid invalid PSRLQ PSRLDQ invalid invalid PSLLQ PSLLDQVRdq, Ib VRdq, Ib VRdq, Ib VRdq, Ibinvalid invalid invalid invalid invalid invalid invalid invalidGroup 15none66,F2, F30F AEFXSAVE FXRSTOR LDMXCSR STMXCSR invalid LFENCE 3 MFENCE 3 SFENCE 3M M Md MdCLFLUSHMbinvalid invalid invalid invalid invalid invalid invalid invalidGroup 16 n/a. 0F 18PREFETCH PREFETCH PREFETCH PREFETCH NOP 4 NOP 4 NOP 4 NOP 4NTA T0 T1 T2Group P n/a. 0F 0DPREFETCH PREFETCH Prefetch PREFETCH Prefetch Prefetch Prefetch PrefetchExclusive Modified Reserved 5 Modified Reserved 5 Reserved 5 Reserved 5 Reserved 5Note:1. See Table A-7 on page 390 for ModRM extensions of this two-byte opcode to encode SWAPGS.2. Invalid in 64-bit mode.3. See Table A-7 on page 390 for ModRM extensions of this two-byte opcode to encode LFENCE, MFENCE, <strong>and</strong> SFENCE.4. This instruction takes a ModRM byte.5. Reserved prefetch encodings are aliased to the /0 encoding (PREFETCH Exclusive) for future compatibility.Appendix A: Opcode <strong>and</strong> Oper<strong>and</strong> Encodings 389


AMD64 Technology 24594 Rev. 3.10 February 2005A.2.5 ModRMExtensions toOpcodes 0F 01 <strong>and</strong>0F AETable A-7 shows the ModRM r/m field encodings for the 0F 01<strong>and</strong> 0F AE opcodes, shown in Table A-6. The 0F 01 /7 opcode isshared by the INVLPG, SWAPGS, <strong>and</strong> RDTSCP instructions<strong>and</strong> the 0F AE opcode is shared by the LFENCE, MFENCE, <strong>and</strong>SFENCE instructions. The opcodes are differentiated by thefact that the binary value of the ModRM mod field is always 11for SWAPGS, RDTSCP, <strong>and</strong> the xFENCE instructions, <strong>and</strong> anyvalue except 11 for INVLPG <strong>and</strong> CLFLUSH.Table A-7.Opcode0F 01 /7mod=110F 01 /3mod=110F AE /5mod=110F AE /6mod=110F AE /7mod=11Opcode 0F 01 <strong>and</strong> 0F AE ModRM ExtensionsModRM r/m Field0 1 2 3 4 5 6 7SWAPGS RDTSCP invalid invalid invalid invalid invalid invalidinvalid invalid invalid invalid invalid invalid invalid invalidLFENCEMFENCESFENCEA.2.6 3DNow!OpcodesThe 64-bit media instructions include the MMX instructions<strong>and</strong> the AMD 3DNow! instructions. The MMX instructions areencoded using two opcode bytes, as described in “Two-ByteOpcodes” on page 380.The 3DNow! instructions are encoded using two 0Fh opcodebytes <strong>and</strong> an immediate byte that is located at the last byteposition of the instruction encoding. Thus, the format for3DNow! instructions is:0Fh 0Fh [ModRM] [SIB] [displacement] imm8_opcodeTable A-8 on page 391 <strong>and</strong> Table A-9 on page 392 show theimmediate byte following the opcode bytes for 3DNow!instructions. In these tables, rows show the high nibble of theimmediate byte, <strong>and</strong> columns show the low nibble of theimmediate byte. Table A-8 shows the immediate bytes whoselow nibble is in the range 0–7h. Table A-9 shows the same forimmediate bytes whose low nibble is in the range 8–Fh.Byte values shown as reserved in these tables haveimplementation-specific functions, which can include aninvalid-opcode exception.390 Appendix A: Opcode <strong>and</strong> Oper<strong>and</strong> Encodings


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable A-8. Immediate Byte for 3DNow! Opcodes, Low Nibble 0–7hNibble 1 0 1 2 3 4 5 6 70reserved reserved reserved reserved reserved reserved reserved reserved123456789ABCDEFreserved reserved reserved reserved reserved reserved reserved reservedreserved reserved reserved reserved reserved reserved reserved reservedreserved reserved reserved reserved reserved reserved reserved reservedreserved reserved reserved reserved reserved reserved reserved reservedreserved reserved reserved reserved reserved reserved reserved reservedreserved reserved reserved reserved reserved reserved reserved reservedreserved reserved reserved reserved reserved reserved reserved reservedreserved reserved reserved reserved reserved reserved reserved reservedPFCMPGE reserved reserved reserved PFMIN reserved PFRCP PFRSQRTPq, Qq Pq, Qq Pq, Qq Pq, QqPFCMPGT reserved reserved reserved PFMAX reserved PFRCPIT1 PFRSQIT1Pq, Qq Pq, Qq Pq, Qq Pq, QqPFCMPEQ reserved reserved reserved PFMUL reserved PFRCPIT2 PMULHRWPq, Qq Pq, Qq Pq, Qq Pq, Qqreserved reserved reserved reserved reserved reserved reserved reservedreserved reserved reserved reserved reserved reserved reserved reservedreserved reserved reserved reserved reserved reserved reserved reservedreserved reserved reserved reserved reserved reserved reserved reservedNote:1. All 3DNow! opcodes consist of two OFh bytes. This table shows the immediate byte for 3DNow! opcodes. Rows show the highnibble of the immediate byte. Columns show the low nibble of the immediate byte.Appendix A: Opcode <strong>and</strong> Oper<strong>and</strong> Encodings 391


AMD64 Technology 24594 Rev. 3.10 February 2005Table A-9.Immediate Byte for 3DNow! Opcodes, Low Nibble 8–FhNibble 1 8 9 A B C D E F0reserved reserved reserved reserved PI2FW PI2FD reserved reservedPq, Qq Pq, Qq1reserved reserved reserved reserved PF2IW PF2ID reserved reservedPq, Qq Pq, Qq2reserved reserved reserved reserved reserved reserved reserved reserved3456789ABCDEFreserved reserved reserved reserved reserved reserved reserved reservedreserved reserved reserved reserved reserved reserved reserved reservedreserved reserved reserved reserved reserved reserved reserved reservedreserved reserved reserved reserved reserved reserved reserved reservedreserved reserved reserved reserved reserved reserved reserved reservedreserved reserved PFNACC reserved reserved reserved PFPNACC reservedPq, QqPq, Qqreserved reserved PFSUB reserved reserved reserved PFADD reservedPq, QqPq, Qqreserved reserved PFSUBR reserved reserved reserved PFACC reservedPq, QqPq, Qqreserved reserved reserved PSWAPD reserved reserved reserved PAVGUSBPq, QqPq, Qqreserved reserved reserved reserved reserved reserved reserved reservedreserved reserved reserved reserved reserved reserved reserved reservedreserved reserved reserved reserved reserved reserved reserved reservedreserved reserved reserved reserved reserved reserved reserved reservedNote:1. All 3DNow! opcodes consist of two OFh bytes. This table shows the immediate byte for 3DNow! opcodes. Rows show the highnibble of the immediate byte. Columns show the low nibble of the immediate byte.A.2.7 x87 EncodingsAll x87 instructions begin with an opcode byte in the range D8hto DFh, as shown in Table A-2 on page 379. These opcodes arefollowed by a ModRM byte that further defines the opcode.Table A-10 shows both the opcode byte <strong>and</strong> the ModRM byte foreach x87 instruction.392 Appendix A: Opcode <strong>and</strong> Oper<strong>and</strong> Encodings


24594 Rev. 3.10 February 2005 AMD64 TechnologyThere are two significant ranges for the ModRM byte for x87opcodes: 00–BFh <strong>and</strong> C0–FFh. When the value of the ModRMbyte falls within the first range, 00–BFh, the opcode uses onlythe reg field to further define the opcode. When the value of theModRM byte falls within the second range, C0–FFh, the opcodeuses the entire ModRM byte to further define the opcode.Byte values shown as reserved or invalid in Table A-10 haveimplementation-specific functions, which can include aninvalid-opcode exception.The basic instructions FNSTENV, FNSTCW, FNCLEX, FNINIT,FNSAVE, FNSTSW, <strong>and</strong> FNSTSW do not check for possiblefloating point exceptions before operating. Utility versions ofthese mnemonics are provided that insert an FWAIT (opcode9B) before the corresponding non-waiting instruction. These areFSTENV, FSTCW, FCLEX, FINIT, FSAVE, <strong>and</strong> FSTSW. Forfurther information on wait <strong>and</strong> non-waiting versions of theseinstructions, see their corresponding pages in <strong>Volume</strong> 5.Appendix A: Opcode <strong>and</strong> Oper<strong>and</strong> Encodings 393


AMD64 Technology 24594 Rev. 3.10 February 2005Table A-10.x87 Opcodes <strong>and</strong> ModRM ExtensionsOpcodeD8ModRMmodField!1111ModRM reg Field/0 /1 /2 /3 /4 /5 /6 /700–BFFADD FMUL FCOM FCOMP FSUB FSUBR FDIV FDIVRmem32real mem32real mem32real mem32real mem32real mem32real mem32real mem32realC0 C8 D0 D8 E0 E8 F0 F8FADD FMUL FCOM FCOMP FSUB FSUBR FDIV FDIVRST(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 F9FADD FMUL FCOM FCOMP FSUB FSUBR FDIV FDIVRST(0), ST(1) 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(0), ST(1)C2 CA D2 DA E2 EA F2 FAFADD FMUL FCOM FCOMP FSUB FSUBR FDIV FDIVRST(0), ST(2) 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(0), ST(2)C3 CB D3 DB E3 EB F3 FBFADD FMUL FCOM FCOMP FSUB FSUBR FDIV FDIVRST(0), ST(3) 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(0), ST(3)C4 CC D4 DC E4 EC F4 FCFADD FMUL FCOM FCOMP FSUB FSUBR FDIV FDIVRST(0), ST(4) 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(0), ST(4)C5 CD D5 DD E5 ED F5 FDFADD FMUL FCOM FCOMP FSUB FSUBR FDIV FDIVRST(0), ST(5) 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(0), ST(5)C6 CE D6 DE E6 EE F6 FEFADD FMUL FCOM FCOMP FSUB FSUBR FDIV FDIVRST(0), ST(6) 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(0), ST(6)C7 CF D7 DF E7 EF F7 FFFADD FMUL FCOM FCOMP FSUB FSUBR FDIV FDIVRST(0), ST(7) 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(0), ST(7)394 Appendix A: Opcode <strong>and</strong> Oper<strong>and</strong> Encodings


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable A-10.x87 Opcodes <strong>and</strong> ModRM Extensions (continued)OpcodeD9ModRMmodField!1111ModRM reg Field/0 /1 /2 /3 /4 /5 /6 /700–BFFLD invalid FST FSTP FLDENV FLDCW FNSTENV FNSTCWmem32real mem32real mem32real mem14/28env mem16 mem14/28env mem16C0 C8 D0 D8 E0 E8 F0 F8FLD FXCH FNOP reserved FCHS FLD1 F2XM1 FPREMST(0), ST(0) ST(0), ST(0)C1 C9 D1 D9 E1 E9 F1 F9FLD FXCH invalid reserved FABS FLDL2T FYL2X FYL2XP1ST(0), ST(1) ST(0), ST(1)C2 CA D2 DA E2 EA F2 FAFLD FXCH invalid reserved invalid FLDL2E FPTAN FSQRTST(0), ST(2) ST(0), ST(2)C3 CB D3 DB E3 EB F3 FBFLD FXCH invalid reserved invalid FLDPI FPATAN FSINCOSST(0), ST(3) ST(0), ST(3)C4 CC D4 DC E4 EC F4 FCFLD FXCH invalid reserved FTST FLDLG2 FXTRACT FRNDINTST(0), ST(4) ST(0), ST(4)C5 CD D5 DD E5 ED F5 FDFLD FXCH invalid reserved FXAM FLDLN2 FPREM1 FSCALEST(0), ST(5) ST(0), ST(5)C6 CE D6 DE E6 EE F6 FEFLD FXCH invalid reserved invalid FLDZ FDECSTP FSINST(0), ST(6) ST(0), ST(6)C7 CF D7 DF E7 EF F7 FFFLD FXCH invalid reserved invalid invalid FINCSTP FCOSST(0), ST(7) ST(0), ST(7)Appendix A: Opcode <strong>and</strong> Oper<strong>and</strong> Encodings 395


AMD64 Technology 24594 Rev. 3.10 February 2005Table A-10.x87 Opcodes <strong>and</strong> ModRM Extensions (continued)OpcodeDAModRMmodField!1111ModRM reg Field/0 /1 /2 /3 /4 /5 /6 /700–BFFIADD FIMUL FICOM FICOMP FISUB FISUBR FIDIV FIDIVRmem32int mem32int mem32int mem32int mem32int mem32int mem32int mem32intC0 C8 D0 D8 E0 E8 F0 F8FCMOVB FCMOVE FCMOVBE FCMOVU invalid invalid invalid invalidST(0), ST(0) ST(0), ST(0) ST(0), ST(0) ST(0), ST(0)C1 C9 D1 D9 E1 E9 F1 F9FCMOVB FCMOVE FCMOVBE FCMOVU invalid FUCOMPP invalid invalidST(0), ST(1) ST(0), ST(1) ST(0), ST(1) ST(0), ST(1)C2 CA D2 DA E2 EA F2 FAFCMOVB FCMOVE FCMOVBE FCMOVU invalid invalid invalid invalidST(0), ST(2) ST(0), ST(2) ST(0), ST(2) ST(0), ST(2)C3 CB D3 DB E3 EB F3 FBFCMOVB FCMOVE FCMOVBE FCMOVU invalid invalid invalid invalidST(0), ST(3) ST(0), ST(3) ST(0), ST(3) ST(0), ST(3)C4 CC D4 DC E4 EC F4 FCFCMOVB FCMOVE FCMOVBE FCMOVU invalid invalid invalid invalidST(0), ST(4) ST(0), ST(4) ST(0), ST(4) ST(0), ST(4)C5 CD D5 DD E5 ED F5 FDFCMOVB FCMOVE FCMOVBE FCMOVU invalid invalid invalid invalidST(0), ST(5) ST(0), ST(5) ST(0), ST(5) ST(0), ST(5)C6 CE D6 DE E6 EE F6 FEFCMOVB FCMOVE FCMOVBE FCMOVU invalid invalid invalid invalidST(0), ST(6) ST(0), ST(6) ST(0), ST(6) ST(0), ST(6)C7 CF D7 DF E7 EF F7 FFFCMOVB FCMOVE FCMOVBE FCMOVU invalid invalid invalid invalidST(0), ST(7) ST(0), ST(7) ST(0), ST(7) ST(0), ST(7)396 Appendix A: Opcode <strong>and</strong> Oper<strong>and</strong> Encodings


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable A-10.x87 Opcodes <strong>and</strong> ModRM Extensions (continued)OpcodeDBModRMmodField!1111ModRM reg Field/0 /1 /2 /3 /4 /5 /6 /700–BFFILD FISTTP FIST FISTP invalid FLD invalid FSTPmem32int mem32int mem32int mem32int mem80real mem80realC0 C8 D0 D8 E0 E8 F0 F8FCMOVNB FCMOVNE FCMOVNBE FCMOVNU reserved FUCOMI FCOMI invalidST(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 F9FCMOVNB FCMOVNE FCMOVNBE FCMOVNU reserved FUCOMI FCOMI invalidST(0), ST(1) ST(0), ST(1) ST(0), ST(1) ST(0), ST(1) ST(0), ST(1) ST(0), ST(1)C2 CA D2 DA E2 EA F2 FAFCMOVNB FCMOVNE FCMOVNBE FCMOVNU FNCLEX FUCOMI FCOMI invalidST(0), ST(2) ST(0), ST(2) ST(0), ST(2) ST(0), ST(2) ST(0), ST(2) ST(0), ST(2)C3 CB D3 DB E3 EB F3 FBFCMOVNB FCMOVNE FCMOVNBE FCMOVNU FNINIT FUCOMI FCOMI invalidST(0), ST(3) ST(0), ST(3) ST(0), ST(3) ST(0), ST(3) ST(0), ST(3) ST(0), ST(3)C4 CC D4 DC E4 EC F4 FCFCMOVNB FCMOVNE FCMOVNBE FCMOVNU reserved FUCOMI FCOMI invalidST(0), ST(4) ST(0), ST(4) ST(0), ST(4) ST(0), ST(4) ST(0), ST(4) ST(0), ST(4)C5 CD D5 DD E5 ED F5 FDFCMOVNB FCMOVNE FCMOVNBE FCMOVNU invalid FUCOMI FCOMI invalidST(0), ST(5) ST(0), ST(5) ST(0), ST(5) ST(0), ST(5) ST(0), ST(5) ST(0), ST(5)C6 CE D6 DE E6 EE F6 FEFCMOVNB FCMOVNE FCMOVNBE FCMOVNU invalid FUCOMI FCOMI invalidST(0), ST(6) ST(0), ST(6) ST(0), ST(6) ST(0), ST(6) ST(0), ST(6) ST(0), ST(6)C7 CF D7 DF E7 EF F7 FFFCMOVNB FCMOVNE FCMOVNBE FCMOVNU invalid FUCOMI FCOMI invalidST(0), ST(7) ST(0), ST(7) ST(0), ST(7) ST(0), ST(7) ST(0), ST(7) ST(0), ST(7)Appendix A: Opcode <strong>and</strong> Oper<strong>and</strong> Encodings 397


AMD64 Technology 24594 Rev. 3.10 February 2005Table A-10.x87 Opcodes <strong>and</strong> ModRM Extensions (continued)OpcodeDCModRMmodField!1111ModRM reg Field/0 /1 /2 /3 /4 /5 /6 /700–BFFADD FMUL FCOM FCOMP FSUB FSUBR FDIV FDIVRmem64real mem64real mem64real mem64real mem64real mem64real mem64real mem64realC0 C8 D0 D8 E0 E8 F0 F8FADD FMUL reserved reserved FSUBR FSUB FDIVR FDIVST(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 F9FADD FMUL reserved reserved FSUBR FSUB FDIVR FDIVST(1), ST(0) ST(1), ST(0) ST(1), ST(0) ST(1), ST(0) ST(1), ST(0) ST(1), ST(0)C2 CA D2 DA E2 EA F2 FAFADD FMUL reserved reserved FSUBR FSUB FDIVR FDIVST(2), ST(0) ST(2), ST(0) ST(2), ST(0) ST(2), ST(0) ST(2), ST(0) ST(2), ST(0)C3 CB D3 DB E3 EB F3 FBFADD FMUL reserved reserved FSUBR FSUB FDIVR FDIVST(3), ST(0) ST(3), ST(0) ST(3), ST(0) ST(3), ST(0) ST(3), ST(0) ST(3), ST(0)C4 CC D4 DC E4 EC F4 FCFADD FMUL reserved reserved FSUBR FSUB FDIVR FDIVST(4), ST(0) ST(4), ST(0) ST(4), ST(0) ST(4), ST(0) ST(4), ST(0) ST(4), ST(0)C5 CD D5 DD E5 ED F5 FDFADD FMUL reserved reserved FSUBR FSUB FDIVR FDIVST(5), ST(0) ST(5), ST(0) ST(5), ST(0) ST(5), ST(0) ST(5), ST(0) ST(5), ST(0)C6 CE D6 DE E6 EE F6 FEFADD FMUL reserved reserved FSUBR FSUB FDIVR FDIVST(6), ST(0) ST(6), ST(0) ST(6), ST(0) ST(6), ST(0) ST(6), ST(0) ST(6), ST(0)C7 CF D7 DF E7 EF F7 FFFADD FMUL reserved reserved FSUBR FSUB FDIVR FDIVST(7), ST(0) ST(7), ST(0) ST(7), ST(0) ST(7), ST(0) ST(7), ST(0) ST(7), ST(0)398 Appendix A: Opcode <strong>and</strong> Oper<strong>and</strong> Encodings


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable A-10.x87 Opcodes <strong>and</strong> ModRM Extensions (continued)OpcodeDDModRMmodField!111100–BFFLD FISTTP FST FSTP FRSTOR invalid FNSAVE FNSTSWmem64real mem64int mem64real mem64realModRM reg Field/0 /1 /2 /3 /4 /5 /6 /7mem98/108envmem98/108envC0 C8 D0 D8 E0 E8 F0 F8mem16FFREE reserved FST FSTP FUCOM FUCOMP invalid invalidST(0) ST(0) ST(0) ST(0), ST(0) ST(0)C1 C9 D1 D9 E1 E9 F1 F9FFREE reserved FST FSTP FUCOM FUCOMP invalid invalidST(1) ST(1) ST(1) ST(1), ST(0) ST(1)C2 CA D2 DA E2 EA F2 FAFFREE reserved FST FSTP FUCOM FUCOMP invalid invalidST(2) ST(2) ST(2) ST(2), ST(0) ST(2)C3 CB D3 DB E3 EB F3 FBFFREE reserved FST FSTP FUCOM FUCOMP invalid invalidST(3) ST(3) ST(3) ST(3), ST(0) ST(3)C4 CC D4 DC E4 EC F4 FCFFREE reserved FST FSTP FUCOM FUCOMP invalid invalidST(4) ST(4) ST(4) ST(4), ST(0) ST(4)C5 CD D5 DD E5 ED F5 FDFFREE reserved FST FSTP FUCOM FUCOMP invalid invalidST(5) ST(5) ST(5) ST(5), ST(0) ST(5)C6 CE D6 DE E6 EE F6 FEFFREE reserved FST FSTP FUCOM FUCOMP invalid invalidST(6) ST(6) ST(6) ST(6), ST(0) ST(6)C7 CF D7 DF E7 EF F7 FFFFREE reserved FST FSTP FUCOM FUCOMP invalid invalidST(7) ST(7) ST(7) ST(7), ST(0) ST(7)Appendix A: Opcode <strong>and</strong> Oper<strong>and</strong> Encodings 399


AMD64 Technology 24594 Rev. 3.10 February 2005Table A-10.x87 Opcodes <strong>and</strong> ModRM Extensions (continued)OpcodeDEModRMmodField!1111ModRM reg Field/0 /1 /2 /3 /4 /5 /6 /700–BFFIADD FIMUL FICOM FICOMP FISUB FISUBR FIDIV FIDIVRmem16int mem16int mem16int mem16int mem16int mem16int mem16int mem16intC0 C8 D0 D8 E0 E8 F0 F8FADDP FMULP reserved invalid FSUBRP FSUBP FDIVRP FDIVPST(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 F9FADDP FMULP reserved FCOMPP FSUBRP FSUBP FDIVRP FDIVPST(1), ST(0) ST(1), ST(0) ST(1), ST(0) ST(1), ST(0) ST(1), ST(0) ST(1), ST(0)C2 CA D2 DA E2 EA F2 FAFADDP FMULP reserved invalid FSUBRP FSUBP FDIVRP FDIVPST(2), ST(0) ST(2), ST(0) ST(2), ST(0) ST(2), ST(0) ST(2), ST(0) ST(2), ST(0)C3 CB D3 DB E3 EB F3 FBFADDP FMULP reserved invalid FSUBRP FSUBP FDIVRP FDIVPST(3), ST(0) ST(3), ST(0) ST(3), ST(0) ST(3), ST(0) ST(3), ST(0) ST(3), ST(0)C4 CC D4 DC E4 EC F4 FCFADDP FMULP reserved invalid FSUBRP FSUBP FDIVRP FDIVPST(4), ST(0) ST(4), ST(0) ST(4), ST(0) ST(4), ST(0) ST(4), ST(0) ST(4), ST(0)C5 CD D5 DD E5 ED F5 FDFADDP FMULP reserved invalid FSUBRP FSUBP FDIVRP FDIVPST(5), ST(0) ST(5), ST(0) ST(5), ST(0) ST(5), ST(0) ST(5), ST(0) ST(5), ST(0)C6 CE D6 DE E6 EE F6 FEFADDP FMULP reserved invalid FSUBRP FSUBP FDIVRP FDIVPST(6), ST(0) ST(6), ST(0) ST(6), ST(0) ST(6), ST(0) ST(6), ST(0) ST(6), ST(0)C7 CF D7 DF E7 EF F7 FFFADDP FMULP reserved invalid FSUBRP FSUBP FDIVRP FDIVPST(7), ST(0) ST(7), ST(0) ST(7), ST(0) ST(7), ST(0) ST(7), ST(0) ST(7), ST(0)400 Appendix A: Opcode <strong>and</strong> Oper<strong>and</strong> Encodings


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable A-10.x87 Opcodes <strong>and</strong> ModRM Extensions (continued)OpcodeDFModRMmodField!1111ModRM reg Field/0 /1 /2 /3 /4 /5 /6 /700–BFFILD FISTTP FIST FISTP FBLD FILD FBSTP FISTPmem16int mem16int mem16int mem16int mem80dec mem64int mem80dec mem64intC0 C8 D0 D8 E0 E8 F0 F8reserved reserved reserved reserved FNSTSW FUCOMIP FCOMIP invalidAX ST(0), ST(0) ST(0), ST(0)C1 C9 D1 D9 E1 E9 F1 F9reserved reserved reserved reserved invalid FUCOMIP FCOMIP invalidST(0), ST(1) ST(0), ST(1)C2 CA D2 DA E2 EA F2 FAreserved reserved reserved reserved invalid FUCOMIP FCOMIP invalidST(0), ST(2) ST(0), ST(2)C3 CB D3 DB E3 EB F3 FBreserved reserved reserved reserved invalid FUCOMIP FCOMIP invalidST(0), ST(3) ST(0), ST(3)C4 CC D4 DC E4 EC F4 FCreserved reserved reserved reserved invalid FUCOMIP FCOMIP invalidST(0), ST(4) ST(0), ST(4)C5 CD D5 DD E5 ED F5 FDreserved reserved reserved reserved invalid FUCOMIP FCOMIP invalidST(0), ST(5) ST(0), ST(5)C6 CE D6 DE E6 EE F6 FEreserved reserved reserved reserved invalid FUCOMIP FCOMIP invalidST(0), ST(6) ST(0), ST(6)C7 CF D7 DF E7 EF F7 FFreserved reserved reserved reserved invalid FUCOMIP FCOMIP invalidST(0), ST(7) ST(0), ST(7)Appendix A: Opcode <strong>and</strong> Oper<strong>and</strong> Encodings 401


AMD64 Technology 24594 Rev. 3.10 February 2005A.2.8 rFLAGSCondition Codes forx87 OpcodesTable A-11 shows the rFLAGS condition codes specified by theopcode <strong>and</strong> ModRM bytes of the FCMOVcc instructions.Table A-11.rFLAGS Condition Codes for FCMOVccOpcode(hex)DADBModRMmodField11ModRMregFieldrFLAGS Value cc Mnemonic Condition000 CF = 1 B Below001 ZF = 1 E Equal010 CF = 1 or ZF = 1 BE Below or Equal011 PF = 1 U Unordered000 CF = 0 NB Not Below001 ZF = 0 NE Not Equal010 CF = 0 <strong>and</strong> ZF = 0 NBE Not Below or Equal011 PF = 0 NU Not UnorderedA.3 Oper<strong>and</strong> EncodingsRegister <strong>and</strong> memory oper<strong>and</strong>s are encoded using the moderegister-memory(ModRM) <strong>and</strong> the scale-index-base (SIB) bytesthat follow the opcodes. In some instructions, the ModRM byteis followed by an SIB byte, which defines the instruction’smemory-addressing mode for the complex-addressing modes.A.3.1 ModRMOper<strong>and</strong> ReferencesFigure A-2 on page 403 shows the format of a ModRM byte.There are three fields—mod, reg, <strong>and</strong> r/m. The reg field not onlyprovides additional opcode bits—as described above beginningwith “ModRM Extensions to One-Byte <strong>and</strong> Two-Byte Opcodes”on page 387 <strong>and</strong> ending with “x87 Encodings” on page 392—but is also used with the other two fields to specify oper<strong>and</strong>s.The mod <strong>and</strong> r/m fields are used together with each other <strong>and</strong>,in 64-bit mode, with the REX.R <strong>and</strong> REX.B bits of the REXprefix, to specify the location of the instruction’s oper<strong>and</strong>s <strong>and</strong>certain of the possible addressing modes (specifically, the noncomplexmodes).402 Appendix A: Opcode <strong>and</strong> Oper<strong>and</strong> Encodings


24594 Rev. 3.10 February 2005 AMD64 TechnologyBits:76543210modreg r/m ModRMREX.R bit of REX prefix canextend this field to 4 bitsREX.B bit of REX prefix canextend this field to 4 bits513-305.epsFigure A-2.ModRM-Byte FormatThe two sections below describe the ModRM oper<strong>and</strong>encodings, first for 32-bit <strong>and</strong> 64-bit references, <strong>and</strong> then for 16-bit references.16-Bit Register <strong>and</strong> Memory References. Table A-12 shows thenotation <strong>and</strong> encoding conventions for register references usingthe ModRM reg field. This table is comparable to Table A-14 onpage 406 but applies only when the address-size is 16-bit.Table A-13 on page 404 shows the notation <strong>and</strong> encodingconventions for 16-bit memory references using the ModRMbyte. This table is comparable to Table A-15 on page 407.Table A-12.ModRM Register References, 16-Bit AddressingMnemonicNotationModRM reg Field/0 /1 /2 /3 /4 /5 /6 /7reg8 AL CL DL BL AH CH DH BHreg16 AX CX DX BX SP BP SI DIreg32 EAX ECX EDX EBX ESP EBP ESI EDImmx MMX0 MMX1 MMX2 MMX3 MMX4 MMX5 MMX6 MMX7xmm XMM0 XMM1 XMM2 XMM3 XMM4 XMM5 XMM6 XMM7sReg ES CS SS DS FS GS iinvalid invalidcReg CR0 CR1 CR2 CR3 CR4 CR5 CR6 CR7dReg DR0 DR1 DR2 DR3 DR4 DR5 DR6 DR7Appendix A: Opcode <strong>and</strong> Oper<strong>and</strong> Encodings 403


AMD64 Technology 24594 Rev. 3.10 February 2005Table A-13.ModRM Memory References, 16-Bit Addressing[BX+SI]Effective Address 1ModRMmodField(binary)ModRM reg Field 2/0 /1 /2 /3 /4 /5 /6 /7Complete ModRM Byte (hex)ModRMr/mField(binary)00 08 10 18 20 28 30 38 000[BX+DI] 01 09 11 19 21 29 31 39 001[BP+SI] 02 0A 12 1A 22 2A 32 3A 010[BP+DI] 03 0B 13 1B 23 2B 33 3B 01100[SI] 04 0C 14 1C 24 2C 34 3C 100[DI] 05 0D 15 1D 25 2D 35 3D 101[disp16] 06 0E 16 1E 26 2E 36 3E 110[BX] 07 0F 17 1F 27 2F 37 3F 111[BX+SI+disp8]40 48 50 58 60 68 70 78 000[BX+DI+disp8] 41 49 51 59 61 69 71 79 001[BP+SI+disp8] 42 4A 52 5A 62 6A 72 7A 010[BP+DI+disp8] 43 4B 53 5B 63 6B 73 7B 01101[SI+disp8] 44 4C 54 5C 64 6C 74 7C 100[DI+disp8] 45 4D 55 5D 65 6D 75 7D 101[BP+disp8] 46 4E 56 5E 66 6E 76 7E 110[BX+disp8] 47 4F 57 5F 67 6F 77 7F 111[BX+SI+disp16]80 88 90 98 A0 A8 B0 B8 000[BX+DI+disp16] 81 89 91 99 A1 A9 B1 B9 001[BP+SI+disp16] 82 8A 92 9A A2 AA B2 BA 010[BP+DI+disp16] 83 8B 93 9B A3 AB B3 BB 01110[SI+disp16] 84 8C 94 9C A4 AC B4 BC 100[DI+disp16] 85 8D 95 9D A5 AD B5 BD 101[BP+disp16] 86 8E 96 9E A6 AE B6 BE 110[BX+disp16] 87 8F 97 9F A7 AF B7 BF 111Note:1. In these combinations, “disp8” <strong>and</strong> “disp16” indicate an 8-bit or 16-bit signed displacement.2. See Table A-12 for complete specification of ModRM “reg” field.404 Appendix A: Opcode <strong>and</strong> Oper<strong>and</strong> Encodings


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable A-13.ModRM Memory References, 16-Bit Addressing (continued)AL/AX/EAX/MMX0/XMM0Effective Address 1ModRMmodField(binary)ModRM reg Field 2/0 /1 /2 /3 /4 /5 /6 /7Complete ModRM Byte (hex)C0 C8 D0 D8 E0 E8 F0 F8 000CL/CX/ECX/MMX1/XMM1 C1 C9 D1 D9 E1 E9 F1 F9 001DL/DX/EDX/MMX2/XMM2 C2 CA D2 DA E2 EA F2 FA 010BL/BX/EBX/MMX3/XMM3 C3 CB D3 DB E3 EB F3 FB 01111AH/SP/ESP/MMX4/XMM4 C4 CC D4 DC E4 EC F4 FC 100CH/BP/EBP/MMX5/XMM5 C5 CD D5 DD E5 ED F5 FD 101DH/SI/ESI/MMX6/XMM6 C6 CE D6 DE E6 EE F6 FE 110BH/DI/EDI/MMX7/XMM7 C7 CF D7 DF E7 EF F7 FF 111Note:1. In these combinations, “disp8” <strong>and</strong> “disp16” indicate an 8-bit or 16-bit signed displacement.2. See Table A-12 for complete specification of ModRM “reg” field.ModRMr/mField(binary)Register <strong>and</strong> Memory References for 32-Bit <strong>and</strong> 64-Bit Addressing.Table A-14 on page 406 shows the encoding for 32-bit <strong>and</strong> 64-bitregister references using the ModRM reg field. The first ninerows of Table A-14 show references when the REX.R bit iscleared to 0, <strong>and</strong> the last nine rows show references when theREX.R bit is set to 1. In this table, Mnemonic Notation meansthe syntax notation shown in “Mnemonic Syntax” on page 43for a register, <strong>and</strong> ModRM Notation (/r) means the opcodesyntaxnotation shown in “Opcode Syntax” on page 46 for theregister.Table A-15 on page 407 shows the encoding for 32-bit <strong>and</strong> 64-bitmemory references using the ModRM byte. This table describes32-bit <strong>and</strong> 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 completeModRM byte (one value for each binary encoding of theModRM-byte reg field), followed by the binary encoding of theModRM 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 (binary000) to 7 (binary 111).Appendix A: Opcode <strong>and</strong> Oper<strong>and</strong> Encodings 405


AMD64 Technology 24594 Rev. 3.10 February 2005Table A-14.reg8MnemonicNotationModRM Register References, 32-Bit <strong>and</strong> 64-Bit AddressingREX.R BitModRM reg Field/0 /1 /2 /3 /4 /5 /6 /7AL CL DL BL AH/SPL CH/BPL DH/SIL BH/DILreg16 AX CX DX BX SP BP SI DIreg32 EAX ECX EDX EBX ESP EBP ESI EDIreg64 RAX RCX RDX RBX RSP RBP RSI RDImmx 0 MMX0 MMX1 MMX2 MMX3 MMX4 MMX5 MMX6 MMX7xmm XMM0 XMM1 XMM2 XMM3 XMM4 XMM5 XMM6 XMM7sReg ES CS SS DS FS GS invalid invalidcReg CR0 CR1 CR2 CR3 CR4 CR5 CR6 CR7dReg DR0 DR1 DR2 DR3 DR4 DR5 DR6 DR7reg8R8B R9B R10B R11B R12B R13B R14B R15Breg16 R8W R9W R10W R11W R12W R13W R14W R15Wreg32 R8D R9D R10D R11D R12D R13D R14D R15Dreg64 R8 R9 R10 R11 R12 R13 R14 R15mmx 1 MMX0 MMX1 MMX2 MMX3 MMX4 MMX5 MMX6 MMX7xmm XMM8 XMM9 XMM10 XMM11 XMM12 XMM13 XMM14 XMM15sReg ES CS SS DS FS GS invalid invalidcReg CR8 CR9 CR10 CR11 CR12 CR13 CR14 CR15dReg DR8 DR9 DR10 DR11 DR12 DR13 DR14 DR15406 Appendix A: Opcode <strong>and</strong> Oper<strong>and</strong> Encodings


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable A-15.ModRM Memory References, 32-Bit <strong>and</strong> 64-Bit Addressing[rAX]ModRMEffective Address 1ModRM reg Field 3modField/0 /1 /2 /3 /4 /5 /6 /7REX.B = 0 REX.B = 1 (binary) Complete ModRM Byte (hex)[r8]ModRMr/mField(binary)00 08 10 18 20 28 30 38 000[rCX] [r9] 01 09 11 19 21 29 31 39 001[rDX] [r10] 02 0A 12 1A 22 2A 32 3A 010[rBX] [r11] 03 0B 13 1B 23 2B 33 3B 01100[SIB] 4 [SIB] 4 04 0C 14 1C 24 2C 34 3C 100[RIP+disp32] or [disp32] 2 [rIP+disp32] or [disp32] 2 05 0D 15 1D 25 2D 35 3D 101[rSI] [r14] 06 0E 16 1E 26 2E 36 3E 110[rDI] [r15] 07 0F 17 1F 27 2F 37 3F 111[rAX+disp8][r8+disp8]40 48 50 58 60 68 70 78 000[rCX+disp8] [r9+disp8] 41 49 51 59 61 69 71 79 001[rDX+disp8] [r10+disp8] 42 4A 52 5A 62 6A 72 7A 010[rBX+disp8] [r11+disp8] 43 4B 53 5B 63 6B 73 7B 01101[SIB+disp8] 4 [SIB+disp8] 4 44 4C 54 5C 64 6C 74 7C 100[rBP+disp8] [r13+disp8] 45 4D 55 5D 65 6D 75 7D 101[rSI+disp8] [r14+disp8] 46 4E 56 5E 66 6E 76 7E 110[rDI+disp8] [r15+disp8] 47 4F 57 5F 67 6F 77 7F 111[rAX+disp32][r8+disp32]80 88 90 98 A0 A8 B0 B8 000[rCX+disp32] [r9+disp32] 81 89 91 99 A1 A9 B1 B9 001[rDX+disp32] [r10+disp32] 82 8A 92 9A A2 AA B2 BA 010[rBX+disp32] [r11+disp32] 83 8B 93 9B A3 AB B3 BB 01110[SIB+disp32] 4 [SIB+disp32] 4 84 8C 94 9C A4 AC B4 BC 100[rBP+disp32] [r13+disp32] 85 8D 95 9D A5 AD B5 BD 101[rSI+disp32] [r14+disp32] 86 8E 96 9E A6 AE B6 BE 110[rDI+disp32] [r15+disp32] 87 8F 97 9F A7 AF B7 BF 111Note:1. In these combinations, “disp8” <strong>and</strong> “disp32” indicate an 8-bit or 32-bit signed displacement.2. In 64-bit mode, the effective address is [RIP+disp32]. In all other modes, the effective address is [disp32]. If the address-size prefixis used in 64-bit mode to override 64-bit addressing, the [RIP+disp32] effective address is truncated after computation to 64 bits.3. See Table A-14 for complete specification of ModRM “reg” field.4. An SIB byte follows the ModRM byte to identify the memory oper<strong>and</strong>.Appendix A: Opcode <strong>and</strong> Oper<strong>and</strong> Encodings 407


AMD64 Technology 24594 Rev. 3.10 February 2005Table A-15.ModRM Memory References, 32-Bit <strong>and</strong> 64-Bit Addressing (continued)ModRMEffective Address 1ModRM reg Field 3modField/0 /1 /2 /3 /4 /5 /6 /7REX.B = 0 REX.B = 1 (binary) Complete ModRM Byte (hex)AL/rAX/MMX0/XMM0r8/MMX0/XMM8ModRMr/mField(binary)C0 C8 D0 D8 E0 E8 F0 F8 000CL/rCX/MMX1/XMM1 r9/MMX1/XMM9 C1 C9 D1 D9 E1 E9 F1 F9 001DL/rDX/MMX2/XMM2 r10/MMX2/XMM10 C2 CA D2 DA E2 EA F2 FA 010BL/rBX/MMX3/XMM3 r11/MMX3/XMM11 C3 CB D3 DB E3 EB F3 FB 01111AH/SPL/rSP/MMX4/XMM4 r12/MMX4/XMM12 C4 CC D4 DC E4 EC F4 FC 100CH/BPL/rBP/MMX5/XMM5 r13/MMX5/XMM13 C5 CD D5 DD E5 ED F5 FD 101DH/SIL/rSI/MMX6/XMM6 r14/MMX6/XMM14 C6 CE D6 DE E6 EE F6 FE 110BH/DIL/rDI/MMX7/XMM7 r15/MMX7/XMM15 C7 CF D7 DF E7 EF F7 FF 111Note:1. In these combinations, “disp8” <strong>and</strong> “disp32” indicate an 8-bit or 32-bit signed displacement.2. In 64-bit mode, the effective address is [RIP+disp32]. In all other modes, the effective address is [disp32]. If the address-size prefixis used in 64-bit mode to override 64-bit addressing, the [RIP+disp32] effective address is truncated after computation to 64 bits.3. See Table A-14 for complete specification of ModRM “reg” field.4. An SIB byte follows the ModRM byte to identify the memory oper<strong>and</strong>.A.3.2 SIB Oper<strong>and</strong>ReferencesFigure A-3 on page 409 shows the format of a scale-index-base(SIB) byte. Some instructions have an SIB byte following theirModRM byte to define memory addressing for the complexaddressingmodes described in “Effective Addresses” in<strong>Volume</strong> 1. The SIB byte has three fields—scale, index, <strong>and</strong>base—that define the scale factor, index-register number, <strong>and</strong>base-register number for 32-bit <strong>and</strong> 64-bit complex addressingmodes. In 64-bit mode, the REX.B <strong>and</strong> REX.X bits extend theencoding of the SIB byte’s base <strong>and</strong> index fields.408 Appendix A: Opcode <strong>and</strong> Oper<strong>and</strong> Encodings


24594 Rev. 3.10 February 2005 AMD64 TechnologyBits:7 6 5 4 3 2 1 0scale index base SIBREX.X bit of REX prefix canextend this field to 4 bitsREX.B bit of REX prefix canextend this field to 4 bits513-306.epsFigure A-3.SIB Byte FormatTable A-16.REX.B Bit01Table A-16 shows the encodings for the SIB byte’s base field,which specifies the base register for addressing. Table A-17 onpage 410 shows the encodings for the effective addressreferenced by a complete SIB byte, including its scale <strong>and</strong> indexfields. The /0 through /7 notation for the SIB base field meansthat the three-bit field contains a value between zero (binary000) <strong>and</strong> 7 (binary 111).SIB base Field ReferencesModRM mod Field00SIB base Field/0 /1 /2 /3 /4 /5 /6 /7disp3201 rAX rCX rDX rBX rSP rBP+disp810 rBP+disp3200disp3201 r8 r9 r10 r11 r12 r13+disp810 r13+disp32rSIr14rDIr15Appendix A: Opcode <strong>and</strong> Oper<strong>and</strong> Encodings 409


AMD64 Technology 24594 Rev. 3.10 February 2005Table A-17.SIB Memory ReferencesEffective AddressSIBscaleFieldSIBindexFieldSIB base Field 1REX.B = 0: rAX rCX rDX rBX rSP note 1 rSI rDIREX.B = 1: r8 r9 r10 r11 r12 note 1 r14 r15/0 /1 /2 /3 /4 /5 /6 /7REX.X = 0 REX.X = 1 Complete SIB Byte (hex)[rAX+base][r8+base]000 00 01 02 03 04 05 06 07[rCX+base] [r9+base] 001 08 09 0A 0B 0C 0D 0E 0F[rDX+base] [r10+base] 010 10 11 12 13 14 15 16 17[rBX+base] [r11+base] 011 18 19 1A 1B 1C 1D 1E 1F00[base] [r12+base] 100 20 21 22 23 24 25 26 27[rBP+base] [r13+base] 101 28 29 2A 2B 2C 2D 2E 2F[rSI+base] [r14+base] 110 30 31 32 33 34 35 36 37[rDI+base] [r15+base] 111 38 39 3A 3B 3C 3D 3E 3F[rAX*2+base][r8*2+base]000 40 41 42 43 44 45 46 47[rCX*2+base] [r9*2+base] 001 48 49 4A 4B 4C 4D 4E 4F[rDX*2+base] [r10*2+base] 010 50 51 52 53 54 55 56 57[rBX*2+base] [r11*2+base] 011 58 59 5A 5B 5C 5D 5E 5F01[base] [r12*2+base] 100 60 61 62 63 64 65 66 67[rBP*2+base] [r13*2+base] 101 68 69 6A 6B 6C 6D 6E 6F[rSI*2+base] [r14*2+base] 110 70 71 72 73 74 75 76 77[rDI*2+base] [r15*2+base] 111 78 79 7A 7B 7C 7D 7E 7F[rAX*4+base][r8*4+base]000 80 81 82 83 84 85 86 87[rCX*4+base] [r9*4+base] 001 88 89 8A 8B 8C 8D 8E 8F[rDX*4+base] [r10*4+base] 010 90 91 92 93 94 95 96 97[rBX*4+base] [r11*4+base] 011 98 99 9A 9B 9C 9D 9E 9F10[base] [r12*4+base] 100 A0 A1 A2 A3 A4 A5 A6 A7[rBP*4+base] [r13*4+base] 101 A8 A9 AA AB AC AD AE AF[rSI*4+base] [r14*4+base] 110 B0 B1 B2 B3 B4 B5 B6 B7[rDI*4+base] [r15*4+base] 111 B8 B9 BA BB BC BD BE BFNote:1. See Table A-16 on page 409 for complete specification of SIB “base” field.410 Appendix A: Opcode <strong>and</strong> Oper<strong>and</strong> Encodings


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable A-17.SIB Memory References (continued)[rAX*8+base]Effective Address[r8*8+base]SIBscaleFieldSIBindexFieldSIB base Field 1REX.B = 0: rAX rCX rDX rBX rSP note 1 rSI rDIREX.B = 1: r8 r9 r10 r11 r12 note 1 r14 r15/0 /1 /2 /3 /4 /5 /6 /7REX.X = 0 REX.X = 1 Complete SIB Byte (hex)000 C0 C1 C2 C3 C4 C5 C6 C7[rCX*8+base] [r9*8+base] 001 C8 C9 CA CB CC CD CE CF[rDX*8+base] [r10*8+base] 010 D0 D1 D2 D3 D4 D5 D6 D7[rBX*8+base] [r11*8+base] 011 D8 D9 DA DB DC DD DE DF11[base] [r12*8+base] 100 E0 E1 E2 E3 E4 E5 E6 E7[rBP*8+base] [r13*8+base] 101 E8 E9 EA EB EC ED EE EF[rSI*8+base] [r14*8+base] 110 F0 F1 F2 F3 F4 F5 F6 F7[rDI*8+base] [r15*8+base] 111 F8 F9 FA FB FC FD FE FFNote:1. See Table A-16 on page 409 for complete specification of SIB “base” field.Appendix A: Opcode <strong>and</strong> Oper<strong>and</strong> Encodings 411


AMD64 Technology 24594 Rev. 3.10 February 2005412 Appendix A: Opcode <strong>and</strong> Oper<strong>and</strong> Encodings


24594 Rev. 3.10 February 2005 AMD64 TechnologyAppendix B<strong>General</strong>-<strong>Purpose</strong> <strong>Instructions</strong> in 64-BitModeThis appendix provides details of the general-purposeinstructions in 64-bit mode <strong>and</strong> its differences from legacy <strong>and</strong>compatibility modes. The appendix covers only the generalpurposeinstructions (those described in Chapter 3, “<strong>General</strong>-<strong>Purpose</strong> Instruction Reference”). It does not cover the 128-bitmedia, 64-bit media, or x87 floating-point instructions becausethose instructions are not affected by 64-bit mode, other than inthe access by such instructions to extended GPR <strong>and</strong> XMMregisters when using a REX prefix.B.1 <strong>General</strong> Rules for 64-Bit ModeIn 64-bit mode, the following general rules apply to instructions<strong>and</strong> their oper<strong>and</strong>s:• “Promoted to 64 Bit”: If an instruction’s oper<strong>and</strong> size (16-bitor 32-bit) in legacy <strong>and</strong> compatibility modes depends on theCS.D bit <strong>and</strong> the oper<strong>and</strong>-size override prefix, then theoper<strong>and</strong>-size choices in 64-bit mode are extended from 16-bit<strong>and</strong> 32-bit to include 64 bits (with a REX prefix), or theoper<strong>and</strong> size is fixed at 64 bits. Such instructions are said tobe “Promoted to 64 bits” in Table B-1. However, byte-oper<strong>and</strong>opcodes of such instructions are not promoted.• Byte-Oper<strong>and</strong> Opcodes Not Promoted: As stated above in“Promoted to 64 Bit”, byte-oper<strong>and</strong> opcodes of promotedinstructions are not promoted. Those opcodes continue tooperate only on bytes.• Fixed Oper<strong>and</strong> Size: If an instruction’s oper<strong>and</strong> size is fixedin legacy mode (thus, independent of CS.D <strong>and</strong> prefixoverrides), that oper<strong>and</strong> size is usually fixed at the same sizein 64-bit mode. For example, CPUID operates on 32-bitoper<strong>and</strong>s, irrespective of attempts to override the oper<strong>and</strong>size.• Default Oper<strong>and</strong> Size: The default oper<strong>and</strong> size for mostinstructions is 32 bits, <strong>and</strong> a REX prefix must be used tochange the oper<strong>and</strong> size to 64 bits. However, two groups ofinstructions default to 64-bit oper<strong>and</strong> size <strong>and</strong> do not need aREX prefix: (1) near branches <strong>and</strong> (2) all instructions,Appendix B: <strong>General</strong>-<strong>Purpose</strong> <strong>Instructions</strong> in 64-Bit Mode 413


AMD64 Technology 24594 Rev. 3.10 February 2005except far branches, that implicitly reference the RSP. SeeTable B-5 on page 447 for a list of all instructions thatdefault to 64-bit oper<strong>and</strong> size.• Zero-Extension of 32-Bit Results: Operations on 32-bitoper<strong>and</strong>s in 64-bit mode zero-extend the high 32 bits of 64-bit GPR destination registers.• No Extension of 8-Bit <strong>and</strong> 16-Bit Results: Operations on 8-bit<strong>and</strong> 16-bit oper<strong>and</strong>s in 64-bit mode leave the high 56 or 48bits, respectively, of 64-bit GPR destination registersunchanged.• Shift <strong>and</strong> Rotate Counts: When the oper<strong>and</strong> size is 64 bits,shifts <strong>and</strong> rotates use one additional bit (6 bits total) tospecify shift-count or rotate-count, allowing 64-bit shifts <strong>and</strong>rotates.• Immediates: The maximum size of immediate oper<strong>and</strong>s is 32bits, except that 64-bit immediates can be MOVed into 64-bitGPRs. In 64-bit mode, when the oper<strong>and</strong> size is 64 bits,immediates are sign-extended to 64 bits during use, buttheir actual size (for value representation) remains amaximum of 32 bits.• Displacements: The maximum size of an addressdisplacement is 32 bits. In 64-bit mode, displacements aresign-extended to 64 bits during use, but their actual size (forvalue representation) remains a maximum of 32 bits.• Undefined High 32 Bits After Mode Change: The processordoes not preserve the upper 32 bits of the 64-bit GPRs acrossswitches from 64-bit mode to compatibility or legacy modes.In compatibility or legacy mode, the upper 32 bits of theGPRs are undefined <strong>and</strong> not accessible to software.B.2 Operation <strong>and</strong> Oper<strong>and</strong> Size in 64-Bit ModeTable B-1 on page 415 lists the integer instructions, showingoper<strong>and</strong> size in 64-bit mode <strong>and</strong> the state of the high 32 bits ofdestination registers when 32-bit oper<strong>and</strong>s are used. Opcodes,such as byte-oper<strong>and</strong> versions of several instructions, that donot appear in Table B-1 are covered by the general rulesdescribed in “<strong>General</strong> Rules for 64-Bit Mode” on page 413.414 Appendix B: <strong>General</strong>-<strong>Purpose</strong> <strong>Instructions</strong> in 64-Bit Mode


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable B-1.Operations <strong>and</strong> Oper<strong>and</strong>s in 64-Bit ModeInstruction <strong>and</strong>Opcode (hex) 1AAA - ASCII Adjust after Addition37AAD - ASCII Adjust AX before DivisionD5AAM - ASCII Adjust AX after MultiplyD4AAS - ASCII Adjust AL after Subtraction3FADC—Add with Carry11131581 /283 /2Type ofOperation 2Promoted to64 bits.DefaultOper<strong>and</strong>Size 3For 32-BitOper<strong>and</strong> Size 4INVALID IN 64-BIT MODE (invalid-opcode exception)INVALID IN 64-BIT MODE (invalid-opcode exception)INVALID IN 64-BIT MODE (invalid-opcode exception)INVALID IN 64-BIT MODE (invalid-opcode exception)32 bitsZero-extends 32-bit register resultsto 64 bits.For 64-BitOper<strong>and</strong> Size 4Note:1. See “<strong>General</strong> Rules for 64-Bit Mode” on page 413, for opcodes that do not appear in this table.2. The type of operation, excluding considerations of oper<strong>and</strong> size or extension of results. See “<strong>General</strong> Rules for 64-Bit Mode” onpage 413 for definitions of “Promoted to 64 bits” <strong>and</strong> related topics.3. If “Type of Operation” is 64 bits, a REX prefix is needed for 64-bit oper<strong>and</strong> size, unless the instruction size defaults to 64 bits. Ifthe oper<strong>and</strong> size is fixed, oper<strong>and</strong>-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<strong>and</strong>s, notsource oper<strong>and</strong>s. Unless otherwise stated, 8-bit <strong>and</strong> 16-bit results leave the high 56 or 48 bits, respectively, of 64-bit destinationregisters unchanged. Immediates <strong>and</strong> branch displacements are sign-extended to 64 bits.5. Any pointer registers (rDI, rSI) or count registers (rCX) are address-sized <strong>and</strong> default to 64 bits. For 32-bit address size, any pointer<strong>and</strong> count registers are zero-extended to 64 bits.6. The default oper<strong>and</strong> size can be overridden to 16 bits with 66h prefix, but there is no 32-bit oper<strong>and</strong>-size override in 64-bit mode.Appendix B: <strong>General</strong>-<strong>Purpose</strong> <strong>Instructions</strong> in 64-Bit Mode 415


AMD64 Technology 24594 Rev. 3.10 February 2005Table B-1.Operations <strong>and</strong> Oper<strong>and</strong>s in 64-Bit Mode (continued)ADD—Signed or Unsigned Add01030581 /083 /0AND—Logical AND21232581 /483 /4ARPL - Adjust Requestor Privilege Level63BOUND - Check Array Against Bounds62Instruction <strong>and</strong>Opcode (hex) 1Type ofOperation 2Promoted to64 bits.Promoted to64 bits.DefaultOper<strong>and</strong>Size 332 bits32 bitsFor 32-BitOper<strong>and</strong> Size 4Zero-extends 32-bit register resultsto 64 bits.Zero-extends 32-bit register resultsto 64 bits.OPCODE USED as MOVSXD in 64-BIT MODEINVALID IN 64-BIT MODE (invalid-opcode exception)For 64-BitOper<strong>and</strong> Size 4BSF—Bit Scan Forward0F BCPromoted to64 bits.32 bitsZero-extends 32-bit register resultsto 64 bits.Note:1. See “<strong>General</strong> Rules for 64-Bit Mode” on page 413, for opcodes that do not appear in this table.2. The type of operation, excluding considerations of oper<strong>and</strong> size or extension of results. See “<strong>General</strong> Rules for 64-Bit Mode” onpage 413 for definitions of “Promoted to 64 bits” <strong>and</strong> related topics.3. If “Type of Operation” is 64 bits, a REX prefix is needed for 64-bit oper<strong>and</strong> size, unless the instruction size defaults to 64 bits. Ifthe oper<strong>and</strong> size is fixed, oper<strong>and</strong>-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<strong>and</strong>s, notsource oper<strong>and</strong>s. Unless otherwise stated, 8-bit <strong>and</strong> 16-bit results leave the high 56 or 48 bits, respectively, of 64-bit destinationregisters unchanged. Immediates <strong>and</strong> branch displacements are sign-extended to 64 bits.5. Any pointer registers (rDI, rSI) or count registers (rCX) are address-sized <strong>and</strong> default to 64 bits. For 32-bit address size, any pointer<strong>and</strong> count registers are zero-extended to 64 bits.6. The default oper<strong>and</strong> size can be overridden to 16 bits with 66h prefix, but there is no 32-bit oper<strong>and</strong>-size override in 64-bit mode.416 Appendix B: <strong>General</strong>-<strong>Purpose</strong> <strong>Instructions</strong> in 64-Bit Mode


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable B-1.Operations <strong>and</strong> Oper<strong>and</strong>s in 64-Bit Mode (continued)BSR—Bit Scan Reverse0F BDBSWAP—Byte SwapBT—Bit Test0F C8 through 0F CF0F A30F BA /4BTC—Bit Test <strong>and</strong> Complement0F BB0F BA /7BTR—Bit Test <strong>and</strong> Reset0F B30F BA /6BTS—Bit Test <strong>and</strong> Set0F AB0F BA /5Instruction <strong>and</strong>Opcode (hex) 1Type ofOperation 2Promoted to64 bits.Promoted to64 bits.Promoted to64 bits.Promoted to64 bits.Promoted to64 bits.Promoted to64 bits.DefaultOper<strong>and</strong>Size 332 bits32 bitsZero-extends 32-bit register resultsto 64 bits.Zero-extends 32-bit register resultsto 64 bits.32 bits No GPR register results.32 bits32 bits32 bitsFor 32-BitOper<strong>and</strong> Size 4Zero-extends 32-bit register resultsto 64 bits.Zero-extends 32-bit register resultsto 64 bits.Zero-extends 32-bit register resultsto 64 bits.For 64-BitOper<strong>and</strong> Size 4Swap all 8 bytesof a 64-bit GPR.Note:1. See “<strong>General</strong> Rules for 64-Bit Mode” on page 413, for opcodes that do not appear in this table.2. The type of operation, excluding considerations of oper<strong>and</strong> size or extension of results. See “<strong>General</strong> Rules for 64-Bit Mode” onpage 413 for definitions of “Promoted to 64 bits” <strong>and</strong> related topics.3. If “Type of Operation” is 64 bits, a REX prefix is needed for 64-bit oper<strong>and</strong> size, unless the instruction size defaults to 64 bits. Ifthe oper<strong>and</strong> size is fixed, oper<strong>and</strong>-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<strong>and</strong>s, notsource oper<strong>and</strong>s. Unless otherwise stated, 8-bit <strong>and</strong> 16-bit results leave the high 56 or 48 bits, respectively, of 64-bit destinationregisters unchanged. Immediates <strong>and</strong> branch displacements are sign-extended to 64 bits.5. Any pointer registers (rDI, rSI) or count registers (rCX) are address-sized <strong>and</strong> default to 64 bits. For 32-bit address size, any pointer<strong>and</strong> count registers are zero-extended to 64 bits.6. The default oper<strong>and</strong> size can be overridden to 16 bits with 66h prefix, but there is no 32-bit oper<strong>and</strong>-size override in 64-bit mode.Appendix B: <strong>General</strong>-<strong>Purpose</strong> <strong>Instructions</strong> in 64-Bit Mode 417


AMD64 Technology 24594 Rev. 3.10 February 2005Table B-1.Operations <strong>and</strong> Oper<strong>and</strong>s in 64-Bit Mode (continued)Instruction <strong>and</strong>Opcode (hex) 1Type ofOperation 2DefaultOper<strong>and</strong>Size 3For 32-BitOper<strong>and</strong> Size 4For 64-BitOper<strong>and</strong> Size 4CALL—Procedure Call Near See “Near Branches in 64-Bit Mode” in <strong>Volume</strong> 1.E8FF /2Promoted to64 bits.Promoted to64 bits.64 bits Can’t encode. 6 displacementsign-extended toRIP = RIP + 32-bit64 bits.64 bits Can’t encode. 6 from register ormemory.RIP = 64-bit offsetCALL—Procedure Call Far See “Branches to 64-Bit Offsets” in <strong>Volume</strong> 1.9AINVALID IN 64-BIT MODE (invalid-opcode exception)FF /3Promoted to64 bits.32 bitsIf selector points to a gate, thenRIP = 64-bit offset from gate, elseRIP = zero-extended 32-bit offset fromfar pointer referenced in instruction.CBW, CWDE, CDQE—Convert Byte toWord, Convert Word to Doubleword,Convert Doubleword to Quadword98Promoted to64 bits.32 bits(size of destinationregister)CWDE: Convertsword todoubleword.Zero-extends EAXto RAX.CDQE (newmnemonic):Convertsdoubleword toquadword.RAX = signextendedEAX.CDQCDQE (new mnemonic)see CWD, CDQ, CQOsee CBW, CWDE, CDQENote:1. See “<strong>General</strong> Rules for 64-Bit Mode” on page 413, for opcodes that do not appear in this table.2. The type of operation, excluding considerations of oper<strong>and</strong> size or extension of results. See “<strong>General</strong> Rules for 64-Bit Mode” onpage 413 for definitions of “Promoted to 64 bits” <strong>and</strong> related topics.3. If “Type of Operation” is 64 bits, a REX prefix is needed for 64-bit oper<strong>and</strong> size, unless the instruction size defaults to 64 bits. Ifthe oper<strong>and</strong> size is fixed, oper<strong>and</strong>-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<strong>and</strong>s, notsource oper<strong>and</strong>s. Unless otherwise stated, 8-bit <strong>and</strong> 16-bit results leave the high 56 or 48 bits, respectively, of 64-bit destinationregisters unchanged. Immediates <strong>and</strong> branch displacements are sign-extended to 64 bits.5. Any pointer registers (rDI, rSI) or count registers (rCX) are address-sized <strong>and</strong> default to 64 bits. For 32-bit address size, any pointer<strong>and</strong> count registers are zero-extended to 64 bits.6. The default oper<strong>and</strong> size can be overridden to 16 bits with 66h prefix, but there is no 32-bit oper<strong>and</strong>-size override in 64-bit mode.418 Appendix B: <strong>General</strong>-<strong>Purpose</strong> <strong>Instructions</strong> in 64-Bit Mode


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable B-1.Operations <strong>and</strong> Oper<strong>and</strong>s in 64-Bit Mode (continued)CDWECLC—Clear Carry FlagF8CLD—Clear Direction FlagFCCLFLUSH—Cache Line Invalidate0F AE /7CLI—Clear Interrupt FlagFACLTS—Clear Task-Switched Flag in CR00F 06CMC—Complement Carry FlagF5Instruction <strong>and</strong>Opcode (hex) 1CMOVcc—Conditional Move0F 40 through 0F 4FType ofOperation 2Same aslegacy mode.Same aslegacy mode.Same aslegacy mode.Same aslegacy mode.Same aslegacy mode.Same aslegacy mode.Promoted to64 bits.DefaultOper<strong>and</strong>Size 3Not relevant.Not relevant.Not relevant.Not relevant.Not relevant.Not relevant.32 bitsFor 32-BitOper<strong>and</strong> Size 4see CBW, CWDE, CDQENo GPR register results.No GPR register results.No GPR register results.No GPR register results.No GPR register results.No GPR register results.Zero-extends 32-bit register resultsto 64 bits. Thisoccurs even if thecondition is false.For 64-BitOper<strong>and</strong> Size 4Note:1. See “<strong>General</strong> Rules for 64-Bit Mode” on page 413, for opcodes that do not appear in this table.2. The type of operation, excluding considerations of oper<strong>and</strong> size or extension of results. See “<strong>General</strong> Rules for 64-Bit Mode” onpage 413 for definitions of “Promoted to 64 bits” <strong>and</strong> related topics.3. If “Type of Operation” is 64 bits, a REX prefix is needed for 64-bit oper<strong>and</strong> size, unless the instruction size defaults to 64 bits. Ifthe oper<strong>and</strong> size is fixed, oper<strong>and</strong>-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<strong>and</strong>s, notsource oper<strong>and</strong>s. Unless otherwise stated, 8-bit <strong>and</strong> 16-bit results leave the high 56 or 48 bits, respectively, of 64-bit destinationregisters unchanged. Immediates <strong>and</strong> branch displacements are sign-extended to 64 bits.5. Any pointer registers (rDI, rSI) or count registers (rCX) are address-sized <strong>and</strong> default to 64 bits. For 32-bit address size, any pointer<strong>and</strong> count registers are zero-extended to 64 bits.6. The default oper<strong>and</strong> size can be overridden to 16 bits with 66h prefix, but there is no 32-bit oper<strong>and</strong>-size override in 64-bit mode.Appendix B: <strong>General</strong>-<strong>Purpose</strong> <strong>Instructions</strong> in 64-Bit Mode 419


AMD64 Technology 24594 Rev. 3.10 February 2005Table B-1.Operations <strong>and</strong> Oper<strong>and</strong>s in 64-Bit Mode (continued)Instruction <strong>and</strong>Opcode (hex) 1Type ofOperation 2DefaultOper<strong>and</strong>Size 3For 32-BitOper<strong>and</strong> Size 4For 64-BitOper<strong>and</strong> Size 4CMP—Compare393B3DPromoted to64 bits.32 bitsZero-extends 32-bit register resultsto 64 bits.81 /783 /7CMPS, CMPSW, CMPSD, CMPSQ—Compare StringsA7Promoted to64 bits.32 bitsCMPSD:Compare StringDoublewords.See footnote 5CMPSQ (newmnemonic):Compare StringQuadwordsSee footnote 5CMPXCHG—Compare <strong>and</strong> Exchange0F B1Promoted to64 bits.32 bitsZero-extends 32-bit register resultsto 64 bits.CMPXCHG8B—Compare <strong>and</strong> ExchangeEight Bytes0F C7 /1Same aslegacy mode.32 bits.Zero-extends EDX<strong>and</strong> EAX to 64bits.CMPXCHG16B(new mnemonic):Compare <strong>and</strong>Exchange 16Bytes.CPUID—Processor Identification0F A2Same aslegacy mode.Oper<strong>and</strong> sizefixed at 32bits.Zero-extends 32-bit register results to64 bits.Note:1. See “<strong>General</strong> Rules for 64-Bit Mode” on page 413, for opcodes that do not appear in this table.2. The type of operation, excluding considerations of oper<strong>and</strong> size or extension of results. See “<strong>General</strong> Rules for 64-Bit Mode” onpage 413 for definitions of “Promoted to 64 bits” <strong>and</strong> related topics.3. If “Type of Operation” is 64 bits, a REX prefix is needed for 64-bit oper<strong>and</strong> size, unless the instruction size defaults to 64 bits. Ifthe oper<strong>and</strong> size is fixed, oper<strong>and</strong>-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<strong>and</strong>s, notsource oper<strong>and</strong>s. Unless otherwise stated, 8-bit <strong>and</strong> 16-bit results leave the high 56 or 48 bits, respectively, of 64-bit destinationregisters unchanged. Immediates <strong>and</strong> branch displacements are sign-extended to 64 bits.5. Any pointer registers (rDI, rSI) or count registers (rCX) are address-sized <strong>and</strong> default to 64 bits. For 32-bit address size, any pointer<strong>and</strong> count registers are zero-extended to 64 bits.6. The default oper<strong>and</strong> size can be overridden to 16 bits with 66h prefix, but there is no 32-bit oper<strong>and</strong>-size override in 64-bit mode.420 Appendix B: <strong>General</strong>-<strong>Purpose</strong> <strong>Instructions</strong> in 64-Bit Mode


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable B-1.Operations <strong>and</strong> Oper<strong>and</strong>s in 64-Bit Mode (continued)Instruction <strong>and</strong>Opcode (hex) 1Type ofOperation 2DefaultOper<strong>and</strong>Size 3For 32-BitOper<strong>and</strong> Size 4For 64-BitOper<strong>and</strong> Size 4CQO (new mnemonic)see CWD, CDQ, CQOCWD, CDQ, CQO—Convert Word toDoubleword, Convert Doubleword toQuadword, Convert Quadword to DoubleQuadword99Promoted to64 bits.32 bits(size of destinationregister)CDQ: Convertsdoubleword toquadword.Sign-extends EAXto EDX. ZeroextendsEDX toRDX. RAX isunchanged.CQO (newmnemonic):Convertsquadword todoublequadword.Sign-extends RAXto RDX. RAX isunchanged.DAA - Decimal Adjust AL after Addition27DAS - Decimal Adjust AL after Subtraction2FINVALID IN 64-BIT MODE (invalid-opcode exception)INVALID IN 64-BIT MODE (invalid-opcode exception)DEC—Decrement by 1FF /1Promoted to64 bits.32 bitsZero-extends 32-bit register resultsto 64 bits.48 through 4F OPCODE USED as REX PREFIX in 64-BIT MODEDIV—Unsigned DivideF7 /6Promoted to64 bits.32 bitsZero-extends 32-bit register resultsto 64 bits.RDX:RAX containa 64-bit quotient(RAX) <strong>and</strong> 64-bitremainder (RDX).ENTER—Create Procedure Stack FrameC8Promoted to64 bits.64 bits Can’t encode 6Note:1. See “<strong>General</strong> Rules for 64-Bit Mode” on page 413, for opcodes that do not appear in this table.2. The type of operation, excluding considerations of oper<strong>and</strong> size or extension of results. See “<strong>General</strong> Rules for 64-Bit Mode” onpage 413 for definitions of “Promoted to 64 bits” <strong>and</strong> related topics.3. If “Type of Operation” is 64 bits, a REX prefix is needed for 64-bit oper<strong>and</strong> size, unless the instruction size defaults to 64 bits. Ifthe oper<strong>and</strong> size is fixed, oper<strong>and</strong>-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<strong>and</strong>s, notsource oper<strong>and</strong>s. Unless otherwise stated, 8-bit <strong>and</strong> 16-bit results leave the high 56 or 48 bits, respectively, of 64-bit destinationregisters unchanged. Immediates <strong>and</strong> branch displacements are sign-extended to 64 bits.5. Any pointer registers (rDI, rSI) or count registers (rCX) are address-sized <strong>and</strong> default to 64 bits. For 32-bit address size, any pointer<strong>and</strong> count registers are zero-extended to 64 bits.6. The default oper<strong>and</strong> size can be overridden to 16 bits with 66h prefix, but there is no 32-bit oper<strong>and</strong>-size override in 64-bit mode.Appendix B: <strong>General</strong>-<strong>Purpose</strong> <strong>Instructions</strong> in 64-Bit Mode 421


AMD64 Technology 24594 Rev. 3.10 February 2005Table B-1.Operations <strong>and</strong> Oper<strong>and</strong>s in 64-Bit Mode (continued)Instruction <strong>and</strong>Opcode (hex) 1Type ofOperation 2DefaultOper<strong>and</strong>Size 3For 32-BitOper<strong>and</strong> Size 4For 64-BitOper<strong>and</strong> Size 4HLT—HaltF4Same aslegacy mode.Not relevant.No GPR register results.IDIV—Signed DivideF7 /7Promoted to64 bits.32 bitsZero-extends 32-bit register resultsto 64 bits.RDX:RAX containa 64-bit quotient(RAX) <strong>and</strong> 64-bitremainder (RDX).IMUL - Signed MultiplyF7 /5RDX:RAX = RAX *reg/mem64(i.e., 128-bitresult)0F AF69Promoted to64 bits.32 bitsZero-extends 32-bit register resultsto 64 bits.reg64 = reg64 *reg/mem64reg64 =reg/mem64 *imm326Breg64 =reg/mem64 *imm8IN—Input From PortE5EDSame aslegacy mode.32 bitsZero-extends 32-bit register results to64 bits.Note:1. See “<strong>General</strong> Rules for 64-Bit Mode” on page 413, for opcodes that do not appear in this table.2. The type of operation, excluding considerations of oper<strong>and</strong> size or extension of results. See “<strong>General</strong> Rules for 64-Bit Mode” onpage 413 for definitions of “Promoted to 64 bits” <strong>and</strong> related topics.3. If “Type of Operation” is 64 bits, a REX prefix is needed for 64-bit oper<strong>and</strong> size, unless the instruction size defaults to 64 bits. Ifthe oper<strong>and</strong> size is fixed, oper<strong>and</strong>-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<strong>and</strong>s, notsource oper<strong>and</strong>s. Unless otherwise stated, 8-bit <strong>and</strong> 16-bit results leave the high 56 or 48 bits, respectively, of 64-bit destinationregisters unchanged. Immediates <strong>and</strong> branch displacements are sign-extended to 64 bits.5. Any pointer registers (rDI, rSI) or count registers (rCX) are address-sized <strong>and</strong> default to 64 bits. For 32-bit address size, any pointer<strong>and</strong> count registers are zero-extended to 64 bits.6. The default oper<strong>and</strong> size can be overridden to 16 bits with 66h prefix, but there is no 32-bit oper<strong>and</strong>-size override in 64-bit mode.422 Appendix B: <strong>General</strong>-<strong>Purpose</strong> <strong>Instructions</strong> in 64-Bit Mode


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable B-1.Operations <strong>and</strong> Oper<strong>and</strong>s in 64-Bit Mode (continued)Instruction <strong>and</strong>Opcode (hex) 1Type ofOperation 2DefaultOper<strong>and</strong>Size 3For 32-BitOper<strong>and</strong> Size 4For 64-BitOper<strong>and</strong> Size 4INC—Increment by 1FF /0Promoted to64 bits.32 bitsZero-extends 32-bit register resultsto 64 bits.40 through 47 OPCODE USED as REX PREFIX in 64-BIT MODEINS, INSW, INSD—Input String6DSame aslegacy mode.32 bitsINSD: Input String Doublewords.No GPR register results.See footnote 5INT n—Interrupt to VectorCDINT3—Interrupt to Debug VectorPromoted to64 bits.Not relevant.See “Long-Mode Interrupt ControlTransfers” in <strong>Volume</strong> 2.CCINTO - Interrupt to Overflow VectorCEINVALID IN 64-BIT MODE (invalid-opcode exception)INVD—Invalidate Internal Caches0F 08Same aslegacy mode.Not relevant.No GPR register results.INVLPG—Invalidate TLB Entry0F 01 /7Promoted to64 bits.Not relevant.No GPR register results.Note:1. See “<strong>General</strong> Rules for 64-Bit Mode” on page 413, for opcodes that do not appear in this table.2. The type of operation, excluding considerations of oper<strong>and</strong> size or extension of results. See “<strong>General</strong> Rules for 64-Bit Mode” onpage 413 for definitions of “Promoted to 64 bits” <strong>and</strong> related topics.3. If “Type of Operation” is 64 bits, a REX prefix is needed for 64-bit oper<strong>and</strong> size, unless the instruction size defaults to 64 bits. Ifthe oper<strong>and</strong> size is fixed, oper<strong>and</strong>-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<strong>and</strong>s, notsource oper<strong>and</strong>s. Unless otherwise stated, 8-bit <strong>and</strong> 16-bit results leave the high 56 or 48 bits, respectively, of 64-bit destinationregisters unchanged. Immediates <strong>and</strong> branch displacements are sign-extended to 64 bits.5. Any pointer registers (rDI, rSI) or count registers (rCX) are address-sized <strong>and</strong> default to 64 bits. For 32-bit address size, any pointer<strong>and</strong> count registers are zero-extended to 64 bits.6. The default oper<strong>and</strong> size can be overridden to 16 bits with 66h prefix, but there is no 32-bit oper<strong>and</strong>-size override in 64-bit mode.Appendix B: <strong>General</strong>-<strong>Purpose</strong> <strong>Instructions</strong> in 64-Bit Mode 423


AMD64 Technology 24594 Rev. 3.10 February 2005Table B-1.Operations <strong>and</strong> Oper<strong>and</strong>s in 64-Bit Mode (continued)IRET, IRETD, IRETQ—Interrupt ReturnCFPromoted to64 bits.32 bitsIRETD: InterruptReturnDoubleword.See “Long-ModeInterrupt ControlTransfers” in<strong>Volume</strong> 2.Jcc—Jump Conditional See “Near Branches in 64-Bit Mode” in <strong>Volume</strong> 1.70 through 7F0F 80 through 0F 8FJCXZ, JECXZ, JRCXZ—Jump on CX/ECX/RCXZeroE3Instruction <strong>and</strong>Opcode (hex) 1Type ofOperation 2Promoted to64 bits.Promoted to64 bits.DefaultOper<strong>and</strong>Size 3For 32-BitOper<strong>and</strong> Size 4For 64-BitOper<strong>and</strong> Size 4IRETQ (newmnemonic):Interrupt ReturnQuadword.See “Long-ModeInterrupt ControlTransfers” in<strong>Volume</strong> 2.64 bits 6 RIP = RIP + 8-bitdisplacementsign-extended to64 bits.RIP = RIP + 32-bitdisplacementsign-extended to64 bits.64 bits Can’t encode. 6 RIP = RIP + 8-bitdisplacementsign-extended to64 bits.See footnote 5Note:1. See “<strong>General</strong> Rules for 64-Bit Mode” on page 413, for opcodes that do not appear in this table.2. The type of operation, excluding considerations of oper<strong>and</strong> size or extension of results. See “<strong>General</strong> Rules for 64-Bit Mode” onpage 413 for definitions of “Promoted to 64 bits” <strong>and</strong> related topics.3. If “Type of Operation” is 64 bits, a REX prefix is needed for 64-bit oper<strong>and</strong> size, unless the instruction size defaults to 64 bits. Ifthe oper<strong>and</strong> size is fixed, oper<strong>and</strong>-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<strong>and</strong>s, notsource oper<strong>and</strong>s. Unless otherwise stated, 8-bit <strong>and</strong> 16-bit results leave the high 56 or 48 bits, respectively, of 64-bit destinationregisters unchanged. Immediates <strong>and</strong> branch displacements are sign-extended to 64 bits.5. Any pointer registers (rDI, rSI) or count registers (rCX) are address-sized <strong>and</strong> default to 64 bits. For 32-bit address size, any pointer<strong>and</strong> count registers are zero-extended to 64 bits.6. The default oper<strong>and</strong> size can be overridden to 16 bits with 66h prefix, but there is no 32-bit oper<strong>and</strong>-size override in 64-bit mode.424 Appendix B: <strong>General</strong>-<strong>Purpose</strong> <strong>Instructions</strong> in 64-Bit Mode


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable B-1.Operations <strong>and</strong> Oper<strong>and</strong>s in 64-Bit Mode (continued)JMP—Jump Near See “Near Branches in 64-Bit Mode” in <strong>Volume</strong> 1.EBE9FF /4Promoted to64 bits.JMP—Jump Far See “Branches to 64-Bit Offsets” in <strong>Volume</strong> 1.EAFF /5LAHF - Load Status Flags into AH Register9FLAR—Load Access Rights Byte0F 02Instruction <strong>and</strong>Opcode (hex) 1Type ofOperation 2Promoted to64 bits.Same as legacymode.Same aslegacy mode.DefaultOper<strong>and</strong>Size 364 bits Can’t encode. 6 RIP = RIP + 8-bitdisplacementsign-extended to64 bits.RIP = RIP + 32-bitdisplacementsign-extended to64 bits.INVALID IN 64-BIT MODE (invalid-opcode exception)32 bitsNot relevant.32 bitsFor 32-BitOper<strong>and</strong> Size 4RIP = 64-bit offsetfrom register ormemory.If selector points to a gate, thenRIP = 64-bit offset from gate, elseRIP = zero-extended 32-bit offset fromfar pointer referenced in instruction.Zero-extends 32-bit register resultsto 64 bits.For 64-BitOper<strong>and</strong> Size 4Note:1. See “<strong>General</strong> Rules for 64-Bit Mode” on page 413, for opcodes that do not appear in this table.2. The type of operation, excluding considerations of oper<strong>and</strong> size or extension of results. See “<strong>General</strong> Rules for 64-Bit Mode” onpage 413 for definitions of “Promoted to 64 bits” <strong>and</strong> related topics.3. If “Type of Operation” is 64 bits, a REX prefix is needed for 64-bit oper<strong>and</strong> size, unless the instruction size defaults to 64 bits. Ifthe oper<strong>and</strong> size is fixed, oper<strong>and</strong>-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<strong>and</strong>s, notsource oper<strong>and</strong>s. Unless otherwise stated, 8-bit <strong>and</strong> 16-bit results leave the high 56 or 48 bits, respectively, of 64-bit destinationregisters unchanged. Immediates <strong>and</strong> branch displacements are sign-extended to 64 bits.5. Any pointer registers (rDI, rSI) or count registers (rCX) are address-sized <strong>and</strong> default to 64 bits. For 32-bit address size, any pointer<strong>and</strong> count registers are zero-extended to 64 bits.6. The default oper<strong>and</strong> size can be overridden to 16 bits with 66h prefix, but there is no 32-bit oper<strong>and</strong>-size override in 64-bit mode.Appendix B: <strong>General</strong>-<strong>Purpose</strong> <strong>Instructions</strong> in 64-Bit Mode 425


AMD64 Technology 24594 Rev. 3.10 February 2005Table B-1.Operations <strong>and</strong> Oper<strong>and</strong>s in 64-Bit Mode (continued)Instruction <strong>and</strong>Opcode (hex) 1Type ofOperation 2DefaultOper<strong>and</strong>Size 3For 32-BitOper<strong>and</strong> Size 4For 64-BitOper<strong>and</strong> Size 4LDS - Load DS Far PointerC5INVALID IN 64-BIT MODE (invalid-opcode exception)LEA—Load Effective Address8DPromoted to64 bits.32 bitsZero-extends 32-bit register resultsto 64 bits.LEAVE—Delete Procedure Stack FrameC9Promoted to64 bits.64 bits Can’t encode 6LES - Load ES Far PointerC4INVALID IN 64-BIT MODE (invalid-opcode exception)LFENCE—Load Fence0F AE /5Same aslegacy mode.Not relevant.No GPR register results.LFS—Load FS Far Pointer0F B4Same aslegacy mode.32 bitsZero-extends 32-bit register results to64 bits.LGDT—Load Global Descriptor TableRegister0F 01 /2Promoted to64 bits.Oper<strong>and</strong> sizefixed at 64bits.No GPR register results.Loads 8-byte base <strong>and</strong> 2-byte limit.LGS—Load GS Far Pointer0F B5Same aslegacy mode.32 bitsZero-extends 32-bit register results to64 bits.Note:1. See “<strong>General</strong> Rules for 64-Bit Mode” on page 413, for opcodes that do not appear in this table.2. The type of operation, excluding considerations of oper<strong>and</strong> size or extension of results. See “<strong>General</strong> Rules for 64-Bit Mode” onpage 413 for definitions of “Promoted to 64 bits” <strong>and</strong> related topics.3. If “Type of Operation” is 64 bits, a REX prefix is needed for 64-bit oper<strong>and</strong> size, unless the instruction size defaults to 64 bits. Ifthe oper<strong>and</strong> size is fixed, oper<strong>and</strong>-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<strong>and</strong>s, notsource oper<strong>and</strong>s. Unless otherwise stated, 8-bit <strong>and</strong> 16-bit results leave the high 56 or 48 bits, respectively, of 64-bit destinationregisters unchanged. Immediates <strong>and</strong> branch displacements are sign-extended to 64 bits.5. Any pointer registers (rDI, rSI) or count registers (rCX) are address-sized <strong>and</strong> default to 64 bits. For 32-bit address size, any pointer<strong>and</strong> count registers are zero-extended to 64 bits.6. The default oper<strong>and</strong> size can be overridden to 16 bits with 66h prefix, but there is no 32-bit oper<strong>and</strong>-size override in 64-bit mode.426 Appendix B: <strong>General</strong>-<strong>Purpose</strong> <strong>Instructions</strong> in 64-Bit Mode


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable B-1.Operations <strong>and</strong> Oper<strong>and</strong>s in 64-Bit Mode (continued)Instruction <strong>and</strong>Opcode (hex) 1Type ofOperation 2DefaultOper<strong>and</strong>Size 3For 32-BitOper<strong>and</strong> Size 4For 64-BitOper<strong>and</strong> Size 4LIDT—Load Interrupt Descriptor TableRegister0F 01 /3Promoted to64 bits.Oper<strong>and</strong> sizefixed at 64bits.No GPR register results.Loads 8-byte base <strong>and</strong> 2-byte limit.LLDT—Load Local Descriptor Table Register0F 00 /2Promoted to64 bits.Oper<strong>and</strong> sizefixed at 16bits.No GPR register results.References 16-byte descriptor to load64-bit base.LMSW—Load Machine Status Word0F 01 /6Same aslegacy mode.Oper<strong>and</strong> sizefixed at 16bits.No GPR register results.LODS, LODSW, LODSD, LODSQ—LoadStringADPromoted to64 bits.32 bitsLODSD: LoadStringDoublewords.Zero-extends 32-bit register resultsto 64 bits.See footnote 5LODSQ (newmnemonic): LoadStringQuadwords.See footnote 5LOOP—LoopE2LOOPZ, LOOPE—Loop if Zero/EqualE1LOOPNZ, LOOPNE—Loop if NotZero/EqualE0Promoted to64 bits.64 bits Can’t encode. 6 RIP = RIP + 8-bitdisplacementsign-extended to64 bits.See footnote 5Note:1. See “<strong>General</strong> Rules for 64-Bit Mode” on page 413, for opcodes that do not appear in this table.2. The type of operation, excluding considerations of oper<strong>and</strong> size or extension of results. See “<strong>General</strong> Rules for 64-Bit Mode” onpage 413 for definitions of “Promoted to 64 bits” <strong>and</strong> related topics.3. If “Type of Operation” is 64 bits, a REX prefix is needed for 64-bit oper<strong>and</strong> size, unless the instruction size defaults to 64 bits. Ifthe oper<strong>and</strong> size is fixed, oper<strong>and</strong>-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<strong>and</strong>s, notsource oper<strong>and</strong>s. Unless otherwise stated, 8-bit <strong>and</strong> 16-bit results leave the high 56 or 48 bits, respectively, of 64-bit destinationregisters unchanged. Immediates <strong>and</strong> branch displacements are sign-extended to 64 bits.5. Any pointer registers (rDI, rSI) or count registers (rCX) are address-sized <strong>and</strong> default to 64 bits. For 32-bit address size, any pointer<strong>and</strong> count registers are zero-extended to 64 bits.6. The default oper<strong>and</strong> size can be overridden to 16 bits with 66h prefix, but there is no 32-bit oper<strong>and</strong>-size override in 64-bit mode.Appendix B: <strong>General</strong>-<strong>Purpose</strong> <strong>Instructions</strong> in 64-Bit Mode 427


AMD64 Technology 24594 Rev. 3.10 February 2005Table B-1.Operations <strong>and</strong> Oper<strong>and</strong>s in 64-Bit Mode (continued)Instruction <strong>and</strong>Opcode (hex) 1Type ofOperation 2DefaultOper<strong>and</strong>Size 3For 32-BitOper<strong>and</strong> Size 4For 64-BitOper<strong>and</strong> Size 4LSL—Load Segment Limit0F 03Same aslegacy mode.32 bitsZero-extends 32-bit register results to64 bits.LSS —Load SS Segment Register0F B2Same aslegacy mode.32 bitsZero-extends 32-bit register results to64 bits.LTR—Load Task Register0F 00 /3Promoted to64 bits.Oper<strong>and</strong> sizefixed at 16bits.No GPR register results.References 16-byte descriptor to load64-bit base.MFENCE—Memory Fence0F AE /6Same aslegacy mode.Not relevant.No GPR register results.Note:1. See “<strong>General</strong> Rules for 64-Bit Mode” on page 413, for opcodes that do not appear in this table.2. The type of operation, excluding considerations of oper<strong>and</strong> size or extension of results. See “<strong>General</strong> Rules for 64-Bit Mode” onpage 413 for definitions of “Promoted to 64 bits” <strong>and</strong> related topics.3. If “Type of Operation” is 64 bits, a REX prefix is needed for 64-bit oper<strong>and</strong> size, unless the instruction size defaults to 64 bits. Ifthe oper<strong>and</strong> size is fixed, oper<strong>and</strong>-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<strong>and</strong>s, notsource oper<strong>and</strong>s. Unless otherwise stated, 8-bit <strong>and</strong> 16-bit results leave the high 56 or 48 bits, respectively, of 64-bit destinationregisters unchanged. Immediates <strong>and</strong> branch displacements are sign-extended to 64 bits.5. Any pointer registers (rDI, rSI) or count registers (rCX) are address-sized <strong>and</strong> default to 64 bits. For 32-bit address size, any pointer<strong>and</strong> count registers are zero-extended to 64 bits.6. The default oper<strong>and</strong> size can be overridden to 16 bits with 66h prefix, but there is no 32-bit oper<strong>and</strong>-size override in 64-bit mode.428 Appendix B: <strong>General</strong>-<strong>Purpose</strong> <strong>Instructions</strong> in 64-Bit Mode


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable B-1.Operations <strong>and</strong> Oper<strong>and</strong>s in 64-Bit Mode (continued)Instruction <strong>and</strong>Opcode (hex) 1Type ofOperation 2DefaultOper<strong>and</strong>Size 3For 32-BitOper<strong>and</strong> Size 4For 64-BitOper<strong>and</strong> Size 4MOV—Move898BC7Zero-extends 32-bit register resultsto 64 bits.Promoted toB8 through BF32 bits64 bits.A1 (moffset) Zero-extends 32-bit register resultsto 64 bits.Memory offsetsA3 (moffset)are address-sized<strong>and</strong> default to 64bits.32-bit immediateis sign-extendedto 64 bits.64-bit immediate.Memory offsetsare address-sized<strong>and</strong> default to 64bits.MOV—Move to/from Segment Registers8C8ESame aslegacy mode.32 bitsOper<strong>and</strong> sizefixed at 16bits.Zero-extends 32-bit register results to64 bits.No GPR register results.MOV(CRn)—Move to/from ControlRegisters0F 220F 20Promoted to64 bits.Oper<strong>and</strong> sizefixed at 64bits.The high 32 bits of control registersdiffer in their writability <strong>and</strong> reservedstatus. See “<strong>System</strong> Resources” in<strong>Volume</strong> 2 for details.Note:1. See “<strong>General</strong> Rules for 64-Bit Mode” on page 413, for opcodes that do not appear in this table.2. The type of operation, excluding considerations of oper<strong>and</strong> size or extension of results. See “<strong>General</strong> Rules for 64-Bit Mode” onpage 413 for definitions of “Promoted to 64 bits” <strong>and</strong> related topics.3. If “Type of Operation” is 64 bits, a REX prefix is needed for 64-bit oper<strong>and</strong> size, unless the instruction size defaults to 64 bits. Ifthe oper<strong>and</strong> size is fixed, oper<strong>and</strong>-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<strong>and</strong>s, notsource oper<strong>and</strong>s. Unless otherwise stated, 8-bit <strong>and</strong> 16-bit results leave the high 56 or 48 bits, respectively, of 64-bit destinationregisters unchanged. Immediates <strong>and</strong> branch displacements are sign-extended to 64 bits.5. Any pointer registers (rDI, rSI) or count registers (rCX) are address-sized <strong>and</strong> default to 64 bits. For 32-bit address size, any pointer<strong>and</strong> count registers are zero-extended to 64 bits.6. The default oper<strong>and</strong> size can be overridden to 16 bits with 66h prefix, but there is no 32-bit oper<strong>and</strong>-size override in 64-bit mode.Appendix B: <strong>General</strong>-<strong>Purpose</strong> <strong>Instructions</strong> in 64-Bit Mode 429


AMD64 Technology 24594 Rev. 3.10 February 2005Table B-1.Operations <strong>and</strong> Oper<strong>and</strong>s in 64-Bit Mode (continued)MOV(DRn)—Move to/from DebugRegisters0F 210F 23Promoted to64 bits.Oper<strong>and</strong> sizefixed at 64bits.MOVD—Move Doubleword or QuadwordZero-extends 32-0F 6Ebit register resultsPromoted toto 64 bits.0F 7E32 bits64 bits.66 0F 6E Zero-extends 32-bit register results66 0F 7Eto 128 bits.MOVNTI—Move Non-TemporalDoubleword0F C3MOVS, MOVSW, MOVSD, MOVSQ—MoveStringA5Instruction <strong>and</strong>Opcode (hex) 1Type ofOperation 2Promoted to64 bits.Promoted to64 bits.DefaultOper<strong>and</strong>Size 3The high 32 bits of debug registersdiffer in their writability <strong>and</strong> reservedstatus. See “Debug <strong>and</strong> PerformanceResources” in <strong>Volume</strong> 2 for details.32 bits No GPR register results.32 bitsFor 32-BitOper<strong>and</strong> Size 4MOVSD: MoveStringDoublewords.See footnote 5For 64-BitOper<strong>and</strong> Size 4Zero-extends 64-bit register resultsto 128 bits.MOVSQ (newmnemonic):Move StringQuadwords.See footnote 5Note:1. See “<strong>General</strong> Rules for 64-Bit Mode” on page 413, for opcodes that do not appear in this table.2. The type of operation, excluding considerations of oper<strong>and</strong> size or extension of results. See “<strong>General</strong> Rules for 64-Bit Mode” onpage 413 for definitions of “Promoted to 64 bits” <strong>and</strong> related topics.3. If “Type of Operation” is 64 bits, a REX prefix is needed for 64-bit oper<strong>and</strong> size, unless the instruction size defaults to 64 bits. Ifthe oper<strong>and</strong> size is fixed, oper<strong>and</strong>-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<strong>and</strong>s, notsource oper<strong>and</strong>s. Unless otherwise stated, 8-bit <strong>and</strong> 16-bit results leave the high 56 or 48 bits, respectively, of 64-bit destinationregisters unchanged. Immediates <strong>and</strong> branch displacements are sign-extended to 64 bits.5. Any pointer registers (rDI, rSI) or count registers (rCX) are address-sized <strong>and</strong> default to 64 bits. For 32-bit address size, any pointer<strong>and</strong> count registers are zero-extended to 64 bits.6. The default oper<strong>and</strong> size can be overridden to 16 bits with 66h prefix, but there is no 32-bit oper<strong>and</strong>-size override in 64-bit mode.430 Appendix B: <strong>General</strong>-<strong>Purpose</strong> <strong>Instructions</strong> in 64-Bit Mode


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable B-1.Operations <strong>and</strong> Oper<strong>and</strong>s in 64-Bit Mode (continued)Instruction <strong>and</strong>Opcode (hex) 1Type ofOperation 2DefaultOper<strong>and</strong>Size 3For 32-BitOper<strong>and</strong> Size 4For 64-BitOper<strong>and</strong> Size 4MOVSX—Move with Sign-Extend0F BE0F BFPromoted to64 bits.32 bitsZero-extends 32-bit register resultsto 64 bits.Sign-extends byteto quadword.Sign-extendsword toquadword.MOVSXD—Move with Sign-ExtendDoubleword63Newinstruction,availableonly in 64-bitmode. (Inother modes,this opcodeis ARPLinstruction.)32 bitsZero-extends 32-bit register resultsto 64 bits.Sign-extendsdoubleword toquadword.MOVZX—Move with Zero-Extend0F B60F B7Promoted to64 bits.32 bitsZero-extends 32-bit register resultsto 64 bits.Zero-extendsbyte toquadword.Zero-extendsword toquadword.MUL—Multiply UnsignedF7 /4Promoted to64 bits.32 bitsZero-extends 32-bit register resultsto 64 bits.RDX:RAX=RAX *quadword inregister ormemory.Note:1. See “<strong>General</strong> Rules for 64-Bit Mode” on page 413, for opcodes that do not appear in this table.2. The type of operation, excluding considerations of oper<strong>and</strong> size or extension of results. See “<strong>General</strong> Rules for 64-Bit Mode” onpage 413 for definitions of “Promoted to 64 bits” <strong>and</strong> related topics.3. If “Type of Operation” is 64 bits, a REX prefix is needed for 64-bit oper<strong>and</strong> size, unless the instruction size defaults to 64 bits. Ifthe oper<strong>and</strong> size is fixed, oper<strong>and</strong>-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<strong>and</strong>s, notsource oper<strong>and</strong>s. Unless otherwise stated, 8-bit <strong>and</strong> 16-bit results leave the high 56 or 48 bits, respectively, of 64-bit destinationregisters unchanged. Immediates <strong>and</strong> branch displacements are sign-extended to 64 bits.5. Any pointer registers (rDI, rSI) or count registers (rCX) are address-sized <strong>and</strong> default to 64 bits. For 32-bit address size, any pointer<strong>and</strong> count registers are zero-extended to 64 bits.6. The default oper<strong>and</strong> size can be overridden to 16 bits with 66h prefix, but there is no 32-bit oper<strong>and</strong>-size override in 64-bit mode.Appendix B: <strong>General</strong>-<strong>Purpose</strong> <strong>Instructions</strong> in 64-Bit Mode 431


AMD64 Technology 24594 Rev. 3.10 February 2005Table B-1.Operations <strong>and</strong> Oper<strong>and</strong>s in 64-Bit Mode (continued)Instruction <strong>and</strong>Opcode (hex) 1Type ofOperation 2DefaultOper<strong>and</strong>Size 3For 32-BitOper<strong>and</strong> Size 4For 64-BitOper<strong>and</strong> Size 4NEG—Negate Two’s ComplementF7 /3Promoted to64 bits.32 bitsZero-extends 32-bit register resultsto 64 bits.NOP—No Operation90Same aslegacy mode.Not relevant.No GPR register results.NOT—Negate One’s ComplementF7 /2Promoted to64 bits.32 bitsZero-extends 32-bit register resultsto 64 bits.OR—Logical OR090B0DPromoted to64 bits.32 bitsZero-extends 32-bit register resultsto 64 bits.81 /183 /1OUT—Output to PortE7EFSame aslegacy mode.32 bits No GPR register results.OUTS, OUTSW, OUTSD—Output String6FSame aslegacy mode.32 bitsWrites doubleword to I/O port.No GPR register results.See footnote 5Note:1. See “<strong>General</strong> Rules for 64-Bit Mode” on page 413, for opcodes that do not appear in this table.2. The type of operation, excluding considerations of oper<strong>and</strong> size or extension of results. See “<strong>General</strong> Rules for 64-Bit Mode” onpage 413 for definitions of “Promoted to 64 bits” <strong>and</strong> related topics.3. If “Type of Operation” is 64 bits, a REX prefix is needed for 64-bit oper<strong>and</strong> size, unless the instruction size defaults to 64 bits. Ifthe oper<strong>and</strong> size is fixed, oper<strong>and</strong>-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<strong>and</strong>s, notsource oper<strong>and</strong>s. Unless otherwise stated, 8-bit <strong>and</strong> 16-bit results leave the high 56 or 48 bits, respectively, of 64-bit destinationregisters unchanged. Immediates <strong>and</strong> branch displacements are sign-extended to 64 bits.5. Any pointer registers (rDI, rSI) or count registers (rCX) are address-sized <strong>and</strong> default to 64 bits. For 32-bit address size, any pointer<strong>and</strong> count registers are zero-extended to 64 bits.6. The default oper<strong>and</strong> size can be overridden to 16 bits with 66h prefix, but there is no 32-bit oper<strong>and</strong>-size override in 64-bit mode.432 Appendix B: <strong>General</strong>-<strong>Purpose</strong> <strong>Instructions</strong> in 64-Bit Mode


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable B-1.Operations <strong>and</strong> Oper<strong>and</strong>s in 64-Bit Mode (continued)POP—Pop Stack8F /058 through 5FPOP—Pop (segment register from) Stack0F A1 (POP FS)0F A9 (POP GS)1F (POP DS)07 (POP ES)17 (POP SS)POPA, POPAD - Pop All to GPR Words orDoublewords61POPF, POPFD, POPFQ—Pop to rFLAGSWord, Doublword, or Quadword9DPREFETCH—Prefetch L1 Data-Cache Line0F 0D /0Instruction <strong>and</strong>Opcode (hex) 1Type ofOperation 2Promoted to64 bits.Same aslegacy mode.Promoted to64 bits.Same aslegacy mode.DefaultOper<strong>and</strong>Size 364 bits Cannot encode 6 No GPR registerresults.64 bits Cannot encode 6 No GPR registerresults.INVALID IN 64-BIT MODE (invalid-opcode exception)INVALID IN 64-BIT MODE (invalid-opcode exception)64 bits Cannot encode 6 POPFQ (newmnemonic): Pops64 bits off stack,writes low 32 bitsinto EFLAGS <strong>and</strong>zero-extends thehigh 32 bits ofRFLAGS.Not relevant.For 32-BitOper<strong>and</strong> Size 4No GPR register results.For 64-BitOper<strong>and</strong> Size 4Note:1. See “<strong>General</strong> Rules for 64-Bit Mode” on page 413, for opcodes that do not appear in this table.2. The type of operation, excluding considerations of oper<strong>and</strong> size or extension of results. See “<strong>General</strong> Rules for 64-Bit Mode” onpage 413 for definitions of “Promoted to 64 bits” <strong>and</strong> related topics.3. If “Type of Operation” is 64 bits, a REX prefix is needed for 64-bit oper<strong>and</strong> size, unless the instruction size defaults to 64 bits. Ifthe oper<strong>and</strong> size is fixed, oper<strong>and</strong>-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<strong>and</strong>s, notsource oper<strong>and</strong>s. Unless otherwise stated, 8-bit <strong>and</strong> 16-bit results leave the high 56 or 48 bits, respectively, of 64-bit destinationregisters unchanged. Immediates <strong>and</strong> branch displacements are sign-extended to 64 bits.5. Any pointer registers (rDI, rSI) or count registers (rCX) are address-sized <strong>and</strong> default to 64 bits. For 32-bit address size, any pointer<strong>and</strong> count registers are zero-extended to 64 bits.6. The default oper<strong>and</strong> size can be overridden to 16 bits with 66h prefix, but there is no 32-bit oper<strong>and</strong>-size override in 64-bit mode.Appendix B: <strong>General</strong>-<strong>Purpose</strong> <strong>Instructions</strong> in 64-Bit Mode 433


AMD64 Technology 24594 Rev. 3.10 February 2005Table B-1.Operations <strong>and</strong> Oper<strong>and</strong>s in 64-Bit Mode (continued)PREFETCHlevel—Prefetch Data to CacheLevel level0F 18 /0-3PREFETCHW—Prefetch L1 Data-Cache Linefor Write0F 0D /1PUSH—Push onto StackFF /650 through 576A68Instruction <strong>and</strong>Opcode (hex) 1PUSH—Push (segment register) onto Stack0F A0 (PUSH FS)0F A8 (PUSH GS)0E (PUSH CS)1E (PUSH DS)06 (PUSH ES)16 (PUSH SS)Type ofOperation 2Same aslegacy mode.Same aslegacy mode.Promoted to64 bits.Promoted to64 bits.DefaultOper<strong>and</strong>Size 3Not relevant.Not relevant.For 32-BitOper<strong>and</strong> Size 4No GPR register results.No GPR register results.64 bits Cannot encode 664 bits Cannot encode 6INVALID IN 64-BIT MODE (invalid-opcode exception)For 64-BitOper<strong>and</strong> Size 4Note:1. See “<strong>General</strong> Rules for 64-Bit Mode” on page 413, for opcodes that do not appear in this table.2. The type of operation, excluding considerations of oper<strong>and</strong> size or extension of results. See “<strong>General</strong> Rules for 64-Bit Mode” onpage 413 for definitions of “Promoted to 64 bits” <strong>and</strong> related topics.3. If “Type of Operation” is 64 bits, a REX prefix is needed for 64-bit oper<strong>and</strong> size, unless the instruction size defaults to 64 bits. Ifthe oper<strong>and</strong> size is fixed, oper<strong>and</strong>-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<strong>and</strong>s, notsource oper<strong>and</strong>s. Unless otherwise stated, 8-bit <strong>and</strong> 16-bit results leave the high 56 or 48 bits, respectively, of 64-bit destinationregisters unchanged. Immediates <strong>and</strong> branch displacements are sign-extended to 64 bits.5. Any pointer registers (rDI, rSI) or count registers (rCX) are address-sized <strong>and</strong> default to 64 bits. For 32-bit address size, any pointer<strong>and</strong> count registers are zero-extended to 64 bits.6. The default oper<strong>and</strong> size can be overridden to 16 bits with 66h prefix, but there is no 32-bit oper<strong>and</strong>-size override in 64-bit mode.434 Appendix B: <strong>General</strong>-<strong>Purpose</strong> <strong>Instructions</strong> in 64-Bit Mode


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable B-1.Operations <strong>and</strong> Oper<strong>and</strong>s in 64-Bit Mode (continued)PUSHA, PUSHAD - Push All to GPR Wordsor Doublewords60PUSHF, PUSHFD, PUSHFQ—Push rFLAGSWord, Doubleword, or Quadword ontoStack9CRCL—Rotate Through Carry LeftD1 /2D3 /2C1 /2RCR—Rotate Through Carry RightD1 /3D3 /3C1 /3RDMSR—Read Model-Specific Register0F 32Instruction <strong>and</strong>Opcode (hex) 1Type ofOperation 2Promoted to64 bits.Promoted to64 bits.Promoted to64 bits.Same aslegacy mode.DefaultOper<strong>and</strong>Size 3INVALID IN 64-BIT MODE (invalid-opcode exception)64 bits Cannot encode 6 mnemonic):Pushes the 64-bitPUSHFQ (newRFLAGS register.32 bits32 bitsNot relevant.For 32-BitOper<strong>and</strong> Size 4Zero-extends 32-bit register resultsto 64 bits.Zero-extends 32-bit register resultsto 64 bits.For 64-BitOper<strong>and</strong> Size 4Uses 6-bit count.Uses 6-bit count.RDX[31:0] contains MSR[63:32],RAX[31:0] contains MSR[31:0]. Zeroextends32-bit register results to 64bits.Note:1. See “<strong>General</strong> Rules for 64-Bit Mode” on page 413, for opcodes that do not appear in this table.2. The type of operation, excluding considerations of oper<strong>and</strong> size or extension of results. See “<strong>General</strong> Rules for 64-Bit Mode” onpage 413 for definitions of “Promoted to 64 bits” <strong>and</strong> related topics.3. If “Type of Operation” is 64 bits, a REX prefix is needed for 64-bit oper<strong>and</strong> size, unless the instruction size defaults to 64 bits. Ifthe oper<strong>and</strong> size is fixed, oper<strong>and</strong>-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<strong>and</strong>s, notsource oper<strong>and</strong>s. Unless otherwise stated, 8-bit <strong>and</strong> 16-bit results leave the high 56 or 48 bits, respectively, of 64-bit destinationregisters unchanged. Immediates <strong>and</strong> branch displacements are sign-extended to 64 bits.5. Any pointer registers (rDI, rSI) or count registers (rCX) are address-sized <strong>and</strong> default to 64 bits. For 32-bit address size, any pointer<strong>and</strong> count registers are zero-extended to 64 bits.6. The default oper<strong>and</strong> size can be overridden to 16 bits with 66h prefix, but there is no 32-bit oper<strong>and</strong>-size override in 64-bit mode.Appendix B: <strong>General</strong>-<strong>Purpose</strong> <strong>Instructions</strong> in 64-Bit Mode 435


AMD64 Technology 24594 Rev. 3.10 February 2005Table B-1.Operations <strong>and</strong> Oper<strong>and</strong>s in 64-Bit Mode (continued)Instruction <strong>and</strong>Opcode (hex) 1Type ofOperation 2DefaultOper<strong>and</strong>Size 3For 32-BitOper<strong>and</strong> Size 4For 64-BitOper<strong>and</strong> Size 4RDPMC—Read Performance-MonitoringCounters0F 33Same aslegacy mode.Not relevant.RDX[31:0] contains PMC[63:32],RAX[31:0] contains PMC[31:0]. Zeroextends32-bit register results to 64bits.RDTSC—Read Time-Stamp Counter0F 31Same aslegacy mode.Not relevant.RDX[31:0] contains TSC[63:32],RAX[31:0] contains TSC[31:0]. Zeroextends32-bit register results to 64bits.RDTSCP—Read Time-Stamp Counter <strong>and</strong>Processor ID0F 01 F9Same aslegacy mode.Not relevant.RDX[31:0] contains TSC[63:32],RAX[31:0] contains TSC[31:0].RCX[31:0] contains the TSC_AUX MSRC000_0103h[31:0]. Zero-extends 32-bitregister results to 64 bits.REP INS—Repeat Input StringF3 6DSame aslegacy mode.32 bitsReads doubleword I/O port.See footnote 5REP LODS—Repeat Load StringF3 ADPromoted to64 bits.32 bitsZero-extends EAXto 64 bits.See footnote 5 See footnote 5REP MOVS—Repeat Move StringF3 A5Promoted to64 bits.32 bitsNo GPR register results.See footnote 5REP OUTS—Repeat Output String to PortF3 6FSame aslegacy mode.32 bitsWrites doubleword to I/O port.No GPR register results.See footnote 5Note:1. See “<strong>General</strong> Rules for 64-Bit Mode” on page 413, for opcodes that do not appear in this table.2. The type of operation, excluding considerations of oper<strong>and</strong> size or extension of results. See “<strong>General</strong> Rules for 64-Bit Mode” onpage 413 for definitions of “Promoted to 64 bits” <strong>and</strong> related topics.3. If “Type of Operation” is 64 bits, a REX prefix is needed for 64-bit oper<strong>and</strong> size, unless the instruction size defaults to 64 bits. Ifthe oper<strong>and</strong> size is fixed, oper<strong>and</strong>-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<strong>and</strong>s, notsource oper<strong>and</strong>s. Unless otherwise stated, 8-bit <strong>and</strong> 16-bit results leave the high 56 or 48 bits, respectively, of 64-bit destinationregisters unchanged. Immediates <strong>and</strong> branch displacements are sign-extended to 64 bits.5. Any pointer registers (rDI, rSI) or count registers (rCX) are address-sized <strong>and</strong> default to 64 bits. For 32-bit address size, any pointer<strong>and</strong> count registers are zero-extended to 64 bits.6. The default oper<strong>and</strong> size can be overridden to 16 bits with 66h prefix, but there is no 32-bit oper<strong>and</strong>-size override in 64-bit mode.436 Appendix B: <strong>General</strong>-<strong>Purpose</strong> <strong>Instructions</strong> in 64-Bit Mode


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable B-1.Operations <strong>and</strong> Oper<strong>and</strong>s in 64-Bit Mode (continued)Instruction <strong>and</strong>Opcode (hex) 1Type ofOperation 2DefaultOper<strong>and</strong>Size 3For 32-BitOper<strong>and</strong> Size 4For 64-BitOper<strong>and</strong> Size 4REP STOS—Repeat Store StringF3 ABPromoted to64 bits.32 bitsNo GPR register results.See footnote 5REPx CMPS —Repeat Compare StringF3 A7Promoted to64 bits.32 bitsNo GPR register results.See footnote 5REPx SCAS —Repeat Scan StringF3 AFPromoted to64 bits.32 bitsNo GPR register results.See footnote 5RET—Return from Call Near See “Near Branches in 64-Bit Mode” in <strong>Volume</strong> 1.C2C3Promoted to64 bits.64 bits Cannot encode. 6 No GPR registerresults.RET—Return from Call FarCBCAPromoted to64 bits.32 bitsSee “Control Transfers” in <strong>Volume</strong> 1<strong>and</strong> “Control-Transfer PrivilegeChecks” in <strong>Volume</strong> 2.ROL—Rotate LeftD1 /0D3 /0Promoted to64 bits.32 bitsZero-extends 32-bit register resultsto 64 bits.Uses 6-bit count.C1 /0Note:1. See “<strong>General</strong> Rules for 64-Bit Mode” on page 413, for opcodes that do not appear in this table.2. The type of operation, excluding considerations of oper<strong>and</strong> size or extension of results. See “<strong>General</strong> Rules for 64-Bit Mode” onpage 413 for definitions of “Promoted to 64 bits” <strong>and</strong> related topics.3. If “Type of Operation” is 64 bits, a REX prefix is needed for 64-bit oper<strong>and</strong> size, unless the instruction size defaults to 64 bits. Ifthe oper<strong>and</strong> size is fixed, oper<strong>and</strong>-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<strong>and</strong>s, notsource oper<strong>and</strong>s. Unless otherwise stated, 8-bit <strong>and</strong> 16-bit results leave the high 56 or 48 bits, respectively, of 64-bit destinationregisters unchanged. Immediates <strong>and</strong> branch displacements are sign-extended to 64 bits.5. Any pointer registers (rDI, rSI) or count registers (rCX) are address-sized <strong>and</strong> default to 64 bits. For 32-bit address size, any pointer<strong>and</strong> count registers are zero-extended to 64 bits.6. The default oper<strong>and</strong> size can be overridden to 16 bits with 66h prefix, but there is no 32-bit oper<strong>and</strong>-size override in 64-bit mode.Appendix B: <strong>General</strong>-<strong>Purpose</strong> <strong>Instructions</strong> in 64-Bit Mode 437


AMD64 Technology 24594 Rev. 3.10 February 2005Table B-1.Operations <strong>and</strong> Oper<strong>and</strong>s in 64-Bit Mode (continued)Instruction <strong>and</strong>Opcode (hex) 1Type ofOperation 2DefaultOper<strong>and</strong>Size 3For 32-BitOper<strong>and</strong> Size 4For 64-BitOper<strong>and</strong> Size 4ROR—Rotate RightD1 /1D3 /1Promoted to64 bits.32 bitsZero-extends 32-bit register resultsto 64 bits.Uses 6-bit count.C1 /1RSM—Resume from <strong>System</strong> ManagementMode0F AANew SMMstate-savearea.Not relevant.See “<strong>System</strong>-Management Mode” in<strong>Volume</strong> 2.SAHF - Store AH into Flags9ESame as legacymode.Not relevant.No GPR register results.SAL—Shift Arithmetic LeftD1 /4D3 /4Promoted to64 bits.32 bitsZero-extends 32-bit register resultsto 64 bits.Uses 6-bit count.C1 /4SAR—Shift Arithmetic RightD1 /7D3 /7Promoted to64 bits.32 bitsZero-extends 32-bit register resultsto 64 bits.Uses 6-bit count.C1 /7Note:1. See “<strong>General</strong> Rules for 64-Bit Mode” on page 413, for opcodes that do not appear in this table.2. The type of operation, excluding considerations of oper<strong>and</strong> size or extension of results. See “<strong>General</strong> Rules for 64-Bit Mode” onpage 413 for definitions of “Promoted to 64 bits” <strong>and</strong> related topics.3. If “Type of Operation” is 64 bits, a REX prefix is needed for 64-bit oper<strong>and</strong> size, unless the instruction size defaults to 64 bits. Ifthe oper<strong>and</strong> size is fixed, oper<strong>and</strong>-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<strong>and</strong>s, notsource oper<strong>and</strong>s. Unless otherwise stated, 8-bit <strong>and</strong> 16-bit results leave the high 56 or 48 bits, respectively, of 64-bit destinationregisters unchanged. Immediates <strong>and</strong> branch displacements are sign-extended to 64 bits.5. Any pointer registers (rDI, rSI) or count registers (rCX) are address-sized <strong>and</strong> default to 64 bits. For 32-bit address size, any pointer<strong>and</strong> count registers are zero-extended to 64 bits.6. The default oper<strong>and</strong> size can be overridden to 16 bits with 66h prefix, but there is no 32-bit oper<strong>and</strong>-size override in 64-bit mode.438 Appendix B: <strong>General</strong>-<strong>Purpose</strong> <strong>Instructions</strong> in 64-Bit Mode


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable B-1.Operations <strong>and</strong> Oper<strong>and</strong>s in 64-Bit Mode (continued)Instruction <strong>and</strong>Opcode (hex) 1Type ofOperation 2DefaultOper<strong>and</strong>Size 3For 32-BitOper<strong>and</strong> Size 4For 64-BitOper<strong>and</strong> Size 4SBB—Subtract with Borrow191B1DPromoted to64 bits.32 bitsZero-extends 32-bit register resultsto 64 bits.81 /383 /3SCAS, SCASW, SCASD, SCASQ—ScanStringAFPromoted to64 bits.32 bitsSCASD: ScanStringDoublewords.Zero-extends 32-bit register resultsto 64 bits.See footnote 5SCASQ (newmnemonic): ScanStringQuadwords.See footnote 5SFENCE—Store Fence0F AE /7Same aslegacy mode.Not relevant.No GPR register results.SGDT—Store Global Descriptor TableRegister0F 01 /0Promoted to64 bits.Oper<strong>and</strong> sizefixed at 64bits.No GPR register results.Stores 8-byte base <strong>and</strong> 2-byte limit.Note:1. See “<strong>General</strong> Rules for 64-Bit Mode” on page 413, for opcodes that do not appear in this table.2. The type of operation, excluding considerations of oper<strong>and</strong> size or extension of results. See “<strong>General</strong> Rules for 64-Bit Mode” onpage 413 for definitions of “Promoted to 64 bits” <strong>and</strong> related topics.3. If “Type of Operation” is 64 bits, a REX prefix is needed for 64-bit oper<strong>and</strong> size, unless the instruction size defaults to 64 bits. Ifthe oper<strong>and</strong> size is fixed, oper<strong>and</strong>-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<strong>and</strong>s, notsource oper<strong>and</strong>s. Unless otherwise stated, 8-bit <strong>and</strong> 16-bit results leave the high 56 or 48 bits, respectively, of 64-bit destinationregisters unchanged. Immediates <strong>and</strong> branch displacements are sign-extended to 64 bits.5. Any pointer registers (rDI, rSI) or count registers (rCX) are address-sized <strong>and</strong> default to 64 bits. For 32-bit address size, any pointer<strong>and</strong> count registers are zero-extended to 64 bits.6. The default oper<strong>and</strong> size can be overridden to 16 bits with 66h prefix, but there is no 32-bit oper<strong>and</strong>-size override in 64-bit mode.Appendix B: <strong>General</strong>-<strong>Purpose</strong> <strong>Instructions</strong> in 64-Bit Mode 439


AMD64 Technology 24594 Rev. 3.10 February 2005Table B-1.Operations <strong>and</strong> Oper<strong>and</strong>s in 64-Bit Mode (continued)Instruction <strong>and</strong>Opcode (hex) 1Type ofOperation 2DefaultOper<strong>and</strong>Size 3For 32-BitOper<strong>and</strong> Size 4For 64-BitOper<strong>and</strong> Size 4SHL—Shift LeftD1 /4D3 /4Promoted to64 bits.32 bitsZero-extends 32-bit register resultsto 64 bits.Uses 6-bit count.C1 /4SHLD—Shift Left Double0F A40F A5Promoted to64 bits.32 bitsZero-extends 32-bit register resultsto 64 bits.Uses 6-bit count.SHR—Shift RightD1 /5D3 /5Promoted to64 bits.32 bitsZero-extends 32-bit register resultsto 64 bits.Uses 6-bit count.C1 /5SHRD—Shift Right Double0F AC0F ADPromoted to64 bits.32 bitsZero-extends 32-bit register resultsto 64 bits.Uses 6-bit count.SIDT—Store Interrupt Descriptor TableRegister0F 01 /1Promoted to64 bits.Oper<strong>and</strong> sizefixed at 64bits.No GPR register results.Stores 8-byte base <strong>and</strong> 2-byte limit.SLDT—Store Local Descriptor Table Register0F 00 /0Same aslegacy mode.32Zero-extends 2-byte LDT selector to 64bits.Note:1. See “<strong>General</strong> Rules for 64-Bit Mode” on page 413, for opcodes that do not appear in this table.2. The type of operation, excluding considerations of oper<strong>and</strong> size or extension of results. See “<strong>General</strong> Rules for 64-Bit Mode” onpage 413 for definitions of “Promoted to 64 bits” <strong>and</strong> related topics.3. If “Type of Operation” is 64 bits, a REX prefix is needed for 64-bit oper<strong>and</strong> size, unless the instruction size defaults to 64 bits. Ifthe oper<strong>and</strong> size is fixed, oper<strong>and</strong>-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<strong>and</strong>s, notsource oper<strong>and</strong>s. Unless otherwise stated, 8-bit <strong>and</strong> 16-bit results leave the high 56 or 48 bits, respectively, of 64-bit destinationregisters unchanged. Immediates <strong>and</strong> branch displacements are sign-extended to 64 bits.5. Any pointer registers (rDI, rSI) or count registers (rCX) are address-sized <strong>and</strong> default to 64 bits. For 32-bit address size, any pointer<strong>and</strong> count registers are zero-extended to 64 bits.6. The default oper<strong>and</strong> size can be overridden to 16 bits with 66h prefix, but there is no 32-bit oper<strong>and</strong>-size override in 64-bit mode.440 Appendix B: <strong>General</strong>-<strong>Purpose</strong> <strong>Instructions</strong> in 64-Bit Mode


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable B-1.Operations <strong>and</strong> Oper<strong>and</strong>s in 64-Bit Mode (continued)Instruction <strong>and</strong>Opcode (hex) 1Type ofOperation 2DefaultOper<strong>and</strong>Size 3For 32-BitOper<strong>and</strong> Size 4For 64-BitOper<strong>and</strong> Size 4SMSW—Store Machine Status Word0F 01 /4Same aslegacy mode.32Zero-extends 32-bit register resultsto 64 bits.Stores 64-bitmachine statusword (CR0).STC—Set Carry FlagF9Same aslegacy mode.Not relevant.No GPR register results.STD—Set Direction FlagFDSame aslegacy mode.Not relevant.No GPR register results.STI - Set Interrupt FlagFBSame aslegacy mode.Not relevant.No GPR register results.STOS, STOSW, STOSD, STOSQ- StoreStringABPromoted to64 bits.32 bitsSTOSD: StoreStringDoublewords.See footnote 5STOSQ (newmnemonic):Store StringQuadwords.See footnote 5STR—Store Task Register0F 00 /1Same aslegacy mode.32Zero-extends 2-byte TR selector to 64bits.Note:1. See “<strong>General</strong> Rules for 64-Bit Mode” on page 413, for opcodes that do not appear in this table.2. The type of operation, excluding considerations of oper<strong>and</strong> size or extension of results. See “<strong>General</strong> Rules for 64-Bit Mode” onpage 413 for definitions of “Promoted to 64 bits” <strong>and</strong> related topics.3. If “Type of Operation” is 64 bits, a REX prefix is needed for 64-bit oper<strong>and</strong> size, unless the instruction size defaults to 64 bits. Ifthe oper<strong>and</strong> size is fixed, oper<strong>and</strong>-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<strong>and</strong>s, notsource oper<strong>and</strong>s. Unless otherwise stated, 8-bit <strong>and</strong> 16-bit results leave the high 56 or 48 bits, respectively, of 64-bit destinationregisters unchanged. Immediates <strong>and</strong> branch displacements are sign-extended to 64 bits.5. Any pointer registers (rDI, rSI) or count registers (rCX) are address-sized <strong>and</strong> default to 64 bits. For 32-bit address size, any pointer<strong>and</strong> count registers are zero-extended to 64 bits.6. The default oper<strong>and</strong> size can be overridden to 16 bits with 66h prefix, but there is no 32-bit oper<strong>and</strong>-size override in 64-bit mode.Appendix B: <strong>General</strong>-<strong>Purpose</strong> <strong>Instructions</strong> in 64-Bit Mode 441


AMD64 Technology 24594 Rev. 3.10 February 2005Table B-1.Operations <strong>and</strong> Oper<strong>and</strong>s in 64-Bit Mode (continued)SUB—Subtract292B2D81 /583 /5SWAPGS—Swap GS Register withKernelGSbase MSR0F 01 /7SYSCALL—Fast <strong>System</strong> Call0F 05SYSENTER—<strong>System</strong> Call0F 34SYSEXIT—<strong>System</strong> Return0F 35SYSRET—Fast <strong>System</strong> Return0F 07Instruction <strong>and</strong>Opcode (hex) 1Type ofOperation 2Promoted to64 bits.Newinstruction,availableonly in 64-bitmode. (Inother modes,this opcodeis invalid.)Promoted to64 bits.Promoted to64 bits.DefaultOper<strong>and</strong>Size 332 bitsNot relevant.Not relevant.Zero-extends 32-bit register resultsto 64 bits.See “SWAPGS Instruction” in<strong>Volume</strong> 2.See “SYSCALL <strong>and</strong> SYSRET<strong>Instructions</strong>” in <strong>Volume</strong> 2 for details.INVALID IN LONG MODE (invalid-opcode exception)INVALID IN LONG MODE (invalid-opcode exception)32 bitsFor 32-BitOper<strong>and</strong> Size 4For 64-BitOper<strong>and</strong> Size 4See “SYSCALL <strong>and</strong> SYSRET<strong>Instructions</strong>” in <strong>Volume</strong> 2 for details.Note:1. See “<strong>General</strong> Rules for 64-Bit Mode” on page 413, for opcodes that do not appear in this table.2. The type of operation, excluding considerations of oper<strong>and</strong> size or extension of results. See “<strong>General</strong> Rules for 64-Bit Mode” onpage 413 for definitions of “Promoted to 64 bits” <strong>and</strong> related topics.3. If “Type of Operation” is 64 bits, a REX prefix is needed for 64-bit oper<strong>and</strong> size, unless the instruction size defaults to 64 bits. Ifthe oper<strong>and</strong> size is fixed, oper<strong>and</strong>-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<strong>and</strong>s, notsource oper<strong>and</strong>s. Unless otherwise stated, 8-bit <strong>and</strong> 16-bit results leave the high 56 or 48 bits, respectively, of 64-bit destinationregisters unchanged. Immediates <strong>and</strong> branch displacements are sign-extended to 64 bits.5. Any pointer registers (rDI, rSI) or count registers (rCX) are address-sized <strong>and</strong> default to 64 bits. For 32-bit address size, any pointer<strong>and</strong> count registers are zero-extended to 64 bits.6. The default oper<strong>and</strong> size can be overridden to 16 bits with 66h prefix, but there is no 32-bit oper<strong>and</strong>-size override in 64-bit mode.442 Appendix B: <strong>General</strong>-<strong>Purpose</strong> <strong>Instructions</strong> in 64-Bit Mode


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable B-1.Operations <strong>and</strong> Oper<strong>and</strong>s in 64-Bit Mode (continued)Instruction <strong>and</strong>Opcode (hex) 1Type ofOperation 2DefaultOper<strong>and</strong>Size 3For 32-BitOper<strong>and</strong> Size 4For 64-BitOper<strong>and</strong> Size 4TEST—Test Bits85A9F7 /0Promoted to64 bits.32 bits No GPR register results.UD2—Undefined Operation0F 0BSame aslegacy mode.Not relevant.No GPR register results.VERR—Verify Segment for Reads0F 00 /4Same aslegacy mode.Oper<strong>and</strong> sizefixed at 16bitsNo GPR register results.VERW—Verify Segment for Writes0F 00 /5Same aslegacy mode.Oper<strong>and</strong> sizefixed at 16bitsNo GPR register results.WAIT—Wait for Interrupt9BSame aslegacy mode.Not relevant.No GPR register results.WBINVD—Writeback <strong>and</strong> Invalidate AllCaches0F 09Same aslegacy mode.Not relevant.No GPR register results.WRMSR—Write to Model-Specific Register0F 30Same aslegacy mode.Not relevant.No GPR register results.MSR[63:32] = RDX[31:0]MSR[31:0] = RAX[31:0]Note:1. See “<strong>General</strong> Rules for 64-Bit Mode” on page 413, for opcodes that do not appear in this table.2. The type of operation, excluding considerations of oper<strong>and</strong> size or extension of results. See “<strong>General</strong> Rules for 64-Bit Mode” onpage 413 for definitions of “Promoted to 64 bits” <strong>and</strong> related topics.3. If “Type of Operation” is 64 bits, a REX prefix is needed for 64-bit oper<strong>and</strong> size, unless the instruction size defaults to 64 bits. Ifthe oper<strong>and</strong> size is fixed, oper<strong>and</strong>-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<strong>and</strong>s, notsource oper<strong>and</strong>s. Unless otherwise stated, 8-bit <strong>and</strong> 16-bit results leave the high 56 or 48 bits, respectively, of 64-bit destinationregisters unchanged. Immediates <strong>and</strong> branch displacements are sign-extended to 64 bits.5. Any pointer registers (rDI, rSI) or count registers (rCX) are address-sized <strong>and</strong> default to 64 bits. For 32-bit address size, any pointer<strong>and</strong> count registers are zero-extended to 64 bits.6. The default oper<strong>and</strong> size can be overridden to 16 bits with 66h prefix, but there is no 32-bit oper<strong>and</strong>-size override in 64-bit mode.Appendix B: <strong>General</strong>-<strong>Purpose</strong> <strong>Instructions</strong> in 64-Bit Mode 443


AMD64 Technology 24594 Rev. 3.10 February 2005Table B-1.Operations <strong>and</strong> Oper<strong>and</strong>s in 64-Bit Mode (continued)Instruction <strong>and</strong>Opcode (hex) 1Type ofOperation 2DefaultOper<strong>and</strong>Size 3For 32-BitOper<strong>and</strong> Size 4For 64-BitOper<strong>and</strong> Size 4XADD—Exchange <strong>and</strong> Add0F C1Promoted to64 bits.32 bitsZero-extends 32-bit register resultsto 64 bits.XCHG—Exchange Register/Memory withRegister8790Promoted to64 bits.32 bitsZero-extends 32-bit register resultsto 64 bits.XOR—Logical Exclusive OR313335Promoted to64 bits.32 bitsZero-extends 32-bit register resultsto 64 bits.81 /683 /6Note:1. See “<strong>General</strong> Rules for 64-Bit Mode” on page 413, for opcodes that do not appear in this table.2. The type of operation, excluding considerations of oper<strong>and</strong> size or extension of results. See “<strong>General</strong> Rules for 64-Bit Mode” onpage 413 for definitions of “Promoted to 64 bits” <strong>and</strong> related topics.3. If “Type of Operation” is 64 bits, a REX prefix is needed for 64-bit oper<strong>and</strong> size, unless the instruction size defaults to 64 bits. Ifthe oper<strong>and</strong> size is fixed, oper<strong>and</strong>-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<strong>and</strong>s, notsource oper<strong>and</strong>s. Unless otherwise stated, 8-bit <strong>and</strong> 16-bit results leave the high 56 or 48 bits, respectively, of 64-bit destinationregisters unchanged. Immediates <strong>and</strong> branch displacements are sign-extended to 64 bits.5. Any pointer registers (rDI, rSI) or count registers (rCX) are address-sized <strong>and</strong> default to 64 bits. For 32-bit address size, any pointer<strong>and</strong> count registers are zero-extended to 64 bits.6. The default oper<strong>and</strong> size can be overridden to 16 bits with 66h prefix, but there is no 32-bit oper<strong>and</strong>-size override in 64-bit mode.B.3 Invalid <strong>and</strong> Reassigned <strong>Instructions</strong> in 64-Bit ModeTable B-2 lists instructions that are illegal in 64-bit mode.Attempted use of these instructions generates an invalidopcodeexception (#UD).444 Appendix B: <strong>General</strong>-<strong>Purpose</strong> <strong>Instructions</strong> in 64-Bit Mode


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable B-2.Invalid <strong>Instructions</strong> in 64-Bit ModeMnemonicOpcode(hex)DescriptionAAA 37 ASCII Adjust After AdditionAAD D5 ASCII Adjust Before DivisionAAM D4 ASCII Adjust After MultiplyAAS 3F ASCII Adjust After SubtractionBOUND 62 Check Array BoundsCALL (far) 9A Procedure Call Far (far absolute)DAA 27 Decimal Adjust after AdditionDAS 2F Decimal Adjust after SubtractionINTO CE Interrupt to Overflow VectorJMP (far) EA Jump Far (absolute)LDS C5 Load DS Far PointerLES C4 Load ES Far PointerPOP DS 1F Pop Stack into DS SegmentPOP ES 07 Pop Stack into ES SegmentPOP SS 17 Pop Stack into SS SegmentPOPA, POPAD 61 Pop All to GPR Words or DoublewordsPUSH CS 0E Push CS Segment Selector onto StackPUSH DS 1E Push DS Segment Selector onto StackPUSH ES 06 Push ES Segment Selector onto StackPUSH SS 16 Push SS Segment Selector onto StackPUSHA, PUSHAD 60 Push All to GPR Words or DoublewordsRedundant Grp1 82 /2 Redundant encoding of group1 Eb,Ib opcodesSALC D6 Set AL According to CFTable B-3 lists instructions that are reassigned to differentfunctions in 64-bit mode. Attempted use of these instructionsgenerates the reassigned function.Appendix B: <strong>General</strong>-<strong>Purpose</strong> <strong>Instructions</strong> in 64-Bit Mode 445


AMD64 Technology 24594 Rev. 3.10 February 2005Table B-3.Reassigned <strong>Instructions</strong> in 64-Bit ModeMnemonicOpcode(hex)DescriptionARPL 63DEC <strong>and</strong> INC 40-4FOpcode for MOVSXD instruction in 64-bit mode.In all other modes, this is the Adjust RequestorPrivilege Level instruction opcode.REX prefixes in 64-bit mode. In all other modes,decrement by 1 <strong>and</strong> increment by 1.Table B-4 lists instructions that are illegal in long mode.Attempted use of these instructions generates an invalidopcodeexception (#UD).Table B-4.Invalid <strong>Instructions</strong> in Long ModeMnemonicOpcode(hex)DescriptionSYSENTER 0F 34 <strong>System</strong> CallSYSEXIT 0F 35 <strong>System</strong> ReturnB.4 <strong>Instructions</strong> with 64-Bit Default Oper<strong>and</strong> SizeIn 64-bit mode, two groups of instructions default to 64-bitoper<strong>and</strong> size without the need for a REX prefix:• Near branches —CALL, Jcc, JrCX, JMP, LOOP, <strong>and</strong> RET.• All instructions, except far branches, that implicitly referencethe RSP—CALL, ENTER, LEAVE, POP, PUSH, <strong>and</strong> RET(CALL <strong>and</strong> RET are in both groups of instructions).Table B-5 lists these instructions.446 Appendix B: <strong>General</strong>-<strong>Purpose</strong> <strong>Instructions</strong> in 64-Bit Mode


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable B-5.<strong>Instructions</strong> Defaulting to 64-Bit Oper<strong>and</strong> SizeMnemonicOpcode(hex)ImplicitlyReferenceRSPDescriptionCALL E8, FF /2 yes Call Procedure NearENTER C8 yes Create Procedure Stack FrameJcc many no Jump Conditional NearJMP E9, EB, FF /4 no Jump NearLEAVE C9 yes Delete Procedure Stack FrameLOOP E2 no LoopLOOPcc E0, E1 no Loop ConditionalPOP reg/mem 8F /0 yes Pop Stack (register or memory)POP reg 58-5F yes Pop Stack (register)POP FS 0F A1 yesPOP GS 0F A9 yesPOPF, POPFD,POPFQ9DyesPUSH imm8 6A yesPUSH imm32 68 yesPUSH reg/mem FF /6 yesPop Stack into FS SegmentRegisterPop Stack into GS SegmentRegisterPop to rFLAGS Word,Doubleword, or QuadwordPush onto Stack (sign-extendedbyte)Push onto Stack (sign-extendeddoubleword)Push onto Stack (register ormemory)PUSH reg 50-57 yes Push onto Stack (register)PUSH FS 0F A0 yesPush FS Segment Register ontoStackAppendix B: <strong>General</strong>-<strong>Purpose</strong> <strong>Instructions</strong> in 64-Bit Mode 447


AMD64 Technology 24594 Rev. 3.10 February 2005Table B-5.<strong>Instructions</strong> Defaulting to 64-Bit Oper<strong>and</strong> Size (continued)MnemonicThe 64-bit default oper<strong>and</strong> size can be overridden to 16 bitsusing the 66h oper<strong>and</strong>-size override. However, it is not possibleto override the oper<strong>and</strong> size to 32 bits because there is no 32-bitoper<strong>and</strong>-size override prefix for 64-bit mode. See “Oper<strong>and</strong>-Size Override Prefix” on page 5 for details.B.5 Single-Byte INC <strong>and</strong> DEC <strong>Instructions</strong> in 64-Bit ModeB.6 NOP in 64-Bit ModePUSH GS 0F A8 yesPUSHF, PUSHFD,PUSHFQOpcode(hex)9CImplicitlyReferenceRSPPush GS Segment Register ontoStackIn 64-bit mode, the legacy encodings for the 16 single-byte INC<strong>and</strong> DEC instructions (one for each of the eight GPRs) are usedto encode the REX prefix values, as described in “REXPrefixes” on page 14. Therefore, these single-byte opcodes forINC <strong>and</strong> DEC are not available in 64-bit mode, although theyare available in legacy <strong>and</strong> compatibility modes. Thefunctionality of these INC <strong>and</strong> DEC instructions is stillavailable in 64-bit mode, however, using the ModRM forms ofthose instructions (opcodes FF/0 <strong>and</strong> FF/1).Programs written for the legacy x86 architecture commonly useopcode 90h (the XCHG EAX, EAX instruction) as a one-byteNOP. In 64-bit mode, the processor treats opcode 90h speciallyin order to preserve this legacy NOP use. Without specialh<strong>and</strong>ling in 64-bit mode, the instruction would not be a true nooperation.Therefore, in 64-bit mode the processor treats XCHGEAX, EAX as a true NOP, regardless of oper<strong>and</strong> size.This special h<strong>and</strong>ling does not apply to the two-byte ModRMform of the XCHG instruction. Unless a 64-bit oper<strong>and</strong> size isspecified using a REX prefix byte, using the two byte form of448 Appendix B: <strong>General</strong>-<strong>Purpose</strong> <strong>Instructions</strong> in 64-Bit ModeyesDescriptionPush rFLAGS Word,Doubleword, or Quadwordonto StackRET C2, C3 yes Return From Call (near)


24594 Rev. 3.10 February 2005 AMD64 TechnologyXCHG to exchange a register with itself will not result in a nooperationbecause the default operation size is 32 bits in 64-bitmode.B.7 Segment Override Prefixes in 64-Bit ModeIn 64-bit mode, the CS, DS, ES, SS segment-override prefixeshave no effect. These four prefixes are no longer treated assegment-override prefixes in the context of multiple-prefixrules. Instead, they are treated as null prefixes.The FS <strong>and</strong> GS segment-override prefixes are treated as truesegment-override prefixes in 64-bit mode. Use of the FS <strong>and</strong> GSprefixes cause their respective segment bases to be added tothe effective address calculation. See “FS <strong>and</strong> GS Registers in64-Bit Mode” in <strong>Volume</strong> 2 for details.Appendix B: <strong>General</strong>-<strong>Purpose</strong> <strong>Instructions</strong> in 64-Bit Mode 449


AMD64 Technology 24594 Rev. 3.10 February 2005450 Appendix B: <strong>General</strong>-<strong>Purpose</strong> <strong>Instructions</strong> in 64-Bit Mode


24594 Rev. 3.10 February 2005 AMD64 TechnologyAppendix CDifferences Between Long Mode <strong>and</strong> LegacyModeTable C-1 summarizes the major differences between 64-bitmode <strong>and</strong> legacy protected mode. The third column indicatesdifferences between 64-bit mode <strong>and</strong> legacy mode. The fourthcolumn indicates whether that difference also applies tocompatibility mode.Table C-1.Differences Between Long Mode <strong>and</strong> Legacy ModeType Subject 64-Bit Mode DifferenceApplies ToCompatibilityMode?ApplicationProgrammingAddressingData <strong>and</strong> AddressSizesInstructionDifferencesRIP-relative addressing availableDefault data size is 32 bitsREX Prefix toggles data size to 64 bitsDefault address size is 64 bitsAddress size prefix toggles address size to 32 bitsVarious opcodes are invalid or changed in 64-bit mode(see Table B-2 on page 445 <strong>and</strong> Table B-3 on page 446)Various opcodes are invalid in long mode (see Table B-4on page 446)MOV reg,imm32 becomes MOV reg,imm64 (with REXoper<strong>and</strong> size prefix)REX is always enabledDirect-offset forms of MOV to or from accumulatorbecome 64-bit offsetsMOVD extended to MOV 64 bits between MMX registers<strong>and</strong> long GPRs (with REX oper<strong>and</strong>-size prefix)noyesnoAppendix C: Differences Between Long Mode <strong>and</strong> Legacy Mode 451


AMD64 Technology 24594 Rev. 3.10 February 2005Table C-1.Differences Between Long Mode <strong>and</strong> Legacy Mode (continued)Type Subject 64-Bit Mode DifferenceApplies ToCompatibilityMode?x86 Modes Real <strong>and</strong> virtual-8086 modes not supported yesTask Switching Task switching not supported yes64-bit virtual addressesAddressing4-level paging structuresyesPAE must always be enabledCS, DS, ES, SS segment bases are ignoredSegmentationCS, DS, ES, FS, GS, SS segment limits are ignorednoCS, DS, ES, SS Segment prefixes are ignoredAll pushes are 8 bytes16-bit interrupt <strong>and</strong> trap gates are illegal<strong>System</strong>ProgrammingException <strong>and</strong>Interrupt H<strong>and</strong>ling32-bit interrupt <strong>and</strong> trap gates are redefined as 64-bitgates <strong>and</strong> are exp<strong>and</strong>ed to 16 bytesSS is set to null on stack switchyesSS:RSP is pushed unconditionallyAll pushes are 8 bytes16-bit call gates are illegalCall Gates32-bit call gate type is redefined as 64-bit call gate <strong>and</strong> isexp<strong>and</strong>ed to 16 bytes.yesSS is set to null on stack switch<strong>System</strong>-DescriptorRegistersGDT, IDT, LDT, TR base registers exp<strong>and</strong>ed to 64 bitsyes<strong>System</strong>-DescriptorTable Entries <strong>and</strong>Pseudo-descriptorsLGDT <strong>and</strong> LIDT use exp<strong>and</strong>ed 10-byte pseudodescriptors.LLDT <strong>and</strong> LTR use exp<strong>and</strong>ed 16-byte table entries.no452 Appendix C: Differences Between Long Mode <strong>and</strong> Legacy Mode


24594 Rev. 3.10 February 2005 AMD64 TechnologyAppendix DInstruction Subsets <strong>and</strong> CPUID Feature SetsTable D-1 is an alphabetical list of the AMD64 instruction set,including the instructions from all five of the instructionsubsets that make up the entire AMD64 instruction-setarchitecture:• Chapter 3, “<strong>General</strong>-<strong>Purpose</strong> Instruction Reference.”• Chapter 4, “<strong>System</strong> Instruction Reference.”• “128-Bit Media Instruction Reference” in <strong>Volume</strong> 4.• “64-Bit Media Instruction Reference” in <strong>Volume</strong> 5.• “x87 Floating-Point Instruction Reference” in <strong>Volume</strong> 5.Several instructions belong to—<strong>and</strong> are described in—multipleinstruction subsets. Table D-1 shows the minimum currentprivilege level (CPL) required to execute each instruction <strong>and</strong>the instruction subset(s) to which the instruction belongs. Foreach instruction subset, the CPUID feature set(s) that enablesthe instruction is shown.D.1 Instruction SubsetsFigure D-1 on page 454 shows the relationship between the fiveinstruction subsets <strong>and</strong> the CPUID feature sets. Dashed-linepolygons represent the instruction subsets. Circles representthe major CPUID feature sets that enable various classes ofinstructions. (There are a few additional CPUID feature sets,not shown, each of which apply to only a few instructions.)The overlapping of the 128-bit <strong>and</strong> 64-bit media instructionsubsets indicates that these subsets share some commonmnemonics. However, these common mnemonics either havedistinct opcodes for each subset or they take oper<strong>and</strong>s in boththe MMX <strong>and</strong> XMM register sets.The horizontal axis of Figure D-1 shows how the subsets <strong>and</strong>CPUID feature sets have evolved over time.Appendix D: Instruction Subsets <strong>and</strong> CPUID Feature Sets 453


AMD64 Technology 24594 Rev. 3.10 February 2005<strong>General</strong>-<strong>Purpose</strong> <strong>Instructions</strong>Basic<strong>Instructions</strong>Long-Mode<strong>Instructions</strong><strong>System</strong> <strong>Instructions</strong>x87 <strong>Instructions</strong>x87 <strong>Instructions</strong>MMX<strong>Instructions</strong>AMD Extensionsto MMX<strong>Instructions</strong>SSE<strong>Instructions</strong>SSE3<strong>Instructions</strong>64-Bit Media<strong>Instructions</strong>128-Bit Media<strong>Instructions</strong>AMD 3DNow!<strong>Instructions</strong>AMD Extensionto3DNow!<strong>Instructions</strong>Time of IntroductionSSE2<strong>Instructions</strong>Dashed-line boxes show instruction subsets.Circles show major CPUID feature sets.(Minor features sets are not shown.)Figure D-1.Instruction Subsets vs. CPUID Feature Sets454 Appendix D: Instruction Subsets <strong>and</strong> CPUID Feature Sets


24594 Rev. 3.10 February 2005 AMD64 TechnologyD.2 CPUID Feature SetsThe CPUID feature sets shown in Figure D-1 <strong>and</strong> listed inTable D-1 on page 457 include:• Basic <strong>Instructions</strong>—<strong>Instructions</strong> that are supported in allhardware implementations of the AMD64 architecture,except that the following instructions are implemented onlyif their associated CPUID function bit is set:- CLFLUSH, indicated by EDX bit 19 of CPUID st<strong>and</strong>ardfunction 1.- CMPXCHG8B, indicated by EDX bit 8 of CPUIDst<strong>and</strong>ard function 1 <strong>and</strong> extended function 8000_0001h.- CMPXCHG16B, indicated by ECX bit 13 of CPUIDst<strong>and</strong>ard function 1.- CMOVcc (conditional moves), indicated by EDX bit 15 ofCPUID st<strong>and</strong>ard function 1 <strong>and</strong> extended function8000_0001h.- RDMSR <strong>and</strong> WRMSR, indicated by EDX bit 5 of CPUIDst<strong>and</strong>ard function 1 <strong>and</strong> extended function 8000_0001h.- RDTSC, indicated by EDX bit 4 of CPUID st<strong>and</strong>ardfunction 1 <strong>and</strong> extended function 8000_0001h.- RDTSCP, indicated by EDX bit 27 of CPUID extendedfunction 8000_0001h.- SYSCALL <strong>and</strong> SYSRET, indicated by EDX bit 11 ofCPUID extended function 8000_0001h.- SYSENTER <strong>and</strong> SYSEXIT, indicated by EDX bit 11 ofCPUID st<strong>and</strong>ard function 1.• x87 <strong>Instructions</strong>—Legacy floating-point instructions that usethe ST(0)–ST(7) stack registers (FPR0–FPR7 physicalregisters) <strong>and</strong> are supported if the following bits are set:- On-chip floating-point unit, indicated by EDX bit 0 ofCPUID st<strong>and</strong>ard function 1 <strong>and</strong> extended function8000_0001h.- FCMOVcc (conditional moves), indicated by EDX bit 15of CPUID st<strong>and</strong>ard function 1 <strong>and</strong> extended function8000_0001h. This bit indicates support for x87 floatingpointconditional moves (FCMOVcc) whenever the On-Chip Floating-Point Unit bit (bit 0) is also set.• MMX <strong>Instructions</strong>—Vector integer instructions that areimplemented in the MMX instruction set, use the MMXAppendix D: Instruction Subsets <strong>and</strong> CPUID Feature Sets 455


AMD64 Technology 24594 Rev. 3.10 February 2005logical registers (FPR0–FPR7 physical registers), <strong>and</strong> aresupported if the following bit is set:- MMX instructions, indicated by EDX bit 23 of CPUIDst<strong>and</strong>ard function 1 <strong>and</strong> extended function 8000_0001h.• AMD 3DNow! <strong>Instructions</strong>—Vector floating-pointinstructions that comprise the AMD 3DNow! technology, usethe MMX logical registers (FPR0–FPR7 physical registers),<strong>and</strong> are supported if the following bit is set:- AMD 3DNow! instructions, indicated by EDX bit 31 ofCPUID extended function 8000_0001h.• AMD Extensions to MMX <strong>Instructions</strong>—Vector integerinstructions that use the MMX registers <strong>and</strong> are supported ifthe following bit is set:- AMD extensions to MMX instructions, indicated by EDXbit 22 of CPUID extended function 8000_0001h.• AMD Extensions to 3DNow! <strong>Instructions</strong>—Vector floatingpointinstructions that use the MMX registers <strong>and</strong> aresupported if the following bit is set:- AMD extensions to 3DNow! instructions, indicated byEDX bit 30 of CPUID extended function 8000_0001h.• SSE <strong>Instructions</strong>—Vector integer instructions that use theMMX registers, single-precision vector <strong>and</strong> scalar floatingpointinstructions that use the XMM registers, plus otherinstructions for data-type conversion, prefetching, cachecontrol, <strong>and</strong> memory-access ordering. These instructions aresupported if the following bits are set:- SSE, indicated by EDX bit 25 of CPUID st<strong>and</strong>ardfunction 1.- FXSAVE <strong>and</strong> FXRSTOR, indicated by EDX bit 24 ofCPUID st<strong>and</strong>ard function 1 <strong>and</strong> extended function8000_0001h.Several SSE opcodes are also implemented by the AMDExtensions to MMX <strong>Instructions</strong>.• SSE2 <strong>Instructions</strong>—Vector <strong>and</strong> scalar integer <strong>and</strong> doubleprecisionfloating-point instructions that use the XMMregisters, plus other instructions for data-type conversion,cache control, <strong>and</strong> memory-access ordering. Theseinstructions are supported if the following bit is set:- SSE2, indicated by EDX bit 26 of CPUID st<strong>and</strong>ardfunction 1.456 Appendix D: Instruction Subsets <strong>and</strong> CPUID Feature Sets


24594 Rev. 3.10 February 2005 AMD64 TechnologySeveral instructions originally implemented as MMXinstructions are extended in the SSE2 instruction set toinclude opcodes that use XMM registers.• SSE3 <strong>Instructions</strong>—Horizontal addition <strong>and</strong> subtraction ofpacked single-precision <strong>and</strong> double-precision floating pointvalues, simultaneous addition <strong>and</strong> subtraction of packedsingle-precision <strong>and</strong> double-precision values, move withdupication, <strong>and</strong> floating-point-to-integer conversion. Theseinstructions are supported if the following bit is set:- SSE3, indicated by ECX bit 0 of CPUID st<strong>and</strong>ardfunction 1.• Long-Mode <strong>Instructions</strong>—<strong>Instructions</strong> introduced by AMDwith the AMD64 architecture. These instructions aresupported if the following bit is set:- Long mode, indicated by EDX bit 29 of CPUID extendedfunction 8000_0001h.For complete details on the CPUID feature sets listed inTable D-1, see “Processor Feature Identification” in <strong>Volume</strong> 2.D.3 Instruction ListTable D-1.Instruction Subsets <strong>and</strong> CPUID Feature SetsInstructionInstruction Subset<strong>and</strong> CPUID Feature Set(s) 1Mnemonic Description CPL<strong>General</strong>-<strong>Purpose</strong>128-BitMedia64-BitMediax87<strong>System</strong>AAAASCII Adjust AfterAddition3BasicAADASCII Adjust BeforeDivision3BasicAAMASCII Adjust AfterMultiply3BasicAASASCII Adjust AfterSubtraction3BasicADC Add with Carry 3 Basic1. Columns indicate the instruction subsets. Entries indicate the CPUID feature set(s) to which the instruction belongs.2. Mnemonic is used for two different instructions. Assemblers can distinguish them by the number <strong>and</strong> type of oper<strong>and</strong>s.Appendix D: Instruction Subsets <strong>and</strong> CPUID Feature Sets 457


AMD64 Technology 24594 Rev. 3.10 February 2005Table D-1.Instruction Subsets <strong>and</strong> CPUID Feature Sets (continued)ADD Signed or Unsigned Add 3 BasicADDPDADDPSADDSDADDSSADDSUBPDADDSUBPSAdd Packed Double-Precision Floating-PointAdd Packed Single-Precision Floating-PointAdd Scalar Double-Precision Floating-PointAdd Scalar Single-Precision Floating-PointAdd <strong>and</strong> SubtractDouble-PrecisionAdd <strong>and</strong> Subtract Single-PrecisionAND Logical AND 3 BasicANDNPDANDNPSANDPDANDPSARPLInstructionMnemonic Description CPLLogical Bitwise AND NOTPacked Double-PrecisionFloating-PointLogical Bitwise AND NOTPacked Single-PrecisionFloating-PointLogical Bitwise ANDPacked Double-PrecisionFloating-PointLogical Bitwise ANDPacked Single-PrecisionFloating-PointAdjust RequestorPrivilege Level33333333333<strong>General</strong>-<strong>Purpose</strong>BOUND Check Array Bounds 3 BasicInstruction Subset<strong>and</strong> CPUID Feature Set(s) 1128-BitMediaSSE2SSESSE2SSESSE3SSE3SSE2SSESSE2SSE64-BitMediax87<strong>System</strong>Basic1. Columns indicate the instruction subsets. Entries indicate the CPUID feature set(s) to which the instruction belongs.2. Mnemonic is used for two different instructions. Assemblers can distinguish them by the number <strong>and</strong> type of oper<strong>and</strong>s.458 Appendix D: Instruction Subsets <strong>and</strong> CPUID Feature Sets


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable D-1.Instruction Subsets <strong>and</strong> CPUID Feature Sets (continued)BSF Bit Scan Forward 3 BasicBSR Bit Scan Reverse 3 BasicBSWAP Byte Swap 3 BasicBT Bit Test 3 BasicBTC Bit Test <strong>and</strong> Complement 3 BasicBTR Bit Test <strong>and</strong> Reset 3 BasicBTS Bit Test <strong>and</strong> Set 3 BasicCALL Procedure Call 3 BasicCBW Convert Byte to Word 3 BasicCDQCDQEConvert Doubleword toQuadwordConvert Doubleword toQuadword33BasicLong ModeCLC Clear Carry Flag 3 BasicCLD Clear Direction Flag 3 BasicCLFLUSH Cache Line Flush 3 CLFLUSHCLI Clear Interrupt Flag 3 BasicCLTSClear Task-Switched Flagin CR0CMC Complement Carry Flag 3 BasicCMOVcc Conditional Move 3 CMOVccCMP Compare 3 BasicCMPPDInstructionMnemonic Description CPLCompare PackedDouble-PrecisionFloating-Point03<strong>General</strong>-<strong>Purpose</strong>Instruction Subset<strong>and</strong> CPUID Feature Set(s) 1128-BitMediaSSE264-BitMedia1. Columns indicate the instruction subsets. Entries indicate the CPUID feature set(s) to which the instruction belongs.2. Mnemonic is used for two different instructions. Assemblers can distinguish them by the number <strong>and</strong> type of oper<strong>and</strong>s.x87<strong>System</strong>BasicAppendix D: Instruction Subsets <strong>and</strong> CPUID Feature Sets 459


AMD64 Technology 24594 Rev. 3.10 February 2005Table D-1.Instruction Subsets <strong>and</strong> CPUID Feature Sets (continued)CMPPSCompare Packed Single-Precision Floating-PointCMPS Compare Strings 3 BasicCMPSB Compare Strings by Byte 3 BasicCMPSDCMPSDCMPSQCMPSSCMPSWCompare Strings byDoublewordCompare Scalar Double-Precision Floating-PointCompare Strings byQuadwordCompare Scalar Single-Precision Floating-PointCompare Strings byWord333333Basic 2Long ModeBasicCMPXCHG Compare <strong>and</strong> Exchange 3 BasicCMPXCHG8BCMPXCHG16BCOMISDCOMISSCompare <strong>and</strong> ExchangeEight BytesCompare <strong>and</strong> ExchangeSixteen BytesCompare Ordered ScalarDouble-PrecisionFloating-PointCompare Ordered ScalarSingle-PrecisionFloating-Point333CMPXCHG8BCMPXCHG16BCPUID Processor Identification 3 BasicCQOInstructionMnemonic Description CPLConvert Quadword toDouble Quadword33<strong>General</strong>-<strong>Purpose</strong>Long ModeInstruction Subset<strong>and</strong> CPUID Feature Set(s) 1128-BitMediaSSESSE2 2SSESSE2SSE64-BitMediax87<strong>System</strong>1. Columns indicate the instruction subsets. Entries indicate the CPUID feature set(s) to which the instruction belongs.2. Mnemonic is used for two different instructions. Assemblers can distinguish them by the number <strong>and</strong> type of oper<strong>and</strong>s.460 Appendix D: Instruction Subsets <strong>and</strong> CPUID Feature Sets


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable D-1.Instruction Subsets <strong>and</strong> CPUID Feature Sets (continued)InstructionInstruction Subset<strong>and</strong> CPUID Feature Set(s) 1Mnemonic Description CPL<strong>General</strong>-<strong>Purpose</strong>128-BitMedia64-BitMediax87<strong>System</strong>CVTDQ2PDConvert PackedDoubleword Integers toPacked Double-PrecisionFloating-Point3SSE2CVTDQ2PSConvert PackedDoubleword Integers toPacked Single-PrecisionFloating-Point3SSE2CVTPD2DQConvert Packed Double-Precision Floating-Pointto Packed DoublewordIntegers3SSE2CVTPD2PIConvert Packed Double-Precision Floating-Pointto Packed DoublewordIntegers3SSE2SSE2CVTPD2PSConvert Packed Double-Precision Floating-Pointto Packed Single-Precision Floating-Point3SSE2CVTPI2PDConvert PackedDoubleword Integers toPacked Double-PrecisionFloating-Point3SSE2SSE2CVTPI2PSConvert PackedDoubleword Integers toPacked Single-PrecisionFloating-Point3SSESSECVTPS2DQConvert Packed Single-Precision Floating-Pointto Packed DoublewordIntegers3SSE21. Columns indicate the instruction subsets. Entries indicate the CPUID feature set(s) to which the instruction belongs.2. Mnemonic is used for two different instructions. Assemblers can distinguish them by the number <strong>and</strong> type of oper<strong>and</strong>s.Appendix D: Instruction Subsets <strong>and</strong> CPUID Feature Sets 461


AMD64 Technology 24594 Rev. 3.10 February 2005Table D-1.Instruction Subsets <strong>and</strong> CPUID Feature Sets (continued)InstructionInstruction Subset<strong>and</strong> CPUID Feature Set(s) 1Mnemonic Description CPL<strong>General</strong>-<strong>Purpose</strong>128-BitMedia64-BitMediax87<strong>System</strong>CVTPS2PDConvert Packed Single-Precision Floating-Pointto Packed Double-Precision Floating-Point3SSE2CVTPS2PIConvert Packed Single-Precision Floating-Pointto Packed DoublewordIntegers3SSESSECVTSD2SIConvert Scalar Double-Precision Floating-Pointto Signed Doublewordor Quadword Integer3SSE2CVTSD2SSConvert Scalar Double-Precision Floating-Pointto Scalar Single-PrecisionFloating-Point3SSE2CVTSI2SDConvert SignedDoubleword orQuadword Integer toScalar Double-PrecisionFloating-Point3SSE2CVTSI2SSConvert SignedDoubleword orQuadword Integer toScalar Single-PrecisionFloating-Point3SSECVTSS2SDConvert Scalar Single-Precision Floating-Pointto Scalar Double-Precision Floating-Point3SSE21. Columns indicate the instruction subsets. Entries indicate the CPUID feature set(s) to which the instruction belongs.2. Mnemonic is used for two different instructions. Assemblers can distinguish them by the number <strong>and</strong> type of oper<strong>and</strong>s.462 Appendix D: Instruction Subsets <strong>and</strong> CPUID Feature Sets


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable D-1.Instruction Subsets <strong>and</strong> CPUID Feature Sets (continued)InstructionInstruction Subset<strong>and</strong> CPUID Feature Set(s) 1Mnemonic Description CPL<strong>General</strong>-<strong>Purpose</strong>128-BitMedia64-BitMediax87<strong>System</strong>CVTSS2SIConvert Scalar Single-Precision Floating-Pointto Signed Doublewordor Quadword Integer3SSECVTTPD2DQConvert Packed Double-Precision Floating-Pointto Packed DoublewordIntegers, Truncated3SSE2CVTTPD2PIConvert Packed Double-Precision Floating-Pointto Packed DoublewordIntegers, Truncated3SSE2SSE2CVTTPS2DQConvert Packed Single-Precision Floating-Pointto Packed DoublewordIntegers, Truncated3SSE2CVTTPS2PIConvert Packed Single-Precision Floating-Pointto Packed DoublewordIntegers, Truncated3SSESSECVTTSD2SIConvert Scalar Double-Precision Floating-Pointto Signed Doublewordor Quadword Integer,Truncated3SSE2CVTTSS2SIConvert Scalar Single-Precision Floating-Pointto Signed Doublewordor Quadword Integer,Truncated3SSECWDConvert Word toDoubleword3Basic1. Columns indicate the instruction subsets. Entries indicate the CPUID feature set(s) to which the instruction belongs.2. Mnemonic is used for two different instructions. Assemblers can distinguish them by the number <strong>and</strong> type of oper<strong>and</strong>s.Appendix D: Instruction Subsets <strong>and</strong> CPUID Feature Sets 463


AMD64 Technology 24594 Rev. 3.10 February 2005Table D-1.Instruction Subsets <strong>and</strong> CPUID Feature Sets (continued)CWDEDAADASConvert Word toDoublewordDecimal Adjust afterAdditionDecimal Adjust afterSubtraction333BasicBasicBasicDEC Decrement by 1 3 BasicDIV Unsigned Divide 3 BasicDIVPDDIVPSDIVSDDIVSSEMMSENTERF2XM1FABSDivide Packed Double-Precision Floating-PointDivide Packed Single-Precision Floating-PointDivide Scalar Double-Precision Floating-PointDivide Scalar Single-Precision Floating-PointEnter/Exit MultimediaStateCreate Procedure StackFrameFloating-Point Compute2x–1Floating-Point AbsoluteValue33333333BasicSSE2SSESSE2SSEMMXFADD Floating-Point Add 3 X87FADDPInstructionMnemonic Description CPLFloating-Point Add <strong>and</strong>Pop3<strong>General</strong>-<strong>Purpose</strong>Instruction Subset<strong>and</strong> CPUID Feature Set(s) 1128-BitMedia64-BitMediax87MMXX87X87X87<strong>System</strong>1. Columns indicate the instruction subsets. Entries indicate the CPUID feature set(s) to which the instruction belongs.2. Mnemonic is used for two different instructions. Assemblers can distinguish them by the number <strong>and</strong> type of oper<strong>and</strong>s.464 Appendix D: Instruction Subsets <strong>and</strong> CPUID Feature Sets


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable D-1.Instruction Subsets <strong>and</strong> CPUID Feature Sets (continued)InstructionInstruction Subset<strong>and</strong> CPUID Feature Set(s) 1Mnemonic Description CPL<strong>General</strong>-<strong>Purpose</strong>128-BitMedia64-BitMediax87<strong>System</strong>FBLDFloating-Point LoadBinary-Coded Decimal3X87FBSTPFloating-Point StoreBinary-Coded DecimalInteger <strong>and</strong> Pop3X87FCHSFloating-Point ChangeSign3X87FCLEXFloating-Point ClearFlags3X87FCMOVBFloating-PointConditional Move IfBelow3X87,CMOVccFCMOVBEFloating-PointConditional Move IfBelow or Equal3X87,CMOVccFCMOVEFloating-PointConditional Move IfEqual3X87,CMOVccFCMOVNBFloating-PointConditional Move If NotBelow3X87,CMOVccFCMOVNBEFloating-PointConditional Move If NotBelow or Equal3X87,CMOVccFCMOVNEFloating-PointConditional Move If NotEqual3X87,CMOVccFCMOVNUFloating-PointConditional Move If NotUnordered3X87,CMOVcc1. Columns indicate the instruction subsets. Entries indicate the CPUID feature set(s) to which the instruction belongs.2. Mnemonic is used for two different instructions. Assemblers can distinguish them by the number <strong>and</strong> type of oper<strong>and</strong>s.Appendix D: Instruction Subsets <strong>and</strong> CPUID Feature Sets 465


AMD64 Technology 24594 Rev. 3.10 February 2005Table D-1.Instruction Subsets <strong>and</strong> CPUID Feature Sets (continued)FCMOVUFloating-PointConditional Move IfUnordered3X87,CMOVccFCOM Floating-Point Compare 3 X87FCOMIFCOMIPFCOMPFCOMPPFloating-Point Compare<strong>and</strong> Set FlagsFloating-Point Compare<strong>and</strong> Set Flags <strong>and</strong> PopFloating-Point Compare<strong>and</strong> PopFloating-Point Compare<strong>and</strong> Pop Twice3333FCOS Floating-Point Cosine 3 X87FDECSTPFloating-PointDecrement Stack-TopPointer3FDIV Floating-Point Divide 3 X87FDIVPFDIVRFDIVRPFEMMSFFREEFIADDInstructionMnemonic Description CPLFloating-Point Divide<strong>and</strong> PopFloating-Point DivideReverseFloating-Point DivideReverse <strong>and</strong> PopFast Enter/ExitMultimedia StateFree Floating-PointRegisterFloating-Point AddInteger to Stack Top333333<strong>General</strong>-<strong>Purpose</strong>Instruction Subset<strong>and</strong> CPUID Feature Set(s) 1128-BitMedia64-BitMedia3DNow!x87X87X87X87X87X87X87X87X873DNow!X87X87<strong>System</strong>1. Columns indicate the instruction subsets. Entries indicate the CPUID feature set(s) to which the instruction belongs.2. Mnemonic is used for two different instructions. Assemblers can distinguish them by the number <strong>and</strong> type of oper<strong>and</strong>s.466 Appendix D: Instruction Subsets <strong>and</strong> CPUID Feature Sets


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable D-1.Instruction Subsets <strong>and</strong> CPUID Feature Sets (continued)FICOMFICOMPFIDIVFIDIVRFILDFIMULFINCSTPFloating-Point IntegerCompareFloating-Point IntegerCompare <strong>and</strong> PopFloating-Point IntegerDivideFloating-Point IntegerDivide ReverseFloating-Point LoadIntegerFloating-Point IntegerMultiplyFloating-Point IncrementStack-Top Pointer3333333FINIT Floating-Point Initialize 3 X87FISTFISTPFISTTPFISUBFISUBRInstructionMnemonic Description CPLFloating-Point IntegerStoreFloating-Point IntegerStore <strong>and</strong> PopFloating-Point IntegerTruncate <strong>and</strong> StoreFloating-Point IntegerSubtractFloating-Point IntegerSubtract Reverse33333<strong>General</strong>-<strong>Purpose</strong>Instruction Subset<strong>and</strong> CPUID Feature Set(s) 1128-BitMedia64-BitMediaFLD Floating-Point Load 3 X87FLD1 Floating-Point Load +1.0 3 X87x87X87X87X87X87X87X87X87X87X87SSE3X87X87<strong>System</strong>1. Columns indicate the instruction subsets. Entries indicate the CPUID feature set(s) to which the instruction belongs.2. Mnemonic is used for two different instructions. Assemblers can distinguish them by the number <strong>and</strong> type of oper<strong>and</strong>s.Appendix D: Instruction Subsets <strong>and</strong> CPUID Feature Sets 467


AMD64 Technology 24594 Rev. 3.10 February 2005Table D-1.Instruction Subsets <strong>and</strong> CPUID Feature Sets (continued)InstructionInstruction Subset<strong>and</strong> CPUID Feature Set(s) 1Mnemonic Description CPL<strong>General</strong>-<strong>Purpose</strong>128-BitMedia64-BitMediax87<strong>System</strong>FLDCWFloating-Point Load x87Control Word3X87FLDENVFloating-Point Load x87Environment3X87FLDL2EFloating-Point LoadLog 2 e3X87FLDL2TFloating-Point LoadLog 2 103X87FLDLG2Floating-Point LoadLog 10 23X87FLDLN2 Floating-Point Load Ln 2 3 X87FLDPI Floating-Point Load Pi 3 X87FLDZ Floating-Point Load +0.0 3 X87FMUL Floating-Point Multiply 3 X87FMULPFloating-Point Multiply<strong>and</strong> Pop3X87FNCLEXFloating-Point No-WaitClear Flags3X87FNINITFloating-Point No-WaitInitialize3X87FNOPFloating-Point NoOperation3X87FNSAVESave No-Wait x87 <strong>and</strong>MMX State3X87X87FNSTCWFloating-Point No-WaitStore x87 Control Word3X87FNSTENVFloating-Point No-WaitStore x87 Environment3X871. Columns indicate the instruction subsets. Entries indicate the CPUID feature set(s) to which the instruction belongs.2. Mnemonic is used for two different instructions. Assemblers can distinguish them by the number <strong>and</strong> type of oper<strong>and</strong>s.468 Appendix D: Instruction Subsets <strong>and</strong> CPUID Feature Sets


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable D-1.Instruction Subsets <strong>and</strong> CPUID Feature Sets (continued)FNSTSWFPATANFPREMFPREM1FPTANFRNDINTFRSTORFloating-Point No-WaitStore x87 Status WordFloating-Point PartialArctangentFloating-Point PartialRemainderFloating-Point PartialRemainderFloating-Point PartialTangentFloating-Point Round toIntegerRestore x87 <strong>and</strong> MMXState3333333FSAVE Save x87 <strong>and</strong> MMX State 3 X87 X87FSCALE Floating-Point Scale 3 X87FSIN Floating-Point Sine 3 X87FSINCOSFSQRTFSTFSTCWFSTENVInstructionMnemonic Description CPLFloating-Point Sine <strong>and</strong>CosineFloating-Point SquareRootFloating-Point StoreStack TopFloating-Point Store x87Control WordFloating-Point Store x87Environment33333<strong>General</strong>-<strong>Purpose</strong>Instruction Subset<strong>and</strong> CPUID Feature Set(s) 1128-BitMedia64-BitMediaX87x87X87X87X87X87X87X87X87X87X87X87X87X87<strong>System</strong>1. Columns indicate the instruction subsets. Entries indicate the CPUID feature set(s) to which the instruction belongs.2. Mnemonic is used for two different instructions. Assemblers can distinguish them by the number <strong>and</strong> type of oper<strong>and</strong>s.Appendix D: Instruction Subsets <strong>and</strong> CPUID Feature Sets 469


AMD64 Technology 24594 Rev. 3.10 February 2005Table D-1.Instruction Subsets <strong>and</strong> CPUID Feature Sets (continued)FSTPFSTSWFloating-Point StoreStack Top <strong>and</strong> PopFloating-Point Store x87Status Word33FSUB Floating-Point Subtract 3 X87FSUBPFSUBRFSUBRPFTSTFUCOMFUCOMIInstructionMnemonic Description CPLFloating-Point Subtract<strong>and</strong> PopFloating-Point SubtractReverseFloating-Point SubtractReverse <strong>and</strong> PopFloating-Point Test withZeroFloating-PointUnordered CompareFloating-PointUnordered Compare<strong>and</strong> Set Flags333333<strong>General</strong>-<strong>Purpose</strong>Instruction Subset<strong>and</strong> CPUID Feature Set(s) 1128-BitMedia64-BitMediax87X87X87X87X87X87X87X87X87<strong>System</strong>FUCOMIPFloating-PointUnordered Compare<strong>and</strong> Set Flags <strong>and</strong> Pop3X87FUCOMPFloating-PointUnordered Compare<strong>and</strong> Pop3X87FUCOMPPFloating-PointUnordered Compare<strong>and</strong> Pop Twice3X87FWAITWait for x87 Floating-Point Exceptions3X871. Columns indicate the instruction subsets. Entries indicate the CPUID feature set(s) to which the instruction belongs.2. Mnemonic is used for two different instructions. Assemblers can distinguish them by the number <strong>and</strong> type of oper<strong>and</strong>s.470 Appendix D: Instruction Subsets <strong>and</strong> CPUID Feature Sets


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable D-1.Instruction Subsets <strong>and</strong> CPUID Feature Sets (continued)FXAM Floating-Point Examine 3 X87FXCH Floating-Point Exchange 3 X87FXRSTORFXSAVEFXTRACTRestore XMM, MMX, <strong>and</strong>x87 StateSave XMM, MMX, <strong>and</strong>x87 StateFloating-Point ExtractExponent <strong>and</strong>Signific<strong>and</strong>333FXSAVE,FXRSTORFXSAVE,FXRSTORFXSAVE,FXRSTORFXSAVE,FXRSTORFXSAVE,FXRSTORFXSAVE,FXRSTORFYL2X Floating-Point y * log2x 3 X87FYL2XP1HADDPDHADDPSFloating-Pointy * log2(x +1)Horizontal Add PackedDoubleHorizontal Add PackedSingle33SSE33 SSE3HLT Halt 0 BasicHSUBPDHSUBPSInstructionMnemonic Description CPLHorizontal SubtractPacked DoubleHorizontal SubtractPacked Single<strong>General</strong>-<strong>Purpose</strong>3 SSE33 SSE3IDIV Signed Divide 3 BasicIMUL Signed Multiply 3 BasicIN Input from Port 3 BasicINC Increment by 1 3 BasicINS Input String 3 BasicINSB Input String Byte 3 BasicInstruction Subset<strong>and</strong> CPUID Feature Set(s) 1128-BitMedia64-BitMedia1. Columns indicate the instruction subsets. Entries indicate the CPUID feature set(s) to which the instruction belongs.2. Mnemonic is used for two different instructions. Assemblers can distinguish them by the number <strong>and</strong> type of oper<strong>and</strong>s.x87X87X87<strong>System</strong>Appendix D: Instruction Subsets <strong>and</strong> CPUID Feature Sets 471


AMD64 Technology 24594 Rev. 3.10 February 2005Table D-1.Instruction Subsets <strong>and</strong> CPUID Feature Sets (continued)INSD Input String Doubleword 3 BasicINSW Input String Word 3 BasicINT Interrupt to Vector 3 BasicINT 3INTOInterrupt to DebugVectorInterrupt to OverflowVector3 Basic3 BasicINVD Invalidate Caches 0 BasicINVLPG Invalidate TLB Entry 0 BasicIRET Interrupt Return Word 3 BasicIRETDIRETQInterrupt ReturnDoublewordInterrupt ReturnQuadwordJcc Jump Condition 3 BasicJCXZ Jump if CX Zero 3 BasicJECXZ Jump if ECX Zero 3 BasicJMP Jump 3 BasicJRCXZ Jump if RCX Zero 3 BasicLAHFLoad Status Flags intoAH Register333BasicBasicLongModeLAR Load Access Rights Byte 3 BasicLDDQULDMXCSRInstructionMnemonic Description CPLLoad Unaligned DoubleQuadwordLoad MXCSRControl/Status Register33<strong>General</strong>-<strong>Purpose</strong>Instruction Subset<strong>and</strong> CPUID Feature Set(s) 1128-BitMediaSSE3SSE64-BitMedia1. Columns indicate the instruction subsets. Entries indicate the CPUID feature set(s) to which the instruction belongs.2. Mnemonic is used for two different instructions. Assemblers can distinguish them by the number <strong>and</strong> type of oper<strong>and</strong>s.x87<strong>System</strong>472 Appendix D: Instruction Subsets <strong>and</strong> CPUID Feature Sets


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable D-1.Instruction Subsets <strong>and</strong> CPUID Feature Sets (continued)LDS Load DS Far Pointer 3 BasicLEA Load Effective Address 3 BasicLEAVEDelete Procedure StackFrame3BasicLES Load ES Far Pointer 3 BasicLFENCE Load Fence 3 SSE2LFS Load FS Far Pointer 3 BasicLGDTLoad Global DescriptorTable RegisterLGS Load GS Far Pointer 3 BasicLIDTLLDTLMSWInstructionMnemonic Description CPLLoad InterruptDescriptor Table RegisterLoad Local DescriptorTable RegisterLoad Machine StatusWordLODS Load String 3 BasicLODSB Load String Byte 3 BasicLODSD Load String Doubleword 3 BasicLODSQ Load String Quadword 3 Long ModeLODSW Load String Word 3 BasicLOOP Loop 3 BasicLOOPE Loop if Equal 3 BasicLOOPNE Loop if Not Equal 3 BasicLOOPNZ Loop if Not Zero 3 Basic0000<strong>General</strong>-<strong>Purpose</strong>Instruction Subset<strong>and</strong> CPUID Feature Set(s) 1128-BitMedia64-BitMediax87<strong>System</strong>BasicBasicBasicBasic1. Columns indicate the instruction subsets. Entries indicate the CPUID feature set(s) to which the instruction belongs.2. Mnemonic is used for two different instructions. Assemblers can distinguish them by the number <strong>and</strong> type of oper<strong>and</strong>s.Appendix D: Instruction Subsets <strong>and</strong> CPUID Feature Sets 473


AMD64 Technology 24594 Rev. 3.10 February 2005Table D-1.Instruction Subsets <strong>and</strong> CPUID Feature Sets (continued)LOOPZ Loop if Zero 3 BasicLSL Load Segment Limit 3 BasicLSSLoad SS SegmentRegister3LTR Load Task Register 0 BasicMASKMOVDQUMASKMOVQMAXPDMAXPSMAXSDMAXSSMasked Move DoubleQuadword UnalignedMasked MoveQuadwordMaximum PackedDouble-PrecisionFloating-PointMaximum PackedSingle-PrecisionFloating-PointMaximum ScalarDouble-PrecisionFloating-PointMaximum Scalar Single-Precision Floating-Point3333BasicMFENCE Memory Fence 3 SSE2MINPDMINPSMINSDInstructionMnemonic Description CPLMinimum PackedDouble-PrecisionFloating-PointMinimum Packed Single-Precision Floating-PointMinimum Scalar Double-Precision Floating-Point33333<strong>General</strong>-<strong>Purpose</strong>Instruction Subset<strong>and</strong> CPUID Feature Set(s) 1128-BitMediaSSE2SSE2SSESSE2SSESSE2SSESSE264-BitMediaSSE,MMXExtensions1. Columns indicate the instruction subsets. Entries indicate the CPUID feature set(s) to which the instruction belongs.2. Mnemonic is used for two different instructions. Assemblers can distinguish them by the number <strong>and</strong> type of oper<strong>and</strong>s.x87<strong>System</strong>474 Appendix D: Instruction Subsets <strong>and</strong> CPUID Feature Sets


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable D-1.Instruction Subsets <strong>and</strong> CPUID Feature Sets (continued)MINSSMinimum Scalar Single-Precision Floating-PointMOV Move 3 BasicMOV CRnMOV DRnMOVAPDMOVAPSMOVDMOVDDUPMOVDQ2QMOVDQAMOVDQUMOVHLPSMOVHPDInstructionMnemonic Description CPLMove to/from ControlRegistersMove to/from DebugRegistersMove Aligned PackedDouble-PrecisionFloating-PointMove Aligned PackedSingle-PrecisionFloating-PointMove Doubleword orQuadwordMove Double-Precision<strong>and</strong> DupicateMove Quadword toQuadwordMove Aligned DoubleQuadwordMove Unaligned DoubleQuadwordMove Packed Single-Precision Floating-PointHigh to LowMove High PackedDouble-PrecisionFloating-Point300333333333<strong>General</strong>-<strong>Purpose</strong>Instruction Subset<strong>and</strong> CPUID Feature Set(s) 1128-BitMediaSSESSE2SSEMMX, SSE2 SSE2 MMXSSE3SSE2SSE2SSE2SSESSE264-BitMediaSSE2x87<strong>System</strong>BasicBasic1. Columns indicate the instruction subsets. Entries indicate the CPUID feature set(s) to which the instruction belongs.2. Mnemonic is used for two different instructions. Assemblers can distinguish them by the number <strong>and</strong> type of oper<strong>and</strong>s.Appendix D: Instruction Subsets <strong>and</strong> CPUID Feature Sets 475


AMD64 Technology 24594 Rev. 3.10 February 2005Table D-1.Instruction Subsets <strong>and</strong> CPUID Feature Sets (continued)MOVHPSMOVLHPSMOVLPDMOVLPSMOVMSKPDMOVMSKPSMOVNTDQMOVNTIMOVNTPDMOVNTPSInstructionMnemonic Description CPLMove High PackedSingle-PrecisionFloating-PointMove Packed Single-Precision Floating-PointLow to HighMove Low PackedDouble-PrecisionFloating-PointMove Low PackedSingle-PrecisionFloating-PointExtract Packed Double-Precision Floating-PointSign MaskExtract Packed Single-Precision Floating-PointSign MaskMove Non-TemporalDouble QuadwordMove Non-TemporalDoubleword orQuadwordMove Non-TemporalPacked Double-PrecisionFloating-PointMove Non-TemporalPacked Single-PrecisionFloating-Point33333<strong>General</strong>-<strong>Purpose</strong>SSE2SSESSESSE2SSESSE23 SSE SSE3 SSE23 SSE23 SSE23 SSEInstruction Subset<strong>and</strong> CPUID Feature Set(s) 1128-BitMedia64-BitMediax87<strong>System</strong>1. Columns indicate the instruction subsets. Entries indicate the CPUID feature set(s) to which the instruction belongs.2. Mnemonic is used for two different instructions. Assemblers can distinguish them by the number <strong>and</strong> type of oper<strong>and</strong>s.476 Appendix D: Instruction Subsets <strong>and</strong> CPUID Feature Sets


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable D-1.Instruction Subsets <strong>and</strong> CPUID Feature Sets (continued)MOVNTQMove Non-TemporalQuadword3SSE,MMXExtensionsMOVQ Move Quadword 3 SSE2 MMXMOVQ2DQMove Quadword toQuadwordMOVS Move String 3 BasicMOVSB Move String Byte 3 BasicMOVSD Move String Doubleword 3 Basic 2MOVSDMOVSHDUPMOVSLDUPMove Scalar Double-Precision Floating-PointMove Single-PrecisionHigh <strong>and</strong> DuplicateMove Single-PrecisionLow <strong>and</strong> Duplicate3 SSE2 SSE23 SSE2 2MOVSQ Move String Quadword 3 Long ModeMOVSSMove Scalar Single-Precision Floating-PointMOVSW Move String Word 3 BasicMOVSX Move with Sign-Extend 3 BasicMOVSXDMOVUPDInstructionMnemonic Description CPLMove with Sign-ExtendDoublewordMove Unaligned PackedDouble-PrecisionFloating-Point33333<strong>General</strong>-<strong>Purpose</strong>Long ModeInstruction Subset<strong>and</strong> CPUID Feature Set(s) 1128-BitMediaSSE3SSE3SSESSE264-BitMediax87<strong>System</strong>1. Columns indicate the instruction subsets. Entries indicate the CPUID feature set(s) to which the instruction belongs.2. Mnemonic is used for two different instructions. Assemblers can distinguish them by the number <strong>and</strong> type of oper<strong>and</strong>s.Appendix D: Instruction Subsets <strong>and</strong> CPUID Feature Sets 477


AMD64 Technology 24594 Rev. 3.10 February 2005Table D-1.Instruction Subsets <strong>and</strong> CPUID Feature Sets (continued)MOVUPSMove Unaligned PackedSingle-PrecisionFloating-PointMOVZX Move with Zero-Extend 3 BasicMUL Multiply Unsigned 3 BasicMULPDMULPSMULSDMULSSNEGMultiply Packed Double-Precision Floating-PointMultiply Packed Single-Precision Floating-PointMultiply Scalar Double-Precision Floating-PointMultiply Scalar Single-Precision Floating-PointTwo's ComplementNegation333333BasicNOP No Operation 3 BasicNOTOne's ComplementNegation3BasicOR Logical OR 3 BasicORPDORPSInstructionMnemonic Description CPLLogical Bitwise ORPacked Double-PrecisionFloating-PointLogical Bitwise ORPacked Single-PrecisionFloating-Point33<strong>General</strong>-<strong>Purpose</strong>OUT Output to Port 3 BasicOUTS Output String 3 BasicOUTSB Output String Byte 3 BasicInstruction Subset<strong>and</strong> CPUID Feature Set(s) 1128-BitMediaSSESSE2SSESSE2SSESSE2SSE64-BitMediax87<strong>System</strong>1. Columns indicate the instruction subsets. Entries indicate the CPUID feature set(s) to which the instruction belongs.2. Mnemonic is used for two different instructions. Assemblers can distinguish them by the number <strong>and</strong> type of oper<strong>and</strong>s.478 Appendix D: Instruction Subsets <strong>and</strong> CPUID Feature Sets


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable D-1.Instruction Subsets <strong>and</strong> CPUID Feature Sets (continued)OUTSDOutput StringDoubleword3BasicOUTSW Output String Word 3 BasicPACKSSDWPACKSSWBPACKUSWBPack with SaturationSigned Doubleword toWordPack with SaturationSigned Word to BytePack with SaturationSigned Word toUnsigned Byte333SSE2SSE2SSE2MMXMMXMMXPADDB Packed Add Bytes 3 SSE2 MMXPADDDPacked AddDoublewords3SSE2MMXPADDQ Packed Add Quadwords 3 SSE2 SSE2PADDSBPADDSWPADDUSBPADDUSWPacked Add Signed withSaturation BytesPacked Add Signed withSaturation WordsPacked Add Unsignedwith Saturation BytesPacked Add Unsignedwith Saturation Words3333SSE2SSE2SSE2SSE2MMXMMXMMXMMXPADDW Packed Add Words 3 SSE2 MMXPANDPANDNInstructionMnemonic Description CPLPacked Logical BitwiseANDPacked Logical BitwiseAND NOT33<strong>General</strong>-<strong>Purpose</strong>Instruction Subset<strong>and</strong> CPUID Feature Set(s) 1128-BitMediaSSE2SSE264-BitMediaMMXMMXx87<strong>System</strong>1. Columns indicate the instruction subsets. Entries indicate the CPUID feature set(s) to which the instruction belongs.2. Mnemonic is used for two different instructions. Assemblers can distinguish them by the number <strong>and</strong> type of oper<strong>and</strong>s.Appendix D: Instruction Subsets <strong>and</strong> CPUID Feature Sets 479


AMD64 Technology 24594 Rev. 3.10 February 2005Table D-1.Instruction Subsets <strong>and</strong> CPUID Feature Sets (continued)InstructionInstruction Subset<strong>and</strong> CPUID Feature Set(s) 1Mnemonic Description CPL<strong>General</strong>-<strong>Purpose</strong>128-BitMedia64-BitMediax87<strong>System</strong>PAVGBPacked AverageUnsigned Bytes3SSE2SSE, MMXExtensionsPAVGUSBPacked AverageUnsigned Bytes33DNow!PAVGWPacked AverageUnsigned Words3SSE2SSE, MMXExtensionsPCMPEQBPacked Compare EqualBytes3SSE2MMXPCMPEQDPacked Compare EqualDoublewords3SSE2MMXPCMPEQWPacked Compare EqualWords3SSE2MMXPCMPGTBPacked CompareGreater Than SignedBytes3SSE2MMXPCMPGTDPacked CompareGreater Than SignedDoublewords3SSE2MMXPCMPGTWPacked CompareGreater Than SignedWords3SSE2MMXPEXTRW Packed Extract Word 3SSE2SSE, MMXExtensionsPF2IDPacked Floating-Point toInteger DoublewordConversion33DNow!PF2IWPacked Floating-Point toInteger WordConversion33DNow!Extensions1. Columns indicate the instruction subsets. Entries indicate the CPUID feature set(s) to which the instruction belongs.2. Mnemonic is used for two different instructions. Assemblers can distinguish them by the number <strong>and</strong> type of oper<strong>and</strong>s.480 Appendix D: Instruction Subsets <strong>and</strong> CPUID Feature Sets


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable D-1.Instruction Subsets <strong>and</strong> CPUID Feature Sets (continued)InstructionInstruction Subset<strong>and</strong> CPUID Feature Set(s) 1Mnemonic Description CPL<strong>General</strong>-<strong>Purpose</strong>128-BitMedia64-BitMediax87<strong>System</strong>PFACCPacked Floating-PointAccumulate33DNow!PFADDPacked Floating-PointAdd33DNow!PFCMPEQPacked Floating-PointCompare Equal33DNow!PFCMPGEPacked Floating-PointCompare Greater orEqual33DNow!PFCMPGTPacked Floating-PointCompare Greater Than33DNow!PFMAXPacked Floating-PointMaximum33DNow!PFMINPacked Floating-PointMinimum33DNow!PFMULPacked Floating-PointMultiply33DNow!PFNACCPacked Floating-PointNegative Accumulate33DNow!ExtensionsPFPNACCPacked Floating-PointPositive-NegativeAccumulate33DNow!ExtensionsPFRCPPacked Floating-PointReciprocalApproximation33DNow!PFRCPIT1Packed Floating-PointReciprocal, Iteration 133DNow!PFRCPIT2Packed Floating-PointReciprocal or ReciprocalSquare Root, Iteration 233DNow!1. Columns indicate the instruction subsets. Entries indicate the CPUID feature set(s) to which the instruction belongs.2. Mnemonic is used for two different instructions. Assemblers can distinguish them by the number <strong>and</strong> type of oper<strong>and</strong>s.Appendix D: Instruction Subsets <strong>and</strong> CPUID Feature Sets 481


AMD64 Technology 24594 Rev. 3.10 February 2005Table D-1.Instruction Subsets <strong>and</strong> CPUID Feature Sets (continued)InstructionInstruction Subset<strong>and</strong> CPUID Feature Set(s) 1Mnemonic Description CPL<strong>General</strong>-<strong>Purpose</strong>128-BitMedia64-BitMediax87<strong>System</strong>PFRSQIT1Packed Floating-PointReciprocal Square Root,Iteration 133DNow!PFRSQRTPacked Floating-PointReciprocal Square RootApproximation33DNow!PFSUBPacked Floating-PointSubtract33DNow!PFSUBRPacked Floating-PointSubtract Reverse33DNow!PI2FDPacked Integer toFloating-PointDoubleword Conversion33DNow!PI2FWPacked Integer ToFloating-Point WordConversion33DNow!ExtensionsPINSRW Packed Insert Word 3SSE2SSE, MMXExtensionsPMADDWDPacked Multiply Words<strong>and</strong> Add Doublewords3SSE2MMXPMAXSWPacked MaximumSigned Words3SSE2SSE, MMXExtensionsPMAXUBPacked MaximumUnsigned Bytes3SSE2SSE, MMXExtensionsPMINSWPacked Minimum SignedWords3SSE2SSE, MMXExtensionsPMINUBPacked MinimumUnsigned Bytes3SSE2SSE, MMXExtensionsPMOVMSKB Packed Move Mask Byte 3SSE2SSE, MMXExtensions1. Columns indicate the instruction subsets. Entries indicate the CPUID feature set(s) to which the instruction belongs.2. Mnemonic is used for two different instructions. Assemblers can distinguish them by the number <strong>and</strong> type of oper<strong>and</strong>s.482 Appendix D: Instruction Subsets <strong>and</strong> CPUID Feature Sets


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable D-1.Instruction Subsets <strong>and</strong> CPUID Feature Sets (continued)PMULHRWPMULHUWPMULHWPMULLWPMULUDQPacked Multiply HighRounded WordPacked Multiply HighUnsigned WordPacked Multiply HighSigned WordPacked Multiply LowSigned WordPacked MultiplyUnsigned Doubleword<strong>and</strong> Store QuadwordPOP Pop Stack 3 BasicPOPA Pop All to GPR Words 3 BasicPOPADPop All to GPRDoublewords333333BasicPOPF Pop to FLAGS Word 3 BasicPOPFDPOPFQPORPREFETCHPREFETCHlevelPREFETCHWInstructionMnemonic Description CPLPop to EFLAGSDoublewordPop to RFLAGSQuadwordPacked Logical BitwiseORPrefetch L1 Data-CacheLinePrefetch Data to CacheLevel levelPrefetch L1 Data-CacheLine for Write333333<strong>General</strong>-<strong>Purpose</strong>BasicLong Mode3DNow!,Long ModeSSE, MMXExtensions3DNow!, LongModeInstruction Subset<strong>and</strong> CPUID Feature Set(s) 1128-BitMediaSSE2SSE2SSE2SSE2SSE264-BitMedia3DNow!SSE, MMXExtensionsMMXMMXSSE2MMXx87<strong>System</strong>1. Columns indicate the instruction subsets. Entries indicate the CPUID feature set(s) to which the instruction belongs.2. Mnemonic is used for two different instructions. Assemblers can distinguish them by the number <strong>and</strong> type of oper<strong>and</strong>s.Appendix D: Instruction Subsets <strong>and</strong> CPUID Feature Sets 483


AMD64 Technology 24594 Rev. 3.10 February 2005Table D-1.Instruction Subsets <strong>and</strong> CPUID Feature Sets (continued)InstructionInstruction Subset<strong>and</strong> CPUID Feature Set(s) 1Mnemonic Description CPL<strong>General</strong>-<strong>Purpose</strong>128-BitMedia64-BitMediax87<strong>System</strong>PSADBWPacked Sum of AbsoluteDifferences of Bytes intoa Word3SSE2SSE, MMXExtensionsPSHUFDPacked ShuffleDoublewords3SSE2PSHUFHWPacked Shuffle HighWords3SSE2PSHUFLWPacked Shuffle LowWords3SSE2PSHUFW Packed Shuffle Words 3SSE, MMXExtensionsPSLLDPacked Shift Left LogicalDoublewords3SSE2MMXPSLLDQPacked Shift Left LogicalDouble Quadword3SSE2PSLLQPacked Shift Left LogicalQuadwords3SSE2MMXPSLLWPacked Shift Left LogicalWords3SSE2MMXPSRADPacked Shift RightArithmetic Doublewords3SSE2MMXPSRAWPacked Shift RightArithmetic Words3SSE2MMXPSRLDPacked Shift RightLogical Doublewords3SSE2MMXPSRLDQPacked Shift RightLogical DoubleQuadword3SSE21. Columns indicate the instruction subsets. Entries indicate the CPUID feature set(s) to which the instruction belongs.2. Mnemonic is used for two different instructions. Assemblers can distinguish them by the number <strong>and</strong> type of oper<strong>and</strong>s.484 Appendix D: Instruction Subsets <strong>and</strong> CPUID Feature Sets


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable D-1.Instruction Subsets <strong>and</strong> CPUID Feature Sets (continued)PSRLQPSRLWPacked Shift RightLogical QuadwordsPacked Shift RightLogical Words33SSE2SSE2MMXMMXPSUBB Packed Subtract Bytes 3 SSE2 MMXPSUBDPSUBQPSUBSBPSUBSWPSUBUSBPSUBUSWPacked SubtractDoublewordsPacked SubtractQuadwordPacked Subtract SignedWith Saturation BytesPacked Subtract Signedwith Saturation WordsPacked SubtractUnsigned <strong>and</strong> SaturateBytesPacked SubtractUnsigned <strong>and</strong> SaturateWords333333SSE2SSE2SSE2SSE2SSE2SSE2MMXSSE2MMXMMXMMXMMXPSUBW Packed Subtract Words 3 SSE2 MMXPSWAPDPUNPCKHBWPUNPCKHDQPUNPCKHQDQInstructionMnemonic Description CPLPacked SwapDoublewordUnpack <strong>and</strong> InterleaveHigh BytesUnpack <strong>and</strong> InterleaveHigh DoublewordsUnpack <strong>and</strong> InterleaveHigh Quadwords3333<strong>General</strong>-<strong>Purpose</strong>Instruction Subset<strong>and</strong> CPUID Feature Set(s) 1128-BitMediaSSE2SSE2SSE264-BitMedia3DNow!ExtensionsMMXMMXx87<strong>System</strong>1. Columns indicate the instruction subsets. Entries indicate the CPUID feature set(s) to which the instruction belongs.2. Mnemonic is used for two different instructions. Assemblers can distinguish them by the number <strong>and</strong> type of oper<strong>and</strong>s.Appendix D: Instruction Subsets <strong>and</strong> CPUID Feature Sets 485


AMD64 Technology 24594 Rev. 3.10 February 2005Table D-1.Instruction Subsets <strong>and</strong> CPUID Feature Sets (continued)PUNPCKHWDPUNPCKLBWPUNPCKLDQPUNPCKLQDQPUNPCKLWDUnpack <strong>and</strong> InterleaveHigh WordsUnpack <strong>and</strong> InterleaveLow BytesUnpack <strong>and</strong> InterleaveLow DoublewordsUnpack <strong>and</strong> InterleaveLow QuadwordsUnpack <strong>and</strong> InterleaveLow WordsPUSH Push onto Stack 3 BasicPUSHAPUSHADPUSHFPUSHFDPUSHFQPXORRCLRCPPSInstructionMnemonic Description CPLPush All GPR Words ontoStackPush All GPRDoublewords onto StackPush EFLAGS Word ontoStackPush EFLAGSDoubleword onto StackPush RFLAGS Quadwordonto StackPacked Logical BitwiseExclusive ORRotate Through CarryLeftReciprocal PackedSingle-PrecisionFloating-Point3333333333333<strong>General</strong>-<strong>Purpose</strong>BasicBasicBasicBasicLong ModeBasicInstruction Subset<strong>and</strong> CPUID Feature Set(s) 1128-BitMediaSSE2SSE2SSE2SSE2SSE2SSE2SSE64-BitMediaMMXMMXMMX3DNow!MMXx87<strong>System</strong>1. Columns indicate the instruction subsets. Entries indicate the CPUID feature set(s) to which the instruction belongs.2. Mnemonic is used for two different instructions. Assemblers can distinguish them by the number <strong>and</strong> type of oper<strong>and</strong>s.486 Appendix D: Instruction Subsets <strong>and</strong> CPUID Feature Sets


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable D-1.Instruction Subsets <strong>and</strong> CPUID Feature Sets (continued)RCPSSRCRRDMSRRDPMCRDTSCRDTSCPReciprocal Scalar Single-Precision Floating-PointRotate Through CarryRightRead Model-SpecificRegisterRead Performance-Monitoring CounterRead Time-StampCounterRead Time-StampCounter <strong>and</strong> ProcessorID33033BasicRET Return from Call 3 BasicROL Rotate Left 3 BasicROR Rotate Right 3 BasicRSMRSQRTPSRSQRTSSInstructionMnemonic Description CPLResume from <strong>System</strong>Management ModeReciprocal Square RootPacked Single-PrecisionFloating-PointReciprocal Square RootScalar Single-PrecisionFloating-Point3333<strong>General</strong>-<strong>Purpose</strong>SAHF Store AH into Flags 3 BasicSAL Shift Arithmetic Left 3 BasicSAR Shift Arithmetic Right 3 BasicSBB Subtract with Borrow 3 BasicInstruction Subset<strong>and</strong> CPUID Feature Set(s) 1128-BitMediaSSESSESSE64-BitMediax87<strong>System</strong>RDMSR,WRMSRBasicTSCRDTSCPBasic1. Columns indicate the instruction subsets. Entries indicate the CPUID feature set(s) to which the instruction belongs.2. Mnemonic is used for two different instructions. Assemblers can distinguish them by the number <strong>and</strong> type of oper<strong>and</strong>s.Appendix D: Instruction Subsets <strong>and</strong> CPUID Feature Sets 487


AMD64 Technology 24594 Rev. 3.10 February 2005Table D-1.Instruction Subsets <strong>and</strong> CPUID Feature Sets (continued)SCAS Scan String 3 BasicSCASB Scan String as Bytes 3 BasicSCASDSCASQScan String asDoublewordScan String asQuadword33BasicLong ModeSCASW Scan String as Words 3 BasicSETcc Set Byte if Condition 3 BasicSFENCE Store Fence 3SGDTStore Global DescriptorTable Register3SSE, MMXExtensionsSHL Shift Left 3 BasicSHLD Shift Left Double 3 BasicSHR Shift Right 3 BasicSHRD Shift Right Double 3 BasicSHUFPDSHUFPSSIDTSLDTSMSWInstructionMnemonic Description CPLShuffle Packed Double-Precision Floating-PointShuffle Packed Single-Precision Floating-PointStore InterruptDescriptor Table RegisterStore Local DescriptorTable RegisterStore Machine StatusWord33333<strong>General</strong>-<strong>Purpose</strong>Instruction Subset<strong>and</strong> CPUID Feature Set(s) 1128-BitMediaSSE2SSE64-BitMediax87<strong>System</strong>BasicBasicBasicBasic1. Columns indicate the instruction subsets. Entries indicate the CPUID feature set(s) to which the instruction belongs.2. Mnemonic is used for two different instructions. Assemblers can distinguish them by the number <strong>and</strong> type of oper<strong>and</strong>s.488 Appendix D: Instruction Subsets <strong>and</strong> CPUID Feature Sets


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable D-1.Instruction Subsets <strong>and</strong> CPUID Feature Sets (continued)SQRTPDSQRTPSSQRTSDSQRTSSSquare Root PackedDouble-PrecisionFloating-PointSquare Root PackedSingle-PrecisionFloating-PointSquare Root ScalarDouble-PrecisionFloating-PointSquare Root ScalarSingle-PrecisionFloating-PointSTC Set Carry Flag 3 BasicSTD Set Direction Flag 3 Basic3333STI Set Interrupt Flag 3 BasicSTMXCSRStore MXCSRControl/Status RegisterSTOS Store String 3 BasicSTOSB Store String Bytes 3 BasicSTOSDStore StringDoublewords33BasicSTOSQ Store String Quadwords 3 Long ModeSTOSW Store String Words 3 BasicSTR Store Task Register 3 BasicSUB Subtract 3 BasicSUBPDInstructionMnemonic Description CPLSubtract Packed Double-Precision Floating-Point3<strong>General</strong>-<strong>Purpose</strong>Instruction Subset<strong>and</strong> CPUID Feature Set(s) 1128-BitMediaSSE2SSESSE2SSESSESSE264-BitMedia1. Columns indicate the instruction subsets. Entries indicate the CPUID feature set(s) to which the instruction belongs.2. Mnemonic is used for two different instructions. Assemblers can distinguish them by the number <strong>and</strong> type of oper<strong>and</strong>s.x87<strong>System</strong>Appendix D: Instruction Subsets <strong>and</strong> CPUID Feature Sets 489


AMD64 Technology 24594 Rev. 3.10 February 2005Table D-1.Instruction Subsets <strong>and</strong> CPUID Feature Sets (continued)SUBPSSUBSDSUBSSSWAPGSSubtract Packed Single-Precision Floating-PointSubtract Scalar Double-Precision Floating-PointSubtract Scalar Single-Precision Floating-PointSwap GS Register withKernelGSbase MSRSYSCALL Fast <strong>System</strong> Call 3SYSENTER <strong>System</strong> Call 3SYSEXIT <strong>System</strong> Return 0SYSRET Fast <strong>System</strong> Return 0TEST Test Bits 3 BasicUCOMISDUCOMISSUnordered CompareScalar Double-PrecisionFloating-PointUnordered CompareScalar Single-PrecisionFloating-Point333033SSESSE2SSESSE2SSELong ModeSYSCALL,SYSRETSYSENTER,SYSEXITSYSENTER,SYSEXITSYSCALL,SYSRETUD2 Undefined Operation 3 BasicUNPCKHPDUNPCKHPSInstructionMnemonic Description CPLUnpack High Double-Precision Floating-PointUnpack High Single-Precision Floating-Point33<strong>General</strong>-<strong>Purpose</strong>Instruction Subset<strong>and</strong> CPUID Feature Set(s) 1128-BitMediaSSE2SSE64-BitMedia1. Columns indicate the instruction subsets. Entries indicate the CPUID feature set(s) to which the instruction belongs.2. Mnemonic is used for two different instructions. Assemblers can distinguish them by the number <strong>and</strong> type of oper<strong>and</strong>s.x87<strong>System</strong>490 Appendix D: Instruction Subsets <strong>and</strong> CPUID Feature Sets


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable D-1.Instruction Subsets <strong>and</strong> CPUID Feature Sets (continued)UNPCKLPDUNPCKLPSUnpack Low Double-Precision Floating-PointUnpack Low Single-Precision Floating-Point33VERR Verify Segment for Reads 3 BasicVERWWAITWBINVDWRMSRVerify Segment forWritesWait for x87 Floating-Point ExceptionsWriteback <strong>and</strong> InvalidateCachesWrite to Model-SpecificRegisterXADD Exchange <strong>and</strong> Add 3 BasicXCHG Exchange 3 BasicXLAT Translate Table Index 3 BasicXLATBTranslate Table Index(No Oper<strong>and</strong>s)33003BasicXOR Exclusive OR 3 BasicXORPDXORPSInstructionMnemonic Description CPLLogical Bitwise ExclusiveOR Packed Double-Precision Floating-PointLogical Bitwise ExclusiveOR Packed Single-Precision Floating-Point33<strong>General</strong>-<strong>Purpose</strong>Instruction Subset<strong>and</strong> CPUID Feature Set(s) 1128-BitMediaSSE2SSESSE2SSE64-BitMedia1. Columns indicate the instruction subsets. Entries indicate the CPUID feature set(s) to which the instruction belongs.2. Mnemonic is used for two different instructions. Assemblers can distinguish them by the number <strong>and</strong> type of oper<strong>and</strong>s.x87X87<strong>System</strong>BasicBasicRDMSR,WRMSRAppendix D: Instruction Subsets <strong>and</strong> CPUID Feature Sets 491


AMD64 Technology 24594 Rev. 3.10 February 2005492 Appendix D: Instruction Subsets <strong>and</strong> CPUID Feature Sets


24594 Rev. 3.10 February 2005 AMD64 TechnologyAppendix EInstruction Effects on RFLAGSThe flags in the RFLAGS register are described in “FlagsRegister” in <strong>Volume</strong> 1 <strong>and</strong> “RFLAGS Register” in <strong>Volume</strong> 2.Table E-1 summarizes the effect that instructions have on theseflags. The table includes all instructions that affect the flags.<strong>Instructions</strong> not shown have no effect on RFLAGS.The following codes are used within the table:• 0—The flag is always cleared to 0.• 1—The flag is always set to 1.• AH—The flag is loaded with value from AH register.• Mod—The flag is modified, depending on the results of theinstruction.• Pop—The flag is loaded with value popped off of the stack.• Tst—The flag is tested.• U—The effect on the flag is undefined.• Gray shaded cells indicate that the flag is not affected by theinstruction.Table E-1.Instruction Effects on RFLAGSInstructionMnemonicID21VIP20VIF19AC18VM17RFLAGS Mnemonic <strong>and</strong> Bit NumberRF16NT14IOPL13-12OF11DF10IF9TF8SF7ZF6AF4PF2CF0AAAAASU U UTstModUModAADAAMUMod Mod U Mod UADC Mod Mod Mod Mod ModTstModADD Mod Mod Mod Mod Mod ModAND 0 Mod Mod U Mod 0ARPLBSFBSRModU U Mod U U UAppendix E: Instruction Effects on RFLAGS 493


AMD64 Technology 24594 Rev. 3.10 February 2005Table E-1.Instruction Effects on RFLAGS (continued)InstructionMnemonicBTBTCBTRBTSU U U U U ModCLC 0CLD 0CLI Mod TST ModCMCCMOVcc Tst Tst Tst Tst TstCMP Mod Mod Mod Mod Mod ModCMPSx Mod Tst Mod Mod Mod Mod ModCMPXCHG Mod Mod Mod Mod Mod ModCMPXCHG8BCMPXCHG16BCOMISDCOMISSDAADASModModMod0 0 Mod 0 Mod ModU Mod Mod TstMod ModDEC Mod Mod Mod Mod ModDIV U U U U U UFCMOVcc Tst Tst TstFCOMIFCOMIPFUCOMIFUCOMIPModTstModMod ModIDIV U U U U U UIMUL Mod U U U U ModINC Mod Mod Mod Mod ModINID21VIP20VIF19AC18VM17RFLAGS Mnemonic <strong>and</strong> Bit NumberRF16NT14IOPL13-12TstOF11DF10IF9TF8SF7ZF6AF4PF2CF0494 Appendix E: Instruction Effects on RFLAGS


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable E-1.Instruction Effects on RFLAGS (continued)InstructionMnemonicINSx Tst TstINTINT 3INTOMod ModModIRETx Pop Pop Pop PopTstModTstMod0 Mod Tst Mod 00 Mod Tst Tst Mod ModTstPop Pop TstPopTstPopPop Pop Pop Pop Pop Pop Pop Pop PopJcc Tst Tst Tst Tst TstLARLODSxLOOPELOOPNELSLMOVSxMUL Mod U U U U ModNEG Mod Mod Mod Mod Mod ModOR 0 Mod Mod U Mod 0OUTOUTSx Tst TstPOPFx Pop Tst Mod Pop Tst 0 PopRCL 1RCL countRCR 1RCR countID21VIP20VIF19AC18VM17RFLAGS Mnemonic <strong>and</strong> Bit NumberRF16NT14IOPL13-12TstTstPopOF11TstTstModTstModPop Pop Pop Pop Pop Pop Pop Pop PopModUModUDF10IF9TF8SF7ZF6AF4PF2CF0TstModTstModTstModTstModAppendix E: Instruction Effects on RFLAGS 495


AMD64 Technology 24594 Rev. 3.10 February 2005Table E-1.Instruction Effects on RFLAGS (continued)InstructionMnemonicROL 1 Mod ModROL count U ModROR 1 Mod ModROR count U ModRSM Mod Mod Mod Mod Mod Mod Mod Mod Mod Mod Mod Mod Mod Mod Mod Mod ModSAHF AH AH AH AH AHSAL 1 Mod Mod Mod U Mod ModSAL count U Mod Mod U Mod ModSAR 1 Mod Mod Mod U Mod ModSAR count U Mod Mod U Mod ModSBB Mod Mod Mod Mod ModSCASx Mod Tst Mod Mod Mod Mod ModSETcc Tst Tst Tst Tst TstSHLD 1SHRD 1SHLD countSHRD countTstModMod Mod Mod U Mod ModU Mod Mod U Mod ModSHR 1 Mod Mod Mod U Mod ModSHR count U Mod Mod U Mod ModSTC 1STD 1STI Mod Tst ModSTOSxID21VIP20VIF19AC18RFLAGS Mnemonic <strong>and</strong> Bit NumberSUB Mod Mod Mod Mod Mod ModSYSCALL Mod Mod Mod Mod 0 0 Mod Mod Mod Mod Mod Mod Mod Mod Mod Mod ModSYSENTER 0 0 0VM17RF16NT14IOPL13-12OF11DF10TstIF9TF8SF7ZF6AF4PF2CF0496 Appendix E: Instruction Effects on RFLAGS


24594 Rev. 3.10 February 2005 AMD64 TechnologyTable E-1.Instruction Effects on RFLAGS (continued)InstructionMnemonicSYSRET Mod Mod Mod Mod 0 Mod Mod Mod Mod Mod Mod Mod Mod Mod Mod ModTEST 0 Mod Mod U Mod 0UCOMISDUCOMISSVERRVERWID21VIP20VIF19AC18VM17RFLAGS Mnemonic <strong>and</strong> Bit NumberRF16NT14IOPL13-120 0 Mod 0 Mod ModXADD Mod Mod Mod Mod Mod ModXOR 0 Mod Mod U Mod 0OF11DF10IF9TF8SF7ZF6ModAF4PF2CF0Appendix E: Instruction Effects on RFLAGS 497


AMD64 Technology 24594 Rev. 3.10 February 2005498 Appendix E: Instruction Effects on RFLAGS


24594 Rev. 3.10 February 2005 AMD64 TechnologyIndexNumerics12-bit Br<strong>and</strong> ID.......................................... 12516-bit mode................................................ xvii32-bit mode................................................ xvii64-bit mode................................................ xvii8-Bit Br<strong>and</strong> ID ........................................... 121AAAA ............................................................. 61AAD ............................................................. 62AAM............................................................. 63AAS .............................................................. 64ADC.............................................................. 65ADD ............................................................. 67address size prefix .................................. 6, 25addressingbyte registers............................................ 17effective address............ 404, 407, 408, 410PC-relative................................................ 23RIP-relative .................................... xxiii, 23AND ............................................................. 69APIC ID ..................................................... 121ARPL ......................................................... 298Bbase field ........................................... 409, 410biased exponent........................................ xviiBOUND ........................................................ 72Br<strong>and</strong> ID ............................................ 121, 125BSF............................................................... 74BSR .............................................................. 76BSWAP......................................................... 78BT ................................................................. 79BTC .............................................................. 81BTR .............................................................. 83BTS............................................................... 85byte order of instructions ............................ 1byte register addressing............................. 17CCALL............................................................ 15far call....................................................... 89near call.................................................... 87CBW ............................................................. 96CDQ.............................................................. 97CDQE ........................................................... 96CLC .............................................................. 98CLD .............................................................. 99CLFLUSH.................................................. 100CLI ............................................................. 300CLTS .......................................................... 302CMC........................................................... 102CMOVcc ............................................ 103, 386CMP ........................................................... 107CMPSx....................................................... 110CMPXCHG................................................ 113CMPXCHG16B ......................................... 115CMPXCHG8B ........................................... 115commit...................................................... xviiicompatibility mode ................................. xviiicondition codesrFLAGS .......................................... 386, 402count.......................................................... 414CPUID ....................................................... 117extended functions ............................... 117feature sets ............................................ 455L1 Cache Information ........................... 130L2 Cache <strong>and</strong> TLB Information ........... 132st<strong>and</strong>ard functions ................................ 117CPUID instructionlong-mode address sizes........................ 134testing for............................................... 117CQD ............................................................. 97CWD ............................................................ 97CWDE.......................................................... 96DDAA ........................................................... 136DAS............................................................ 137data types128-bit media ........................................... 3664-bit media ............................................. 38general-purpose....................................... 32x87 ............................................................ 40DEC ............................................. 17, 138, 448direct referencing.................................... xviiidisplacements............................ xviii, 22, 414DIV ............................................................ 140double quadword..................................... xviiidoubleword .............................................. xviiiEeAX–eSP register ..................................... xxveffective address .............. 404, 407, 408, 410effective address size................................ xixeffective oper<strong>and</strong> size............................... xixeFLAGS register....................................... xxveIP register ............................................... xxvelement ...................................................... xixIndex 499


AMD64 Technology 24594 Rev. 3.10 February 2005endian order........................................ xxvii, 1ENTER................................................. 15, 142exceptions............................................. xix, 41exponent.................................................... xviiFFCMOVcc................................................... 402flush ............................................................ xixGgeneral-purpose registers .......................... 30HHLT ............................................................ 303IIDIV ........................................................... 144IGN............................................................... xximmediate oper<strong>and</strong>s........................... 23, 414IMUL.......................................................... 146IN................................................................ 149INC ............................................... 17, 151, 448index field ................................................. 410indirect ........................................................ xxINSB ........................................................... 153INSD........................................................... 153<strong>Instructions</strong>SSE3........................................................ 457instructions128-bit media.......................................... 4573DNow!................................................ 45664-bit media............................................ 457byte order ................................................... 1effects on rFLAGS ................................. 493formats........................................................ 1general-purpose ............................... 59, 457invalid in 64-bit mode............................ 444invalid in long mode .............................. 446MMX.................................................... 455opcodes ............................................. 20, 375origins ..................................................... 453reassigned in 64-bit mode ..................... 445SSE.......................................................... 456SSE-2....................................................... 456subsets .............................................. 27, 453system ............................................. 297, 457x87................................................... 455, 457INSW.......................................................... 153INSx ........................................................... 153INT ............................................................. 156INT 3 .......................................................... 304interrupt vectors......................................... 41INTO........................................................... 164INVD .......................................................... 307INVLPG............................................. 308, 390IRET .......................................................... 309IRETD ....................................................... 309IRETQ ....................................................... 309JJcc................................................ 15, 165, 386JCXZ.......................................................... 169JECXZ ....................................................... 169JMP.............................................................. 15far jump ................................................. 173near jump............................................... 171JRCXZ....................................................... 169JrCXZ .......................................................... 15LL1 cache <strong>and</strong> TLB information ............... 130L2 Cache <strong>and</strong> TLB Information .............. 132LAHF......................................................... 178LAR ........................................................... 315LDS ............................................................ 179LEA............................................................ 182LEAVE................................................. 15, 184legacy mode ................................................ xxlegacy x86 ................................................... xxLES ............................................................ 179LFENCE ............................................ 186, 390LFS ............................................................ 179LGDT ................................................... 15, 318LGS ............................................................ 179LIDT .................................................... 15, 320LLDT ................................................... 15, 322LMSW........................................................ 324LOCK prefix ............................................... 10LODSB....................................................... 187LODSD ...................................................... 187LODSQ ...................................................... 187LODSW...................................................... 187LODSx ....................................................... 187long mode.................................................... xxlong-mode address sizes .......................... 134LOOP ........................................................... 15LOOPcc ....................................................... 15LOOPx ....................................................... 189LSB ............................................................. xxilsb ............................................................... xxiLSL ............................................................ 325LSS............................................................. 179LTR ...................................................... 15, 327Mmask ........................................................... xxiMBZ ............................................................ xxi500 Index


24594 Rev. 3.10 February 2005 AMD64 TechnologyMFENCE ........................................... 191, 390mod field ................................................... 407mode-register-memory (ModRM)............ 402modes......................................................... 45116-bit ....................................................... xvii32-bit ....................................................... xvii64-bit ............................................... xvii, 451compatibility ................................ xviii, 451legacy ........................................................ xxlong.................................................... xx, 451protected ................................................ xxiireal .......................................................... xxiivirtual-8086 ........................................... xxivModRM ...................................................... 402ModRM byte............ 19, 20, 24, 387, 392, 402moffset........................................................ xxiMOV ........................................................... 192MOV CR(n).................................................. 15MOV DR(n).................................................. 15MOV(CRn)................................................. 329MOV(DRn)................................................. 331MOVD ........................................................ 196MOVMSKPD.............................................. 199MOVMSKPS .............................................. 201MOVNTI..................................................... 203MOVSX ...................................................... 207MOVSx ....................................................... 205MOVSXD ................................................... 208MOVZX...................................................... 209MSB............................................................. xximsb.............................................................. xxiMSR .......................................................... xxviMUL ........................................................... 210NNEG............................................................ 212NOP.................................................... 214, 448NOT ............................................................ 215notation ............................................... 43, 375Ooctword ....................................................... xxioffset ..................................................... xxi, 22opcodes ........................................................ 203DNow!................................................ 390group 1 .................................................... 388group 10 .................................................. 389group 11 .................................................. 389group 12 .................................................. 389group 13 .................................................. 389group 14 .................................................. 389group 15 .................................................. 389group 16 .................................................. 389group 1a ................................................. 388group 2 ................................................... 388group 3 ................................................... 388group 4 ................................................... 388group 5 ................................................... 388group 6 ................................................... 388group 7 ................................................... 388group 8 ................................................... 388group 9 ................................................... 389group P ................................................... 389groups..................................................... 387ModRM byte .......................................... 387one-byte opcode map ............................ 377two-byte opcode map ............................ 380x87 opcode map..................................... 392oper<strong>and</strong>sencodings ............................................... 402immediate ........................................ 23, 414size ...................................... 5, 413, 414, 446OR.............................................................. 216OUT ........................................................... 219OUTS ......................................................... 221OUTSB....................................................... 221OUTSD ...................................................... 221OUTSW ..................................................... 221overflow..................................................... xxiiPpacked ....................................................... xxiiPC-relative addressing............................... 23POP............................................................ 223POP FS ........................................................ 15POP GS........................................................ 15POP reg ....................................................... 15POP reg/mem.............................................. 15POPAD....................................................... 226POPAx ....................................................... 226POPF ......................................................... 227POPFD....................................................... 227POPFQ................................................. 15, 227PREFETCH............................................... 230PREFETCHlevel ...................................... 232PREFETCHW ........................................... 230prefixesaddress size.......................................... 6, 25LOCK........................................................ 10oper<strong>and</strong> size............................................... 5repeat ....................................................... 10REX .................................................... 14, 24segment ...................................................... 9processor feature identification(rFLAGS.ID)..................................... 117Index 501


AMD64 Technology 24594 Rev. 3.10 February 2005Processor Name ........................................ 129Functions 8000_0002h, 8000_0003h,8000_0004h ....................................... 129processor signature .................................. 125processor vendor............................... 118, 125processor version ...................................... 119protected mode ......................................... xxiiPUSH ......................................................... 234PUSH FS...................................................... 15PUSH GS ..................................................... 15PUSH imm32............................................... 15PUSH imm8................................................. 15PUSH reg..................................................... 15PUSH reg/mem ........................................... 15PUSHA ...................................................... 236PUSHAD.................................................... 236PUSHF....................................................... 237PUSHFD .................................................... 237PUSHFQ .............................................. 15, 237Qquadword................................................... xxiiRr/m field ............................................. 387, 390r8–r15........................................................ xxvirAX–rSP.................................................... xxviRAZ............................................................ xxiiRCL ............................................................ 239RCR............................................................ 242RDMSR...................................................... 333RDPMC...................................................... 334RDTSC ....................................................... 336RDTSCP..................................................... 337real address mode. See real modereal mode................................................... xxiireg field ............................. 387, 403, 406, 407registerseAX–eSP................................................. xxveFLAGS................................................... xxveIP ........................................................... xxvencodings.................................................. 17general-purpose ....................................... 30MMX ......................................................... 38r8–r15..................................................... xxvirAX–rSP................................................. xxvirFLAGS ......................... xxvii, 386, 402, 493rIP.......................................................... xxviisegment..................................................... 32system ....................................................... 33x87............................................................. 40XMM ......................................................... 35relative....................................................... xxiiREPx prefixes............................................. 10reserved..................................................... xxiiRETfar return................................................ 247near return............................................. 245RET (Near) ................................................. 15revision history.......................................... xiiiREX prefixes ................................ 14, 24, 402REX.B bit .............................. 17, 47, 407, 409REX.R bit............................................ 16, 406REX.W bit................................................... 16REX.X bit.................................................... 16rFLAGS conditions codes ................ 386, 402rFLAGS register ............................. xxvii, 493rIP register.............................................. xxviiRIP-relative addressing .................... xxiii, 23ROL............................................................ 251ROR ........................................................... 253rotate count .............................................. 414RSM ........................................................... 339SSAHF ......................................................... 255SAL ............................................................ 256SAR............................................................ 259SBB ............................................................ 262scale field.................................................. 410scale-index-base (SIB).............................. 402SCAS.......................................................... 265SCASB ....................................................... 265SCASD....................................................... 265SCASQ....................................................... 265SCASW ...................................................... 265segment prefixes .................................. 9, 449segment registers ....................................... 32set ............................................................. xxiiiSETcc................................................. 267, 386SFENCE ............................................ 270, 390SGDT ......................................................... 341shift count ................................................. 414SHL............................................................ 271SHLD ......................................................... 272SHR ........................................................... 274SHRD......................................................... 276SIB ............................................................. 402SIB byte................................... 19, 21, 24, 408SIDT........................................................... 343SLDT.......................................................... 345SMSW ........................................................ 347SSE ........................................................... xxiiiSSE2 ......................................................... xxiiiSSE3 ......................................................... xxiii502 Index


24594 Rev. 3.10 February 2005 AMD64 TechnologySTC............................................................. 278STD ............................................................ 279STI.............................................................. 348sticky bits ................................................. xxivSTOS .......................................................... 280STOSB ........................................................ 280STOSD........................................................ 280STOSQ........................................................ 280STOSW....................................................... 280STR ............................................................ 350SUB ............................................................ 282SWAPGS ............................................ 352, 390syntax........................................................... 43SYSCALL................................................... 354SYSENTER................................................ 359SYSEXIT.................................................... 361SYSRET..................................................... 363system data structures ............................... 34TTEST .......................................................... 285TSS ............................................................ xxivUUD2 ............................................................ 367underflow ................................................. xxivVvector ........................................................ xxivVERR......................................................... 368VERW ........................................................ 370virtual-8086 mode.................................... xxivWWBINVD .................................................... 372WRMSR ..................................................... 373XXADD......................................................... 287XCHG......................................................... 289XLATx........................................................ 291XOR ........................................................... 293Zzero-extension ........................................... 414Index 503


AMD64 Technology 24594 Rev. 3.10 February 2005504 Index

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!