x86-64 Complete Documentation

Instructions

Integer data move instructions

mov Move

MOV copies the contents of its source (second) operand into its destination (first) operand.

In all forms of the MOV instruction, the two operands are the same size, except for moving between a segment register and an r/m32 operand. These instructions are treated exactly like the corresponding 16-bit equivalent (so that, for example, \c{MOV DS,EAX} functions identically to MOV DS,AX but saves a prefix when in 32-bit mode), except that when a segment register is moved into a 32-bit destination, the top two bytes of the result are undefined.

MOV may not use CS as a destination.

CR4 is only a supported register on the Pentium and above.

Test registers are supported on 386/486 processors and on some non-Intel Pentium class processors.

mov al, moffs | mov ax, moffs | mov eax, moffs | mov rax, moffs | mov moffs, al | mov moffs, ax

Moves a full 64 bit immediate into a register. mov takes immediates up to 32 bits and sign extends them, which silently turns a large address into the wrong number, so NASM accepts movabs as the spelling that means "the whole 64 bits are here". It assembles to a 10 byte instruction, against 5 to 7 for the mov forms.

movabs al, moffs | movabs ax, moffs | movabs eax, moffs | movabs rax, moffs | movabs moffs, al | movabs moffs, ax
movrs reg8, mem8 | movrs reg16, mem16 | movrs reg32, mem32 | movrs reg64, mem64

Load effective address

lea Load Effective Address

LEA, despite its syntax, does not access memory. It calculates the effective address specified by its second operand as if it were going to load or store data from it, but instead it stores the calculated address into the register specified by its first operand. This can be used to perform quite complex calculations (e.g. \c{LEA EAX,[EBX+ECX*4+100]}) in one instruction.

LEA, despite being a purely arithmetic instruction which accesses no memory, still requires square brackets around its second operand, as if it were a memory reference.

The size of the calculation is the current address size, and the size that the result is stored as is the current operand size. If the address and operand size are not the same, then if the addressing mode was 32-bits, the low 16-bits are stored, and if the address was 16-bits, it is zero-extended to 32-bits before storing.

lea reg16, mem | lea reg32, mem | lea reg64, mem | lea reg16, imm16 | lea reg32, imm32 | lea reg64, imm32

The basic 8 arithmetic operations

adc Add with Carry

ADC performs integer addition: it adds its two operands together, plus the value of the carry flag, and leaves the result in its destination (first) operand. The destination operand can be a register or a memory location. The source operand can be a register, a memory location or an immediate value.

The flags are set according to the result of the operation: in particular, the carry flag is affected and can be used by a subsequent ADC instruction.

In the forms with an 8-bit immediate second operand and a longer first operand, the second operand is considered to be signed, and is sign-extended to the length of the first operand. In these cases, the BYTE qualifier is necessary to force NASM to generate this form of the instruction.

To add two numbers without also adding the contents of the carry flag, use ADD (ADD).

adc r/m8, reg8 | adc r/m16, reg16 | adc r/m32, reg32 | adc r/m64, reg64 | adc reg8, r/m8 | adc reg16, r/m16

add Add

ADD performs integer addition: it adds its two operands together, and leaves the result in its destination (first) operand. The destination operand can be a register or a memory location. The source operand can be a register, a memory location or an immediate value.

The flags are set according to the result of the operation: in particular, the carry flag is affected and can be used by a subsequent ADC instruction.

In the forms with an 8-bit immediate second operand and a longer first operand, the second operand is considered to be signed, and is sign-extended to the length of the first operand. In these cases, the BYTE qualifier is necessary to force NASM to generate this form of the instruction.

add r/m8, reg8 | add r/m16, reg16 | add r/m32, reg32 | add r/m64, reg64 | add reg8, r/m8 | add reg16, r/m16

and Logical AND

AND performs a bitwise AND operation between its two operands (i.e. each bit of the result is 1 if and only if the corresponding bits of the two inputs were both 1), and stores the result in the destination (first) operand. The destination operand can be a register or a memory location. The source operand can be a register, a memory location or an immediate value.

In the forms with an 8-bit immediate second operand and a longer first operand, the second operand is considered to be signed, and is sign-extended to the length of the first operand. In these cases, the BYTE qualifier is necessary to force NASM to generate this form of the instruction.

The MMX instruction PAND (see PAND) performs the same operation on the 64-bit MMX registers.

and r/m8, reg8 | and r/m16, reg16 | and r/m32, reg32 | and r/m64, reg64 | and reg8, r/m8 | and reg16, r/m16

cmp Compare Two Operands

CMP performs a 'mental' subtraction of its second operand from its first operand, and affects the flags as if the subtraction had taken place, but does not store the result of the subtraction anywhere.

In the forms with an 8-bit immediate second operand and a longer first operand, the second operand is considered to be signed, and is sign-extended to the length of the first operand. In these cases, the BYTE qualifier is necessary to force NASM to generate this form of the instruction.

The destination operand can be a register or a memory location. The source can be a register, memory location or an immediate value of the same size as the destination.

cmp r/m8, reg8 | cmp r/m16, reg16 | cmp r/m32, reg32 | cmp r/m64, reg64 | cmp reg8, r/m8 | cmp reg16, r/m16

or Logical Inclusive OR

OR performs a bitwise OR operation between its two operands (i.e. each bit of the result is 1 if and only if at least one of the corresponding bits of the two inputs was 1), and stores the result in the destination (first) operand.

In the forms with an 8-bit immediate second operand and a longer first operand, the second operand is considered to be signed, and is sign-extended to the length of the first operand. In these cases, the BYTE qualifier is necessary to force NASM to generate this form of the instruction.

The MMX instruction POR (see POR) performs the same operation on the 64-bit MMX registers.

or r/m8, reg8 | or r/m16, reg16 | or r/m32, reg32 | or r/m64, reg64 | or reg8, r/m8 | or reg16, r/m16

sbb Subtract with Borrow

SBB performs integer subtraction: it subtracts its second operand, plus the value of the carry flag, from its first, and leaves the result in its destination (first) operand. The flags are set according to the result of the operation: in particular, the carry flag is affected and can be used by a subsequent SBB instruction.

In the forms with an 8-bit immediate second operand and a longer first operand, the second operand is considered to be signed, and is sign-extended to the length of the first operand. In these cases, the BYTE qualifier is necessary to force NASM to generate this form of the instruction.

To subtract one number from another without also subtracting the contents of the carry flag, use SUB (SUB).

sbb r/m8, reg8 | sbb r/m16, reg16 | sbb r/m32, reg32 | sbb r/m64, reg64 | sbb reg8, r/m8 | sbb reg16, r/m16

sub Subtract

SUB performs integer subtraction: it subtracts its second operand from its first, and leaves the result in its destination (first) operand. The flags are set according to the result of the operation: in particular, the carry flag is affected and can be used by a subsequent SBB instruction (SBB).

In the forms with an 8-bit immediate second operand and a longer first operand, the second operand is considered to be signed, and is sign-extended to the length of the first operand. In these cases, the BYTE qualifier is necessary to force NASM to generate this form of the instruction.

sub r/m8, reg8 | sub r/m16, reg16 | sub r/m32, reg32 | sub r/m64, reg64 | sub reg8, r/m8 | sub reg16, r/m16

xor Logical Exclusive OR

XOR performs a bitwise XOR operation between its two operands (i.e. each bit of the result is 1 if and only if exactly one of the corresponding bits of the two inputs was 1), and stores the result in the destination (first) operand.

In the forms with an 8-bit immediate second operand and a longer first operand, the second operand is considered to be signed, and is sign-extended to the length of the first operand. In these cases, the BYTE qualifier is necessary to force NASM to generate this form of the instruction.

The MMX instruction PXOR (see PXOR) performs the same operation on the 64-bit MMX registers.

xor r/m8, reg8 | xor r/m16, reg16 | xor r/m32, reg32 | xor r/m64, reg64 | xor reg8, r/m8 | xor reg16, r/m16

Bitwise testing

test Logical Compare

TEST performs a 'mental' bitwise AND of its two operands, and affects the flags as if the operation had taken place, but does not store the result of the operation anywhere.

test r/m8, reg8 | test r/m16, reg16 | test r/m32, reg32 | test r/m64, reg64 | test al, imm8 | test ax, imm16

The basic shift and rotate operations

rcl Rotate Left through Carry Flag

RCL and RCR perform a 9-bit, 17-bit or 33-bit bitwise rotation operation, involving the given source/destination (first) operand and the carry bit. Thus, for example, in the operation RCL AL,1, a 9-bit rotation is performed in which AL is shifted left by 1, the top bit of AL moves into the carry flag, and the original value of the carry flag is placed in the low bit of AL.

The number of bits to rotate by is given by the second operand. Only the bottom five bits of the rotation count are considered by processors above the 8086.

You can force the longer (286 and upwards, beginning with a C1 byte) form of RCL foo,1 by using a BYTE prefix: \c{RCL foo,BYTE 1}. Similarly with RCR.

rcl r/m8, 1 | rcl r/m16, 1 | rcl r/m32, 1 | rcl r/m64, 1 | rcl r/m8, cl | rcl r/m16, cl

rcr Rotate Right through Carry Flag

RCL and RCR perform a 9-bit, 17-bit or 33-bit bitwise rotation operation, involving the given source/destination (first) operand and the carry bit. Thus, for example, in the operation RCL AL,1, a 9-bit rotation is performed in which AL is shifted left by 1, the top bit of AL moves into the carry flag, and the original value of the carry flag is placed in the low bit of AL.

The number of bits to rotate by is given by the second operand. Only the bottom five bits of the rotation count are considered by processors above the 8086.

You can force the longer (286 and upwards, beginning with a C1 byte) form of RCL foo,1 by using a BYTE prefix: \c{RCL foo,BYTE 1}. Similarly with RCR.

rcr r/m8, 1 | rcr r/m16, 1 | rcr r/m32, 1 | rcr r/m64, 1 | rcr r/m8, cl | rcr r/m16, cl

rol Rotate Left

ROL and ROR perform a bitwise rotation operation on the given source/destination (first) operand. Thus, for example, in the operation ROL AL,1, an 8-bit rotation is performed in which AL is shifted left by 1 and the original top bit of AL moves round into the low bit.

The number of bits to rotate by is given by the second operand. Only the bottom five bits of the rotation count are considered by processors above the 8086.

You can force the longer (286 and upwards, beginning with a C1 byte) form of ROL foo,1 by using a BYTE prefix: \c{ROL foo,BYTE 1}. Similarly with ROR.

rol r/m8, 1 | rol r/m16, 1 | rol r/m32, 1 | rol r/m64, 1 | rol r/m8, cl | rol r/m16, cl

ror Rotate Right

ROL and ROR perform a bitwise rotation operation on the given source/destination (first) operand. Thus, for example, in the operation ROL AL,1, an 8-bit rotation is performed in which AL is shifted left by 1 and the original top bit of AL moves round into the low bit.

The number of bits to rotate by is given by the second operand. Only the bottom five bits of the rotation count are considered by processors above the 8086.

You can force the longer (286 and upwards, beginning with a C1 byte) form of ROL foo,1 by using a BYTE prefix: \c{ROL foo,BYTE 1}. Similarly with ROR.

ror r/m8, 1 | ror r/m16, 1 | ror r/m32, 1 | ror r/m64, 1 | ror r/m8, cl | ror r/m16, cl

sal Arithmetic Shift Left

SAL and SAR perform an arithmetic shift operation on the given source/destination (first) operand. The vacated bits are filled with zero for SAL, and with copies of the original high bit of the source operand for SAR.

SAL is a synonym for SHL (see SHL). NASM will assemble either one to the same code, but NDISASM will always disassemble that code as SHL.

The number of bits to shift by is given by the second operand. Only the bottom five bits of the shift count are considered by processors above the 8086.

You can force the longer (286 and upwards, beginning with a C1 byte) form of SAL foo,1 by using a BYTE prefix: \c{SAL foo,BYTE 1}. Similarly with SAR.

sal r/m8, 1 | sal r/m16, 1 | sal r/m32, 1 | sal r/m64, 1 | sal r/m8, cl | sal r/m16, cl

sar Arithmetic Shift Right

SAL and SAR perform an arithmetic shift operation on the given source/destination (first) operand. The vacated bits are filled with zero for SAL, and with copies of the original high bit of the source operand for SAR.

SAL is a synonym for SHL (see SHL). NASM will assemble either one to the same code, but NDISASM will always disassemble that code as SHL.

The number of bits to shift by is given by the second operand. Only the bottom five bits of the shift count are considered by processors above the 8086.

You can force the longer (286 and upwards, beginning with a C1 byte) form of SAL foo,1 by using a BYTE prefix: \c{SAL foo,BYTE 1}. Similarly with SAR.

sar r/m8, 1 | sar r/m16, 1 | sar r/m32, 1 | sar r/m64, 1 | sar r/m8, cl | sar r/m16, cl

shl Logical Shift Left

SHL and SHR perform a logical shift operation on the given source/destination (first) operand. The vacated bits are filled with zero.

A synonym for SHL is SAL (see SAL). NASM will assemble either one to the same code, but NDISASM will always disassemble that code as SHL.

The number of bits to shift by is given by the second operand. Only the bottom five bits of the shift count are considered by processors above the 8086.

You can force the longer (286 and upwards, beginning with a C1 byte) form of SHL foo,1 by using a BYTE prefix: \c{SHL foo,BYTE 1}. Similarly with SHR.

shl r/m8, 1 | shl r/m16, 1 | shl r/m32, 1 | shl r/m64, 1 | shl r/m8, cl | shl r/m16, cl

shr Logical Shift Right

SHL and SHR perform a logical shift operation on the given source/destination (first) operand. The vacated bits are filled with zero.

A synonym for SHL is SAL (see SAL). NASM will assemble either one to the same code, but NDISASM will always disassemble that code as SHL.

The number of bits to shift by is given by the second operand. Only the bottom five bits of the shift count are considered by processors above the 8086.

You can force the longer (286 and upwards, beginning with a C1 byte) form of SHL foo,1 by using a BYTE prefix: \c{SHL foo,BYTE 1}. Similarly with SHR.

shr r/m8, 1 | shr r/m16, 1 | shr r/m32, 1 | shr r/m64, 1 | shr r/m8, cl | shr r/m16, cl

Other basic integer arithmetic

dec Decrement by 1

DEC subtracts 1 from its operand. It does not affect the carry flag: to affect the carry flag, use SUB something,1 (see SUB). DEC affects all the other flags according to the result.

This instruction can be used with a LOCK prefix to allow atomic execution.

See also INC (INC).

dec reg16 | dec reg32 | dec r/m8 | dec r/m16 | dec r/m32 | dec r/m64

div Unsigned Divide

DIV performs unsigned integer division. The explicit operand provided is the divisor; the dividend and destination operands are implicit, in the following way:

  • For DIV r/m8, AX is divided by the given operand; the quotient is stored in AL and the remainder in AH.

  • For DIV r/m16, DX:AX is divided by the given operand; the quotient is stored in AX and the remainder in DX.

  • For DIV r/m32, EDX:EAX is divided by the given operand; the quotient is stored in EAX and the remainder in EDX.

Signed integer division is performed by the IDIV instruction: see IDIV.

div r/m8 | div r/m16 | div r/m32 | div r/m64

idiv Signed Divide

IDIV performs signed integer division. The explicit operand provided is the divisor; the dividend and destination operands are implicit, in the following way:

  • For IDIV r/m8, AX is divided by the given operand; the quotient is stored in AL and the remainder in AH.

  • For IDIV r/m16, DX:AX is divided by the given operand; the quotient is stored in AX and the remainder in DX.

  • For IDIV r/m32, EDX:EAX is divided by the given operand; the quotient is stored in EAX and the remainder in EDX.

Unsigned integer division is performed by the DIV instruction: see DIV.

idiv r/m8 | idiv r/m16 | idiv r/m32 | idiv r/m64

imul Signed Multiply

IMUL performs signed integer multiplication. For the single-operand form, the other operand and destination are implicit, in the following way:

  • For IMUL r/m8, AL is multiplied by the given operand; the product is stored in AX.

  • For IMUL r/m16, AX is multiplied by the given operand; the product is stored in DX:AX.

  • For IMUL r/m32, EAX is multiplied by the given operand; the product is stored in EDX:EAX.

The two-operand form multiplies its two operands and stores the result in the destination (first) operand. The three-operand form multiplies its last two operands and stores the result in the first operand.

The two-operand form with an immediate second operand is in fact a shorthand for the three-operand form, as can be seen by examining the opcode descriptions: in the two-operand form, the code /r takes both its register and r/m parts from the same operand (the first one).

In the forms with an 8-bit immediate operand and another longer source operand, the immediate operand is considered to be signed, and is sign-extended to the length of the other source operand. In these cases, the BYTE qualifier is necessary to force NASM to generate this form of the instruction.

Unsigned integer multiplication is performed by the MUL instruction: see MUL.

imul r/m8 | imul r/m16 | imul r/m32 | imul r/m64 | imul reg16, r/m16 | imul reg32, r/m32

inc Increment by 1

INC adds 1 to its operand. It does not affect the carry flag: to affect the carry flag, use ADD something,1 (see ADD). INC affects all the other flags according to the result.

This instruction can be used with a LOCK prefix to allow atomic execution.

See also DEC (DEC).

inc reg16 | inc reg32 | inc r/m8 | inc r/m16 | inc r/m32 | inc r/m64

mul Unsigned Multiply

MUL performs unsigned integer multiplication. The other operand to the multiplication, and the destination operand, are implicit, in the following way:

  • For MUL r/m8, AL is multiplied by the given operand; the product is stored in AX.

  • For MUL r/m16, AX is multiplied by the given operand; the product is stored in DX:AX.

  • For MUL r/m32, EAX is multiplied by the given operand; the product is stored in EDX:EAX.

Signed integer multiplication is performed by the IMUL instruction: see IMUL.

mul r/m8 | mul r/m16 | mul r/m32 | mul r/m64 | mul reg32, reg32, r/m32 | mul reg64, reg64, r/m64

neg Two's Complement Negation

NEG replaces the contents of its operand by the two's complement negation (invert all the bits and then add one) of the original value. NOT, similarly, performs one's complement (inverts all the bits).

neg r/m8 | neg r/m16 | neg r/m32 | neg r/m64 | neg [reg8], r/m8 | neg [reg16], r/m16

not One's Complement Negation

NEG replaces the contents of its operand by the two's complement negation (invert all the bits and then add one) of the original value. NOT, similarly, performs one's complement (inverts all the bits).

not r/m8 | not r/m16 | not r/m32 | not r/m64 | not [reg8], r/m8 | not [reg16], r/m16

Double width shift

shld Integer Double Precision Shift Left

  • SHLD performs a double-precision left shift. It notionally places its second operand to the right of its first, then shifts the entire bit string thus generated to the left by a number of bits specified in the third operand. It then updates only the first operand according to the result of this. The second operand is not modified.

  • SHRD performs the corresponding right shift: it notionally places the second operand to the left of the first, shifts the whole bit string right, and updates only the first operand.

For example, if EAX holds 0x01234567 and EBX holds 0x89ABCDEF, then the instruction SHLD EAX,EBX,4 would update EAX to hold 0x12345678. Under the same conditions, \c{SHRD EAX,EBX,4} would update EAX to hold 0xF0123456.

The number of bits to shift by is given by the third operand. Only the bottom five bits of the shift count are considered.

shld r/m16, reg16, imm8 | shld r/m32, reg32, imm8 | shld r/m64, reg64, imm8 | shld r/m16, reg16, cl | shld r/m32, reg32, cl | shld r/m64, reg64, cl

shrd Integer Double Precision Shift Right

  • SHLD performs a double-precision left shift. It notionally places its second operand to the right of its first, then shifts the entire bit string thus generated to the left by a number of bits specified in the third operand. It then updates only the first operand according to the result of this. The second operand is not modified.

  • SHRD performs the corresponding right shift: it notionally places the second operand to the left of the first, shifts the whole bit string right, and updates only the first operand.

For example, if EAX holds 0x01234567 and EBX holds 0x89ABCDEF, then the instruction SHLD EAX,EBX,4 would update EAX to hold 0x12345678. Under the same conditions, \c{SHRD EAX,EBX,4} would update EAX to hold 0xF0123456.

The number of bits to shift by is given by the third operand. Only the bottom five bits of the shift count are considered.

shrd r/m16, reg16, imm8 | shrd r/m32, reg32, imm8 | shrd r/m64, reg64, imm8 | shrd r/m16, reg16, cl | shrd r/m32, reg32, cl | shrd r/m64, reg64, cl

Sign and zero extension

cbw Convert Byte to Word

All these instructions sign-extend a short value into a longer one, by replicating the top bit of the original value to fill the extended one.

CBW extends AL into AX by repeating the top bit of AL in every bit of AH. CWDE extends AX into EAX. CWD extends AX into DX:AX by repeating the top bit of AX throughout DX, and CDQ extends EAX into EDX:EAX.

cbw

cdq Convert Doubleword to Quadword

All these instructions sign-extend a short value into a longer one, by replicating the top bit of the original value to fill the extended one.

CBW extends AL into AX by repeating the top bit of AL in every bit of AH. CWDE extends AX into EAX. CWD extends AX into DX:AX by repeating the top bit of AX throughout DX, and CDQ extends EAX into EDX:EAX.

cdq

cdqe Convert Doubleword to Quadword

Sign extends eax into rax, so that a 32 bit signed value read from memory or returned by a syscall can be used in 64 bit arithmetic. It takes no operands and touches no other register. movsxd rax, eax does the same thing in two more bytes.

cdqe

cqo Convert Quadword to Octaword

Sign extends rax into rdx:rax, filling rdx with copies of the sign bit. idiv divides that 128 bit pair, so signed division is written as cqo then idiv; forgetting the cqo leaves whatever rdx happened to hold in the high half and the result is nonsense rather than an error.

cqo

cwd Convert Word to Doubleword

All these instructions sign-extend a short value into a longer one, by replicating the top bit of the original value to fill the extended one.

CBW extends AL into AX by repeating the top bit of AL in every bit of AH. CWDE extends AX into EAX. CWD extends AX into DX:AX by repeating the top bit of AX throughout DX, and CDQ extends EAX into EDX:EAX.

cwd

cwde Convert Word to Doubleword

All these instructions sign-extend a short value into a longer one, by replicating the top bit of the original value to fill the extended one.

CBW extends AL into AX by repeating the top bit of AL in every bit of AH. CWDE extends AX into EAX. CWD extends AX into DX:AX by repeating the top bit of AX throughout DX, and CDQ extends EAX into EDX:EAX.

cwde

movsx Move with Sign-Extension

MOVSX sign-extends its source (second) operand to the length of its destination (first) operand, and copies the result into the destination operand. MOVZX does the same, but zero-extends rather than sign-extending.

movsx ax, al | movsx eax, ax | movsx rax, eax | movsx reg16, r/m8 | movsx reg32, r/m8 | movsx reg64, r/m8

MOVSX sign-extends its source (second) operand to the length of its destination (first) operand, and copies the result into the destination operand. MOVZX does the same, but zero-extends rather than sign-extending.

movsxb ax, al | movsxb reg16, r/m8 | movsxb reg32, r/m8 | movsxb reg64, r/m8

movsxd Move Doubleword to Quadword with Sign-Extension

Copies a 32 bit source into a 64 bit register, sign extending it. This is the instruction to reach for when a signed 32 bit value has to become a 64 bit one, because the ordinary mov eax, ... zero extends instead: writing any 32 bit register clears the top half of its 64 bit name.

movsxd rax, eax | movsxd reg16, r/m32 | movsxd reg32, r/m32 | movsxd reg64, r/m32

MOVSX sign-extends its source (second) operand to the length of its destination (first) operand, and copies the result into the destination operand. MOVZX does the same, but zero-extends rather than sign-extending.

movsxw eax, ax | movsxw reg16, r/m16 | movsxw reg32, r/m16 | movsxw reg64, r/m16

movzx Move with Zero-Extend

MOVSX sign-extends its source (second) operand to the length of its destination (first) operand, and copies the result into the destination operand. MOVZX does the same, but zero-extends rather than sign-extending.

movzx reg16, r/m8 | movzx reg32, r/m8 | movzx reg64, r/m8 | movzx reg16, r/m16 | movzx reg32, r/m16 | movzx reg64, r/m16

MOVSX sign-extends its source (second) operand to the length of its destination (first) operand, and copies the result into the destination operand. MOVZX does the same, but zero-extends rather than sign-extending.

movzxb reg16, r/m8 | movzxb reg32, r/m8 | movzxb reg64, r/m8

MOVSX sign-extends its source (second) operand to the length of its destination (first) operand, and copies the result into the destination operand. MOVZX does the same, but zero-extends rather than sign-extending.

movzxd reg16, r/m32 | movzxd reg32, r/m32 | movzxd reg64, r/m32

MOVSX sign-extends its source (second) operand to the length of its destination (first) operand, and copies the result into the destination operand. MOVZX does the same, but zero-extends rather than sign-extending.

movzxw reg16, r/m16 | movzxw reg32, r/m16 | movzxw reg64, r/m16

Bit operations

bsf Bit Scan Forward

  • BSF searches for the least significant set bit in its source (second) operand, and if it finds one, stores the index in its destination (first) operand. If no set bit is found, the contents of the destination operand are undefined. If the source operand is zero, the zero flag is set.

  • BSR performs the same function, but searches from the top instead, so it finds the most significant set bit.

Bit indices are from 0 (least significant) to 15 or 31 (most significant). The destination operand can only be a register. The source operand can be a register or a memory location.

bsf reg16, r/m16 | bsf reg32, r/m32 | bsf reg64, r/m64

bsr Bit Scan Reverse

  • BSF searches for the least significant set bit in its source (second) operand, and if it finds one, stores the index in its destination (first) operand. If no set bit is found, the contents of the destination operand are undefined. If the source operand is zero, the zero flag is set.

  • BSR performs the same function, but searches from the top instead, so it finds the most significant set bit.

Bit indices are from 0 (least significant) to 15 or 31 (most significant). The destination operand can only be a register. The source operand can be a register or a memory location.

bsr reg16, r/m16 | bsr reg32, r/m32 | bsr reg64, r/m64

bt Bit Test

These instructions all test one bit of their first operand, whose index is given by the second operand, and store the value of that bit into the carry flag. Bit indices are from 0 (least significant) to 15 or 31 (most significant).

In addition to storing the original value of the bit into the carry flag, BTR also resets (clears) the bit in the operand itself. BTS sets the bit, and BTC complements the bit. BT does not modify its operands.

The destination can be a register or a memory location. The source can be a register or an immediate value.

If the destination operand is a register, the bit offset should be in the range 0-15 (for 16-bit operands) or 0-31 (for 32-bit operands). An immediate value outside these ranges will be taken modulo 16/32 by the processor.

If the destination operand is a memory location, then an immediate bit offset follows the same rules as for a register. If the bit offset is in a register, then it can be anything within the signed range of the register used (ie, for a 32-bit operand, it can be (-2^31) to (2^31 - 1)

bt r/m16, reg16 | bt r/m32, reg32 | bt r/m64, reg64 | bt r/m16, imm8 | bt r/m32, imm8 | bt r/m64, imm8

btc Bit Test and Complement

These instructions all test one bit of their first operand, whose index is given by the second operand, and store the value of that bit into the carry flag. Bit indices are from 0 (least significant) to 15 or 31 (most significant).

In addition to storing the original value of the bit into the carry flag, BTR also resets (clears) the bit in the operand itself. BTS sets the bit, and BTC complements the bit. BT does not modify its operands.

The destination can be a register or a memory location. The source can be a register or an immediate value.

If the destination operand is a register, the bit offset should be in the range 0-15 (for 16-bit operands) or 0-31 (for 32-bit operands). An immediate value outside these ranges will be taken modulo 16/32 by the processor.

If the destination operand is a memory location, then an immediate bit offset follows the same rules as for a register. If the bit offset is in a register, then it can be anything within the signed range of the register used (ie, for a 32-bit operand, it can be (-2^31) to (2^31 - 1)

btc r/m16, reg16 | btc r/m32, reg32 | btc r/m64, reg64 | btc r/m16, imm8 | btc r/m32, imm8 | btc r/m64, imm8

btr Bit Test and Reset

These instructions all test one bit of their first operand, whose index is given by the second operand, and store the value of that bit into the carry flag. Bit indices are from 0 (least significant) to 15 or 31 (most significant).

In addition to storing the original value of the bit into the carry flag, BTR also resets (clears) the bit in the operand itself. BTS sets the bit, and BTC complements the bit. BT does not modify its operands.

The destination can be a register or a memory location. The source can be a register or an immediate value.

If the destination operand is a register, the bit offset should be in the range 0-15 (for 16-bit operands) or 0-31 (for 32-bit operands). An immediate value outside these ranges will be taken modulo 16/32 by the processor.

If the destination operand is a memory location, then an immediate bit offset follows the same rules as for a register. If the bit offset is in a register, then it can be anything within the signed range of the register used (ie, for a 32-bit operand, it can be (-2^31) to (2^31 - 1)

btr r/m16, reg16 | btr r/m32, reg32 | btr r/m64, reg64 | btr r/m16, imm8 | btr r/m32, imm8 | btr r/m64, imm8

bts Bit Test and Set

These instructions all test one bit of their first operand, whose index is given by the second operand, and store the value of that bit into the carry flag. Bit indices are from 0 (least significant) to 15 or 31 (most significant).

In addition to storing the original value of the bit into the carry flag, BTR also resets (clears) the bit in the operand itself. BTS sets the bit, and BTC complements the bit. BT does not modify its operands.

The destination can be a register or a memory location. The source can be a register or an immediate value.

If the destination operand is a register, the bit offset should be in the range 0-15 (for 16-bit operands) or 0-31 (for 32-bit operands). An immediate value outside these ranges will be taken modulo 16/32 by the processor.

If the destination operand is a memory location, then an immediate bit offset follows the same rules as for a register. If the bit offset is in a register, then it can be anything within the signed range of the register used (ie, for a 32-bit operand, it can be (-2^31) to (2^31 - 1)

bts r/m16, reg16 | bts r/m32, reg32 | bts r/m64, reg64 | bts r/m16, imm8 | bts r/m32, imm8 | bts r/m64, imm8

The implied operation of this instruction is:

IBTS r/m16,AX,CL,reg16
IBTS r/m32,EAX,CL,reg32

Writes a bit string from the source operand to the destination. CL indicates the number of bits to be copied, from the low bits of the source. (E)AX indicates the low order bit offset in the destination that is written to. For example, if CL is set to 4 and AX (for 16-bit code) is set to 5, bits 0-3 of src will be copied to bits 5-8 of dst. This instruction is very poorly documented, and I have been unable to find any official source of documentation on it.

IBTS is supported only on the early Intel 386s, and conflicts with the opcodes for CMPXCHG486 (on early Intel 486s). NASM supports it only for completeness. Its counterpart is XBTS (see XBTS).

ibts r/m16, reg16 | ibts r/m32, reg32

The implied operation of this instruction is:

XBTS r/m16,reg16,AX,CL
XBTS r/m32,reg32,EAX,CL

Writes a bit string from the source operand to the destination. CL indicates the number of bits to be copied, and (E)AX indicates the low order bit offset in the source. The bits are written to the low order bits of the destination register. For example, if CL is set to 4 and AX (for 16-bit code) is set to 5, bits 5-8 of src will be copied to bits 0-3 of dst. This instruction is very poorly documented, and I have been unable to find any official source of documentation on it.

XBTS is supported only on the early Intel 386s, and conflicts with the opcodes for CMPXCHG486 (on early Intel 486s). NASM supports it only for completeness. Its counterpart is IBTS (see IBTS).

xbts r/m16, reg16 | xbts r/m32, reg32

Endianness handling

bswap Byte Swap

BSWAP swaps the order of the four bytes of a 32-bit register: bits 0-7 exchange places with bits 24-31, and bits 8-15 swap with bits 16-23. There is no explicit 16-bit equivalent: to byte-swap AX, BX, CX or DX, XCHG can be used. When BSWAP is used with a 16-bit register, the result is undefined.

bswap reg32 | bswap reg64 | bswap ax | bswap cx | bswap dx | bswap bx

movbe Move Data After Swapping Bytes

Move Data After Swapping Bytes

movbe reg16, mem16 | movbe reg32, mem32 | movbe reg64, mem64 | movbe mem16, reg16 | movbe mem32, reg32 | movbe mem64, reg64

Decimal arithmetic

These instructions are used in conjunction with the add, subtract, multiply and divide instructions to perform binary-coded decimal arithmetic in unpacked (one BCD digit per byte - easy to translate to and from ASCII, hence the instruction names) form. There are also packed BCD instructions DAA and DAS: see DAA.

  • AAA (ASCII Adjust After Addition) should be used after a one-byte ADD instruction whose destination was the AL register: by means of examining the value in the low nibble of AL and also the auxiliary carry flag AF, it determines whether the addition has overflowed, and adjusts it (and sets the carry flag) if so. You can add long BCD strings together by doing ADD/AAA on the low digits, then doing ADC/AAA on each subsequent digit.

  • AAS (ASCII Adjust AL After Subtraction) works similarly to AAA, but is for use after SUB instructions rather than ADD.

  • AAM (ASCII Adjust AX After Multiply) is for use after you have multiplied two decimal digits together and left the result in AL: it divides AL by ten and stores the quotient in AH, leaving the remainder in AL. The divisor 10 can be changed by specifying an operand to the instruction: a particularly handy use of this is AAM 16, causing the two nibbles in AL to be separated into AH and AL.

  • AAD (ASCII Adjust AX Before Division) performs the inverse operation to AAM: it multiplies AH by ten, adds it to AL, and sets AH to zero. Again, the multiplier 10 can be changed.

aaa

These instructions are used in conjunction with the add, subtract, multiply and divide instructions to perform binary-coded decimal arithmetic in unpacked (one BCD digit per byte - easy to translate to and from ASCII, hence the instruction names) form. There are also packed BCD instructions DAA and DAS: see DAA.

  • AAA (ASCII Adjust After Addition) should be used after a one-byte ADD instruction whose destination was the AL register: by means of examining the value in the low nibble of AL and also the auxiliary carry flag AF, it determines whether the addition has overflowed, and adjusts it (and sets the carry flag) if so. You can add long BCD strings together by doing ADD/AAA on the low digits, then doing ADC/AAA on each subsequent digit.

  • AAS (ASCII Adjust AL After Subtraction) works similarly to AAA, but is for use after SUB instructions rather than ADD.

  • AAM (ASCII Adjust AX After Multiply) is for use after you have multiplied two decimal digits together and left the result in AL: it divides AL by ten and stores the quotient in AH, leaving the remainder in AL. The divisor 10 can be changed by specifying an operand to the instruction: a particularly handy use of this is AAM 16, causing the two nibbles in AL to be separated into AH and AL.

  • AAD (ASCII Adjust AX Before Division) performs the inverse operation to AAM: it multiplies AH by ten, adds it to AL, and sets AH to zero. Again, the multiplier 10 can be changed.

aad | aad imm8

These instructions are used in conjunction with the add, subtract, multiply and divide instructions to perform binary-coded decimal arithmetic in unpacked (one BCD digit per byte - easy to translate to and from ASCII, hence the instruction names) form. There are also packed BCD instructions DAA and DAS: see DAA.

  • AAA (ASCII Adjust After Addition) should be used after a one-byte ADD instruction whose destination was the AL register: by means of examining the value in the low nibble of AL and also the auxiliary carry flag AF, it determines whether the addition has overflowed, and adjusts it (and sets the carry flag) if so. You can add long BCD strings together by doing ADD/AAA on the low digits, then doing ADC/AAA on each subsequent digit.

  • AAS (ASCII Adjust AL After Subtraction) works similarly to AAA, but is for use after SUB instructions rather than ADD.

  • AAM (ASCII Adjust AX After Multiply) is for use after you have multiplied two decimal digits together and left the result in AL: it divides AL by ten and stores the quotient in AH, leaving the remainder in AL. The divisor 10 can be changed by specifying an operand to the instruction: a particularly handy use of this is AAM 16, causing the two nibbles in AL to be separated into AH and AL.

  • AAD (ASCII Adjust AX Before Division) performs the inverse operation to AAM: it multiplies AH by ten, adds it to AL, and sets AH to zero. Again, the multiplier 10 can be changed.

aam | aam imm8

These instructions are used in conjunction with the add, subtract, multiply and divide instructions to perform binary-coded decimal arithmetic in unpacked (one BCD digit per byte - easy to translate to and from ASCII, hence the instruction names) form. There are also packed BCD instructions DAA and DAS: see DAA.

  • AAA (ASCII Adjust After Addition) should be used after a one-byte ADD instruction whose destination was the AL register: by means of examining the value in the low nibble of AL and also the auxiliary carry flag AF, it determines whether the addition has overflowed, and adjusts it (and sets the carry flag) if so. You can add long BCD strings together by doing ADD/AAA on the low digits, then doing ADC/AAA on each subsequent digit.

  • AAS (ASCII Adjust AL After Subtraction) works similarly to AAA, but is for use after SUB instructions rather than ADD.

  • AAM (ASCII Adjust AX After Multiply) is for use after you have multiplied two decimal digits together and left the result in AL: it divides AL by ten and stores the quotient in AH, leaving the remainder in AL. The divisor 10 can be changed by specifying an operand to the instruction: a particularly handy use of this is AAM 16, causing the two nibbles in AL to be separated into AH and AL.

  • AAD (ASCII Adjust AX Before Division) performs the inverse operation to AAM: it multiplies AH by ten, adds it to AL, and sets AH to zero. Again, the multiplier 10 can be changed.

aas

These instructions are used in conjunction with the add and subtract instructions to perform binary-coded decimal arithmetic in packed (one BCD digit per nibble) form. For the unpacked equivalents, see AAA.

DAA should be used after a one-byte ADD instruction whose destination was the AL register: by means of examining the value in the AL and also the auxiliary carry flag AF, it determines whether either digit of the addition has overflowed, and adjusts it (and sets the carry and auxiliary-carry flags) if so. You can add long BCD strings together by doing ADD/DAA on the low two digits, then doing ADC/DAA on each subsequent pair of digits.

DAS works similarly to DAA, but is for use after SUB instructions rather than ADD.

daa

These instructions are used in conjunction with the add and subtract instructions to perform binary-coded decimal arithmetic in packed (one BCD digit per nibble) form. For the unpacked equivalents, see AAA.

DAA should be used after a one-byte ADD instruction whose destination was the AL register: by means of examining the value in the AL and also the auxiliary carry flag AF, it determines whether either digit of the addition has overflowed, and adjusts it (and sets the carry and auxiliary-carry flags) if so. You can add long BCD strings together by doing ADD/DAA on the low two digits, then doing ADC/DAA on each subsequent pair of digits.

DAS works similarly to DAA, but is for use after SUB instructions rather than ADD.

das

Atomic operations

cmpxchg Compare and Exchange

These two instructions perform exactly the same operation; however, apparently some (not all) 486 processors support it under a non-standard opcode, so NASM provides the undocumented CMPXCHG486 form to generate the non-standard opcode.

CMPXCHG compares its destination (first) operand to the value in AL, AX or EAX (depending on the operand size of the instruction). If they are equal, it copies its source (second) operand into the destination and sets the zero flag. Otherwise, it clears the zero flag and copies the destination register to AL, AX or EAX.

The destination can be either a register or a memory location. The source is a register.

CMPXCHG is intended to be used for atomic operations in multitasking or multiprocessor environments. To safely update a value in shared memory, for example, you might load the value into EAX, load the updated value into EBX, and then execute the instruction LOCK CMPXCHG [value],EBX. If value has not changed since being loaded, it is updated with your desired new value, and the zero flag is set to let you know it has worked. (The LOCK prefix prevents another processor doing anything in the middle of this operation: it guarantees atomicity.) However, if another processor has modified the value in between your load and your attempted store, the store does not happen, and you are notified of the failure by a cleared zero flag, so you can go round and try again.

cmpxchg r/m8, reg8 | cmpxchg r/m16, reg16 | cmpxchg r/m32, reg32 | cmpxchg r/m64, reg64

cmpxchg16b Compare and Exchange 16 Bytes

Compare and Exchange 16 Bytes

cmpxchg16b mem128

These two instructions perform exactly the same operation; however, apparently some (not all) 486 processors support it under a non-standard opcode, so NASM provides the undocumented CMPXCHG486 form to generate the non-standard opcode.

CMPXCHG compares its destination (first) operand to the value in AL, AX or EAX (depending on the operand size of the instruction). If they are equal, it copies its source (second) operand into the destination and sets the zero flag. Otherwise, it clears the zero flag and copies the destination register to AL, AX or EAX.

The destination can be either a register or a memory location. The source is a register.

CMPXCHG is intended to be used for atomic operations in multitasking or multiprocessor environments. To safely update a value in shared memory, for example, you might load the value into EAX, load the updated value into EBX, and then execute the instruction LOCK CMPXCHG [value],EBX. If value has not changed since being loaded, it is updated with your desired new value, and the zero flag is set to let you know it has worked. (The LOCK prefix prevents another processor doing anything in the middle of this operation: it guarantees atomicity.) However, if another processor has modified the value in between your load and your attempted store, the store does not happen, and you are notified of the failure by a cleared zero flag, so you can go round and try again.

cmpxchg486 r/m8, reg8 | cmpxchg486 r/m16, reg16 | cmpxchg486 r/m32, reg32

cmpxchg8b Compare and Exchange 8 Bytes

This is a larger and more unwieldy version of CMPXCHG: it compares the 64-bit (eight-byte) value stored at [mem] with the value in EDX:EAX. If they are equal, it sets the zero flag and stores ECX:EBX into the memory area. If they are unequal, it clears the zero flag and stores the memory contents into EDX:EAX.

CMPXCHG8B can be used with the LOCK prefix, to allow atomic execution. This is useful in multi-processor and multi-tasking environments.

cmpxchg8b mem64

xadd Exchange and Add

XADD exchanges the values in its two operands, and then adds them together and writes the result into the destination (first) operand. This instruction can be used with a LOCK prefix for multi-processor synchronisation purposes.

xadd r/m8, reg8 | xadd r/m16, reg16 | xadd r/m32, reg32 | xadd r/m64, reg64

xchg Exchange Register/Memory with Register

XCHG exchanges the values in its two operands. It can be used with a LOCK prefix for purposes of multi-processor synchronisation.

XCHG AX,AX or XCHG EAX,EAX (depending on the BITS setting) generates the opcode 90h, and so is a synonym for NOP (NOP).

xchg ax, reg16 | xchg rax, reg64 | xchg reg16, ax | xchg reg64, rax | xchg eax, reg32na | xchg reg32na, eax

Stack operations

BOUND expects its second operand to point to an area of memory containing two signed values of the same size as its first operand (i.e. two words for the 16-bit form; two doublewords for the 32-bit form). It performs two signed comparisons: if the value in the register passed as its first operand is less than the first of the in-memory values, or is greater than or equal to the second, it throws a BR exception. Otherwise, it does nothing.

bound reg16, mem | bound reg32, mem

ENTER constructs a stack frame for a high-level language procedure call. The first operand (the iw in the opcode definition above refers to the first operand) gives the amount of stack space to allocate for local variables; the second (the ib above) gives the nesting level of the procedure (for languages like Pascal, with nested procedures).

The function of ENTER, with a nesting level of zero, is equivalent to

          PUSH EBP            ; or PUSH BP         in 16 bits
          MOV EBP,ESP         ; or MOV BP,SP       in 16 bits
          SUB ESP,operand1    ; or SUB SP,operand1 in 16 bits

This creates a stack frame with the procedure parameters accessible upwards from EBP, and local variables accessible downwards from EBP.

With a nesting level of one, the stack frame created is 4 (or 2) bytes bigger, and the value of the final frame pointer EBP is accessible in memory at [EBP-4].

This allows ENTER, when called with a nesting level of two, to look at the stack frame described by the previous value of EBP, find the frame pointer at offset -4 from that, and push it along with its new frame pointer, so that when a level-two procedure is called from within a level-one procedure, [EBP-4] holds the frame pointer of the most recent level-one procedure call and [EBP-8] holds that of the most recent level-two call. And so on, for nesting levels up to 31.

Stack frames created by ENTER can be destroyed by the LEAVE instruction: see LEAVE.

enter imm16, imm8 | enter imm16

ENTER constructs a stack frame for a high-level language procedure call. The first operand (the iw in the opcode definition above refers to the first operand) gives the amount of stack space to allocate for local variables; the second (the ib above) gives the nesting level of the procedure (for languages like Pascal, with nested procedures).

The function of ENTER, with a nesting level of zero, is equivalent to

          PUSH EBP            ; or PUSH BP         in 16 bits
          MOV EBP,ESP         ; or MOV BP,SP       in 16 bits
          SUB ESP,operand1    ; or SUB SP,operand1 in 16 bits

This creates a stack frame with the procedure parameters accessible upwards from EBP, and local variables accessible downwards from EBP.

With a nesting level of one, the stack frame created is 4 (or 2) bytes bigger, and the value of the final frame pointer EBP is accessible in memory at [EBP-4].

This allows ENTER, when called with a nesting level of two, to look at the stack frame described by the previous value of EBP, find the frame pointer at offset -4 from that, and push it along with its new frame pointer, so that when a level-two procedure is called from within a level-one procedure, [EBP-4] holds the frame pointer of the most recent level-one procedure call and [EBP-8] holds that of the most recent level-two call. And so on, for nesting levels up to 31.

Stack frames created by ENTER can be destroyed by the LEAVE instruction: see LEAVE.

enterd imm16, imm8 | enterd imm16

ENTER constructs a stack frame for a high-level language procedure call. The first operand (the iw in the opcode definition above refers to the first operand) gives the amount of stack space to allocate for local variables; the second (the ib above) gives the nesting level of the procedure (for languages like Pascal, with nested procedures).

The function of ENTER, with a nesting level of zero, is equivalent to

          PUSH EBP            ; or PUSH BP         in 16 bits
          MOV EBP,ESP         ; or MOV BP,SP       in 16 bits
          SUB ESP,operand1    ; or SUB SP,operand1 in 16 bits

This creates a stack frame with the procedure parameters accessible upwards from EBP, and local variables accessible downwards from EBP.

With a nesting level of one, the stack frame created is 4 (or 2) bytes bigger, and the value of the final frame pointer EBP is accessible in memory at [EBP-4].

This allows ENTER, when called with a nesting level of two, to look at the stack frame described by the previous value of EBP, find the frame pointer at offset -4 from that, and push it along with its new frame pointer, so that when a level-two procedure is called from within a level-one procedure, [EBP-4] holds the frame pointer of the most recent level-one procedure call and [EBP-8] holds that of the most recent level-two call. And so on, for nesting levels up to 31.

Stack frames created by ENTER can be destroyed by the LEAVE instruction: see LEAVE.

enterq imm16, imm8 | enterq imm16

ENTER constructs a stack frame for a high-level language procedure call. The first operand (the iw in the opcode definition above refers to the first operand) gives the amount of stack space to allocate for local variables; the second (the ib above) gives the nesting level of the procedure (for languages like Pascal, with nested procedures).

The function of ENTER, with a nesting level of zero, is equivalent to

          PUSH EBP            ; or PUSH BP         in 16 bits
          MOV EBP,ESP         ; or MOV BP,SP       in 16 bits
          SUB ESP,operand1    ; or SUB SP,operand1 in 16 bits

This creates a stack frame with the procedure parameters accessible upwards from EBP, and local variables accessible downwards from EBP.

With a nesting level of one, the stack frame created is 4 (or 2) bytes bigger, and the value of the final frame pointer EBP is accessible in memory at [EBP-4].

This allows ENTER, when called with a nesting level of two, to look at the stack frame described by the previous value of EBP, find the frame pointer at offset -4 from that, and push it along with its new frame pointer, so that when a level-two procedure is called from within a level-one procedure, [EBP-4] holds the frame pointer of the most recent level-one procedure call and [EBP-8] holds that of the most recent level-two call. And so on, for nesting levels up to 31.

Stack frames created by ENTER can be destroyed by the LEAVE instruction: see LEAVE.

enterw imm16, imm8 | enterw imm16

LEAVE destroys a stack frame of the form created by the ENTER instruction (see ENTER). It is functionally equivalent to MOV ESP,EBP followed by POP EBP (or \c{MOV SP,BP} followed by POP BP in 16-bit mode).

leave

LEAVE destroys a stack frame of the form created by the ENTER instruction (see ENTER). It is functionally equivalent to MOV ESP,EBP followed by POP EBP (or \c{MOV SP,BP} followed by POP BP in 16-bit mode).

leaved

LEAVE destroys a stack frame of the form created by the ENTER instruction (see ENTER). It is functionally equivalent to MOV ESP,EBP followed by POP EBP (or \c{MOV SP,BP} followed by POP BP in 16-bit mode).

leaveq

LEAVE destroys a stack frame of the form created by the ENTER instruction (see ENTER). It is functionally equivalent to MOV ESP,EBP followed by POP EBP (or \c{MOV SP,BP} followed by POP BP in 16-bit mode).

leavew

pop Pop a Value from the Stack

POP loads a value from the stack (from [SS:SP] or [SS:ESP]) and then increments the stack pointer.

The address-size attribute of the instruction determines whether SP or ESP is used as the stack pointer: to deliberately override the default given by the BITS setting, you can use an a16 or a32 prefix.

The operand-size attribute of the instruction determines whether the stack pointer is incremented by 2 or 4: this means that segment register pops in BITS 32 mode will pop 4 bytes off the stack and discard the upper two of them. If you need to override that, you can use an o16 or o32 prefix.

The above opcode listings give two forms for general-purpose register pop instructions: for example, POP BX has the two forms 5B and 8F C3. NASM will always generate the shorter form when given POP BX. NDISASM will disassemble both.

POP CS is not a documented instruction, and is not supported on any processor above the 8086 (since they use 0Fh as an opcode prefix for instruction set extensions). However, at least some 8086 processors do support it, and so NASM generates it for completeness.

pop es | pop cs | pop ss | pop ds | pop fs | pop gs
  • POPAW pops a word from the stack into each of, successively, DI, SI, BP, nothing (it discards a word from the stack which was a placeholder for SP), BX, DX, CX and AX. It is intended to reverse the operation of PUSHAW (see PUSHA), but it ignores the value for SP that was pushed on the stack by PUSHAW.

  • POPAD pops twice as much data, and places the results in EDI, ESI, EBP, nothing (placeholder for ESP), EBX, EDX, ECX and EAX. It reverses the operation of PUSHAD.

POPA is an alias mnemonic for either POPAW or POPAD, depending on the current BITS setting.

Note that the registers are popped in reverse order of their numeric values in opcodes (see the register values).

popa
  • POPAW pops a word from the stack into each of, successively, DI, SI, BP, nothing (it discards a word from the stack which was a placeholder for SP), BX, DX, CX and AX. It is intended to reverse the operation of PUSHAW (see PUSHA), but it ignores the value for SP that was pushed on the stack by PUSHAW.

  • POPAD pops twice as much data, and places the results in EDI, ESI, EBP, nothing (placeholder for ESP), EBX, EDX, ECX and EAX. It reverses the operation of PUSHAD.

POPA is an alias mnemonic for either POPAW or POPAD, depending on the current BITS setting.

Note that the registers are popped in reverse order of their numeric values in opcodes (see the register values).

popad
  • POPAW pops a word from the stack into each of, successively, DI, SI, BP, nothing (it discards a word from the stack which was a placeholder for SP), BX, DX, CX and AX. It is intended to reverse the operation of PUSHAW (see PUSHA), but it ignores the value for SP that was pushed on the stack by PUSHAW.

  • POPAD pops twice as much data, and places the results in EDI, ESI, EBP, nothing (placeholder for ESP), EBX, EDX, ECX and EAX. It reverses the operation of PUSHAD.

POPA is an alias mnemonic for either POPAW or POPAD, depending on the current BITS setting.

Note that the registers are popped in reverse order of their numeric values in opcodes (see the register values).

popaw

push Push Value Onto the Stack

PUSH decrements the stack pointer (SP or ESP) by 2 or 4, and then stores the given value at [SS:SP] or [SS:ESP].

The address-size attribute of the instruction determines whether SP or ESP is used as the stack pointer: to deliberately override the default given by the BITS setting, you can use an a16 or a32 prefix.

The operand-size attribute of the instruction determines whether the stack pointer is decremented by 2 or 4: this means that segment register pushes in BITS 32 mode will push 4 bytes on the stack, of which the upper two are undefined. If you need to override that, you can use an o16 or o32 prefix.

The above opcode listings give two forms for general-purpose register push instructions: for example, PUSH BX has the two forms 53 and FF F3. NASM will always generate the shorter form when given PUSH BX. NDISASM will disassemble both.

Unlike the undocumented and barely supported POP CS, PUSH CS is a perfectly valid and sensible instruction, supported on all processors.

The instruction PUSH SP may be used to distinguish an 8086 from later processors: on an 8086, the value of SP stored is the value it has after the push instruction, whereas on later processors it is the value before the push instruction.

push es | push cs | push ss | push ds | push fs | push gs

PUSHAW pushes, in succession, AX, CX, DX, BX, SP, BP, SI and DI on the stack, decrementing the stack pointer by a total of 16.

PUSHAD pushes, in succession, EAX, ECX, EDX, EBX, ESP, EBP, ESI and EDI on the stack, decrementing the stack pointer by a total of 32.

In both cases, the value of SP or ESP pushed is its original value, as it had before the instruction was executed.

PUSHA is an alias mnemonic for either PUSHAW or PUSHAD, depending on the current BITS setting.

Note that the registers are pushed in order of their numeric values in opcodes (see the register values).

See also POPA (POPA).

pusha

PUSHAW pushes, in succession, AX, CX, DX, BX, SP, BP, SI and DI on the stack, decrementing the stack pointer by a total of 16.

PUSHAD pushes, in succession, EAX, ECX, EDX, EBX, ESP, EBP, ESI and EDI on the stack, decrementing the stack pointer by a total of 32.

In both cases, the value of SP or ESP pushed is its original value, as it had before the instruction was executed.

PUSHA is an alias mnemonic for either PUSHAW or PUSHAD, depending on the current BITS setting.

Note that the registers are pushed in order of their numeric values in opcodes (see the register values).

See also POPA (POPA).

pushad

PUSHAW pushes, in succession, AX, CX, DX, BX, SP, BP, SI and DI on the stack, decrementing the stack pointer by a total of 16.

PUSHAD pushes, in succession, EAX, ECX, EDX, EBX, ESP, EBP, ESI and EDI on the stack, decrementing the stack pointer by a total of 32.

In both cases, the value of SP or ESP pushed is its original value, as it had before the instruction was executed.

PUSHA is an alias mnemonic for either PUSHAW or PUSHAD, depending on the current BITS setting.

Note that the registers are pushed in order of their numeric values in opcodes (see the register values).

See also POPA (POPA).

pushaw

Jumps

ja Jump if above (CF == 0 and ZF == 0)

The conditional jump instructions execute a near (same segment) jump if and only if their conditions are satisfied. For example, JNZ jumps only if the zero flag is not set.

The ordinary form of the instructions has only a 128-byte range; the NEAR form is a 386 extension to the instruction set, and can span the full size of a segment. NASM will not override your choice of jump instruction: if you want Jcc NEAR, you have to use the NEAR keyword.

The SHORT keyword is allowed on the first form of the instruction, for clarity, but is not necessary.

For details of the condition codes, see the condition codes.

ja imm8 {short} | ja imm | ja imm16 {near} | ja imm32 {near}

jae Jump if above or equal (CF == 0)

The conditional jump instructions execute a near (same segment) jump if and only if their conditions are satisfied. For example, JNZ jumps only if the zero flag is not set.

The ordinary form of the instructions has only a 128-byte range; the NEAR form is a 386 extension to the instruction set, and can span the full size of a segment. NASM will not override your choice of jump instruction: if you want Jcc NEAR, you have to use the NEAR keyword.

The SHORT keyword is allowed on the first form of the instruction, for clarity, but is not necessary.

For details of the condition codes, see the condition codes.

jae imm8 {short} | jae imm | jae imm16 {near} | jae imm32 {near}

jb Jump if below (CF == 1)

The conditional jump instructions execute a near (same segment) jump if and only if their conditions are satisfied. For example, JNZ jumps only if the zero flag is not set.

The ordinary form of the instructions has only a 128-byte range; the NEAR form is a 386 extension to the instruction set, and can span the full size of a segment. NASM will not override your choice of jump instruction: if you want Jcc NEAR, you have to use the NEAR keyword.

The SHORT keyword is allowed on the first form of the instruction, for clarity, but is not necessary.

For details of the condition codes, see the condition codes.

jb imm8 {short} | jb imm | jb imm16 {near} | jb imm32 {near}

jbe Jump if below or equal (CF == 1 or ZF == 1)

The conditional jump instructions execute a near (same segment) jump if and only if their conditions are satisfied. For example, JNZ jumps only if the zero flag is not set.

The ordinary form of the instructions has only a 128-byte range; the NEAR form is a 386 extension to the instruction set, and can span the full size of a segment. NASM will not override your choice of jump instruction: if you want Jcc NEAR, you have to use the NEAR keyword.

The SHORT keyword is allowed on the first form of the instruction, for clarity, but is not necessary.

For details of the condition codes, see the condition codes.

jbe imm8 {short} | jbe imm | jbe imm16 {near} | jbe imm32 {near}

jc Jump if carry (CF == 1)

The conditional jump instructions execute a near (same segment) jump if and only if their conditions are satisfied. For example, JNZ jumps only if the zero flag is not set.

The ordinary form of the instructions has only a 128-byte range; the NEAR form is a 386 extension to the instruction set, and can span the full size of a segment. NASM will not override your choice of jump instruction: if you want Jcc NEAR, you have to use the NEAR keyword.

The SHORT keyword is allowed on the first form of the instruction, for clarity, but is not necessary.

For details of the condition codes, see the condition codes.

jc imm8 {short} | jc imm | jc imm16 {near} | jc imm32 {near}

JCXZ performs a short jump (with maximum range 128 bytes) if and only if the contents of the CX register is 0. JECXZ does the same thing, but with ECX.

jcxz imm8 {near|short} | jcxz imm8 {near|short}, cx | jcxz imm8 {near|short}, ecx | jcxz imm8 {near|short}, rcx

je Jump if equal (ZF == 1)

The conditional jump instructions execute a near (same segment) jump if and only if their conditions are satisfied. For example, JNZ jumps only if the zero flag is not set.

The ordinary form of the instructions has only a 128-byte range; the NEAR form is a 386 extension to the instruction set, and can span the full size of a segment. NASM will not override your choice of jump instruction: if you want Jcc NEAR, you have to use the NEAR keyword.

The SHORT keyword is allowed on the first form of the instruction, for clarity, but is not necessary.

For details of the condition codes, see the condition codes.

je imm8 {short} | je imm | je imm16 {near} | je imm32 {near}

jecxz Jump if ECX register is 0

JCXZ performs a short jump (with maximum range 128 bytes) if and only if the contents of the CX register is 0. JECXZ does the same thing, but with ECX.

jecxz imm8 {near|short}

jg Jump if greater (ZF == 0 and SF == OF)

The conditional jump instructions execute a near (same segment) jump if and only if their conditions are satisfied. For example, JNZ jumps only if the zero flag is not set.

The ordinary form of the instructions has only a 128-byte range; the NEAR form is a 386 extension to the instruction set, and can span the full size of a segment. NASM will not override your choice of jump instruction: if you want Jcc NEAR, you have to use the NEAR keyword.

The SHORT keyword is allowed on the first form of the instruction, for clarity, but is not necessary.

For details of the condition codes, see the condition codes.

jg imm8 {short} | jg imm | jg imm16 {near} | jg imm32 {near}

jge Jump if greater or equal (SF == OF)

The conditional jump instructions execute a near (same segment) jump if and only if their conditions are satisfied. For example, JNZ jumps only if the zero flag is not set.

The ordinary form of the instructions has only a 128-byte range; the NEAR form is a 386 extension to the instruction set, and can span the full size of a segment. NASM will not override your choice of jump instruction: if you want Jcc NEAR, you have to use the NEAR keyword.

The SHORT keyword is allowed on the first form of the instruction, for clarity, but is not necessary.

For details of the condition codes, see the condition codes.

jge imm8 {short} | jge imm | jge imm16 {near} | jge imm32 {near}

jl Jump if less (SF != OF)

The conditional jump instructions execute a near (same segment) jump if and only if their conditions are satisfied. For example, JNZ jumps only if the zero flag is not set.

The ordinary form of the instructions has only a 128-byte range; the NEAR form is a 386 extension to the instruction set, and can span the full size of a segment. NASM will not override your choice of jump instruction: if you want Jcc NEAR, you have to use the NEAR keyword.

The SHORT keyword is allowed on the first form of the instruction, for clarity, but is not necessary.

For details of the condition codes, see the condition codes.

jl imm8 {short} | jl imm | jl imm16 {near} | jl imm32 {near}

jle Jump if less or equal (ZF == 1 or SF != OF)

The conditional jump instructions execute a near (same segment) jump if and only if their conditions are satisfied. For example, JNZ jumps only if the zero flag is not set.

The ordinary form of the instructions has only a 128-byte range; the NEAR form is a 386 extension to the instruction set, and can span the full size of a segment. NASM will not override your choice of jump instruction: if you want Jcc NEAR, you have to use the NEAR keyword.

The SHORT keyword is allowed on the first form of the instruction, for clarity, but is not necessary.

For details of the condition codes, see the condition codes.

jle imm8 {short} | jle imm | jle imm16 {near} | jle imm32 {near}

jmp Jump Unconditionally

JMP jumps to a given address. The address may be specified as an absolute segment and offset, or as a relative jump within the current segment.

JMP SHORT imm has a maximum range of 128 bytes, since the displacement is specified as only 8 bits, but takes up less code space. NASM does not choose when to generate JMP SHORT for you: you must explicitly code SHORT every time you want a short jump.

You can choose between the two immediate far jump forms (\c{JMP imm:imm}) by the use of the WORD and DWORD keywords: \c{JMP WORD 0x1234:0x5678}) or JMP DWORD 0x1234:0x56789abc.

The JMP FAR mem forms execute a far jump by loading the destination address out of memory. The address loaded consists of 16 or 32 bits of offset (depending on the operand size), and 16 bits of segment. The operand size may be overridden using \c{JMP WORD FAR mem} or JMP DWORD FAR mem.

The JMP r/m forms execute a near jump (within the same segment), loading the destination address out of memory or out of a register. The keyword NEAR may be specified, for clarity, in these forms, but is not necessary. Again, operand size can be overridden using JMP WORD mem or JMP DWORD mem.

As a convenience, NASM does not require you to jump to a far symbol by coding the cumbersome JMP SEG routine:routine, but instead allows the easier synonym JMP FAR routine.

The JMP r/m forms given above are near calls; NASM will accept the NEAR keyword (e.g. JMP NEAR [address]), even though it is not strictly necessary.

jmp imm64 {abs} | jmp imm8 {short} | jmp imm | jmp imm16 {near} | jmp imm32 {near} | jmp r/m16 {near}
jmpe imm {near} | jmpe imm16 {near} | jmpe imm32 {near} | jmpe imm64 {near} | jmpe r/m16 {near} | jmpe r/m32 {near}

jna Jump if not above (CF == 1 or ZF == 1)

The conditional jump instructions execute a near (same segment) jump if and only if their conditions are satisfied. For example, JNZ jumps only if the zero flag is not set.

The ordinary form of the instructions has only a 128-byte range; the NEAR form is a 386 extension to the instruction set, and can span the full size of a segment. NASM will not override your choice of jump instruction: if you want Jcc NEAR, you have to use the NEAR keyword.

The SHORT keyword is allowed on the first form of the instruction, for clarity, but is not necessary.

For details of the condition codes, see the condition codes.

jna imm8 {short} | jna imm | jna imm16 {near} | jna imm32 {near}

jnae Jump if not above or equal (CF == 1)

The conditional jump instructions execute a near (same segment) jump if and only if their conditions are satisfied. For example, JNZ jumps only if the zero flag is not set.

The ordinary form of the instructions has only a 128-byte range; the NEAR form is a 386 extension to the instruction set, and can span the full size of a segment. NASM will not override your choice of jump instruction: if you want Jcc NEAR, you have to use the NEAR keyword.

The SHORT keyword is allowed on the first form of the instruction, for clarity, but is not necessary.

For details of the condition codes, see the condition codes.

jnae imm8 {short} | jnae imm | jnae imm16 {near} | jnae imm32 {near}

jnb Jump if not below (CF == 0)

The conditional jump instructions execute a near (same segment) jump if and only if their conditions are satisfied. For example, JNZ jumps only if the zero flag is not set.

The ordinary form of the instructions has only a 128-byte range; the NEAR form is a 386 extension to the instruction set, and can span the full size of a segment. NASM will not override your choice of jump instruction: if you want Jcc NEAR, you have to use the NEAR keyword.

The SHORT keyword is allowed on the first form of the instruction, for clarity, but is not necessary.

For details of the condition codes, see the condition codes.

jnb imm8 {short} | jnb imm | jnb imm16 {near} | jnb imm32 {near}

jnbe Jump if not below or equal (CF == 0 and ZF == 0)

The conditional jump instructions execute a near (same segment) jump if and only if their conditions are satisfied. For example, JNZ jumps only if the zero flag is not set.

The ordinary form of the instructions has only a 128-byte range; the NEAR form is a 386 extension to the instruction set, and can span the full size of a segment. NASM will not override your choice of jump instruction: if you want Jcc NEAR, you have to use the NEAR keyword.

The SHORT keyword is allowed on the first form of the instruction, for clarity, but is not necessary.

For details of the condition codes, see the condition codes.

jnbe imm8 {short} | jnbe imm | jnbe imm16 {near} | jnbe imm32 {near}

jnc Jump if not carry (CF == 0)

The conditional jump instructions execute a near (same segment) jump if and only if their conditions are satisfied. For example, JNZ jumps only if the zero flag is not set.

The ordinary form of the instructions has only a 128-byte range; the NEAR form is a 386 extension to the instruction set, and can span the full size of a segment. NASM will not override your choice of jump instruction: if you want Jcc NEAR, you have to use the NEAR keyword.

The SHORT keyword is allowed on the first form of the instruction, for clarity, but is not necessary.

For details of the condition codes, see the condition codes.

jnc imm8 {short} | jnc imm | jnc imm16 {near} | jnc imm32 {near}

jne Jump if not equal (ZF == 0)

The conditional jump instructions execute a near (same segment) jump if and only if their conditions are satisfied. For example, JNZ jumps only if the zero flag is not set.

The ordinary form of the instructions has only a 128-byte range; the NEAR form is a 386 extension to the instruction set, and can span the full size of a segment. NASM will not override your choice of jump instruction: if you want Jcc NEAR, you have to use the NEAR keyword.

The SHORT keyword is allowed on the first form of the instruction, for clarity, but is not necessary.

For details of the condition codes, see the condition codes.

jne imm8 {short} | jne imm | jne imm16 {near} | jne imm32 {near}

jng Jump if not greater (ZF == 1 or SF != OF)

The conditional jump instructions execute a near (same segment) jump if and only if their conditions are satisfied. For example, JNZ jumps only if the zero flag is not set.

The ordinary form of the instructions has only a 128-byte range; the NEAR form is a 386 extension to the instruction set, and can span the full size of a segment. NASM will not override your choice of jump instruction: if you want Jcc NEAR, you have to use the NEAR keyword.

The SHORT keyword is allowed on the first form of the instruction, for clarity, but is not necessary.

For details of the condition codes, see the condition codes.

jng imm8 {short} | jng imm | jng imm16 {near} | jng imm32 {near}

jnge Jump if not greater or equal (SF != OF)

The conditional jump instructions execute a near (same segment) jump if and only if their conditions are satisfied. For example, JNZ jumps only if the zero flag is not set.

The ordinary form of the instructions has only a 128-byte range; the NEAR form is a 386 extension to the instruction set, and can span the full size of a segment. NASM will not override your choice of jump instruction: if you want Jcc NEAR, you have to use the NEAR keyword.

The SHORT keyword is allowed on the first form of the instruction, for clarity, but is not necessary.

For details of the condition codes, see the condition codes.

jnge imm8 {short} | jnge imm | jnge imm16 {near} | jnge imm32 {near}

jnl Jump if not less (SF == OF)

The conditional jump instructions execute a near (same segment) jump if and only if their conditions are satisfied. For example, JNZ jumps only if the zero flag is not set.

The ordinary form of the instructions has only a 128-byte range; the NEAR form is a 386 extension to the instruction set, and can span the full size of a segment. NASM will not override your choice of jump instruction: if you want Jcc NEAR, you have to use the NEAR keyword.

The SHORT keyword is allowed on the first form of the instruction, for clarity, but is not necessary.

For details of the condition codes, see the condition codes.

jnl imm8 {short} | jnl imm | jnl imm16 {near} | jnl imm32 {near}

jnle Jump if not less or equal (ZF == 0 and SF == OF)

The conditional jump instructions execute a near (same segment) jump if and only if their conditions are satisfied. For example, JNZ jumps only if the zero flag is not set.

The ordinary form of the instructions has only a 128-byte range; the NEAR form is a 386 extension to the instruction set, and can span the full size of a segment. NASM will not override your choice of jump instruction: if you want Jcc NEAR, you have to use the NEAR keyword.

The SHORT keyword is allowed on the first form of the instruction, for clarity, but is not necessary.

For details of the condition codes, see the condition codes.

jnle imm8 {short} | jnle imm | jnle imm16 {near} | jnle imm32 {near}

jno Jump if not overflow (OF == 0)

The conditional jump instructions execute a near (same segment) jump if and only if their conditions are satisfied. For example, JNZ jumps only if the zero flag is not set.

The ordinary form of the instructions has only a 128-byte range; the NEAR form is a 386 extension to the instruction set, and can span the full size of a segment. NASM will not override your choice of jump instruction: if you want Jcc NEAR, you have to use the NEAR keyword.

The SHORT keyword is allowed on the first form of the instruction, for clarity, but is not necessary.

For details of the condition codes, see the condition codes.

jno imm8 {short} | jno imm | jno imm16 {near} | jno imm32 {near}

jnp Jump if not parity (PF == 0)

The conditional jump instructions execute a near (same segment) jump if and only if their conditions are satisfied. For example, JNZ jumps only if the zero flag is not set.

The ordinary form of the instructions has only a 128-byte range; the NEAR form is a 386 extension to the instruction set, and can span the full size of a segment. NASM will not override your choice of jump instruction: if you want Jcc NEAR, you have to use the NEAR keyword.

The SHORT keyword is allowed on the first form of the instruction, for clarity, but is not necessary.

For details of the condition codes, see the condition codes.

jnp imm8 {short} | jnp imm | jnp imm16 {near} | jnp imm32 {near}

jns Jump if not sign (SF == 0)

The conditional jump instructions execute a near (same segment) jump if and only if their conditions are satisfied. For example, JNZ jumps only if the zero flag is not set.

The ordinary form of the instructions has only a 128-byte range; the NEAR form is a 386 extension to the instruction set, and can span the full size of a segment. NASM will not override your choice of jump instruction: if you want Jcc NEAR, you have to use the NEAR keyword.

The SHORT keyword is allowed on the first form of the instruction, for clarity, but is not necessary.

For details of the condition codes, see the condition codes.

jns imm8 {short} | jns imm | jns imm16 {near} | jns imm32 {near}

jnz Jump if not zero (ZF == 0)

The conditional jump instructions execute a near (same segment) jump if and only if their conditions are satisfied. For example, JNZ jumps only if the zero flag is not set.

The ordinary form of the instructions has only a 128-byte range; the NEAR form is a 386 extension to the instruction set, and can span the full size of a segment. NASM will not override your choice of jump instruction: if you want Jcc NEAR, you have to use the NEAR keyword.

The SHORT keyword is allowed on the first form of the instruction, for clarity, but is not necessary.

For details of the condition codes, see the condition codes.

jnz imm8 {short} | jnz imm | jnz imm16 {near} | jnz imm32 {near}

jo Jump if overflow (OF == 1)

The conditional jump instructions execute a near (same segment) jump if and only if their conditions are satisfied. For example, JNZ jumps only if the zero flag is not set.

The ordinary form of the instructions has only a 128-byte range; the NEAR form is a 386 extension to the instruction set, and can span the full size of a segment. NASM will not override your choice of jump instruction: if you want Jcc NEAR, you have to use the NEAR keyword.

The SHORT keyword is allowed on the first form of the instruction, for clarity, but is not necessary.

For details of the condition codes, see the condition codes.

jo imm8 {short} | jo imm | jo imm16 {near} | jo imm32 {near}

jp Jump if parity (PF == 1)

The conditional jump instructions execute a near (same segment) jump if and only if their conditions are satisfied. For example, JNZ jumps only if the zero flag is not set.

The ordinary form of the instructions has only a 128-byte range; the NEAR form is a 386 extension to the instruction set, and can span the full size of a segment. NASM will not override your choice of jump instruction: if you want Jcc NEAR, you have to use the NEAR keyword.

The SHORT keyword is allowed on the first form of the instruction, for clarity, but is not necessary.

For details of the condition codes, see the condition codes.

jp imm8 {short} | jp imm | jp imm16 {near} | jp imm32 {near}

jpe Jump if parity even (PF == 1)

The conditional jump instructions execute a near (same segment) jump if and only if their conditions are satisfied. For example, JNZ jumps only if the zero flag is not set.

The ordinary form of the instructions has only a 128-byte range; the NEAR form is a 386 extension to the instruction set, and can span the full size of a segment. NASM will not override your choice of jump instruction: if you want Jcc NEAR, you have to use the NEAR keyword.

The SHORT keyword is allowed on the first form of the instruction, for clarity, but is not necessary.

For details of the condition codes, see the condition codes.

jpe imm8 {short} | jpe imm | jpe imm16 {near} | jpe imm32 {near}

jpo Jump if parity odd (PF == 0)

The conditional jump instructions execute a near (same segment) jump if and only if their conditions are satisfied. For example, JNZ jumps only if the zero flag is not set.

The ordinary form of the instructions has only a 128-byte range; the NEAR form is a 386 extension to the instruction set, and can span the full size of a segment. NASM will not override your choice of jump instruction: if you want Jcc NEAR, you have to use the NEAR keyword.

The SHORT keyword is allowed on the first form of the instruction, for clarity, but is not necessary.

For details of the condition codes, see the condition codes.

jpo imm8 {short} | jpo imm | jpo imm16 {near} | jpo imm32 {near}

jrcxz Jump if RCX register is 0

JCXZ performs a short jump (with maximum range 128 bytes) if and only if the contents of the CX register is 0. JECXZ does the same thing, but with ECX.

jrcxz imm8 {near|short}

js Jump if sign (SF == 1)

The conditional jump instructions execute a near (same segment) jump if and only if their conditions are satisfied. For example, JNZ jumps only if the zero flag is not set.

The ordinary form of the instructions has only a 128-byte range; the NEAR form is a 386 extension to the instruction set, and can span the full size of a segment. NASM will not override your choice of jump instruction: if you want Jcc NEAR, you have to use the NEAR keyword.

The SHORT keyword is allowed on the first form of the instruction, for clarity, but is not necessary.

For details of the condition codes, see the condition codes.

js imm8 {short} | js imm | js imm16 {near} | js imm32 {near}

jz Jump if zero (ZF == 1)

The conditional jump instructions execute a near (same segment) jump if and only if their conditions are satisfied. For example, JNZ jumps only if the zero flag is not set.

The ordinary form of the instructions has only a 128-byte range; the NEAR form is a 386 extension to the instruction set, and can span the full size of a segment. NASM will not override your choice of jump instruction: if you want Jcc NEAR, you have to use the NEAR keyword.

The SHORT keyword is allowed on the first form of the instruction, for clarity, but is not necessary.

For details of the condition codes, see the condition codes.

jz imm8 {short} | jz imm | jz imm16 {near} | jz imm32 {near}

LOOP decrements its counter register (either CX or ECX - if one is not specified explicitly, the BITS setting dictates which is used) by one, and if the counter does not become zero as a result of this operation, it jumps to the given label. The jump has a range of 128 bytes.

LOOPE (or its synonym LOOPZ) adds the additional condition that it only jumps if the counter is nonzero and the zero flag is set. Similarly, LOOPNE (and LOOPNZ) jumps only if the counter is nonzero and the zero flag is clear.

loop imm8 {near|short} | loop imm8 {near|short}, cx | loop imm8 {near|short}, ecx | loop imm8 {near|short}, rcx

LOOP decrements its counter register (either CX or ECX - if one is not specified explicitly, the BITS setting dictates which is used) by one, and if the counter does not become zero as a result of this operation, it jumps to the given label. The jump has a range of 128 bytes.

LOOPE (or its synonym LOOPZ) adds the additional condition that it only jumps if the counter is nonzero and the zero flag is set. Similarly, LOOPNE (and LOOPNZ) jumps only if the counter is nonzero and the zero flag is clear.

loopd imm8 {near|short}

LOOP decrements its counter register (either CX or ECX - if one is not specified explicitly, the BITS setting dictates which is used) by one, and if the counter does not become zero as a result of this operation, it jumps to the given label. The jump has a range of 128 bytes.

LOOPE (or its synonym LOOPZ) adds the additional condition that it only jumps if the counter is nonzero and the zero flag is set. Similarly, LOOPNE (and LOOPNZ) jumps only if the counter is nonzero and the zero flag is clear.

loope imm8 {near|short} | loope imm8 {near|short}, cx | loope imm8 {near|short}, ecx | loope imm8 {near|short}, rcx

LOOP decrements its counter register (either CX or ECX - if one is not specified explicitly, the BITS setting dictates which is used) by one, and if the counter does not become zero as a result of this operation, it jumps to the given label. The jump has a range of 128 bytes.

LOOPE (or its synonym LOOPZ) adds the additional condition that it only jumps if the counter is nonzero and the zero flag is set. Similarly, LOOPNE (and LOOPNZ) jumps only if the counter is nonzero and the zero flag is clear.

looped imm8 {near|short}

LOOP decrements its counter register (either CX or ECX - if one is not specified explicitly, the BITS setting dictates which is used) by one, and if the counter does not become zero as a result of this operation, it jumps to the given label. The jump has a range of 128 bytes.

LOOPE (or its synonym LOOPZ) adds the additional condition that it only jumps if the counter is nonzero and the zero flag is set. Similarly, LOOPNE (and LOOPNZ) jumps only if the counter is nonzero and the zero flag is clear.

loopeq imm8 {near|short}

LOOP decrements its counter register (either CX or ECX - if one is not specified explicitly, the BITS setting dictates which is used) by one, and if the counter does not become zero as a result of this operation, it jumps to the given label. The jump has a range of 128 bytes.

LOOPE (or its synonym LOOPZ) adds the additional condition that it only jumps if the counter is nonzero and the zero flag is set. Similarly, LOOPNE (and LOOPNZ) jumps only if the counter is nonzero and the zero flag is clear.

loopew imm8 {near|short}

LOOP decrements its counter register (either CX or ECX - if one is not specified explicitly, the BITS setting dictates which is used) by one, and if the counter does not become zero as a result of this operation, it jumps to the given label. The jump has a range of 128 bytes.

LOOPE (or its synonym LOOPZ) adds the additional condition that it only jumps if the counter is nonzero and the zero flag is set. Similarly, LOOPNE (and LOOPNZ) jumps only if the counter is nonzero and the zero flag is clear.

loopne imm8 {near|short} | loopne imm8 {near|short}, cx | loopne imm8 {near|short}, ecx | loopne imm8 {near|short}, rcx

LOOP decrements its counter register (either CX or ECX - if one is not specified explicitly, the BITS setting dictates which is used) by one, and if the counter does not become zero as a result of this operation, it jumps to the given label. The jump has a range of 128 bytes.

LOOPE (or its synonym LOOPZ) adds the additional condition that it only jumps if the counter is nonzero and the zero flag is set. Similarly, LOOPNE (and LOOPNZ) jumps only if the counter is nonzero and the zero flag is clear.

loopned imm8 {near|short}

LOOP decrements its counter register (either CX or ECX - if one is not specified explicitly, the BITS setting dictates which is used) by one, and if the counter does not become zero as a result of this operation, it jumps to the given label. The jump has a range of 128 bytes.

LOOPE (or its synonym LOOPZ) adds the additional condition that it only jumps if the counter is nonzero and the zero flag is set. Similarly, LOOPNE (and LOOPNZ) jumps only if the counter is nonzero and the zero flag is clear.

loopneq imm8 {near|short}

LOOP decrements its counter register (either CX or ECX - if one is not specified explicitly, the BITS setting dictates which is used) by one, and if the counter does not become zero as a result of this operation, it jumps to the given label. The jump has a range of 128 bytes.

LOOPE (or its synonym LOOPZ) adds the additional condition that it only jumps if the counter is nonzero and the zero flag is set. Similarly, LOOPNE (and LOOPNZ) jumps only if the counter is nonzero and the zero flag is clear.

loopnew imm8 {near|short}

LOOP decrements its counter register (either CX or ECX - if one is not specified explicitly, the BITS setting dictates which is used) by one, and if the counter does not become zero as a result of this operation, it jumps to the given label. The jump has a range of 128 bytes.

LOOPE (or its synonym LOOPZ) adds the additional condition that it only jumps if the counter is nonzero and the zero flag is set. Similarly, LOOPNE (and LOOPNZ) jumps only if the counter is nonzero and the zero flag is clear.

loopnz imm8 {near|short} | loopnz imm8 {near|short}, cx | loopnz imm8 {near|short}, ecx | loopnz imm8 {near|short}, rcx

LOOP decrements its counter register (either CX or ECX - if one is not specified explicitly, the BITS setting dictates which is used) by one, and if the counter does not become zero as a result of this operation, it jumps to the given label. The jump has a range of 128 bytes.

LOOPE (or its synonym LOOPZ) adds the additional condition that it only jumps if the counter is nonzero and the zero flag is set. Similarly, LOOPNE (and LOOPNZ) jumps only if the counter is nonzero and the zero flag is clear.

loopnzd imm8 {near|short}

LOOP decrements its counter register (either CX or ECX - if one is not specified explicitly, the BITS setting dictates which is used) by one, and if the counter does not become zero as a result of this operation, it jumps to the given label. The jump has a range of 128 bytes.

LOOPE (or its synonym LOOPZ) adds the additional condition that it only jumps if the counter is nonzero and the zero flag is set. Similarly, LOOPNE (and LOOPNZ) jumps only if the counter is nonzero and the zero flag is clear.

loopnzq imm8 {near|short}

LOOP decrements its counter register (either CX or ECX - if one is not specified explicitly, the BITS setting dictates which is used) by one, and if the counter does not become zero as a result of this operation, it jumps to the given label. The jump has a range of 128 bytes.

LOOPE (or its synonym LOOPZ) adds the additional condition that it only jumps if the counter is nonzero and the zero flag is set. Similarly, LOOPNE (and LOOPNZ) jumps only if the counter is nonzero and the zero flag is clear.

loopnzw imm8 {near|short}

LOOP decrements its counter register (either CX or ECX - if one is not specified explicitly, the BITS setting dictates which is used) by one, and if the counter does not become zero as a result of this operation, it jumps to the given label. The jump has a range of 128 bytes.

LOOPE (or its synonym LOOPZ) adds the additional condition that it only jumps if the counter is nonzero and the zero flag is set. Similarly, LOOPNE (and LOOPNZ) jumps only if the counter is nonzero and the zero flag is clear.

loopq imm8 {near|short}

LOOP decrements its counter register (either CX or ECX - if one is not specified explicitly, the BITS setting dictates which is used) by one, and if the counter does not become zero as a result of this operation, it jumps to the given label. The jump has a range of 128 bytes.

LOOPE (or its synonym LOOPZ) adds the additional condition that it only jumps if the counter is nonzero and the zero flag is set. Similarly, LOOPNE (and LOOPNZ) jumps only if the counter is nonzero and the zero flag is clear.

loopw imm8 {near|short}

LOOP decrements its counter register (either CX or ECX - if one is not specified explicitly, the BITS setting dictates which is used) by one, and if the counter does not become zero as a result of this operation, it jumps to the given label. The jump has a range of 128 bytes.

LOOPE (or its synonym LOOPZ) adds the additional condition that it only jumps if the counter is nonzero and the zero flag is set. Similarly, LOOPNE (and LOOPNZ) jumps only if the counter is nonzero and the zero flag is clear.

loopz imm8 {near|short} | loopz imm8 {near|short}, cx | loopz imm8 {near|short}, ecx | loopz imm8 {near|short}, rcx

LOOP decrements its counter register (either CX or ECX - if one is not specified explicitly, the BITS setting dictates which is used) by one, and if the counter does not become zero as a result of this operation, it jumps to the given label. The jump has a range of 128 bytes.

LOOPE (or its synonym LOOPZ) adds the additional condition that it only jumps if the counter is nonzero and the zero flag is set. Similarly, LOOPNE (and LOOPNZ) jumps only if the counter is nonzero and the zero flag is clear.

loopzd imm8 {near|short}

LOOP decrements its counter register (either CX or ECX - if one is not specified explicitly, the BITS setting dictates which is used) by one, and if the counter does not become zero as a result of this operation, it jumps to the given label. The jump has a range of 128 bytes.

LOOPE (or its synonym LOOPZ) adds the additional condition that it only jumps if the counter is nonzero and the zero flag is set. Similarly, LOOPNE (and LOOPNZ) jumps only if the counter is nonzero and the zero flag is clear.

loopzq imm8 {near|short}

LOOP decrements its counter register (either CX or ECX - if one is not specified explicitly, the BITS setting dictates which is used) by one, and if the counter does not become zero as a result of this operation, it jumps to the given label. The jump has a range of 128 bytes.

LOOPE (or its synonym LOOPZ) adds the additional condition that it only jumps if the counter is nonzero and the zero flag is set. Similarly, LOOPNE (and LOOPNZ) jumps only if the counter is nonzero and the zero flag is clear.

loopzw imm8 {near|short}

Conditional instructions

cmova Move if above (CF == 0 and ZF == 0)

CMOV moves its source (second) operand into its destination (first) operand if the given condition code is satisfied; otherwise it does nothing.

For a list of condition codes, see the condition codes.

Although the CMOV instructions are flagged P6 and above, they may not be supported by all Pentium Pro processors; the CPUID instruction (CPUID) will return a bit which indicates whether conditional moves are supported.

cmova reg16, r/m16 | cmova reg32, r/m32 | cmova reg64, r/m64 | cmova reg16, reg16, r/m16 | cmova reg32, reg32, r/m32 | cmova reg64, reg64, r/m64

cmovae Move if above or equal (CF == 0)

CMOV moves its source (second) operand into its destination (first) operand if the given condition code is satisfied; otherwise it does nothing.

For a list of condition codes, see the condition codes.

Although the CMOV instructions are flagged P6 and above, they may not be supported by all Pentium Pro processors; the CPUID instruction (CPUID) will return a bit which indicates whether conditional moves are supported.

cmovae reg16, r/m16 | cmovae reg32, r/m32 | cmovae reg64, r/m64 | cmovae reg16, reg16, r/m16 | cmovae reg32, reg32, r/m32 | cmovae reg64, reg64, r/m64

cmovb Move if below (CF == 1)

CMOV moves its source (second) operand into its destination (first) operand if the given condition code is satisfied; otherwise it does nothing.

For a list of condition codes, see the condition codes.

Although the CMOV instructions are flagged P6 and above, they may not be supported by all Pentium Pro processors; the CPUID instruction (CPUID) will return a bit which indicates whether conditional moves are supported.

cmovb reg16, r/m16 | cmovb reg32, r/m32 | cmovb reg64, r/m64 | cmovb reg16, reg16, r/m16 | cmovb reg32, reg32, r/m32 | cmovb reg64, reg64, r/m64

cmovbe Move if below or equal (CF == 1 or ZF == 1)

CMOV moves its source (second) operand into its destination (first) operand if the given condition code is satisfied; otherwise it does nothing.

For a list of condition codes, see the condition codes.

Although the CMOV instructions are flagged P6 and above, they may not be supported by all Pentium Pro processors; the CPUID instruction (CPUID) will return a bit which indicates whether conditional moves are supported.

cmovbe reg16, r/m16 | cmovbe reg32, r/m32 | cmovbe reg64, r/m64 | cmovbe reg16, reg16, r/m16 | cmovbe reg32, reg32, r/m32 | cmovbe reg64, reg64, r/m64

cmovc Move if carry (CF == 1)

CMOV moves its source (second) operand into its destination (first) operand if the given condition code is satisfied; otherwise it does nothing.

For a list of condition codes, see the condition codes.

Although the CMOV instructions are flagged P6 and above, they may not be supported by all Pentium Pro processors; the CPUID instruction (CPUID) will return a bit which indicates whether conditional moves are supported.

cmovc reg16, r/m16 | cmovc reg32, r/m32 | cmovc reg64, r/m64 | cmovc reg16, reg16, r/m16 | cmovc reg32, reg32, r/m32 | cmovc reg64, reg64, r/m64

cmove Move if equal (ZF == 1)

CMOV moves its source (second) operand into its destination (first) operand if the given condition code is satisfied; otherwise it does nothing.

For a list of condition codes, see the condition codes.

Although the CMOV instructions are flagged P6 and above, they may not be supported by all Pentium Pro processors; the CPUID instruction (CPUID) will return a bit which indicates whether conditional moves are supported.

cmove reg16, r/m16 | cmove reg32, r/m32 | cmove reg64, r/m64 | cmove reg16, reg16, r/m16 | cmove reg32, reg32, r/m32 | cmove reg64, reg64, r/m64

cmovg Move if greater (ZF == 0 and SF == OF)

CMOV moves its source (second) operand into its destination (first) operand if the given condition code is satisfied; otherwise it does nothing.

For a list of condition codes, see the condition codes.

Although the CMOV instructions are flagged P6 and above, they may not be supported by all Pentium Pro processors; the CPUID instruction (CPUID) will return a bit which indicates whether conditional moves are supported.

cmovg reg16, r/m16 | cmovg reg32, r/m32 | cmovg reg64, r/m64 | cmovg reg16, reg16, r/m16 | cmovg reg32, reg32, r/m32 | cmovg reg64, reg64, r/m64

cmovge Move if greater or equal (SF == OF)

CMOV moves its source (second) operand into its destination (first) operand if the given condition code is satisfied; otherwise it does nothing.

For a list of condition codes, see the condition codes.

Although the CMOV instructions are flagged P6 and above, they may not be supported by all Pentium Pro processors; the CPUID instruction (CPUID) will return a bit which indicates whether conditional moves are supported.

cmovge reg16, r/m16 | cmovge reg32, r/m32 | cmovge reg64, r/m64 | cmovge reg16, reg16, r/m16 | cmovge reg32, reg32, r/m32 | cmovge reg64, reg64, r/m64

cmovl Move if less (SF != OF)

CMOV moves its source (second) operand into its destination (first) operand if the given condition code is satisfied; otherwise it does nothing.

For a list of condition codes, see the condition codes.

Although the CMOV instructions are flagged P6 and above, they may not be supported by all Pentium Pro processors; the CPUID instruction (CPUID) will return a bit which indicates whether conditional moves are supported.

cmovl reg16, r/m16 | cmovl reg32, r/m32 | cmovl reg64, r/m64 | cmovl reg16, reg16, r/m16 | cmovl reg32, reg32, r/m32 | cmovl reg64, reg64, r/m64

cmovle Move if less or equal (ZF == 1 or SF != OF)

CMOV moves its source (second) operand into its destination (first) operand if the given condition code is satisfied; otherwise it does nothing.

For a list of condition codes, see the condition codes.

Although the CMOV instructions are flagged P6 and above, they may not be supported by all Pentium Pro processors; the CPUID instruction (CPUID) will return a bit which indicates whether conditional moves are supported.

cmovle reg16, r/m16 | cmovle reg32, r/m32 | cmovle reg64, r/m64 | cmovle reg16, reg16, r/m16 | cmovle reg32, reg32, r/m32 | cmovle reg64, reg64, r/m64

cmovna Move if not above (CF == 1 or ZF == 1)

CMOV moves its source (second) operand into its destination (first) operand if the given condition code is satisfied; otherwise it does nothing.

For a list of condition codes, see the condition codes.

Although the CMOV instructions are flagged P6 and above, they may not be supported by all Pentium Pro processors; the CPUID instruction (CPUID) will return a bit which indicates whether conditional moves are supported.

cmovna reg16, r/m16 | cmovna reg32, r/m32 | cmovna reg64, r/m64 | cmovna reg16, reg16, r/m16 | cmovna reg32, reg32, r/m32 | cmovna reg64, reg64, r/m64

cmovnae Move if not above or equal (CF == 1)

CMOV moves its source (second) operand into its destination (first) operand if the given condition code is satisfied; otherwise it does nothing.

For a list of condition codes, see the condition codes.

Although the CMOV instructions are flagged P6 and above, they may not be supported by all Pentium Pro processors; the CPUID instruction (CPUID) will return a bit which indicates whether conditional moves are supported.

cmovnae reg16, r/m16 | cmovnae reg32, r/m32 | cmovnae reg64, r/m64 | cmovnae reg16, reg16, r/m16 | cmovnae reg32, reg32, r/m32 | cmovnae reg64, reg64, r/m64

cmovnb Move if not below (CF == 0)

CMOV moves its source (second) operand into its destination (first) operand if the given condition code is satisfied; otherwise it does nothing.

For a list of condition codes, see the condition codes.

Although the CMOV instructions are flagged P6 and above, they may not be supported by all Pentium Pro processors; the CPUID instruction (CPUID) will return a bit which indicates whether conditional moves are supported.

cmovnb reg16, r/m16 | cmovnb reg32, r/m32 | cmovnb reg64, r/m64 | cmovnb reg16, reg16, r/m16 | cmovnb reg32, reg32, r/m32 | cmovnb reg64, reg64, r/m64

cmovnbe Move if not below or equal (CF == 0 and ZF == 0)

CMOV moves its source (second) operand into its destination (first) operand if the given condition code is satisfied; otherwise it does nothing.

For a list of condition codes, see the condition codes.

Although the CMOV instructions are flagged P6 and above, they may not be supported by all Pentium Pro processors; the CPUID instruction (CPUID) will return a bit which indicates whether conditional moves are supported.

cmovnbe reg16, r/m16 | cmovnbe reg32, r/m32 | cmovnbe reg64, r/m64 | cmovnbe reg16, reg16, r/m16 | cmovnbe reg32, reg32, r/m32 | cmovnbe reg64, reg64, r/m64

cmovnc Move if not carry (CF == 0)

CMOV moves its source (second) operand into its destination (first) operand if the given condition code is satisfied; otherwise it does nothing.

For a list of condition codes, see the condition codes.

Although the CMOV instructions are flagged P6 and above, they may not be supported by all Pentium Pro processors; the CPUID instruction (CPUID) will return a bit which indicates whether conditional moves are supported.

cmovnc reg16, r/m16 | cmovnc reg32, r/m32 | cmovnc reg64, r/m64 | cmovnc reg16, reg16, r/m16 | cmovnc reg32, reg32, r/m32 | cmovnc reg64, reg64, r/m64

cmovne Move if not equal (ZF == 0)

CMOV moves its source (second) operand into its destination (first) operand if the given condition code is satisfied; otherwise it does nothing.

For a list of condition codes, see the condition codes.

Although the CMOV instructions are flagged P6 and above, they may not be supported by all Pentium Pro processors; the CPUID instruction (CPUID) will return a bit which indicates whether conditional moves are supported.

cmovne reg16, r/m16 | cmovne reg32, r/m32 | cmovne reg64, r/m64 | cmovne reg16, reg16, r/m16 | cmovne reg32, reg32, r/m32 | cmovne reg64, reg64, r/m64

cmovng Move if not greater (ZF == 1 or SF != OF)

CMOV moves its source (second) operand into its destination (first) operand if the given condition code is satisfied; otherwise it does nothing.

For a list of condition codes, see the condition codes.

Although the CMOV instructions are flagged P6 and above, they may not be supported by all Pentium Pro processors; the CPUID instruction (CPUID) will return a bit which indicates whether conditional moves are supported.

cmovng reg16, r/m16 | cmovng reg32, r/m32 | cmovng reg64, r/m64 | cmovng reg16, reg16, r/m16 | cmovng reg32, reg32, r/m32 | cmovng reg64, reg64, r/m64

cmovnge Move if not greater or equal (SF != OF)

CMOV moves its source (second) operand into its destination (first) operand if the given condition code is satisfied; otherwise it does nothing.

For a list of condition codes, see the condition codes.

Although the CMOV instructions are flagged P6 and above, they may not be supported by all Pentium Pro processors; the CPUID instruction (CPUID) will return a bit which indicates whether conditional moves are supported.

cmovnge reg16, r/m16 | cmovnge reg32, r/m32 | cmovnge reg64, r/m64 | cmovnge reg16, reg16, r/m16 | cmovnge reg32, reg32, r/m32 | cmovnge reg64, reg64, r/m64

cmovnl Move if not less (SF == OF)

CMOV moves its source (second) operand into its destination (first) operand if the given condition code is satisfied; otherwise it does nothing.

For a list of condition codes, see the condition codes.

Although the CMOV instructions are flagged P6 and above, they may not be supported by all Pentium Pro processors; the CPUID instruction (CPUID) will return a bit which indicates whether conditional moves are supported.

cmovnl reg16, r/m16 | cmovnl reg32, r/m32 | cmovnl reg64, r/m64 | cmovnl reg16, reg16, r/m16 | cmovnl reg32, reg32, r/m32 | cmovnl reg64, reg64, r/m64

cmovnle Move if not less or equal (ZF == 0 and SF == OF)

CMOV moves its source (second) operand into its destination (first) operand if the given condition code is satisfied; otherwise it does nothing.

For a list of condition codes, see the condition codes.

Although the CMOV instructions are flagged P6 and above, they may not be supported by all Pentium Pro processors; the CPUID instruction (CPUID) will return a bit which indicates whether conditional moves are supported.

cmovnle reg16, r/m16 | cmovnle reg32, r/m32 | cmovnle reg64, r/m64 | cmovnle reg16, reg16, r/m16 | cmovnle reg32, reg32, r/m32 | cmovnle reg64, reg64, r/m64

cmovno Move if not overflow (OF == 0)

CMOV moves its source (second) operand into its destination (first) operand if the given condition code is satisfied; otherwise it does nothing.

For a list of condition codes, see the condition codes.

Although the CMOV instructions are flagged P6 and above, they may not be supported by all Pentium Pro processors; the CPUID instruction (CPUID) will return a bit which indicates whether conditional moves are supported.

cmovno reg16, r/m16 | cmovno reg32, r/m32 | cmovno reg64, r/m64 | cmovno reg16, reg16, r/m16 | cmovno reg32, reg32, r/m32 | cmovno reg64, reg64, r/m64

cmovnp Move if not parity (PF == 0)

CMOV moves its source (second) operand into its destination (first) operand if the given condition code is satisfied; otherwise it does nothing.

For a list of condition codes, see the condition codes.

Although the CMOV instructions are flagged P6 and above, they may not be supported by all Pentium Pro processors; the CPUID instruction (CPUID) will return a bit which indicates whether conditional moves are supported.

cmovnp reg16, r/m16 | cmovnp reg32, r/m32 | cmovnp reg64, r/m64 | cmovnp reg16, reg16, r/m16 | cmovnp reg32, reg32, r/m32 | cmovnp reg64, reg64, r/m64

cmovns Move if not sign (SF == 0)

CMOV moves its source (second) operand into its destination (first) operand if the given condition code is satisfied; otherwise it does nothing.

For a list of condition codes, see the condition codes.

Although the CMOV instructions are flagged P6 and above, they may not be supported by all Pentium Pro processors; the CPUID instruction (CPUID) will return a bit which indicates whether conditional moves are supported.

cmovns reg16, r/m16 | cmovns reg32, r/m32 | cmovns reg64, r/m64 | cmovns reg16, reg16, r/m16 | cmovns reg32, reg32, r/m32 | cmovns reg64, reg64, r/m64

cmovnz Move if not zero (ZF == 0)

CMOV moves its source (second) operand into its destination (first) operand if the given condition code is satisfied; otherwise it does nothing.

For a list of condition codes, see the condition codes.

Although the CMOV instructions are flagged P6 and above, they may not be supported by all Pentium Pro processors; the CPUID instruction (CPUID) will return a bit which indicates whether conditional moves are supported.

cmovnz reg16, r/m16 | cmovnz reg32, r/m32 | cmovnz reg64, r/m64 | cmovnz reg16, reg16, r/m16 | cmovnz reg32, reg32, r/m32 | cmovnz reg64, reg64, r/m64

cmovo Move if overflow (OF == 1)

CMOV moves its source (second) operand into its destination (first) operand if the given condition code is satisfied; otherwise it does nothing.

For a list of condition codes, see the condition codes.

Although the CMOV instructions are flagged P6 and above, they may not be supported by all Pentium Pro processors; the CPUID instruction (CPUID) will return a bit which indicates whether conditional moves are supported.

cmovo reg16, r/m16 | cmovo reg32, r/m32 | cmovo reg64, r/m64 | cmovo reg16, reg16, r/m16 | cmovo reg32, reg32, r/m32 | cmovo reg64, reg64, r/m64

cmovp Move if parity (PF == 1)

CMOV moves its source (second) operand into its destination (first) operand if the given condition code is satisfied; otherwise it does nothing.

For a list of condition codes, see the condition codes.

Although the CMOV instructions are flagged P6 and above, they may not be supported by all Pentium Pro processors; the CPUID instruction (CPUID) will return a bit which indicates whether conditional moves are supported.

cmovp reg16, r/m16 | cmovp reg32, r/m32 | cmovp reg64, r/m64 | cmovp reg16, reg16, r/m16 | cmovp reg32, reg32, r/m32 | cmovp reg64, reg64, r/m64

cmovpe Move if parity even (PF == 1)

CMOV moves its source (second) operand into its destination (first) operand if the given condition code is satisfied; otherwise it does nothing.

For a list of condition codes, see the condition codes.

Although the CMOV instructions are flagged P6 and above, they may not be supported by all Pentium Pro processors; the CPUID instruction (CPUID) will return a bit which indicates whether conditional moves are supported.

cmovpe reg16, r/m16 | cmovpe reg32, r/m32 | cmovpe reg64, r/m64 | cmovpe reg16, reg16, r/m16 | cmovpe reg32, reg32, r/m32 | cmovpe reg64, reg64, r/m64

cmovpo Move if parity odd (PF == 0)

CMOV moves its source (second) operand into its destination (first) operand if the given condition code is satisfied; otherwise it does nothing.

For a list of condition codes, see the condition codes.

Although the CMOV instructions are flagged P6 and above, they may not be supported by all Pentium Pro processors; the CPUID instruction (CPUID) will return a bit which indicates whether conditional moves are supported.

cmovpo reg16, r/m16 | cmovpo reg32, r/m32 | cmovpo reg64, r/m64 | cmovpo reg16, reg16, r/m16 | cmovpo reg32, reg32, r/m32 | cmovpo reg64, reg64, r/m64

cmovs Move if sign (SF == 1)

CMOV moves its source (second) operand into its destination (first) operand if the given condition code is satisfied; otherwise it does nothing.

For a list of condition codes, see the condition codes.

Although the CMOV instructions are flagged P6 and above, they may not be supported by all Pentium Pro processors; the CPUID instruction (CPUID) will return a bit which indicates whether conditional moves are supported.

cmovs reg16, r/m16 | cmovs reg32, r/m32 | cmovs reg64, r/m64 | cmovs reg16, reg16, r/m16 | cmovs reg32, reg32, r/m32 | cmovs reg64, reg64, r/m64

cmovz Move if zero (ZF == 1)

CMOV moves its source (second) operand into its destination (first) operand if the given condition code is satisfied; otherwise it does nothing.

For a list of condition codes, see the condition codes.

Although the CMOV instructions are flagged P6 and above, they may not be supported by all Pentium Pro processors; the CPUID instruction (CPUID) will return a bit which indicates whether conditional moves are supported.

cmovz reg16, r/m16 | cmovz reg32, r/m32 | cmovz reg64, r/m64 | cmovz reg16, reg16, r/m16 | cmovz reg32, reg32, r/m32 | cmovz reg64, reg64, r/m64

seta Set byte if above (CF == 0 and ZF == 0)

SETcc sets the given 8-bit operand to zero if its condition is not satisfied, and to 1 if it is.

seta r/m8 | seta reg64 | seta reg32

setae Set byte if above or equal (CF == 0)

SETcc sets the given 8-bit operand to zero if its condition is not satisfied, and to 1 if it is.

setae r/m8 | setae reg64 | setae reg32

setb Set byte if below (CF == 1)

SETcc sets the given 8-bit operand to zero if its condition is not satisfied, and to 1 if it is.

setb r/m8 | setb reg64 | setb reg32

setbe Set byte if below or equal (CF == 1 or ZF == 1)

SETcc sets the given 8-bit operand to zero if its condition is not satisfied, and to 1 if it is.

setbe r/m8 | setbe reg64 | setbe reg32

setc Set byte if carry (CF == 1)

SETcc sets the given 8-bit operand to zero if its condition is not satisfied, and to 1 if it is.

setc r/m8 | setc reg64 | setc reg32

sete Set byte if equal (ZF == 1)

SETcc sets the given 8-bit operand to zero if its condition is not satisfied, and to 1 if it is.

sete r/m8 | sete reg64 | sete reg32

setg Set byte if greater (ZF == 0 and SF == OF)

SETcc sets the given 8-bit operand to zero if its condition is not satisfied, and to 1 if it is.

setg r/m8 | setg reg64 | setg reg32

setge Set byte if greater or equal (SF == OF)

SETcc sets the given 8-bit operand to zero if its condition is not satisfied, and to 1 if it is.

setge r/m8 | setge reg64 | setge reg32

setl Set byte if less (SF != OF)

SETcc sets the given 8-bit operand to zero if its condition is not satisfied, and to 1 if it is.

setl r/m8 | setl reg64 | setl reg32

setle Set byte if less or equal (ZF == 1 or SF != OF)

SETcc sets the given 8-bit operand to zero if its condition is not satisfied, and to 1 if it is.

setle r/m8 | setle reg64 | setle reg32

setna Set byte if not above (CF == 1 or ZF == 1)

SETcc sets the given 8-bit operand to zero if its condition is not satisfied, and to 1 if it is.

setna r/m8 | setna reg64 | setna reg32

setnae Set byte if not above or equal (CF == 1)

SETcc sets the given 8-bit operand to zero if its condition is not satisfied, and to 1 if it is.

setnae r/m8 | setnae reg64 | setnae reg32

setnb Set byte if not below (CF == 0)

SETcc sets the given 8-bit operand to zero if its condition is not satisfied, and to 1 if it is.

setnb r/m8 | setnb reg64 | setnb reg32

setnbe Set byte if not below or equal (CF == 0 and ZF == 0)

SETcc sets the given 8-bit operand to zero if its condition is not satisfied, and to 1 if it is.

setnbe r/m8 | setnbe reg64 | setnbe reg32

setnc Set byte if not carry (CF == 0)

SETcc sets the given 8-bit operand to zero if its condition is not satisfied, and to 1 if it is.

setnc r/m8 | setnc reg64 | setnc reg32

setne Set byte if not equal (ZF == 0)

SETcc sets the given 8-bit operand to zero if its condition is not satisfied, and to 1 if it is.

setne r/m8 | setne reg64 | setne reg32

setng Set byte if not greater (ZF == 1 or SF != OF)

SETcc sets the given 8-bit operand to zero if its condition is not satisfied, and to 1 if it is.

setng r/m8 | setng reg64 | setng reg32

setnge Set byte if not greater or equal (SF != OF)

SETcc sets the given 8-bit operand to zero if its condition is not satisfied, and to 1 if it is.

setnge r/m8 | setnge reg64 | setnge reg32

setnl Set byte if not less (SF == OF)

SETcc sets the given 8-bit operand to zero if its condition is not satisfied, and to 1 if it is.

setnl r/m8 | setnl reg64 | setnl reg32

setnle Set byte if not less or equal (ZF == 0 and SF == OF)

SETcc sets the given 8-bit operand to zero if its condition is not satisfied, and to 1 if it is.

setnle r/m8 | setnle reg64 | setnle reg32

setno Set byte if not overflow (OF == 0)

SETcc sets the given 8-bit operand to zero if its condition is not satisfied, and to 1 if it is.

setno r/m8 | setno reg64 | setno reg32

setnp Set byte if not parity (PF == 0)

SETcc sets the given 8-bit operand to zero if its condition is not satisfied, and to 1 if it is.

setnp r/m8 | setnp reg64 | setnp reg32

setns Set byte if not sign (SF == 0)

SETcc sets the given 8-bit operand to zero if its condition is not satisfied, and to 1 if it is.

setns r/m8 | setns reg64 | setns reg32

setnz Set byte if not zero (ZF == 0)

SETcc sets the given 8-bit operand to zero if its condition is not satisfied, and to 1 if it is.

setnz r/m8 | setnz reg64 | setnz reg32

seto Set byte if overflow (OF == 1)

SETcc sets the given 8-bit operand to zero if its condition is not satisfied, and to 1 if it is.

seto r/m8 | seto reg64 | seto reg32

setp Set byte if parity (PF == 1)

SETcc sets the given 8-bit operand to zero if its condition is not satisfied, and to 1 if it is.

setp r/m8 | setp reg64 | setp reg32

setpe Set byte if parity even (PF == 1)

SETcc sets the given 8-bit operand to zero if its condition is not satisfied, and to 1 if it is.

setpe r/m8 | setpe reg64 | setpe reg32

setpo Set byte if parity odd (PF == 0)

SETcc sets the given 8-bit operand to zero if its condition is not satisfied, and to 1 if it is.

setpo r/m8 | setpo reg64 | setpo reg32

sets Set byte if sign (SF == 1)

SETcc sets the given 8-bit operand to zero if its condition is not satisfied, and to 1 if it is.

sets r/m8 | sets reg64 | sets reg32

setz Set byte if zero (ZF == 1)

SETcc sets the given 8-bit operand to zero if its condition is not satisfied, and to 1 if it is.

setz r/m8 | setz reg64 | setz reg32

Call and return

call Call Procedure

CALL calls a subroutine, by means of pushing the current instruction pointer (IP) and optionally CS as well on the stack, and then jumping to a given address.

CS is pushed as well as IP if and only if the call is a far call, i.e. a destination segment address is specified in the instruction. The forms involving two colon-separated arguments are far calls; so are the CALL FAR mem forms.

The immediate near call takes one of two forms (call imm16/imm32, determined by the current segment size limit. For 16-bit operands, you would use CALL 0x1234, and for 32-bit operands you would use CALL 0x12345678. The value passed as an operand is a relative offset.

You can choose between the two immediate far call forms (CALL imm:imm) by the use of the WORD and DWORD keywords: CALL WORD 0x1234:0x5678) or CALL DWORD 0x1234:0x56789abc.

The CALL FAR mem forms execute a far call by loading the destination address out of memory. The address loaded consists of 16 or 32 bits of offset (depending on the operand size), and 16 bits of segment. The operand size may be overridden using \c{CALL WORD FAR mem} or CALL DWORD FAR mem.

The CALL r/m forms execute a near call (within the same segment), loading the destination address out of memory or out of a register. The keyword NEAR may be specified, for clarity, in these forms, but is not necessary. Again, operand size can be overridden using CALL WORD mem or CALL DWORD mem.

As a convenience, NASM does not require you to call a far procedure symbol by coding the cumbersome CALL SEG routine:routine, but instead allows the easier synonym CALL FAR routine.

The CALL r/m forms given above are near calls; NASM will accept the NEAR keyword (e.g. CALL NEAR [address]), even though it is not strictly necessary.

call imm16 {near} | call imm32 {near} | call imm64 {near} | call r/m16 {near} | call r/m32 {near} | call r/m64 {near}

ret Return from Procedure

  • RET, and its exact synonym RETN, pop IP or EIP from the stack and transfer control to the new address. Optionally, if a numeric second operand is provided, they increment the stack pointer by a further imm16 bytes after popping the return address.

  • RETF executes a far return: after popping IP/EIP, it then pops CS, and then increments the stack pointer by the optional argument if present.

ret | ret imm16
  • RET, and its exact synonym RETN, pop IP or EIP from the stack and transfer control to the new address. Optionally, if a numeric second operand is provided, they increment the stack pointer by a further imm16 bytes after popping the return address.

  • RETF executes a far return: after popping IP/EIP, it then pops CS, and then increments the stack pointer by the optional argument if present.

retd | retd imm16
  • RET, and its exact synonym RETN, pop IP or EIP from the stack and transfer control to the new address. Optionally, if a numeric second operand is provided, they increment the stack pointer by a further imm16 bytes after popping the return address.

  • RETF executes a far return: after popping IP/EIP, it then pops CS, and then increments the stack pointer by the optional argument if present.

retf | retf imm16
  • RET, and its exact synonym RETN, pop IP or EIP from the stack and transfer control to the new address. Optionally, if a numeric second operand is provided, they increment the stack pointer by a further imm16 bytes after popping the return address.

  • RETF executes a far return: after popping IP/EIP, it then pops CS, and then increments the stack pointer by the optional argument if present.

retfd | retfd imm16
  • RET, and its exact synonym RETN, pop IP or EIP from the stack and transfer control to the new address. Optionally, if a numeric second operand is provided, they increment the stack pointer by a further imm16 bytes after popping the return address.

  • RETF executes a far return: after popping IP/EIP, it then pops CS, and then increments the stack pointer by the optional argument if present.

retfq | retfq imm16
  • RET, and its exact synonym RETN, pop IP or EIP from the stack and transfer control to the new address. Optionally, if a numeric second operand is provided, they increment the stack pointer by a further imm16 bytes after popping the return address.

  • RETF executes a far return: after popping IP/EIP, it then pops CS, and then increments the stack pointer by the optional argument if present.

retfw | retfw imm16
  • RET, and its exact synonym RETN, pop IP or EIP from the stack and transfer control to the new address. Optionally, if a numeric second operand is provided, they increment the stack pointer by a further imm16 bytes after popping the return address.

  • RETF executes a far return: after popping IP/EIP, it then pops CS, and then increments the stack pointer by the optional argument if present.

retn | retn imm16
  • RET, and its exact synonym RETN, pop IP or EIP from the stack and transfer control to the new address. Optionally, if a numeric second operand is provided, they increment the stack pointer by a further imm16 bytes after popping the return address.

  • RETF executes a far return: after popping IP/EIP, it then pops CS, and then increments the stack pointer by the optional argument if present.

retnd | retnd imm16
  • RET, and its exact synonym RETN, pop IP or EIP from the stack and transfer control to the new address. Optionally, if a numeric second operand is provided, they increment the stack pointer by a further imm16 bytes after popping the return address.

  • RETF executes a far return: after popping IP/EIP, it then pops CS, and then increments the stack pointer by the optional argument if present.

retnq | retnq imm16
  • RET, and its exact synonym RETN, pop IP or EIP from the stack and transfer control to the new address. Optionally, if a numeric second operand is provided, they increment the stack pointer by a further imm16 bytes after popping the return address.

  • RETF executes a far return: after popping IP/EIP, it then pops CS, and then increments the stack pointer by the optional argument if present.

retnw | retnw imm16
  • RET, and its exact synonym RETN, pop IP or EIP from the stack and transfer control to the new address. Optionally, if a numeric second operand is provided, they increment the stack pointer by a further imm16 bytes after popping the return address.

  • RETF executes a far return: after popping IP/EIP, it then pops CS, and then increments the stack pointer by the optional argument if present.

retq | retq imm16
  • RET, and its exact synonym RETN, pop IP or EIP from the stack and transfer control to the new address. Optionally, if a numeric second operand is provided, they increment the stack pointer by a further imm16 bytes after popping the return address.

  • RETF executes a far return: after popping IP/EIP, it then pops CS, and then increments the stack pointer by the optional argument if present.

retw | retw imm16

Interrupts, system calls, and returns

brkpt

INT1 and INT3 are short one-byte forms of the instructions INT 1 and INT 3 (see INT). They perform a similar function to their longer counterparts, but take up less code space. They are used as breakpoints by debuggers.

  • INT1, and its alternative synonyms INT01 and ICEBP, is an instruction used by in-circuit emulators (ICEs). It is present, though not documented, on some processors down to the 286, but is only documented for the Pentium Pro. INT3 is the instruction normally used as a breakpoint by debuggers.

  • INT3, and its synonym INT03, is not precisely equivalent to INT 3: the short form, since it is designed to be used as a breakpoint, bypasses the normal IOPL checks in virtual-8086 mode, and also does not go through interrupt redirection.

icebp

int Call to Interrupt Procedure

INT causes a software interrupt through a specified vector number from 0 to 255.

The code generated by the INT instruction is always two bytes long: although there are short forms for some INT instructions, NASM does not generate them when it sees the INT mnemonic. In order to generate single-byte breakpoint instructions, use the INT3 or INT1 instructions (see INT1) instead.

int imm8

INT1 and INT3 are short one-byte forms of the instructions INT 1 and INT 3 (see INT). They perform a similar function to their longer counterparts, but take up less code space. They are used as breakpoints by debuggers.

  • INT1, and its alternative synonyms INT01 and ICEBP, is an instruction used by in-circuit emulators (ICEs). It is present, though not documented, on some processors down to the 286, but is only documented for the Pentium Pro. INT3 is the instruction normally used as a breakpoint by debuggers.

  • INT3, and its synonym INT03, is not precisely equivalent to INT 3: the short form, since it is designed to be used as a breakpoint, bypasses the normal IOPL checks in virtual-8086 mode, and also does not go through interrupt redirection.

int01

INT1 and INT3 are short one-byte forms of the instructions INT 1 and INT 3 (see INT). They perform a similar function to their longer counterparts, but take up less code space. They are used as breakpoints by debuggers.

  • INT1, and its alternative synonyms INT01 and ICEBP, is an instruction used by in-circuit emulators (ICEs). It is present, though not documented, on some processors down to the 286, but is only documented for the Pentium Pro. INT3 is the instruction normally used as a breakpoint by debuggers.

  • INT3, and its synonym INT03, is not precisely equivalent to INT 3: the short form, since it is designed to be used as a breakpoint, bypasses the normal IOPL checks in virtual-8086 mode, and also does not go through interrupt redirection.

int03

INT1 and INT3 are short one-byte forms of the instructions INT 1 and INT 3 (see INT). They perform a similar function to their longer counterparts, but take up less code space. They are used as breakpoints by debuggers.

  • INT1, and its alternative synonyms INT01 and ICEBP, is an instruction used by in-circuit emulators (ICEs). It is present, though not documented, on some processors down to the 286, but is only documented for the Pentium Pro. INT3 is the instruction normally used as a breakpoint by debuggers.

  • INT3, and its synonym INT03, is not precisely equivalent to INT 3: the short form, since it is designed to be used as a breakpoint, bypasses the normal IOPL checks in virtual-8086 mode, and also does not go through interrupt redirection.

int1

int3 Interrupt 3 (debug trap)

INT1 and INT3 are short one-byte forms of the instructions INT 1 and INT 3 (see INT). They perform a similar function to their longer counterparts, but take up less code space. They are used as breakpoints by debuggers.

  • INT1, and its alternative synonyms INT01 and ICEBP, is an instruction used by in-circuit emulators (ICEs). It is present, though not documented, on some processors down to the 286, but is only documented for the Pentium Pro. INT3 is the instruction normally used as a breakpoint by debuggers.

  • INT3, and its synonym INT03, is not precisely equivalent to INT 3: the short form, since it is designed to be used as a breakpoint, bypasses the normal IOPL checks in virtual-8086 mode, and also does not go through interrupt redirection.

int3

INTO performs an INT 4 software interrupt (see INT) if and only if the overflow flag is set.

into

IRET returns from an interrupt (hardware or software) by means of popping IP (or EIP), CS and the flags off the stack and then continuing execution from the new CS:IP.

IRETW pops IP, CS and the flags as 2 bytes each, taking 6 bytes off the stack in total. IRETD pops EIP as 4 bytes, pops a further 4 bytes of which the top two are discarded and the bottom two go into CS, and pops the flags as 4 bytes as well, taking 12 bytes off the stack.

IRET is a shorthand for either IRETW or IRETD, depending on the default BITS setting at the time.

iret

IRET returns from an interrupt (hardware or software) by means of popping IP (or EIP), CS and the flags off the stack and then continuing execution from the new CS:IP.

IRETW pops IP, CS and the flags as 2 bytes each, taking 6 bytes off the stack in total. IRETD pops EIP as 4 bytes, pops a further 4 bytes of which the top two are discarded and the bottom two go into CS, and pops the flags as 4 bytes as well, taking 12 bytes off the stack.

IRET is a shorthand for either IRETW or IRETD, depending on the default BITS setting at the time.

iretd

IRET returns from an interrupt (hardware or software) by means of popping IP (or EIP), CS and the flags off the stack and then continuing execution from the new CS:IP.

IRETW pops IP, CS and the flags as 2 bytes each, taking 6 bytes off the stack in total. IRETD pops EIP as 4 bytes, pops a further 4 bytes of which the top two are discarded and the bottom two go into CS, and pops the flags as 4 bytes as well, taking 12 bytes off the stack.

IRET is a shorthand for either IRETW or IRETD, depending on the default BITS setting at the time.

iretq

IRET returns from an interrupt (hardware or software) by means of popping IP (or EIP), CS and the flags off the stack and then continuing execution from the new CS:IP.

IRETW pops IP, CS and the flags as 2 bytes each, taking 6 bytes off the stack in total. IRETD pops EIP as 4 bytes, pops a further 4 bytes of which the top two are discarded and the bottom two go into CS, and pops the flags as 4 bytes as well, taking 12 bytes off the stack.

IRET is a shorthand for either IRETW or IRETD, depending on the default BITS setting at the time.

iretw

syscall Fast System Call

Asks the operating system to do something. rax holds the call number, the arguments go in rdi, rsi, rdx, r10, r8 and r9 in that order, and the result comes back in rax, with a small negative number meaning an error. rcx and r11 are destroyed by the call itself, so anything kept in them has to be saved first.

Programs here run as Linux programs, so this is the only way a program reaches the console or the file system. The syscall page lists the calls this emulator implements.

syscall

SYSENTER executes a fast call to a level 0 system procedure or routine. Before using this instruction, various MSRs need to be set up:

  • SYSENTER_CS_MSR contains the 32-bit segment selector for the privilege level 0 code segment. (This value is also used to compute the segment selector of the privilege level 0 stack segment.)

  • SYSENTER_EIP_MSR contains the 32-bit offset into the privilege level 0 code segment to the first instruction of the selected operating procedure or routine.

  • SYSENTER_ESP_MSR contains the 32-bit stack pointer for the privilege level 0 stack.

SYSENTER performs the following sequence of operations:

  • Loads the segment selector from the SYSENTER_CS_MSR into the CS register.

  • Loads the instruction pointer from the SYSENTER_EIP_MSR into the EIP register.

  • Adds 8 to the value in SYSENTER_CS_MSR and loads it into the SS register.

  • Loads the stack pointer from the SYSENTER_ESP_MSR into the ESP register.

  • Switches to privilege level 0.

  • Clears the VM flag in the EFLAGS register, if the flag is set.

  • Begins executing the selected system procedure.

In particular, note that this instruction des not save the values of CS or (E)IP. If you need to return to the calling code, you need to write your code to cater for this.

For more information, see the Intel Architecture Software Developer's Manual, Volume 2.

sysenter

SYSEXIT executes a fast return to privilege level 3 user code. This instruction is a companion instruction to the SYSENTER instruction, and can only be executed by privilege level 0 code. Various registers need to be set up before calling this instruction:

  • SYSENTER_CS_MSR contains the 32-bit segment selector for the privilege level 0 code segment in which the processor is currently executing. (This value is used to compute the segment selectors for the privilege level 3 code and stack segments.)

  • EDX contains the 32-bit offset into the privilege level 3 code segment to the first instruction to be executed in the user code.

  • ECX contains the 32-bit stack pointer for the privilege level 3 stack.

SYSEXIT performs the following sequence of operations:

  • Adds 16 to the value in SYSENTER_CS_MSR and loads the sum into the CS selector register.

  • Loads the instruction pointer from the EDX register into the EIP register.

  • Adds 24 to the value in SYSENTER_CS_MSR and loads the sum into the SS selector register.

  • Loads the stack pointer from the ECX register into the ESP register.

  • Switches to privilege level 3.

  • Begins executing the user code at the EIP address.

For more information on the use of the SYSENTER and SYSEXIT instructions, see the Intel Architecture Software Developer's Manual, Volume 2.

sysexit

SYSRET is the return instruction used in conjunction with the SYSCALL instruction to provide fast entry/exit to an operating system.

  • The ECX register, which points to the next sequential instruction after the corresponding SYSCALL instruction, is copied into the EIP register.

  • Bits [63-48] of the STAR register specify the selector that is copied into the CS register.

  • Bits [63-48]+1000b of the STAR register specify the selector that is copied into the SS register.

  • Bits [1-0] of the SS register are set to 11b (RPL of 3) regardless of the value of bits [49-48] of the STAR register.

The CS and SS registers should not be modified by the operating system between the execution of the SYSCALL instruction and its corresponding SYSRET instruction.

For more information, see the SYSCALL and SYSRET Instruction Specification (AMD document number 21086.pdf).

sysret

Flag register instructions

clc Clear Carry Flag

These instructions clear various flags. CLC clears the carry flag; CLD clears the direction flag; CLI clears the interrupt flag (thus disabling interrupts); and CLTS clears the task-switched (TS) flag in CR0.

To set the carry, direction, or interrupt flags, use the STC, STD and STI instructions (STC). To invert the carry flag, use CMC (CMC).

clc

cld Clear Direction Flag

These instructions clear various flags. CLC clears the carry flag; CLD clears the direction flag; CLI clears the interrupt flag (thus disabling interrupts); and CLTS clears the task-switched (TS) flag in CR0.

To set the carry, direction, or interrupt flags, use the STC, STD and STI instructions (STC). To invert the carry flag, use CMC (CMC).

cld

These instructions clear various flags. CLC clears the carry flag; CLD clears the direction flag; CLI clears the interrupt flag (thus disabling interrupts); and CLTS clears the task-switched (TS) flag in CR0.

To set the carry, direction, or interrupt flags, use the STC, STD and STI instructions (STC). To invert the carry flag, use CMC (CMC).

cli

cmc Complement Carry Flag

CMC changes the value of the carry flag: if it was 0, it sets it to 1, and vice versa.

cmc

lahf Load AH from Flags

LAHF sets the AH register according to the contents of the low byte of the flags word.

The operation of LAHF is:

 AH <-- SF:ZF:0:AF:0:PF:1:CF

See also SAHF (SAHF).

lahf
  • POPFW pops a word from the stack and stores it in the bottom 16 bits of the flags register (or the whole flags register, on processors below a 386).

  • POPFD pops a doubleword and stores it in the entire flags register.

POPF is an alias mnemonic for either POPFW or POPFD, depending on the current BITS setting.

See also PUSHF (PUSHF).

popf
  • POPFW pops a word from the stack and stores it in the bottom 16 bits of the flags register (or the whole flags register, on processors below a 386).

  • POPFD pops a doubleword and stores it in the entire flags register.

POPF is an alias mnemonic for either POPFW or POPFD, depending on the current BITS setting.

See also PUSHF (PUSHF).

popfd
  • POPFW pops a word from the stack and stores it in the bottom 16 bits of the flags register (or the whole flags register, on processors below a 386).

  • POPFD pops a doubleword and stores it in the entire flags register.

POPF is an alias mnemonic for either POPFW or POPFD, depending on the current BITS setting.

See also PUSHF (PUSHF).

popfq
  • POPFW pops a word from the stack and stores it in the bottom 16 bits of the flags register (or the whole flags register, on processors below a 386).

  • POPFD pops a doubleword and stores it in the entire flags register.

POPF is an alias mnemonic for either POPFW or POPFD, depending on the current BITS setting.

See also PUSHF (PUSHF).

popfw
  • PUSHFW pushes the bottom 16 bits of the flags register (or the whole flags register, on processors below a 386) onto the stack.

  • PUSHFD pushes the entire flags register onto the stack.

PUSHF is an alias mnemonic for either PUSHFW or PUSHFD, depending on the current BITS setting.

See also POPF (POPF).

pushf
  • PUSHFW pushes the bottom 16 bits of the flags register (or the whole flags register, on processors below a 386) onto the stack.

  • PUSHFD pushes the entire flags register onto the stack.

PUSHF is an alias mnemonic for either PUSHFW or PUSHFD, depending on the current BITS setting.

See also POPF (POPF).

pushfd
  • PUSHFW pushes the bottom 16 bits of the flags register (or the whole flags register, on processors below a 386) onto the stack.

  • PUSHFD pushes the entire flags register onto the stack.

PUSHF is an alias mnemonic for either PUSHFW or PUSHFD, depending on the current BITS setting.

See also POPF (POPF).

pushfq
  • PUSHFW pushes the bottom 16 bits of the flags register (or the whole flags register, on processors below a 386) onto the stack.

  • PUSHFD pushes the entire flags register onto the stack.

PUSHF is an alias mnemonic for either PUSHFW or PUSHFD, depending on the current BITS setting.

See also POPF (POPF).

pushfw

sahf Store AH into Flags

SAHF sets the low byte of the flags word according to the contents of the AH register.

The operation of SAHF is:

 AH --> SF:ZF:0:AF:0:PF:1:CF

See also LAHF (LAHF).

sahf

SALC is an early undocumented instruction similar in concept to SETcc (SETcc). Its function is to set AL to zero if the carry flag is clear, or to 0xFF if it is set.

salc

stc Set Carry Flag

These instructions set various flags. STC sets the carry flag; STD sets the direction flag; and STI sets the interrupt flag (thus enabling interrupts).

To clear the carry, direction, or interrupt flags, use the CLC, CLD and CLI instructions (CLC). To invert the carry flag, use CMC (CMC).

stc

std Set Direction Flag

These instructions set various flags. STC sets the carry flag; STD sets the direction flag; and STI sets the interrupt flag (thus enabling interrupts).

To clear the carry, direction, or interrupt flags, use the CLC, CLD and CLI instructions (CLC). To invert the carry flag, use CMC (CMC).

std

These instructions set various flags. STC sets the carry flag; STD sets the direction flag; and STI sets the interrupt flag (thus enabling interrupts).

To clear the carry, direction, or interrupt flags, use the CLC, CLD and CLI instructions (CLC). To invert the carry flag, use CMC (CMC).

sti

String instructions

CMPSB compares the byte at [DS:SI] or [DS:ESI] with the byte at [ES:DI] or [ES:EDI], and sets the flags accordingly. It then increments or decrements (depending on the direction flag: increments if the flag is clear, decrements if it is set) SI and DI (or ESI and EDI).

The registers used are SI and DI if the address size is 16 bits, and ESI and EDI if it is 32 bits. If you need to use an address size not equal to the current BITS setting, you can use an explicit a16 or a32 prefix.

The segment register used to load from [SI] or [ESI] can be overridden by using a segment register name as a prefix (for example, ES CMPSB). The use of ES for the load from [DI] or [EDI] cannot be overridden.

CMPSW and CMPSD work in the same way, but they compare a word or a doubleword instead of a byte, and increment or decrement the addressing registers by 2 or 4 instead of 1.

The REPE and REPNE prefixes (equivalently, REPZ and REPNZ) may be used to repeat the instruction up to CX (or ECX - again, the address size chooses which) times until the first unequal or equal byte is found.

cmpsb

cmpsd Compare Scalar Double-Precision Floating-Point Values

CMPSB compares the byte at [DS:SI] or [DS:ESI] with the byte at [ES:DI] or [ES:EDI], and sets the flags accordingly. It then increments or decrements (depending on the direction flag: increments if the flag is clear, decrements if it is set) SI and DI (or ESI and EDI).

The registers used are SI and DI if the address size is 16 bits, and ESI and EDI if it is 32 bits. If you need to use an address size not equal to the current BITS setting, you can use an explicit a16 or a32 prefix.

The segment register used to load from [SI] or [ESI] can be overridden by using a segment register name as a prefix (for example, ES CMPSB). The use of ES for the load from [DI] or [EDI] cannot be overridden.

CMPSW and CMPSD work in the same way, but they compare a word or a doubleword instead of a byte, and increment or decrement the addressing registers by 2 or 4 instead of 1.

The REPE and REPNE prefixes (equivalently, REPZ and REPNZ) may be used to repeat the instruction up to CX (or ECX - again, the address size chooses which) times until the first unequal or equal byte is found.

cmpsd | cmpsd xmmreg, xmmreg/mem128, imm8

CMPSB compares the byte at [DS:SI] or [DS:ESI] with the byte at [ES:DI] or [ES:EDI], and sets the flags accordingly. It then increments or decrements (depending on the direction flag: increments if the flag is clear, decrements if it is set) SI and DI (or ESI and EDI).

The registers used are SI and DI if the address size is 16 bits, and ESI and EDI if it is 32 bits. If you need to use an address size not equal to the current BITS setting, you can use an explicit a16 or a32 prefix.

The segment register used to load from [SI] or [ESI] can be overridden by using a segment register name as a prefix (for example, ES CMPSB). The use of ES for the load from [DI] or [EDI] cannot be overridden.

CMPSW and CMPSD work in the same way, but they compare a word or a doubleword instead of a byte, and increment or decrement the addressing registers by 2 or 4 instead of 1.

The REPE and REPNE prefixes (equivalently, REPZ and REPNZ) may be used to repeat the instruction up to CX (or ECX - again, the address size chooses which) times until the first unequal or equal byte is found.

cmpsq

CMPSB compares the byte at [DS:SI] or [DS:ESI] with the byte at [ES:DI] or [ES:EDI], and sets the flags accordingly. It then increments or decrements (depending on the direction flag: increments if the flag is clear, decrements if it is set) SI and DI (or ESI and EDI).

The registers used are SI and DI if the address size is 16 bits, and ESI and EDI if it is 32 bits. If you need to use an address size not equal to the current BITS setting, you can use an explicit a16 or a32 prefix.

The segment register used to load from [SI] or [ESI] can be overridden by using a segment register name as a prefix (for example, ES CMPSB). The use of ES for the load from [DI] or [EDI] cannot be overridden.

CMPSW and CMPSD work in the same way, but they compare a word or a doubleword instead of a byte, and increment or decrement the addressing registers by 2 or 4 instead of 1.

The REPE and REPNE prefixes (equivalently, REPZ and REPNZ) may be used to repeat the instruction up to CX (or ECX - again, the address size chooses which) times until the first unequal or equal byte is found.

cmpsw

INSB inputs a byte from the I/O port specified in DX and stores it at [ES:DI] or [ES:EDI]. It then increments or decrements (depending on the direction flag: increments if the flag is clear, decrements if it is set) DI or EDI.

The register used is DI if the address size is 16 bits, and EDI if it is 32 bits. If you need to use an address size not equal to the current BITS setting, you can use an explicit a16 or a32 prefix.

Segment override prefixes have no effect for this instruction: the use of ES for the load from [DI] or [EDI] cannot be overridden.

INSW and INSD work in the same way, but they input a word or a doubleword instead of a byte, and increment or decrement the addressing register by 2 or 4 instead of 1.

The REP prefix may be used to repeat the instruction CX (or ECX - again, the address size chooses which) times.

See also OUTSB, OUTSW and OUTSD (OUTSB).

insb

INSB inputs a byte from the I/O port specified in DX and stores it at [ES:DI] or [ES:EDI]. It then increments or decrements (depending on the direction flag: increments if the flag is clear, decrements if it is set) DI or EDI.

The register used is DI if the address size is 16 bits, and EDI if it is 32 bits. If you need to use an address size not equal to the current BITS setting, you can use an explicit a16 or a32 prefix.

Segment override prefixes have no effect for this instruction: the use of ES for the load from [DI] or [EDI] cannot be overridden.

INSW and INSD work in the same way, but they input a word or a doubleword instead of a byte, and increment or decrement the addressing register by 2 or 4 instead of 1.

The REP prefix may be used to repeat the instruction CX (or ECX - again, the address size chooses which) times.

See also OUTSB, OUTSW and OUTSD (OUTSB).

insd

INSB inputs a byte from the I/O port specified in DX and stores it at [ES:DI] or [ES:EDI]. It then increments or decrements (depending on the direction flag: increments if the flag is clear, decrements if it is set) DI or EDI.

The register used is DI if the address size is 16 bits, and EDI if it is 32 bits. If you need to use an address size not equal to the current BITS setting, you can use an explicit a16 or a32 prefix.

Segment override prefixes have no effect for this instruction: the use of ES for the load from [DI] or [EDI] cannot be overridden.

INSW and INSD work in the same way, but they input a word or a doubleword instead of a byte, and increment or decrement the addressing register by 2 or 4 instead of 1.

The REP prefix may be used to repeat the instruction CX (or ECX - again, the address size chooses which) times.

See also OUTSB, OUTSW and OUTSD (OUTSB).

insw

LODSB loads a byte from [DS:SI] or [DS:ESI] into AL. It then increments or decrements (depending on the direction flag: increments if the flag is clear, decrements if it is set) SI or ESI.

The register used is SI if the address size is 16 bits, and ESI if it is 32 bits. If you need to use an address size not equal to the current BITS setting, you can use an explicit a16 or a32 prefix.

The segment register used to load from [SI] or [ESI] can be overridden by using a segment register name as a prefix (for example, ES LODSB).

LODSW and LODSD work in the same way, but they load a word or a doubleword instead of a byte, and increment or decrement the addressing registers by 2 or 4 instead of 1.

lodsb

LODSB loads a byte from [DS:SI] or [DS:ESI] into AL. It then increments or decrements (depending on the direction flag: increments if the flag is clear, decrements if it is set) SI or ESI.

The register used is SI if the address size is 16 bits, and ESI if it is 32 bits. If you need to use an address size not equal to the current BITS setting, you can use an explicit a16 or a32 prefix.

The segment register used to load from [SI] or [ESI] can be overridden by using a segment register name as a prefix (for example, ES LODSB).

LODSW and LODSD work in the same way, but they load a word or a doubleword instead of a byte, and increment or decrement the addressing registers by 2 or 4 instead of 1.

lodsd

LODSB loads a byte from [DS:SI] or [DS:ESI] into AL. It then increments or decrements (depending on the direction flag: increments if the flag is clear, decrements if it is set) SI or ESI.

The register used is SI if the address size is 16 bits, and ESI if it is 32 bits. If you need to use an address size not equal to the current BITS setting, you can use an explicit a16 or a32 prefix.

The segment register used to load from [SI] or [ESI] can be overridden by using a segment register name as a prefix (for example, ES LODSB).

LODSW and LODSD work in the same way, but they load a word or a doubleword instead of a byte, and increment or decrement the addressing registers by 2 or 4 instead of 1.

lodsq

LODSB loads a byte from [DS:SI] or [DS:ESI] into AL. It then increments or decrements (depending on the direction flag: increments if the flag is clear, decrements if it is set) SI or ESI.

The register used is SI if the address size is 16 bits, and ESI if it is 32 bits. If you need to use an address size not equal to the current BITS setting, you can use an explicit a16 or a32 prefix.

The segment register used to load from [SI] or [ESI] can be overridden by using a segment register name as a prefix (for example, ES LODSB).

LODSW and LODSD work in the same way, but they load a word or a doubleword instead of a byte, and increment or decrement the addressing registers by 2 or 4 instead of 1.

lodsw

MOVSB copies the byte at [DS:SI] or [DS:ESI] to [ES:DI] or [ES:EDI]. It then increments or decrements (depending on the direction flag: increments if the flag is clear, decrements if it is set) SI and DI (or ESI and EDI).

The registers used are SI and DI if the address size is 16 bits, and ESI and EDI if it is 32 bits. If you need to use an address size not equal to the current BITS setting, you can use an explicit a16 or a32 prefix.

The segment register used to load from [SI] or [ESI] can be overridden by using a segment register name as a prefix (for example, es movsb). The use of ES for the store to [DI] or [EDI] cannot be overridden.

MOVSW and MOVSD work in the same way, but they copy a word or a doubleword instead of a byte, and increment or decrement the addressing registers by 2 or 4 instead of 1.

The REP prefix may be used to repeat the instruction CX (or ECX - again, the address size chooses which) times.

movsb

MOVSB copies the byte at [DS:SI] or [DS:ESI] to [ES:DI] or [ES:EDI]. It then increments or decrements (depending on the direction flag: increments if the flag is clear, decrements if it is set) SI and DI (or ESI and EDI).

The registers used are SI and DI if the address size is 16 bits, and ESI and EDI if it is 32 bits. If you need to use an address size not equal to the current BITS setting, you can use an explicit a16 or a32 prefix.

The segment register used to load from [SI] or [ESI] can be overridden by using a segment register name as a prefix (for example, es movsb). The use of ES for the store to [DI] or [EDI] cannot be overridden.

MOVSW and MOVSD work in the same way, but they copy a word or a doubleword instead of a byte, and increment or decrement the addressing registers by 2 or 4 instead of 1.

The REP prefix may be used to repeat the instruction CX (or ECX - again, the address size chooses which) times.

movsq

MOVSB copies the byte at [DS:SI] or [DS:ESI] to [ES:DI] or [ES:EDI]. It then increments or decrements (depending on the direction flag: increments if the flag is clear, decrements if it is set) SI and DI (or ESI and EDI).

The registers used are SI and DI if the address size is 16 bits, and ESI and EDI if it is 32 bits. If you need to use an address size not equal to the current BITS setting, you can use an explicit a16 or a32 prefix.

The segment register used to load from [SI] or [ESI] can be overridden by using a segment register name as a prefix (for example, es movsb). The use of ES for the store to [DI] or [EDI] cannot be overridden.

MOVSW and MOVSD work in the same way, but they copy a word or a doubleword instead of a byte, and increment or decrement the addressing registers by 2 or 4 instead of 1.

The REP prefix may be used to repeat the instruction CX (or ECX - again, the address size chooses which) times.

movsw

OUTSB loads a byte from [DS:SI] or [DS:ESI] and writes it to the I/O port specified in DX. It then increments or decrements (depending on the direction flag: increments if the flag is clear, decrements if it is set) SI or ESI.

The register used is SI if the address size is 16 bits, and ESI if it is 32 bits. If you need to use an address size not equal to the current BITS setting, you can use an explicit a16 or a32 prefix.

The segment register used to load from [SI] or [ESI] can be overridden by using a segment register name as a prefix (for example, es outsb).

OUTSW and OUTSD work in the same way, but they output a word or a doubleword instead of a byte, and increment or decrement the addressing registers by 2 or 4 instead of 1.

The REP prefix may be used to repeat the instruction CX (or ECX - again, the address size chooses which) times.

outsb

OUTSB loads a byte from [DS:SI] or [DS:ESI] and writes it to the I/O port specified in DX. It then increments or decrements (depending on the direction flag: increments if the flag is clear, decrements if it is set) SI or ESI.

The register used is SI if the address size is 16 bits, and ESI if it is 32 bits. If you need to use an address size not equal to the current BITS setting, you can use an explicit a16 or a32 prefix.

The segment register used to load from [SI] or [ESI] can be overridden by using a segment register name as a prefix (for example, es outsb).

OUTSW and OUTSD work in the same way, but they output a word or a doubleword instead of a byte, and increment or decrement the addressing registers by 2 or 4 instead of 1.

The REP prefix may be used to repeat the instruction CX (or ECX - again, the address size chooses which) times.

outsd

OUTSB loads a byte from [DS:SI] or [DS:ESI] and writes it to the I/O port specified in DX. It then increments or decrements (depending on the direction flag: increments if the flag is clear, decrements if it is set) SI or ESI.

The register used is SI if the address size is 16 bits, and ESI if it is 32 bits. If you need to use an address size not equal to the current BITS setting, you can use an explicit a16 or a32 prefix.

The segment register used to load from [SI] or [ESI] can be overridden by using a segment register name as a prefix (for example, es outsb).

OUTSW and OUTSD work in the same way, but they output a word or a doubleword instead of a byte, and increment or decrement the addressing registers by 2 or 4 instead of 1.

The REP prefix may be used to repeat the instruction CX (or ECX - again, the address size chooses which) times.

outsw

SCASB compares the byte in AL with the byte at [ES:DI] or [ES:EDI], and sets the flags accordingly. It then increments or decrements (depending on the direction flag: increments if the flag is clear, decrements if it is set) DI (or EDI).

The register used is DI if the address size is 16 bits, and EDI if it is 32 bits. If you need to use an address size not equal to the current BITS setting, you can use an explicit a16 or a32 prefix.

Segment override prefixes have no effect for this instruction: the use of ES for the load from [DI] or [EDI] cannot be overridden.

SCASW and SCASD work in the same way, but they compare a word to AX or a doubleword to EAX instead of a byte to AL, and increment or decrement the addressing registers by 2 or 4 instead of 1.

The REPE and REPNE prefixes (equivalently, REPZ and REPNZ) may be used to repeat the instruction up to CX (or ECX - again, the address size chooses which) times until the first unequal or equal byte is found.

scasb

SCASB compares the byte in AL with the byte at [ES:DI] or [ES:EDI], and sets the flags accordingly. It then increments or decrements (depending on the direction flag: increments if the flag is clear, decrements if it is set) DI (or EDI).

The register used is DI if the address size is 16 bits, and EDI if it is 32 bits. If you need to use an address size not equal to the current BITS setting, you can use an explicit a16 or a32 prefix.

Segment override prefixes have no effect for this instruction: the use of ES for the load from [DI] or [EDI] cannot be overridden.

SCASW and SCASD work in the same way, but they compare a word to AX or a doubleword to EAX instead of a byte to AL, and increment or decrement the addressing registers by 2 or 4 instead of 1.

The REPE and REPNE prefixes (equivalently, REPZ and REPNZ) may be used to repeat the instruction up to CX (or ECX - again, the address size chooses which) times until the first unequal or equal byte is found.

scasd

SCASB compares the byte in AL with the byte at [ES:DI] or [ES:EDI], and sets the flags accordingly. It then increments or decrements (depending on the direction flag: increments if the flag is clear, decrements if it is set) DI (or EDI).

The register used is DI if the address size is 16 bits, and EDI if it is 32 bits. If you need to use an address size not equal to the current BITS setting, you can use an explicit a16 or a32 prefix.

Segment override prefixes have no effect for this instruction: the use of ES for the load from [DI] or [EDI] cannot be overridden.

SCASW and SCASD work in the same way, but they compare a word to AX or a doubleword to EAX instead of a byte to AL, and increment or decrement the addressing registers by 2 or 4 instead of 1.

The REPE and REPNE prefixes (equivalently, REPZ and REPNZ) may be used to repeat the instruction up to CX (or ECX - again, the address size chooses which) times until the first unequal or equal byte is found.

scasq

SCASB compares the byte in AL with the byte at [ES:DI] or [ES:EDI], and sets the flags accordingly. It then increments or decrements (depending on the direction flag: increments if the flag is clear, decrements if it is set) DI (or EDI).

The register used is DI if the address size is 16 bits, and EDI if it is 32 bits. If you need to use an address size not equal to the current BITS setting, you can use an explicit a16 or a32 prefix.

Segment override prefixes have no effect for this instruction: the use of ES for the load from [DI] or [EDI] cannot be overridden.

SCASW and SCASD work in the same way, but they compare a word to AX or a doubleword to EAX instead of a byte to AL, and increment or decrement the addressing registers by 2 or 4 instead of 1.

The REPE and REPNE prefixes (equivalently, REPZ and REPNZ) may be used to repeat the instruction up to CX (or ECX - again, the address size chooses which) times until the first unequal or equal byte is found.

scasw

STOSB stores the byte in AL at [ES:DI] or [ES:EDI], and sets the flags accordingly. It then increments or decrements (depending on the direction flag: increments if the flag is clear, decrements if it is set) DI (or EDI).

The register used is DI if the address size is 16 bits, and EDI if it is 32 bits. If you need to use an address size not equal to the current BITS setting, you can use an explicit a16 or a32 prefix.

Segment override prefixes have no effect for this instruction: the use of ES for the store to [DI] or [EDI] cannot be overridden.

STOSW and STOSD work in the same way, but they store the word in AX or the doubleword in EAX instead of the byte in AL, and increment or decrement the addressing registers by 2 or 4 instead of 1.

The REP prefix may be used to repeat the instruction CX (or ECX - again, the address size chooses which) times.

stosb

STOSB stores the byte in AL at [ES:DI] or [ES:EDI], and sets the flags accordingly. It then increments or decrements (depending on the direction flag: increments if the flag is clear, decrements if it is set) DI (or EDI).

The register used is DI if the address size is 16 bits, and EDI if it is 32 bits. If you need to use an address size not equal to the current BITS setting, you can use an explicit a16 or a32 prefix.

Segment override prefixes have no effect for this instruction: the use of ES for the store to [DI] or [EDI] cannot be overridden.

STOSW and STOSD work in the same way, but they store the word in AX or the doubleword in EAX instead of the byte in AL, and increment or decrement the addressing registers by 2 or 4 instead of 1.

The REP prefix may be used to repeat the instruction CX (or ECX - again, the address size chooses which) times.

stosd

STOSB stores the byte in AL at [ES:DI] or [ES:EDI], and sets the flags accordingly. It then increments or decrements (depending on the direction flag: increments if the flag is clear, decrements if it is set) DI (or EDI).

The register used is DI if the address size is 16 bits, and EDI if it is 32 bits. If you need to use an address size not equal to the current BITS setting, you can use an explicit a16 or a32 prefix.

Segment override prefixes have no effect for this instruction: the use of ES for the store to [DI] or [EDI] cannot be overridden.

STOSW and STOSD work in the same way, but they store the word in AX or the doubleword in EAX instead of the byte in AL, and increment or decrement the addressing registers by 2 or 4 instead of 1.

The REP prefix may be used to repeat the instruction CX (or ECX - again, the address size chooses which) times.

stosq

STOSB stores the byte in AL at [ES:DI] or [ES:EDI], and sets the flags accordingly. It then increments or decrements (depending on the direction flag: increments if the flag is clear, decrements if it is set) DI (or EDI).

The register used is DI if the address size is 16 bits, and EDI if it is 32 bits. If you need to use an address size not equal to the current BITS setting, you can use an explicit a16 or a32 prefix.

Segment override prefixes have no effect for this instruction: the use of ES for the store to [DI] or [EDI] cannot be overridden.

STOSW and STOSD work in the same way, but they store the word in AX or the doubleword in EAX instead of the byte in AL, and increment or decrement the addressing registers by 2 or 4 instead of 1.

The REP prefix may be used to repeat the instruction CX (or ECX - again, the address size chooses which) times.

stosw

No operation

nop No Operation

NOP performs no operation. Its opcode is the same as that generated by XCHG AX,AX or XCHG EAX,EAX (depending on the processor mode; see XCHG).

nop | nop r/m16 | nop r/m32 | nop r/m64 | nop imm, reg16, r/m16 | nop imm, reg32, r/m32
nop2

Extensions

Everything else the assembler accepts, under the heading NASM files it under. These have no page of their own: the only description of them we are free to publish is the one line below, and blink implements a part of them.

RAO-INT weakly ordered atomic operations

aaddaandaoraxor

Interleaved flags arithmetic

adcxadox

AVX-512 mask register instructions

addbadddaddqaddwandbanddandnbandndandnqandnwandqandwkaddkaddbkadddkaddqkaddwkandkandbkanddkandnkandnbkandndkandnqkandnwkandqkandwkmovkmovbkmovdkmovqkmovwknotknotbknotdknotqknotwkorkorbkordkorqkortestkortestbkortestdkortestqkortestwkorwkshiftlkshiftlbkshiftldkshiftlqkshiftlwkshiftrkshiftrbkshiftrdkshiftrqkshiftrwkshlkshlbkshldkshlqkshlwkshrkshrbkshrdkshrqkshrwktestktestbktestdktestqktestwkunpckkunpckbwkunpckdkunpckdqkunpckqkunpckwkunpckwdkxnorkxnorbkxnordkxnorqkxnorwkxorkxorbkxordkxorqkxorwmovbmovwnotbnotdnotqnotworbordorqortestortestbortestdortestqortestworwshiftlshiftlbshiftldshiftlqshiftlwshiftrshiftrbshiftrdshiftrqshiftrwshlbshlqshlwshrbshrqshrwtestbtestdtestqtestwunpckunpckbwunpckdunpckdqunpckqunpckwunpckwdxnorxnorbxnordxnorqxnorwxorbxordxorqxorw

Willamette Streaming SIMD instructions (SSE2)

addpdaddsdandnpdandpdcmpeqpdcmpeqsdcmplepdcmplesdcmpltpdcmpltsdcmpneqpdcmpneqsdcmpnlepdcmpnlesdcmpnltpdcmpnltsdcmpordpdcmpordsdcmppdcmpunordpdcmpunordsdcomisdcvtdq2pdcvtdq2pscvtpd2dqcvtpd2picvtpd2pscvtpi2pdcvtps2dqcvtps2pdcvtsd2sicvtsd2sscvtsi2sdcvtss2sdcvttpd2dqcvttpd2picvttps2dqcvttsd2sidivpddivsdmaxpdmaxsdminpdminsdmovapdmovhpdmovlpdmovmskpdmovsdmovupdmulpdmulsdorpdshufpdsqrtpdsqrtsdsubpdsubsducomisdunpckhpdunpcklpdxorpd

Katmai Streaming SIMD instructions (SSE -- a.k.a. KNI, XMM, MMX2)

addpsaddssandnpsandpscmpeqpscmpeqsscmplepscmplesscmpltpscmpltsscmpneqpscmpneqsscmpnlepscmpnlesscmpnltpscmpnltsscmpordpscmpordsscmppscmpsscmpunordpscmpunordsscomisscvtpi2pscvtps2picvtsi2sscvtss2sicvttps2picvttss2sidivpsdivssldmxcsrmaxpsmaxssminpsminssmovapsmovhlpsmovhpsmovlhpsmovlpsmovmskpsmovntpsmovssmovupsmulpsmulssorpsrcppsrcpssrsqrtpsrsqrtssshufpssqrtpssqrtssstmxcsrsubpssubssucomissunpckhpsunpcklpsxorps

Prescott New Instructions (SSE3)

addsubpdaddsubpshaddpdhaddpshsubpdhsubpslddqumovddupmovshdupmovsldup

Intel AES instructions

aesdecaesdeclastaesencaesenclastaesimcaeskeygenassist

Intel AES Key Locker

aesdec128klaesdec256klaesdecwide128klaesdecwide256klaesenc128klaesenc256klaesencwide128klaesencwide256klencodekey128encodekey256loadiwkey

BMI1 and BMI2 bit operations

andnbextrblsiblsmskblsrbzhilzcntpdeppexttzcnt

Segment handling instructions

arpllarldsleslfslgdtlgslidtlkgslldtloadallloadall286lsllssltrrdfsbaserdgsbasesgdtsidtsldtstrswapgsverrverwwrfsbasewrgsbase

Machine control and management instructions

bb0_resetbb1_resetcltscpu_readcpu_writecpuiddmintlmswrdmrdmsrrdmsrlistsmintsmintoldsmswumovurdmsruwrmsrwrmsrwrmsrlistwrmsrns

AMD XOP bit operations

blcfillblciblcicblcmskblcsblsfillblsict1mskctzmsk

Penryn New Instructions (SSE4.1)

blendpdblendpsblendvpdblendvpsdppddppsextractpsinsertpsmovntdqampsadbwpackusdwpblendvbpblendwpcmpeqqpextrbpextrdpextrqpextrwphminposuwpinsrbpinsrdpinsrqpmaxsbpmaxsdpmaxudpmaxuwpminsbpminsdpminudpminuwpmovsxbdpmovsxbqpmovsxbwpmovsxdqpmovsxwdpmovsxwqpmovzxbdpmovzxbqpmovzxbwpmovzxdqpmovzxwdpmovzxwqpmuldqpmulldptestroundpdroundpsroundsdroundss

Intel Memory Protection Extensions (MPX)

bndclbndcnbndcubndldxbndmkbndmovbndstx

Permanently undefined instructions

ccmpccmpaccmpaeccmpbccmpbeccmpcccmpeccmpfccmpgccmpgeccmplccmpleccmpnaccmpnaeccmpnbccmpnbeccmpncccmpneccmpngccmpngeccmpnlccmpnleccmpnoccmpnsccmpnzccmpoccmpsccmptccmpzctestctestactestaectestbctestbectestcctestectestfctestgctestgectestlctestlectestnactestnaectestnbctestnbectestncctestnectestngctestngectestnlctestnlectestnoctestnsctestnzctestoctestsctesttctestzfwaitud0ud1ud2ud2aud2budbxlatxlatb

doc 319433-034 May 2018

cldemotemovdir64bmovdiripconfig

Memory management and control

clflushclflushoptclwbclzeroinvdinvlpginvlpgainvpcidpcommitwbinvdwbnoinvd

VMX/SVM Instructions

clgistgivmcallvmclearvmfuncvmlaunchvmloadvmmcallvmptrldvmptrstvmreadvmresumevmrunvmsavevmwritevmxoffvmxon

Intel Control-Flow Enforcement Technology (CET)

clrssbsyendbr32endbr64incsspdincsspqrdsspdrdsspqrstorsspsaveprevsspsetssbsywrssdwrssqwrussdwrussq

User interrupts

cluisenduipistuitestuiuiret

Nehalem New Instructions (SSE4.2)

crc32pcmpestripcmpestrmpcmpgtqpcmpistripcmpistrmpopcnt

MMX (SIMD using the x87 register file)

emmsmovdpackssdwpacksswbpackuswbpaddbpadddpaddsbpaddsiwpaddswpaddusbpadduswpaddwpandpandnpavebpavgusbpcmpeqbpcmpeqdpcmpeqwpcmpgtbpcmpgtdpcmpgtwpdistibpf2idpfaccpfaddpfcmpeqpfcmpgepfcmpgtpfmaxpfminpfmulpfrcppfrcpit1pfrcpit2pfrsqit1pfrsqrtpfsubpfsubrpi2fdpmachriwpmaddwdpmagwpmulhriwpmulhrwapmulhrwcpmulhwpmullwpmvgezbpmvlzbpmvnzbpmvzbporprefetchprefetchwpslldpsllqpsllwpsradpsrawpsrldpsrlqpsrlwpsubbpsubdpsubsbpsubsiwpsubswpsubusbpsubuswpsubwpunpckhbwpunpckhdqpunpckhwdpunpcklbwpunpckldqpunpcklwd

Intel Software Guard Extensions (SGX)

enclsencluenclv

Instructions from ISE doc 319433-040, June 2020

enqcmdenqcmdsxresldtrkxsusldtrk

AMD SSE4A

extrqinsertqmovntsdmovntss

x87 floating point

f2xm1fabsfaddfaddpfbldfbstpfchsfclexfcmovbfcmovbefcmovefcmovnbfcmovnbefcmovnefcmovnufcmovufcomfcomifcomipfcompfcomppfcosfdecstpfdisifdivfdivpfdivrfdivrpfemmsfeniffreeffreepfiaddficomficompfidivfidivrfildfimulfincstpfinitfistfistpfisttpfisubfisubrfldfld1fldcwfldenvfldl2efldl2tfldlg2fldln2fldpifldzfmulfmulpfnclexfndisifnenifninitfnopfnsavefnstcwfnstenvfnstswfpatanfpremfprem1fptanfrndintfrstorfsavefscalefsetpmfsinfsincosfsqrtfstfstcwfstenvfstpfstswfsubfsubpfsubrfsubrpftstfucomfucomifucomipfucompfucomppfxamfxchfxtractfyl2xfyl2xp1

Introduced in Deschutes but necessary for SSE support

fxrstorfxrstor64fxsavefxsave64

Intel SMX

getsec

Galois field operations (GFNI)

gf2p8affineinvqbgf2p8affineqbgf2p8mulbvgf2p8affineinvqbvgf2p8affineqbvgf2p8mulb

Systematic names for the hinting nop instructions

hint_nophint_nop0hint_nop1hint_nop10hint_nop11hint_nop12hint_nop13hint_nop14hint_nop15hint_nop16hint_nop17hint_nop18hint_nop19hint_nop2hint_nop20hint_nop21hint_nop22hint_nop23hint_nop24hint_nop25hint_nop26hint_nop27hint_nop28hint_nop29hint_nop3hint_nop30hint_nop31hint_nop32hint_nop33hint_nop34hint_nop35hint_nop36hint_nop37hint_nop38hint_nop39hint_nop4hint_nop40hint_nop41hint_nop42hint_nop43hint_nop44hint_nop45hint_nop46hint_nop47hint_nop48hint_nop49hint_nop5hint_nop50hint_nop51hint_nop52hint_nop53hint_nop54hint_nop55hint_nop56hint_nop57hint_nop58hint_nop59hint_nop6hint_nop60hint_nop61hint_nop62hint_nop63hint_nop7hint_nop8hint_nop9

Power management

hltmonitormonitordmonitorqmonitorwmonitorxmwaitmwaitxpausetpauseumonitorumwait

History reset

hreset

I/O instructions

inout

Extended Page Tables VMX instructions

inveptinvvpid

Intel Advanced Matrix Extensions (AMX)

ldtilecfgsttilecfgt2rpntlvwz0t2rpntlvwz0rst2rpntlvwz0rst1t2rpntlvwz0t1t2rpntlvwz1t2rpntlvwz1rst2rpntlvwz1rst1t2rpntlvwz1t1tcmmimfp16pstcmmrlfp16pstconjtcmmimfp16pstconjtfp16tcvtrowd2pstcvtrowps2bf16htcvtrowps2bf16ltcvtrowps2phhtcvtrowps2phltdpbf16pstdpbf8pstdpbhf8pstdpbssdtdpbsudtdpbusdtdpbuudtdpfp16pstdphbf8pstdphf8pstileloaddtileloaddrstileloaddrst1tileloaddt1tilemovrowtilereleasetilestoredtilezerotmmultf32psttcmmimfp16psttcmmrlfp16psttdpbf16psttdpfp16psttmmultf32psttransposed

Synchronization and fencing

lfencemfenceserializesfence

AMD Lightweight Profiling (LWP) instructions

llwpcblwpinslwpvalslwpcb

Willamette SSE2 Cacheability Instructions

maskmovdqumovntdqmovntimovntpd

New MMX instructions introduced in Katmai

maskmovqmovntqpavgbpavgwpmaxswpmaxubpminswpminubpmovmskbpmulhuwpsadbwpshufw

VIA (Centaur) security instructions

montmulxcryptcbcxcryptcfbxcryptctrxcryptecbxcryptofbxsha1xsha256xstore

Willamette MMX instructions (SSE2 SIMD Integer Instructions)

movdq2qmovdqamovdqumovqmovq2dqpaddqpinsrwpmuludqpshufdpshufhwpshuflwpslldqpsrldqpsubqpunpckhqdqpunpcklqdq

Tejas New Instructions (SSSE3)

pabsbpabsdpabswpalignrphadddphaddswphaddwphsubdphsubswphsubwpmaddubswpmulhrswpshufbpsignbpsigndpsignw

doc 319433-058 June 2025

pbndkbprefetchrst2

Intel Carry-Less Multiplication instructions (CLMUL)

pclmulhqhqdqpclmulhqlqdqpclmullqhqdqpclmullqlqdqpclmulqdq

AMD Enhanced 3DNow! (Athlon) instructions

pf2iwpfnaccpfpnaccpi2fwpswapd

Geode (Cyrix) 3DNow! additions

pfrcpvpfrsqrtv

Generic memory operations

prefetchit0prefetchit1prefetchntaprefetcht0prefetcht1prefetcht2

Intel Transactional Synchronization Extensions (TSX)

prefetchwt1xabortxbeginxendxtest

Processor trace write

ptwrite

SEV-SNP AMD instructions

pvalidatermpadjustvmgexit

MMX instructions

pxorskinit

Special reads: timestamp, CPU number, performance counters, randomness

rdpidrdpmcrdrandrdseedrdtscrdtscp

Intel memory protection keys for userspace (PKU aka PKEYs)

rdpkruwrpkru

System management mode

rdshrrsdcrsldtrsmrstssvdcsvldtsvtswrshr

Intel SHA acceleration instructions

sha1msg1sha1msg2sha1nextesha1rnds4sha256msg1sha256msg2sha256rnds2vsha512msg1vsha512msg2vsha512rnds2

AVX512 4-iteration Dot Product

v4dpwssdv4dpwssds

AVX512 4-iteration Multiply-Add

v4fmaddpsv4fmaddssv4fnmaddpsv4fnmaddss

AVX10.2 BF16 instructions

vaddbf16vcmpbf16vcomisbf16vdivbf16vfmadd132bf16vfmadd213bf16vfmadd231bf16vfmsub132bf16vfmsub213bf16vfmsub231bf16vfnmadd132bf16vfnmadd213bf16vfnmadd231bf16vfnmsub132bf16vfnmsub213bf16vfnmsub231bf16vfpclassbf16vgetexpbf16vgetmantbf16vmaxbf16vminbf16vmulbf16vrcpbf16vreducebf16vrndscalebf16vrsqrtbf16vscalefbf16vsqrtbf16vsubbf16

AVX-512 instructions

vaddpdvaddpsvaligndvalignqvandnpdvandnpsvandpdvandpsvblendmpdvblendmpsvbroadcastf32x2vbroadcastf32x4vbroadcastf32x8vbroadcastf64x2vbroadcastf64x4vbroadcasti32x2vbroadcasti32x4vbroadcasti32x8vbroadcasti64x2vbroadcasti64x4vbroadcastsdvbroadcastssvcmpeq_oqpdvcmpeq_oqpsvcmpeq_oqsdvcmpeq_oqssvcmpeq_uqpdvcmpeq_uqpsvcmpeq_uspdvcmpeq_uspsvcmpeqpdvcmpeqpsvcmpfalse_oqpdvcmpfalse_oqpsvcmpfalse_ospdvcmpfalse_ospsvcmpfalsepdvcmpfalsepsvcmpge_oqpdvcmpge_oqpsvcmpge_ospdvcmpge_ospsvcmpgepdvcmpgepsvcmpgt_oqpdvcmpgt_oqpsvcmpgt_ospdvcmpgt_ospsvcmpgtpdvcmpgtpsvcmple_oqpdvcmple_oqpsvcmple_ospdvcmple_ospsvcmplepdvcmplepsvcmplt_oqpdvcmplt_oqpsvcmplt_ospdvcmplt_ospsvcmpltpdvcmpltpsvcmpneq_oqpdvcmpneq_oqpsvcmpneq_ospdvcmpneq_ospsvcmpneq_uqpdvcmpneq_uqpsvcmpneq_uspdvcmpneq_uspsvcmpneqpdvcmpneqpsvcmpnge_uqpdvcmpnge_uqpsvcmpnge_uspdvcmpnge_uspsvcmpngepdvcmpngepsvcmpngt_uqpdvcmpngt_uqpsvcmpngt_uspdvcmpngt_uspsvcmpngtpdvcmpngtpsvcmpnle_uqpdvcmpnle_uqpsvcmpnle_uspdvcmpnle_uspsvcmpnlepdvcmpnlepsvcmpnlt_uqpdvcmpnlt_uqpsvcmpnlt_uspdvcmpnlt_uspsvcmpnltpdvcmpnltpsvcmpord_qpdvcmpord_qpsvcmpord_spdvcmpord_spsvcmpordpdvcmpordpsvcmppdvcmppsvcmptrue_uqpdvcmptrue_uqpsvcmptrue_uspdvcmptrue_uspsvcmptruepdvcmptruepsvcmpunord_qpdvcmpunord_qpsvcmpunord_spdvcmpunord_spsvcmpunordpdvcmpunordpsvcompresspdvcompresspsvcvtdq2pdvcvtdq2psvcvtpd2qqvcvtpd2udqvcvtpd2uqqvcvtps2dqvcvtps2pdvcvtps2qqvcvtps2udqvcvtps2uqqvcvtqq2pdvcvtqq2psvcvtsd2usivcvtss2usivcvttpd2qqvcvttpd2udqvcvttpd2uqqvcvttps2dqvcvttps2qqvcvttps2udqvcvttps2uqqvcvttsd2usivcvttss2usivcvtudq2pdvcvtudq2psvcvtuqq2pdvcvtuqq2psvcvtusi2sdvcvtusi2ssvdbpsadbwvdivpdvdivpsvexp2pdvexp2psvexpandpdvexpandpsvextractf32x4vextractf32x8vextractf64x2vextractf64x4vextracti32x4vextracti32x8vextracti64x2vextracti64x4vextractpsvfixupimmpdvfixupimmpsvfixupimmsdvfixupimmssvfmadd132pdvfmadd132psvfmadd213pdvfmadd213psvfmadd231pdvfmadd231psvfmaddsub132pdvfmaddsub132psvfmaddsub213pdvfmaddsub213psvfmaddsub231pdvfmaddsub231psvfmsub132pdvfmsub132psvfmsub213pdvfmsub213psvfmsub231pdvfmsub231psvfmsubadd132pdvfmsubadd132psvfmsubadd213pdvfmsubadd213psvfmsubadd231pdvfmsubadd231psvfnmadd132pdvfnmadd132psvfnmadd213pdvfnmadd213psvfnmadd231pdvfnmadd231psvfnmsub132pdvfnmsub132psvfnmsub213pdvfnmsub213psvfnmsub231pdvfnmsub231psvfpclasspdvfpclasspsvfpclasssdvfpclassssvgatherdpdvgatherdpsvgatherpf0dpdvgatherpf0dpsvgatherpf0qpdvgatherpf0qpsvgatherpf1dpdvgatherpf1dpsvgatherpf1qpdvgatherpf1qpsvgatherqpdvgatherqpsvgetexppdvgetexppsvgetexpsdvgetexpssvgetmantpdvgetmantpsvgetmantsdvgetmantssvinsertf32x4vinsertf32x8vinsertf64x2vinsertf64x4vinserti32x4vinserti32x8vinserti64x2vinserti64x4vmaxpdvmaxphvmaxpsvminpdvminphvminpsvmovapdvmovapsvmovddupvmovdqa32vmovdqa64vmovdqu16vmovdqu32vmovdqu64vmovdqu8vmovntdqvmovntdqavmovntpdvmovntpsvmovshdupvmovsldupvmovupdvmovupsvmulpdvmulpsvorpdvorpsvpabsbvpabsdvpabsqvpabswvpackssdwvpacksswbvpackusdwvpackuswbvpaddbvpadddvpaddqvpaddsbvpaddswvpaddusbvpadduswvpaddwvpalignrvpanddvpandndvpandnqvpandqvpavgbvpavgwvpblendmbvpblendmdvpblendmqvpblendmwvpbroadcastbvpbroadcastdvpbroadcastmb2qvpbroadcastmw2dvpbroadcastqvpbroadcastwvpcmpbvpcmpdvpcmpeqbvpcmpeqdvpcmpeqqvpcmpequbvpcmpequdvpcmpequqvpcmpequwvpcmpeqwvpcmpgebvpcmpgedvpcmpgeqvpcmpgeubvpcmpgeudvpcmpgeuqvpcmpgeuwvpcmpgewvpcmpgtbvpcmpgtdvpcmpgtqvpcmpgtubvpcmpgtudvpcmpgtuqvpcmpgtuwvpcmpgtwvpcmplebvpcmpledvpcmpleqvpcmpleubvpcmpleudvpcmpleuqvpcmpleuwvpcmplewvpcmpltbvpcmpltdvpcmpltqvpcmpltubvpcmpltudvpcmpltuqvpcmpltuwvpcmpltwvpcmpneqbvpcmpneqdvpcmpneqqvpcmpnequbvpcmpnequdvpcmpnequqvpcmpnequwvpcmpneqwvpcmpngtbvpcmpngtdvpcmpngtqvpcmpngtubvpcmpngtudvpcmpngtuqvpcmpngtuwvpcmpngtwvpcmpnlebvpcmpnledvpcmpnleqvpcmpnleubvpcmpnleudvpcmpnleuqvpcmpnleuwvpcmpnlewvpcmpnltbvpcmpnltdvpcmpnltqvpcmpnltubvpcmpnltudvpcmpnltuqvpcmpnltuwvpcmpnltwvpcmpqvpcmpubvpcmpudvpcmpuqvpcmpuwvpcmpwvpcompressdvpcompressqvpconflictdvpconflictqvpermbvpermdvpermi2bvpermi2dvpermi2pdvpermi2psvpermi2qvpermi2wvpermilpdvpermilpsvpermpdvpermpsvpermqvpermt2bvpermt2dvpermt2pdvpermt2psvpermt2qvpermt2wvpermwvpexpanddvpexpandqvpextrbvpextrwvpgatherddvpgatherdqvpgatherqdvpgatherqqvplzcntdvplzcntqvpmadd52huqvpmadd52luqvpmaddubswvpmaddwdvpmaxsbvpmaxsdvpmaxsqvpmaxswvpmaxubvpmaxudvpmaxuqvpmaxuwvpminsbvpminsdvpminsqvpminswvpminubvpminudvpminuqvpminuwvpmovb2mvpmovd2mvpmovdbvpmovdwvpmovm2bvpmovm2dvpmovm2qvpmovm2wvpmovq2mvpmovqbvpmovqdvpmovqwvpmovsdbvpmovsdwvpmovsqbvpmovsqdvpmovsqwvpmovswbvpmovsxbdvpmovsxbqvpmovsxbwvpmovsxdqvpmovsxwdvpmovsxwqvpmovusdbvpmovusdwvpmovusqbvpmovusqdvpmovusqwvpmovuswbvpmovw2mvpmovwbvpmovzxbdvpmovzxbqvpmovzxbwvpmovzxdqvpmovzxwdvpmovzxwqvpmuldqvpmulhrswvpmulhuwvpmulhwvpmulldvpmullqvpmullwvpmultishiftqbvpmuludqvpordvporqvproldvprolqvprolvdvprolvqvprordvprorqvprorvdvprorvqvpsadbwvpscatterddvpscatterdqvpscatterqdvpscatterqqvpshufbvpshufdvpshufhwvpshuflwvpslldvpslldqvpsllqvpsllvdvpsllvqvpsllvwvpsllwvpsradvpsraqvpsravdvpsravqvpsravwvpsrawvpsrldvpsrldqvpsrlqvpsrlvdvpsrlvqvpsrlvwvpsrlwvpsubbvpsubdvpsubqvpsubsbvpsubswvpsubusbvpsubuswvpsubwvpternlogdvpternlogqvptestmbvptestmdvptestmqvptestmwvptestnmbvptestnmdvptestnmqvptestnmwvpunpckhbwvpunpckhdqvpunpckhqdqvpunpckhwdvpunpcklbwvpunpckldqvpunpcklqdqvpunpcklwdvpxordvpxorqvrangepdvrangepsvrangesdvrangessvrcp14pdvrcp14psvrcp14sdvrcp14ssvrcp28pdvrcp28psvrcp28sdvrcp28ssvreducepdvreducepsvreducesdvreducessvrndscalepdvrndscalephvrndscalepsvrndscalesdvrndscaleshvrndscalessvrsqrt14pdvrsqrt14psvrsqrt14sdvrsqrt14ssvrsqrt28pdvrsqrt28psvrsqrt28sdvrsqrt28ssvscalefpdvscalefpsvscalefsdvscalefssvscatterdpdvscatterdpsvscatterpf0dpdvscatterpf0dpsvscatterpf0qpdvscatterpf0qpsvscatterpf1dpdvscatterpf1dpsvscatterpf1qpdvscatterpf1qpsvscatterqpdvscatterqpsvshuff32x4vshuff64x2vshufi32x4vshufi64x2vshufpdvshufpsvsqrtpdvsqrtpsvsubpdvsubpsvunpckhpdvunpckhpsvunpcklpdvunpcklpsvxorpdvxorps

Intel AVX512-FP16 instructions

vaddphvaddshvcmpphvcmpshvcomishvcvtdq2phvcvtpd2phvcvtph2dqvcvtph2pdvcvtph2psvcvtph2psxvcvtph2qqvcvtph2udqvcvtph2uqqvcvtph2uwvcvtph2wvcvtps2phvcvtps2phxvcvtqq2phvcvtsd2shvcvtsh2sdvcvtsh2sivcvtsh2ssvcvtsh2usivcvtsi2shvcvtss2shvcvttph2dqvcvttph2qqvcvttph2udqvcvttph2uqqvcvttph2uwvcvttph2wvcvttsh2sivcvttsh2usivcvtudq2phvcvtuqq2phvcvtusi2shvcvtuw2phvcvtw2phvdivphvdivshvendscalephvendscaleshvfcmaddcphvfcmaddcshvfcmulcpchvfcmulcshvfmadd132phvfmadd213phvfmadd231phvfmaddcphvfmaddcshvfmaddsub132phvfmaddsub213phvfmaddsub231phvfmsub132phvfmsub213phvfmsub231phvfmsubadd132phvfmsubadd213phvfmsubadd231phvfmulcpchvfmulcshvfnmadd132phvfnmadd213phvfnmadd231phvfnmsub132phvfnmsub213phvfnmsub231phvfpclassphvfpclassshvgetexpphvgetexpshvgetmantphvgetmantshvgetmaxphvgetmaxshvgetminphvgetminshvmovshvmovwvmulphvmulshvpmadd132phvpmadd132shvpmadd213phvpmadd213shvpmadd231phvpmadd231shvpmsub132phvpmsub132shvpmsub213phvpmsub213shvpmsub231phvpmsub231shvpnmadd132shvpnmadd213shvpnmadd231shvpnmsub132shvpnmsub213shvpnmsub231shvrcpphvrcpshvreducephvreduceshvrsqrtphvrsqrtshvscalefphvscalefshvsqrtphvsqrtshvsubphvsubshvucomish

Intel AVX instructions

vaddsdvaddssvaddsubpdvaddsubpsvblendpdvblendpsvblendvpdvblendvpsvbroadcastf128vcmpeq_ospdvcmpeq_ospsvcmpeq_ossdvcmpeq_osssvcmpeq_uqsdvcmpeq_uqssvcmpeq_ussdvcmpeq_usssvcmpeqsdvcmpeqssvcmpfalse_oqsdvcmpfalse_oqssvcmpfalse_ossdvcmpfalse_osssvcmpfalsesdvcmpfalsessvcmpge_oqsdvcmpge_oqssvcmpge_ossdvcmpge_osssvcmpgesdvcmpgessvcmpgt_oqsdvcmpgt_oqssvcmpgt_ossdvcmpgt_osssvcmpgtsdvcmpgtssvcmple_oqsdvcmple_oqssvcmple_ossdvcmple_osssvcmplesdvcmplessvcmplt_oqsdvcmplt_oqssvcmplt_ossdvcmplt_osssvcmpltsdvcmpltssvcmpneq_oqsdvcmpneq_oqssvcmpneq_ossdvcmpneq_osssvcmpneq_uqsdvcmpneq_uqssvcmpneq_ussdvcmpneq_usssvcmpneqsdvcmpneqssvcmpnge_uqsdvcmpnge_uqssvcmpnge_ussdvcmpnge_usssvcmpngesdvcmpngessvcmpngt_uqsdvcmpngt_uqssvcmpngt_ussdvcmpngt_usssvcmpngtsdvcmpngtssvcmpnle_uqsdvcmpnle_uqssvcmpnle_ussdvcmpnle_usssvcmpnlesdvcmpnlessvcmpnlt_uqsdvcmpnlt_uqssvcmpnlt_ussdvcmpnlt_usssvcmpnltsdvcmpnltssvcmpord_qsdvcmpord_qssvcmpord_ssdvcmpord_sssvcmpordsdvcmpordssvcmpsdvcmpssvcmptrue_uqsdvcmptrue_uqssvcmptrue_ussdvcmptrue_usssvcmptruesdvcmptruessvcmpunord_qsdvcmpunord_qssvcmpunord_ssdvcmpunord_sssvcmpunordsdvcmpunordssvcomisdvcomissvcvtpd2dqvcvtpd2psvcvtsd2sivcvtsd2ssvcvtsi2sdvcvtsi2ssvcvtss2sdvcvtss2sivcvttpd2dqvcvttsd2sivcvttss2sivdivsdvdivssvdppdvdppsvextractf128vhaddpdvhaddpsvhsubpdvhsubpsvinsertf128vinsertpsvlddquvldmxcsrvldqquvmaskmovdquvmaskmovpdvmaskmovpsvmaxsdvmaxssvminsdvminssvmovdvmovdqavmovdquvmovhlpsvmovhpdvmovhpsvmovlhpsvmovlpdvmovlpsvmovmskpdvmovmskpsvmovntqqvmovqvmovqqavmovqquvmovsdvmovssvmulsdvmulssvpandvpandnvpblendvbvpblendwvpcmpestrivpcmpestrmvpcmpistrivpcmpistrmvperm2f128vpextrdvpextrqvphadddvphaddswvphaddwvphminposuwvphsubdvphsubswvphsubwvpinsrbvpinsrdvpinsrqvpinsrwvpmovmskbvporvpsignbvpsigndvpsignwvptestvpxorvrcppsvrcpssvroundpdvroundpsvroundsdvroundssvrsqrtpsvrsqrtssvsqrtsdvsqrtssvstmxcsrvsubsdvsubssvtestpdvtestpsvucomisdvucomissvzeroallvzeroupper

Intel instruction extension based on pub number 319433-030 dated October 2017

vaesdecvaesdeclastvaesencvaesenclast

Intel AVX AES instructions

vaesimcvaeskeygenassist

AVX no exception conversions

vbcstnebf162psvbcstnebf16psvbcstnesh2psvcvtneebf162psvcvtneeph2psvcvtneobf162psvcvtneoph2ps

Intel AVX2 instructions

vbroadcasti128vextracti128vinserti128vpblenddvperm2i128vpmaskmovdvpmaskmovq

AVX10.2 Compare scalar fp with enhanced eflags instructions

vcomxsdvcomxshvcomxssvucomxsdvucomxshvucomxss

AVX10.2 Convert instructions

vcvt2ph2bf8vcvt2ph2bf8svcvt2ph2hf8vcvt2ph2hf8svcvt2ps2phxvcvtbiasph2bf8vcvtbiasph2bf8svcvtbiasph2hf8vcvtbiasph2hf8svcvthf82phvcvtph2bf8vcvtph2bf8svcvtph2hf8vcvtph2hf8s

AVX10.2 Saturating convert instructions

vcvtbf162ibsvcvtbf162iubsvcvtph2ibsvcvtph2iubsvcvtps2ibsvcvtps2iubsvcvttbf162ibsvcvttbf162iubsvcvttpd2dqsvcvttpd2qqsvcvttpd2udqsvcvttpd2uqqsvcvttph2ibsvcvttph2iubsvcvttps2dqsvcvttps2ibsvcvttps2iubsvcvttps2qqsvcvttps2udqsvcvttps2uqqsvcvttsd2sisvcvttsd2usisvcvttss2sisvcvttss2usis

AVX512 Bfloat16 instructions

vcvtne2ps2bf16vcvtneps2bf16vdpbf16ps

AVX10.2 Integer and FP16 VNNI, media new instructions

vdpphpsvmpsadbwvpdpbssdvpdpbssdsvpdpbsudvpdpbsudsvpdpbuudvpdpbuudsvpdpwsudvpdpwsudsvpdpwusdvpdpwusdsvpdpwuudvpdpwuuds

Intel AVX Carry-Less Multiplication instructions (CLMUL)

vfcmulcphvfmadd132shvfmadd213shvfmadd231shvfmsub132shvfmsub213shvfmsub231shvfmulcphvfnmadd132shvfnmadd213shvfnmadd231shvfnmsub132shvfnmsub213shvfnmsub231shvmaxshvminshvpclmulhqhqdqvpclmulhqlqdqvpclmullqhqdqvpclmullqlqdqvpclmulqdq

Intel Fused Multiply-Add instructions (FMA)

vfmadd123pdvfmadd123psvfmadd123sdvfmadd123ssvfmadd132sdvfmadd132ssvfmadd213sdvfmadd213ssvfmadd231sdvfmadd231ssvfmadd312pdvfmadd312psvfmadd312sdvfmadd312ssvfmadd321pdvfmadd321psvfmadd321sdvfmadd321ssvfmaddsub123pdvfmaddsub123psvfmaddsub312pdvfmaddsub312psvfmaddsub321pdvfmaddsub321psvfmsub123pdvfmsub123psvfmsub123sdvfmsub123ssvfmsub132sdvfmsub132ssvfmsub213sdvfmsub213ssvfmsub231sdvfmsub231ssvfmsub312pdvfmsub312psvfmsub312sdvfmsub312ssvfmsub321pdvfmsub321psvfmsub321sdvfmsub321ssvfmsubadd123pdvfmsubadd123psvfmsubadd312pdvfmsubadd312psvfmsubadd321pdvfmsubadd321psvfnmadd123pdvfnmadd123psvfnmadd123sdvfnmadd123ssvfnmadd132sdvfnmadd132ssvfnmadd213sdvfnmadd213ssvfnmadd231sdvfnmadd231ssvfnmadd312pdvfnmadd312psvfnmadd312sdvfnmadd312ssvfnmadd321pdvfnmadd321psvfnmadd321sdvfnmadd321ssvfnmsub123pdvfnmsub123psvfnmsub123sdvfnmsub123ssvfnmsub132sdvfnmsub132ssvfnmsub213sdvfnmsub213ssvfnmsub231sdvfnmsub231ssvfnmsub312pdvfnmsub312psvfnmsub312sdvfnmsub312ssvfnmsub321pdvfnmsub321psvfnmsub321sdvfnmsub321ss

AMD XOP and FMA4 instructions (SSE5)

vfmaddpdvfmaddpsvfmaddsdvfmaddssvfmaddsubpdvfmaddsubpsvfmsubaddpdvfmsubaddpsvfmsubpdvfmsubpsvfmsubsdvfmsubssvfnmaddpdvfnmaddpsvfnmaddsdvfnmaddssvfnmsubpdvfnmsubpsvfnmsubsdvfnmsubssvfrczpdvfrczpsvfrczsdvfrczssvpcmovvpcombvpcomdvpcomqvpcomubvpcomudvpcomuqvpcomuwvpcomwvphaddbdvphaddbqvphaddbwvphadddqvphaddubdvphaddubqvphaddubwvphaddudqvphadduwdvphadduwqvphaddwdvphaddwqvphsubbwvphsubdqvphsubwdvpmacsddvpmacsdqhvpmacsdqlvpmacssddvpmacssdqhvpmacssdqlvpmacsswdvpmacsswwvpmacswdvpmacswwvpmadcsswdvpmadcswdvppermvprotbvprotdvprotqvprotwvpshabvpshadvpshaqvpshawvpshlbvpshldvpshlqvpshlw

AVX10.2 MINMAX instructions

vminmaxbf16vminmaxpdvminmaxphvminmaxpsvminmaxsdvminmaxshvminmaxss

AVX512 mask intersect instructions

vp2intersectdvp2intersectq

AVX512 Vector Bit Manipulation Instructions 2

vpcompressbvpcompresswvpexpandbvpexpandwvpshlddvpshldqvpshldvdvpshldvqvpshldvwvpshldwvpshrddvpshrdqvpshrdvdvpshrdvqvpshrdvwvpshrdw

AVX512 VNNI

vpdpbusdvpdpbusdsvpdpwssdvpdpwssds

AVX512 Bit Algorithms

vpopcntbvpopcntdvpopcntqvpopcntwvpshufbitqmb

S3M hash instructions

vsm3msg1vsm3msg2vsm3rnds2

SM4 hash instructions

vsm4key4vsm4rnds4

XSAVE group (AVX and extended state)

xgetbvxrstorxrstor64xrstorsxrstors64xsavexsave64xsavecxsavec64xsaveoptxsaveopt64xsavesxsaves64xsetbv

Directives

Directives

Directives tell the assembler what to do. They are not instructions and the processor never sees them.

section

Opens a section: .text for code, .data for initialised data, .bss for space that starts as zeroes, .rodata for constants. Everything after the line belongs to that section until the next one. segment is the same directive under its other name.

global

Makes a label visible outside the file. The program has to declare _start, because that is the label the linker makes the entry point.

extern

Declares that a name is defined in another file, so this one may refer to it.

bits

Assembles for 16, 32 or 64 bit mode. Programs here are 64 bit and the object format already says so, so a program needs this only to say something unusual.

default

Chooses whether a bare memory reference is rel (an offset from rip) or abs (an absolute address). Long mode code is usually written default rel.

cpu

Refuses to assemble instructions newer than the processor named, which is a way to keep a program inside the instruction set a course is teaching.

absolute

Starts a block of labels that describe a layout without emitting anything, the way a structure declaration does.

Data and space

These live in the instruction table and behave like directives: they put bytes in the output, or reserve room for them.

db, dw, dd, dq

Emit bytes, words (2 bytes), doublewords (4) and quadwords (8), in order, where the line is. They take numbers, characters, strings and label addresses: msg: db "hi", 10.

dt, do, dy, dz

Emit 10, 16, 32 and 64 byte values, for the x87 and vector types.

resb, resw, resd, resq

Reserve room without writing anything: buffer: resb 64. They belong in .bss, which costs nothing in the file because it is all zeroes.

equ

Gives a name to a value, evaluated once where it is written: LEN equ 64. Nothing is emitted and nothing can change it later.

incbin

Copies a file into the output at this point, byte for byte.

times

Repeats the rest of the line: times 64 db 0 emits 64 zero bytes, and times 8 - ($ - start) db 0 pads to a fixed size.

The preprocessor

The preprocessor runs over the text before the assembler reads it, so it can define names, repeat blocks and include files, and knows nothing about registers or instructions.

%define

A macro expanded wherever its name appears, with arguments if it was given any. Expanded late, so it sees the value a name has when it is used.

%assign

A single line macro whose value is evaluated at once, and may be reassigned.

%macro

A multi line macro, ended by %endmacro. The number after the name says how many arguments it takes, and %1, %2 stand for them.

%include

Assembles another file here, the way a header is included.

%ifdef, %ifndef, %if

Assemble a block only under a condition, ending at %endif, with %else and %elif in between.

%rep

Repeats a block a fixed number of times, ending at %endrep.

Prefixes and operand sizes

Words that go in front of an instruction or an operand rather than standing on their own.

lock

Makes a read-modify-write instruction atomic against other processors. Only a handful of instructions accept it, and only when the destination is memory.

rep

Repeats a string instruction rcx times, counting down. On movs and stos this is the whole loop, written in one instruction.

repe, repz, repne, repnz

Repeat while the comparison keeps saying equal, or keeps saying not equal, and stop early when it changes. They are for cmps and scas, which set the flags on every step.

o16, o32, o64, a16, a32, a64

Force the operand or address size of one instruction, overriding what the mode implies. NASM chooses these on its own; writing one by hand is for the rare case where the choice matters.

byte, word, dword, qword

Say how wide a memory operand is, which the instruction cannot always work out on its own: mov qword [rsp], 0 writes eight bytes, mov byte [rsp], 0 writes one.

near, short, far

Choose the reach of a jump or call. NASM picks the shortest form that works, so these are for forcing a longer one.

rel, abs

Say whether a memory reference is an offset from rip or an absolute address, for one operand rather than for the file the way default does.

Everything else

The rest of what NASM accepts, from its own tables. These are here so the list is complete; the NASM manual documents them.

absolutebitscommoncpudebugdefaultdollarhexexternfloatglobalstaticlistsectionsegmentwarningsectalignpragmarequired %aliases%arg%assign%clear%defalias%define%defstr%deftok%depend%elif%elifctx%elifdef%elifdefalias%elifdifi%elifdirective%elifempty%elifenv%eliffile%elifid%elifidn%elifidni%elifmacro%elifn%elifnctx%elifndef%elifndefalias%elifndifi%elifndirective%elifnempty%elifnenv%elifnfile%elifnid%elifnidn%elifnidni%elifnmacro%elifnnum%elifnstr%elifntoken%elifnum%elifnusable%elifnusing%elifstr%eliftoken%elifusable%elifusing%else%endif%endm%endmacro%endrep%error%exitmacro%exitrep%fatal%if%ifctx%ifdef%ifdefalias%ifdifi%ifdirective%ifempty%ifenv%iffile%ifid%ifidn%ifidni%ifmacro%ifn%ifnctx%ifndef%ifndefalias%ifndifi%ifndirective%ifnempty%ifnenv%ifnfile%ifnid%ifnidn%ifnidni%ifnmacro%ifnnum%ifnstr%ifntoken%ifnum%ifnusable%ifnusing%ifstr%iftoken%ifusable%ifusing%include%line%local%macro%note%null%pathsearch%pop%pragma%push%rep%repl%require%rmacro%rotate%stacksize%strcat%strlen%substr%undef%undefalias%unmacro%use%warning%xdefine

Registers & Flags

Registers

Sixteen 64 bit general purpose registers. Each one can be used at four widths: rax is the whole register, eax its low 32 bits, ax its low 16 and al its low 8. Writing a 32 bit name clears the top half of the 64 bit register; writing a 16 or 8 bit name leaves the rest alone.

rax eaxaxahal

The accumulator. mul, div and the string instructions use it without being told to, a syscall number goes in it, and a syscall result comes back in it.

rbx ebxbxbhbl

A general register. Called on to survive a function call: a function that writes to it has to put it back before returning.

rcx ecxcxchcl

The counter. loop and the repeated string instructions count down with it, the shift instructions read a variable shift amount from cl, and it carries the fourth argument of a function call. syscall destroys it.

rdx edxdxdhdl

The high half of the product mul writes and of the dividend div reads, and the third argument of a function call or a syscall.

rsi esisisil

The source pointer of the string instructions, and the second argument of a function call or a syscall.

rdi edididil

The destination pointer of the string instructions, and the first argument of a function call or a syscall.

rbp ebpbpbpl

The frame pointer by convention, pointing at the base of the current function's stack frame. Nothing in the hardware requires it, and compilers routinely use it as one more general register.

rsp espspspl

The stack pointer. push, pop, call and ret move it without being told to, and it must point at usable memory whenever any of them runs.

r8 to r15 r8d to r15dr8w to r15wr8b to r15b

The eight registers x86-64 added. r8 and r9 carry the fifth and sixth arguments of a function call; r10 replaces rcx as the fourth argument of a syscall, because syscall destroys rcx. r11 is destroyed too.

rip

The instruction pointer. It cannot be read or written directly, but it can be addressed: [rel label] assembles to an offset from rip, which is how position independent code reaches its own data.

rflags eflagsflags

The flags, listed below. Arithmetic and logic instructions write them, the conditional jumps and setcc read them, and pushfq and popfq move the whole register to and from the stack.

Flags

The flags live in rflags. Arithmetic and logic instructions write them, cmp and test exist to write them without keeping a result, and the conditional instructions read them.

CF bit 0

Carry. Set when an unsigned addition overflowed or an unsigned subtraction borrowed, and by the shift and rotate instructions, which shift the last bit out through it.

PF bit 2

Parity. Set when the low byte of the result has an even number of set bits.

AF bit 4

Adjust. The carry out of bit 3, which only the decimal adjust instructions read.

ZF bit 6

Zero. Set when the result was zero, which is what je and jne read after a cmp.

SF bit 7

Sign. A copy of the top bit of the result, so it is set when the result is negative read as signed.

DF bit 10

Direction. Clear means the string instructions count upwards, set means downwards. cld and std write it, and it is expected to be clear everywhere else.

OF bit 11

Overflow. Set when a signed operation produced a result too large for its destination, which is a different question from the one the carry flag answers.

SSE registers

Floating point arithmetic in a 64 bit program is SSE arithmetic. The xmm registers are wide enough to hold several numbers at once, and each instruction says how much of a register it means: the scalar forms work on the lowest lane alone, so addsd xmm0, xmm1 adds one pair of doubles and cvtsi2sd xmm0, rax turns an integer into a double and writes it into that same lowest lane, both of them leaving the upper lane of the destination as they found it. The moves are the exception: movsd xmm0, [x] loads one double from memory and clears bits 127 to 64, while movsd xmm0, xmm1 copies the low double and leaves the upper lane alone, so where the value came from decides what the rest of the register holds. The packed forms, addpd and mulps among them, apply the same operation to every lane of the register at once, which is the reason the registers are this wide.

The single precision instructions are spelled with ss and ps where the double precision ones use sd and pd, and the calling convention passes floating point arguments in xmm0 to xmm7 and returns them in xmm0.

xmm0 to xmm15 128 bit

Sixteen 128 bit registers. Read as doubles they are two lanes, read as singles four, and read as raw bits sixteen bytes; the registers panel shows all three, because nothing in the register itself records which one the program meant.

mxcsr 32 bit

The control and status register of the unit. It holds the rounding mode, the masks that decide whether an invalid operation raises an exception or quietly produces a NaN, and the flags that record which of those conditions has happened since the flags were last cleared. ldmxcsr and stmxcsr move it to and from memory.

x87 registers

The x87 unit is the floating point hardware x86 had before SSE, and it is still what the f instructions use. Its eight registers are a stack rather than a numbered file: st0 is always the top, fld and fld1 push a value onto it and rename everything below, and faddp adds the top two and pops, so the same register name means a different value after every push. Programs written today use SSE for arithmetic and reach for x87 mainly for the operations SSE has no instruction for, such as fsin, fcos or fpatan.

This emulator keeps the stack as ordinary 64 bit doubles rather than the 80 bit extended values real hardware computes with, so a long chain of x87 arithmetic can differ from a physical processor in the last bits of the result.

A slot the stack has not filled, or has popped, keeps whatever bits it last held. The panel shows those rows blank rather than the stale value, the way info float prints Empty in gdb, and the bits are still a hover away; ftag is the register that says which slots are live.

st0 to st7 64 bit

The stack registers, listed top first: what the panel calls st0 is whatever the last push left on top, and one more push moves that value to st1. An instruction that pops past the bottom of the stack, or pushes onto a full one, raises the stack fault the status word reports.

fctrl 16 bit

The control word: the rounding mode, the precision the unit rounds results to, and the masks that say which exceptions the program wants to be told about. fldcw writes it, which is how code that needs truncation rather than the default round to nearest gets it. The precision field has nothing to decide here, because the stack already holds doubles.

fstat 16 bit

The status word: the exception flags, the condition codes a comparison such as fcom writes, and the three bits that say which register is currently the top of the stack. fstsw ax copies it into ax, which is how an x87 comparison used to reach a conditional jump.

ftag 16 bit

Two bits per register saying whether it holds a number, a zero, a special value such as an infinity, or nothing at all. It is what makes an empty stack slot distinguishable from one holding zero, and what the panel reads to decide which rows to leave blank.

Condition codes

The same sixteen conditions end jcc, setcc and cmovcc: jne jumps, setne writes 1 or 0 to a byte, and cmovne copies a register, all on the same test. The unsigned conditions read the carry flag and the signed ones read the sign and overflow flags, which is why comparing two numbers the wrong way round silently gives the wrong answer.

ConditionAlso writtenMeaningTest
ezequal, zeroZF = 1
nenznot equal, not zeroZF = 0
anbeabove (unsigned)CF = 0 and ZF = 0
aenb, ncabove or equal (unsigned)CF = 0
bnae, cbelow (unsigned)CF = 1
benabelow or equal (unsigned)CF = 1 or ZF = 1
gnlegreater (signed)ZF = 0 and SF = OF
genlgreater or equal (signed)SF = OF
lngeless (signed)SF is not OF
lengless or equal (signed)ZF = 1 or SF is not OF
ssign set, negativeSF = 1
nssign clear, not negativeSF = 0
ooverflowOF = 1
nono overflowOF = 0
ppeparity evenPF = 1
nppoparity oddPF = 0

Syscalls

A program here runs as a Linux program, so everything outside its own memory happens through syscall. Put the call number in rax, the arguments in rdi, rsi, rdx, r10, r8 and r9, and read the result from rax. A result between -1 and -4095 is an error code. rcx and r11 do not survive the call.

The ones to start with

1 - write waits

Writes rdx bytes from the buffer at rsi to the file descriptor in rdi, and returns how many it wrote. Descriptor 1 is standard output and 2 is standard error, so this is how a program prints.

rdi
file descriptor
rsi
buffer (read by the kernel)
rdx
byte count

0 - read waits

Reads up to rdx bytes from the file descriptor in rdi into the buffer at rsi, and returns how many it read. Descriptor 0 is standard input, so this is how a program reads what was typed. A return of 0 means end of input.

rdi
file descriptor
rsi
buffer (written by the kernel)
rdx
byte count

60 - exit

Ends the program with the status in rdi. It never returns, and a program that reaches the end of its code without calling it runs into whatever bytes follow.

rdi
status

231 - exit_group

Ends every thread of the program with the status in rdi. For a program with one thread it is exit.

rdi
status

2 - open waits

Opens the path at rdi with the flags in rsi and, when creating, the mode in rdx. Returns a file descriptor.

rdi
path
rsi
open flags
rdx
mode

3 - close waits

Closes the file descriptor in rdi.

rdi
file descriptor

8 - lseek

Moves the read and write position of the descriptor in rdi to the offset in rsi, interpreted according to rdx, and returns the new position.

rdi
file descriptor
rsi
offset
rdx
whence

5 - fstat

Fills the structure at rsi with what is known about the descriptor in rdi, including its size.

rdi
file descriptor
rsi
o_stat

12 - brk

Moves the end of the data segment to the address in rdi, which is the oldest way to ask for more memory. Called with 0 it returns where the segment currently ends.

rdi
value

9 - mmap

Maps memory: the length in rsi, the protection in rdx, the flags in r10. An anonymous private mapping is how a program asks for a block of memory it can write to.

rdi
pointer
rsi
size
rdx
protection flags
r10
mapping flags
r8
file descriptor
r9
offset

11 - munmap

Unmaps the mapping of rsi bytes at the address in rdi.

rdi
pointer
rsi
size

35 - nanosleep waits

Sleeps for the interval at rdi, a pair of seconds and nanoseconds.

rdi
i_time
rsi
o_time

228 - clock_gettime

Writes the time of the clock named in rdi into the structure at rsi.

rdi
clock
rsi
timespec

39 - getpid

Returns the process id.

Everything this emulator implements

Those syscalls are what the emulator implements, anything missing returns -ENOSYS.

raxCallArguments
4statrdi pathrsi o_stat
6lstatrdi pathrsi o_stat
7pollrdi valuersi valuerdx value
10mprotectrdi pointerrsi sizerdx protection flags
13rt_sigactionrdi signalrsi i_handrdx o_handr10 byte count
14rt_sigprocmaskrdi sighowrsi i_sigsetrdx o_sigsetr10 byte count
16ioctlrdi valuersi valuerdx value
17preadrdi file descriptorrsi buffer (written by the kernel)rdx byte countr10 offset
18pwriterdi file descriptorrsi buffer (read by the kernel)rdx byte countr10 offset
19readvrdi file descriptorrsi iovec array (written)rdx byte count
20writevrdi file descriptorrsi iovec array (read)rdx byte count
21accessrdi pathrsi accmode
22piperdi o_pfds
23selectrdi intrsi io_fdsetrdx io_fdsetr10 io_fdsetr8 io_timev
24sched_yield
25mremaprdi valuersi valuerdx valuer10 valuer8 value
26msyncrdi valuersi valuerdx value
28madviserdi valuersi valuerdx value
32duprdi file descriptor
33dup2rdi file descriptorrsi int
34pause
36getitimerrdi valuersi value
37alarmrdi int
38setitimerrdi valuersi valuerdx value
40sendfilerdi valuersi valuerdx valuer10 value
41socketrdi familyrsi socktyperdx int
42connectrdi file descriptorrsi i_addrrdx addrlen
43acceptrdi file descriptorrsi o_addrrdx long
44sendtordi file descriptorrsi buffer (read by the kernel)rdx sizer10 intr8 i_addrr9 addrlen
45recvfromrdi file descriptorrsi buffer (written by the kernel)rdx sizer10 intr8 o_addrr9 long
46sendmsgrdi valuersi valuerdx value
47recvmsgrdi valuersi valuerdx value
48shutdownrdi valuersi value
49bindrdi file descriptorrsi i_addrrdx addrlen
50listenrdi file descriptorrsi un
51getsocknamerdi file descriptorrsi o_addrrdx long
52getpeernamerdi file descriptorrsi o_addrrdx long
53socketpairrdi familyrsi socktyperdx intr10 o_pfds
54setsockoptrdi valuersi valuerdx valuer10 valuer8 value
55getsockoptrdi valuersi valuerdx valuer10 valuer8 value
56clonerdi cloneflagsrsi pointerrdx pointerr10 pointerr8 pointerr9 pointer
57fork
58vfork
59execverdi valuersi valuerdx value
61wait4rdi process idrsi o_wstatusrdx waitflagsr10 o_rusage
62killrdi process idrsi signal
63unamerdi value
72fcntlrdi file descriptorrsi wat_fcntlrdx un
73flockrdi valuersi value
74fsyncrdi file descriptor
75fdatasyncrdi file descriptor
76truncaterdi stringrsi offset
77ftruncaterdi file descriptorrsi offset
79getcwdrdi buffer (written by the kernel)rsi byte count
80chdirrdi path
81fchdirrdi file descriptor
82renamerdi pathrsi path
83mkdirrdi pathrsi mode
84rmdirrdi path
85creatrdi pathrsi mode
86linkrdi pathrsi path
87unlinkrdi path
88symlinkrdi pathrsi path
89readlinkrdi pathrsi buffer (written by the kernel)rdx byte count
90chmodrdi pathrsi mode
91fchmodrdi file descriptorrsi uid
92chownrdi pathrsi uidrdx gid
93fchownrdi file descriptorrsi uidrdx gid
94lchownrdi pathrsi uidrdx gid
95umaskrdi mode
96gettimeofdayrdi valuersi value
97getrlimitrdi resourcersi o_rlimit
98getrusagerdi valuersi value
99sysinfordi value
100timesrdi value
102getuid
104getgid
105setuidrdi uid
106setgidrdi gid
107geteuid
108getegid
109setpgidrdi valuersi value
110getppid
111getpgrp
112setsid
113setreuidrdi uidrsi uid
114setregidrdi gidrsi gid
115getgroupsrdi valuersi value
116setgroupsrdi valuersi value
117setresuidrdi uidrsi uidrdx uid
118getresuidrdi valuersi valuerdx value
119setresgidrdi gidrsi gidrdx gid
120getresgidrdi valuersi valuerdx value
121getpgidrdi process id
124getsidrdi value
127rt_sigpendingrdi value
130rt_sigsuspendrdi i_sigsetrsi byte count
131sigaltstackrdi valuersi value
132utimerdi valuersi value
133mknodrdi valuersi valuerdx value
137statfsrdi valuersi value
138fstatfsrdi valuersi value
140getpriorityrdi valuersi value
141setpriorityrdi valuersi valuerdx value
142sched_set_paramrdi valuersi value
143sched_get_paramrdi valuersi value
144sched_set_schedulerrdi valuersi valuerdx value
145sched_get_schedulerrdi value
146sched_get_priority_maxrdi value
147sched_get_priority_minrdi value
157prctlrdi valuersi valuerdx valuer10 valuer8 value
158arch_prctlrdi valuersi value
160setrlimitrdi resourcersi i_rlimit
161chrootrdi path
162sync
165mountrdi stringrsi stringrdx msflagsr10 pointerr8 un
186gettid
200tkillrdi process idrsi signal
202futexrdi valuersi valuerdx valuer10 valuer8 valuer9 value
203sched_set_affinityrdi valuersi valuerdx value
204sched_get_affinityrdi valuersi valuerdx value
213epoll_createrdi value
217getdentsrdi valuersi valuerdx value
218set_tid_addressrdi value
221fadviserdi valuersi valuerdx valuer10 value
227clock_settimerdi valuersi value
229clock_getresrdi valuersi value
230clock_nanosleeprdi clockrsi intrdx i_timer10 o_time
232epoll_waitrdi valuersi valuerdx valuer10 value
233epoll_ctlrdi valuersi valuerdx valuer10 value
234tgkillrdi valuersi valuerdx value
235utimesrdi valuersi value
257openatrdi directory descriptorrsi stringrdx open flagsr10 mode
258mkdiratrdi directory descriptorrsi pathrdx mode
259mknodatrdi valuersi valuerdx valuer10 value
260fchownatrdi directory descriptorrsi pathrdx uidr10 gidr8 atflags
261futimesatrdi valuersi valuerdx value
262fstatatrdi directory descriptorrsi pathrdx o_statr10 atflags
263unlinkatrdi directory descriptorrsi pathrdx atflags
264renameatrdi directory descriptorrsi pathrdx directory descriptorr10 path
265linkatrdi directory descriptorrsi pathrdx directory descriptorr10 pathr8 atflags
266symlinkatrdi pathrsi directory descriptorrdx path
267readlinkatrdi directory descriptorrsi stringrdx buffer (written by the kernel)r10 byte count
268fchmodatrdi directory descriptorrsi pathrdx mode
269faccessatrdi directory descriptorrsi pathrdx accmode
270pselect6rdi valuersi valuerdx valuer10 valuer8 valuer9 value
271ppollrdi valuersi valuerdx valuer10 valuer8 value
273set_robust_listrdi valuersi value
274get_robust_listrdi valuersi valuerdx value
280utimensatrdi directory descriptorrsi pathrdx o_time2r10 atflags
281epoll_pwaitrdi valuersi valuerdx valuer10 valuer8 valuer9 value
288accept4rdi file descriptorrsi o_addrrdx longr10 sockflags
291epoll_create1rdi value
292dup3rdi file descriptorrsi intrdx open flags
293pipe2rdi o_pfdsrsi open flags
295preadvrdi file descriptorrsi iovec array (written)rdx byte countr10 offset
296pwritevrdi file descriptorrsi iovec array (read)rdx byte countr10 offset
299recvmmsgrdi valuersi valuerdx valuer10 valuer8 value
302prlimitrdi process idrsi resourcerdx i_rlimitr10 o_rlimit
307sendmmsgrdi valuersi valuerdx valuer10 value
316renameat2rdi directory descriptorrsi pathrdx directory descriptorr10 pathr8 atflags
318getrandomrdi buffer (written by the kernel)rsi byte countrdx int
327preadv2rdi file descriptorrsi iovec array (written)rdx byte countr10 offsetr8 int
328pwritev2rdi file descriptorrsi iovec array (read)rdx byte countr10 offsetr8 int
436close_rangerdi valuersi valuerdx value
439faccessat2rdi directory descriptorrsi pathrdx accmoder10 atflags
441epoll_pwait2rdi valuersi valuerdx valuer10 valuer8 valuer9 value