Template:Short description Template:Lowercase title Template:X86 instruction listings The x86 instruction set refers to the set of instructions that x86-compatible microprocessors support. The instructions are usually part of an executable program, often stored as a computer file and executed on the processor.

The x86 instruction set has been extended several times, introducing wider registers and datatypes as well as new functionality.<ref name=":0">{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

x86 integer instructionsEdit

{{#invoke:Labelled list hatnote|labelledList|Main article|Main articles|Main page|Main pages}} Below is the full 8086/8088 instruction set of Intel (81 instructions total).<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> These instructions are also available in 32-bit mode, in which they operate on 32-bit registers (eax, ebx, etc.) and values instead of their 16-bit (ax, bx, etc.) counterparts. The updated instruction set is grouped according to architecture (i186, i286, i386, i486, i586/i686) and is referred to as (32-bit) x86 and (64-bit) x86-64 (also known as AMD64).

Original 8086/8088 instructionsEdit

This is the original instruction set. In the 'Notes' column, r means register, m means memory address and imm means immediate (i.e. a value).

Template:Sticky header

Added in specific processorsEdit

Added with 80186/80188Edit

Template:Sticky header

Added with 80286Edit

The new instructions added in 80286 add support for x86 protected mode. Some but not all of the instructions are available in real mode as well.

Template:Sticky header

Template:Notelist

Added with 80386Edit

The 80386 added support for 32-bit operation to the x86 instruction set. This was done by widening the general-purpose registers to 32 bits and introducing the concepts of OperandSize and AddressSize – most instruction forms that would previously take 16-bit data arguments were given the ability to take 32-bit arguments by setting their OperandSize to 32 bits, and instructions that could take 16-bit address arguments were given the ability to take 32-bit address arguments by setting their AddressSize to 32 bits. (Instruction forms that work on 8-bit data continue to be 8-bit regardless of OperandSize. Using a data size of 16 bits will cause only the bottom 16 bits of the 32-bit general-purpose registers to be modified – the top 16 bits are left unchanged.)

The default OperandSize and AddressSize to use for each instruction is given by the D bit of the segment descriptor of the current code segment - D=0 makes both 16-bit, D=1 makes both 32-bit. Additionally, they can be overridden on a per-instruction basis with two new instruction prefixes that were introduced in the 80386:

  • 66h: OperandSize override. Will change OperandSize from 16-bit to 32-bit if CS.D=0, or from 32-bit to 16-bit if CS.D=1.
  • 67h: AddressSize override. Will change AddressSize from 16-bit to 32-bit if CS.D=0, or from 32-bit to 16-bit if CS.D=1.

The 80386 also introduced the two new segment registers FS and GS as well as the x86 control, debug and test registers.

The new instructions introduced in the 80386 can broadly be subdivided into two classes:

  • Pre-existing opcodes that needed new mnemonics for their 32-bit OperandSize variants (e.g. CWDE, LODSD)
  • New opcodes that introduced new functionality (e.g. SHLD, SETcc)

For instruction forms where the operand size can be inferred from the instruction's arguments (e.g. ADD EAX,EBX can be inferred to have a 32-bit OperandSize due to its use of EAX as an argument), new instruction mnemonics are not needed and not provided.

Template:Sticky header

Template:Notelist

Template:Sticky header

Template:Notelist

Added with 80486Edit

Instruction Opcode Description Ring
BSWAP r32 Template:Nowrap Byte Order Swap. Usually used to convert between big-endian and little-endian data representations. For 32-bit registers, the operation performed is:
r =   (r << 24)
    | ((r << 8) & 0x00FF0000)
    | ((r >> 8) & 0x0000FF00)
    | (r >> 24);

Using BSWAP with a 16-bit register argument produces an undefined result.Template:Efn

rowspan="5" Template:Yes
CMPXCHG r/m8,r8 Template:Nowrap Compare and Exchange. If accumulator (AL/AX/EAX/RAX) compares equal to first operand,Template:Efn then EFLAGS.ZF is set to 1 and the first operand is overwritten with the second operand. Otherwise, EFLAGS.ZF is set to 0, and first operand is copied into the accumulator.

Instruction atomic only if used with LOCK prefix.

Template:Nowrap
Template:Nowrap
Template:Nowrap
XADD r/m,r8 Template:Nowrap eXchange and ADD. Exchanges the first operand with the second operand, then stores the sum of the two values into the destination operand.

Instruction atomic only if used with LOCK prefix.

XADD r/m,r16
XADD r/m,r32
0F C1 /r
INVLPG m8 Template:Nowrap Invalidate the TLB entries that would be used for the 1-byte memory operand.Template:Efn

Instruction is serializing.

rowspan="3" Template:No
INVD 0F 08 Invalidate Internal Caches.Template:Efn Modified data in the cache are not written back to memory, potentially causing data loss.Template:Efn
WBINVD Template:Nowrap Write Back and Invalidate Cache.Template:Efn Writes back all modified cache lines in the processor's internal cache to main memory and invalidates the internal caches.

Template:NotelistTemplate:Vpad

Added in P5/P6-class processorsEdit

Integer/system instructions that were not present in the basic 80486 instruction set, but were added in various x86 processors prior to the introduction of SSE. (Discontinued instructions are not included.)

Template:Sticky header

Template:Notelist Template:Vpad

Added as instruction set extensionsEdit

Added with x86-64Edit

These instructions can only be encoded in 64 bit mode. They fall in four groups:

  • original instructions that reuse existing opcodes for a different purpose (MOVSXD replacing ARPL)
  • original instructions with new opcodes (SWAPGS)
  • existing instructions extended to a 64 bit address size (JRCXZ)
  • existing instructions extended to a 64 bit operand size (remaining instructions)

Most instructions with a 64 bit operand size encode this using a REX.W prefix; in the absence of the REX.W prefix, the corresponding instruction with 32 bit operand size is encoded. This mechanism also applies to most other instructions with 32 bit operand size. These are not listed here as they do not gain a new mnemonic in Intel syntax when used with a 64 bit operand size.

Instruction Encoding Meaning Ring
CDQE REX.W 98 Sign extend EAX into RAX rowspan="13" Template:Yes
CQO REX.W 99 Sign extend RAX into RDX:RAX
CMPSQ REX.W A7 CoMPare String Quadword
Template:NowrapTemplate:EfnTemplate:Efn Template:Nowrap CoMPare and eXCHanGe 16 Bytes.
Atomic only if used with LOCK prefix.
IRETQ REX.W CF 64-bit Return from Interrupt
JRCXZ rel8 E3 cb Jump if RCX is zero
LODSQ REX.W AD LoaD String Quadword
Template:Nowrap REX.W 63 /rTemplate:Efn MOV with Sign Extend 32-bit to 64-bit
MOVSQ REX.W A5 Move String Quadword
POPFQ 9D POP RFLAGS Register
PUSHFQ 9C PUSH RFLAGS Register
SCASQ REX.W AF SCAn String Quadword
STOSQ REX.W AB STOre String Quadword
SWAPGS 0F 01 F8 Exchange GS base with KernelGSBase MSR Template:No

Template:NotelistTemplate:Vpad

Bit manipulation extensionsEdit

{{#invoke:Labelled list hatnote|labelledList|Main article|Main articles|Main page|Main pages}}

Bit manipulation instructions. For all of the VEX-encoded instructions defined by BMI1 and BMI2, the operand size may be 32 or 64 bits, controlled by the VEX.W bit – none of these instructions are available in 16-bit variants. The VEX-encoded instructions are not available in Real Mode and Virtual-8086 mode - other than that, the bit manipulation instructions are available in all operating modes on supported CPUs.

Bit Manipulation Extension Instruction
mnemonics
Opcode Instruction description Added in
Template:GlossaryTemplate:TermTemplate:DefnTemplate:Glossary end POPCNT r16,r/m16
Template:Nowrap
F3 0F B8 /r Population Count. Counts the number of bits that are set to 1 in its source argument. K10,
Bobcat,
Haswell,
ZhangJiang,
Gracemont
POPCNT r64,r/m64 F3 REX.W 0F B8 /r
LZCNT r16,r/m16
LZCNT r32,r/m32
F3 0F BD /r Count Leading zeroes.Template:Efn
If source operand is all-0s, then LZCNT will return operand size in bits (16/32/64) and set CF=1.
LZCNT r64,r/m64 Template:Nowrap
Template:GlossaryTemplate:TermTemplate:DefnTemplate:Glossary end TZCNT r16,r/m16
TZCNT r32,r/m32
F3 0F BC /r Count Trailing zeroes.Template:Efn
If source operand is all-0s, then TZCNT will return operand size in bits (16/32/64) and set CF=1.
Haswell,
Piledriver,
Jaguar,
ZhangJiang,
Gracemont
TZCNT r64,r/m64 Template:Nowrap
ANDN ra,rb,r/m VEX.LZ.0F38 F2 /r Bitwise AND-NOT: ra = r/m AND NOT(rb)
BEXTR ra,r/m,rb VEX.LZ.0F38 F7 /r Bitfield extract. Bitfield start position is specified in bits [7:0] of rb, length in bits[15:8] of rb. The bitfield is then extracted from the r/m value with zero-extension, then stored in ra. Equivalent toTemplate:Efn
mask = (1 << rb[15:8]) - 1
ra = (r/m >> rb[7:0]) AND mask
BLSI reg,r/m VEX.LZ.0F38 F3 /3 Extract lowest set bit in source argument. Returns 0 if source argument is 0. Equivalent to
dst = (-src) AND src
BLSMSK reg,r/m VEX.LZ.0F38 F3 /2 Generate a bitmask of all-1s bits up to the lowest bit position with a 1 in the source argument. Returns all-1s if source argument is 0. Equivalent to
dst = (src-1) XOR src
BLSR reg,r/m VEX.LZ.0F38 F3 /1 Copy all bits of the source argument, then clear the lowest set bit. Equivalent to
dst = (src-1) AND src
Template:GlossaryTemplate:TermTemplate:DefnTemplate:Glossary end BZHI ra,r/m,rb Template:Small Zero out high-order bits in r/m starting from the bit position specified in rb, then write result to rd. Equivalent to
ra = r/m AND NOT(-1 << rb[7:0])
Haswell,
Template:Nowrap
ZhangJiang,
Gracemont
MULX ra,rb,r/m Template:Small Widening unsigned integer multiply without setting flags. Multiplies EDX/RDX with r/m, then stores the low half of the multiplication result in ra and the high half in rb. If ra and rb specify the same register, only the high half of the result is stored.
PDEP ra,rb,r/m Template:Small Parallel Bit Deposit. Scatters contiguous bits from rb to the bit positions set in r/m, then stores result to ra. Operation performed is:
ra=0; k=0; mask=r/m
for i=0 to opsize-1 do
   if (mask[i] == 1) then
       ra[i]=rb[k]; k=k+1
PEXT ra,rb,r/m Template:Small Parallel Bit Extract. Uses r/m argument as a bit mask to select bits in rb, then compacts the selected bits into a contiguous bit-vector. Operation performed is:
ra=0; k=0; mask=r/m
for i=0 to opsize-1 do
   if (mask[i] == 1) then
       ra[k]=rb[i]; k=k+1
Template:Nowrap Template:Small Rotate right by immediate without affecting flags.
SARX ra,r/m,rb Template:Small Arithmetic shift right without updating flags.
For SARX, SHRX and SHLX, the shift-amount specified in rb is masked to 5 bits for 32-bit operand size and 6 bits for 64-bit operand size.
SHRX ra,r/m,rb Template:Small Logical shift right without updating flags.
SHLX ra,r/m,rb Template:Small Shift left without updating flags.

Template:NotelistTemplate:Vpad

Added with Intel TSXEdit

{{#invoke:Labelled list hatnote|labelledList|Main article|Main articles|Main page|Main pages}}

TSX Subset Instruction Opcode Description Added in
Template:GlossaryTemplate:TermTemplate:DefnTemplate:Glossary end XBEGIN rel16
Template:Nowrap
C7 F8 cw
Template:Nowrap
Start transaction. If transaction fails, perform a branch to the given relative offset. Haswell
(Deprecated on desktop/laptop CPUs from 10th generation (Ice Lake, Comet Lake) onwards, but continues to be available on Xeon-branded server parts (e.g. Ice Lake-SP, Sapphire Rapids))
XABORT imm8 C6 F8 ib Abort transaction with 8-bit immediate as error code.
XEND Template:Nowrap End transaction.
XTEST Template:Nowrap Test if in transactional execution. Sets EFLAGS.ZF to 0 if executed inside a transaction (RTM or HLE), 1 otherwise.
Template:GlossaryTemplate:TermTemplate:DefnTemplate:Glossary end XACQUIRE F2 Instruction prefix to indicate start of hardware lock elision, used with memory atomic instructions only (for other instructions, the F2 prefix may have other meanings). When used with such instructions, may start a transaction instead of performing the memory atomic operation. Haswell
(Discontinued – the last processors to support HLE were Template:Nowrap and Template:Nowrap
XRELEASE F3 Instruction prefix to indicate end of hardware lock elision, used with memory atomic/store instructions only (for other instructions, the F3 prefix may have other meanings). When used with such instructions during hardware lock elision, will end the associated transaction instead of performing the store/atomic.
Template:GlossaryTemplate:TermTemplate:DefnTemplate:Glossary end XSUSLDTRK Template:Nowrap Suspend Tracking Load Addresses Template:Nowrap
XRESLDTRK Template:Nowrap Resume Tracking Load Addresses

Template:Vpad

Added with Intel CETEdit

Intel CET (Control-Flow Enforcement Technology) adds two distinct features to help protect against security exploits such as return-oriented programming: a shadow stack (CET_SS), and indirect branch tracking (CET_IBT).

CET Subset Instruction Opcode Description Ring Added in
Template:GlossaryTemplate:TermTemplate:DefnTemplate:Glossary end INCSSPD r32 F3 0F AE /5 Increment shadow stack pointer rowspan="8" Template:Yes Template:Nowrap
Zen 3
INCSSPQ r64 F3 REX.W 0F AE /5
RDSSPD r32 F3 0F 1E /1 Read shadow stack pointer into register (low 32 bits)Template:Efn
RDSSPQ r64 F3 REX.W 0F 1E /1 Read shadow stack pointer into register (full 64 bits)Template:Efn
SAVEPREVSSP F3 0F 01 EA Save previous shadow stack pointer
RSTORSSP m64 F3 0F 01 /5 Restore saved shadow stack pointer
WRSSD m32,r32 NP 0F 38 F6 /r Write 4 bytes to shadow stack
WRSSQ m64,r64 Template:Nowrap Write 8 bytes to shadow stack
WRUSSD m32,r32 66 0F 38 F5 /r Write 4 bytes to user shadow stack rowspan="4" Template:No
Template:Nowrap Template:Nowrap Write 8 bytes to user shadow stack
SETSSBSY F3 0F 01 E8 Mark shadow stack busy
CLRSSBSY m64 F3 0F AE /6 Clear shadow stack busy flag
Template:GlossaryTemplate:TermTemplate:DefnTemplate:Glossary end ENDBR32 F3 0F 1E FB Terminate indirect branch in 32-bit modeTemplate:Efn rowspan="3" Template:Yes Tiger Lake
ENDBR64 F3 0F 1E FA Terminate indirect branch in 64-bit modeTemplate:Efn
NOTRACK 3ETemplate:Efn Prefix used with indirect CALL/JMP near instructions (opcodes Template:Nowrap and Template:Nowrap) to indicate that the branch target is not required to start with an ENDBR32/64 instruction. Prefix only honored when NO_TRACK_EN flag is set.

Template:NotelistTemplate:Vpad

Added with XSAVEEdit

The XSAVE instruction set extensions are designed to save/restore CPU extended state (typically for the purpose of context switching) in a manner that can be extended to cover new instruction set extensions without the OS context-switching code needing to understand the specifics of the new extensions. This is done by defining a series of state-components, each with a size and offset within a given save area, and each corresponding to a subset of the state needed for one CPU extension or another. The EAX=0Dh CPUID leaf is used to provide information about which state-components the CPU supports and what their sizes/offsets are, so that the OS can reserve the proper amount of space and set the associated enable-bits.

XSAVE Extension Instruction
mnemonics
OpcodeTemplate:Efn Instruction description Ring Added in
Template:GlossaryTemplate:TermTemplate:DefnTemplate:Glossary end XSAVE mem
XSAVE64 mem
NP 0F AE /4
NP REX.W 0F AE /4
Save state components specified by bitmap in EDX:EAX to memory. rowspan="3" Template:Yes Penryn,Template:Efn
Bulldozer,
Jaguar,
Goldmont,
ZhangJiang
XRSTOR mem
XRSTOR64 mem
NP 0F AE /5
Template:Nowrap
Restore state components specified by EDX:EAX from memory.
XGETBV NP 0F 01 D0 Get value of Extended Control Register.
Reads an XCR specified by ECX into EDX:EAX.Template:Efn
XSETBV NP 0F 01 D1 Set Extended Control Register.Template:Efn
Write the value in EDX:EAX to the XCR specified by ECX.
Template:No
Template:GlossaryTemplate:TermTemplate:DefnTemplate:Glossary end XSAVEOPT mem
Template:Nowrap
NP 0F AE /6
NP REX.W 0F AE /6
Save state components specified by EDX:EAX to memory.
Unlike the older XSAVE instruction, XSAVEOPT may abstain from writing processor state items to memory when the CPU can determine that they haven't been modified since the most recent corresponding XRSTOR.
Template:Yes Template:Nowrap
Steamroller,
Puma,
Goldmont,
ZhangJiang
Template:GlossaryTemplate:TermTemplate:DefnTemplate:Glossary end XSAVEC mem
XSAVEC64 mem
NP 0F C7 /4
NP REX.W 0F C7 /4
Save processor extended state components specified by EDX:EAX to memory with compaction. Template:Yes Skylake,
Goldmont,
Zen 1
Template:GlossaryTemplate:TermTemplate:DefnTemplate:Glossary end XSAVES mem
XSAVES64 mem
NP 0F C7 /5
NP REX.W 0F C7 /5
Save processor extended state components specified by EDX:EAX to memory with compaction and optimization if possible. rowspan="2" Template:No Skylake,
Goldmont,
Zen 1
XRSTORS mem
XRSTORS64 mem
NP 0F C7 /3
Template:Nowrap
Restore state components specified by EDX:EAX from memory.

Template:Notelist Template:Vpad

Added with other cross-vendor extensionsEdit

Template:Sticky header

Template:NotelistTemplate:Vpad

Added with other Intel-specific extensionsEdit

Template:Sticky header

Template:NotelistTemplate:Vpad

Added with other AMD-specific extensionsEdit

Template:Sticky header

Template:NotelistTemplate:Vpad

x87 floating-point instructionsEdit

The x87 coprocessor, if present, provides support for floating-point arithmetic. The coprocessor provides eight data registers, each holding one 80-bit floating-point value (1 sign bit, 15 exponent bits, 64 mantissa bits) – these registers are organized as a stack, with the top-of-stack register referred to as "st" or "st(0)", and the other registers referred to as st(1), st(2), ...st(7). It additionally provides a number of control and status registers, including "PC" (precision control, to control whether floating-point operations should be rounded to 24, 53 or 64 mantissa bits) and "RC" (rounding control, to pick rounding-mode: round-to-zero, round-to-positive-infinity, round-to-negative-infinity, round-to-nearest-even) and a 4-bit condition code register "CC", whose four bits are individually referred to as C0, C1, C2 and C3). Not all of the arithmetic instructions provided by x87 obey PC and RC.

Original 8087 instructionsEdit

Template:Sticky header

Template:Notelist

x87 instructions added in later processorsEdit

Template:Sticky header

Template:Notelist

SIMD instructionsEdit

{{#invoke:Labelled list hatnote|labelledList|Main article|Main articles|Main page|Main pages}}

Cryptographic instructionsEdit

{{#invoke:Labelled list hatnote|labelledList|Main article|Main articles|Main page|Main pages}}

Virtualization instructionsEdit

{{#invoke:Labelled list hatnote|labelledList|Main article|Main articles|Main page|Main pages}}

Other instructionsEdit

Template:See also

x86 also includes discontinued instruction sets which are no longer supported by Intel and AMD, and undocumented instructions which execute but are not officially documented.

Undocumented x86 instructionsEdit

The x86 CPUs contain undocumented instructions which are implemented on the chips but not listed in some official documents. They can be found in various sources across the Internet, such as Ralf Brown's Interrupt List and at sandpile.org

Some of these instructions are widely available across many/most x86 CPUs, while others are specific to a narrow range of CPUs.

Undocumented instructions that are widely available across many x86 CPUs includeEdit

Template:Sticky header

Undocumented instructions that appear only in a limited subset of x86 CPUs includeEdit

Template:Sticky header

Undocumented x87 instructionsEdit

Mnemonics Opcodes Description Status
FENI,

FENI8087_NOP

DB E0 FPU Enable Interrupts (8087) Documented for the Intel 80287.<ref name="i80287" />

Present on all Intel x87 FPUs from 80287 onwards. For FPUs other than the ones where they were introduced on (8087 for FENI/FDISI and 80287 for FSETPM), they act as NOPs.

These instructions and their operation on modern CPUs are commonly mentioned in later Intel documentation, but with opcodes omitted and opcode table entries left blank (e.g. Intel SDM 325462-077, April 2022 mentions them twice without opcodes).

The opcodes are, however, recognized by Intel XED.<ref>ISA datafile for Intel XED (April 17, 2022), lines 916-944</ref>

FDISI,

FDISI8087_NOP

DB E1 FPU Disable Interrupts (8087)
FSETPM,

FSETPM287_NOP

DB E4 FPU Set Protected Mode (80287)
(no mnemonic) Template:Nowrap
Template:Nowrap
Template:Nowrap
Template:Nowrap
Template:Nowrap
"Reserved by Cyrix" opcodes These opcodes are listed as reserved opcodes that will produce "unpredictable results" without generating exceptions on at least Cyrix 6x86,<ref>Cyrix 6x86 processor data book, page 6-34</ref> 6x86MX, MII, MediaGX, and AMD Geode GX/LX.<ref>AMD Geode LX Processors Data Book, publication 33234H, p.670</ref> (The documentation for these CPUs all list the same ten opcodes.)

Their actual operation is not known, nor is it known whether their operation is the same on all of these CPUs.

See alsoEdit

ReferencesEdit

Template:Reflist

  • {{#invoke:citation/CS1|citation

|CitationClass=web }}

External linksEdit

Template:Sister project

Template:X86 assembly topics