xor

Logical exclusive OR

Combines the destination and source bit by bit with XOR, storing the result in the destination.

8086 and later

Intel's reference: XOR

CFPFAFZFSFDFOF 0●?●●–0
  • ● set from the result
  • 0 always 0
  • ? undefined afterwards
  • – not changed

Forms

Operands

r/m
A general-purpose register or memory location matching the operation’s size, for example rax or qword [rbp-8]. The byte registers ah, bh, ch and dh cannot be used with a REX prefix, including when the memory address uses r8–r15.
reg
A general-purpose register matching the operation’s size, for example al, ax, eax or rax. The byte registers ah, bh, ch and dh cannot be used with a REX prefix, which is required by spl, bpl, sil, dil and r8–r15.
imm
An immediate value encoded in the instruction, written as a number, character or label. Its encoded width and any sign extension depend on the instruction; arithmetic immediates may be sign-extended, while shift counts are used without sign extension.
acc
The accumulator matching the operation’s size: al, ax, eax or rax. A shorter encoding may be available.

A bit is set when the input bits differ. CF and OF are cleared.

The destination is a register or memory operand; the source is a register, memory operand or immediate, with at most one memory operand. Register and memory operands have the same width. When the instruction writes a 32-bit register, that write clears the upper half of its 64-bit register.

An 8-bit immediate used with a wider operand is sign-extended from −128 through 127. For a 64-bit operation, the longer immediate field is only 32 bits and is also sign-extended; there is no full 64-bit immediate form. The encoded bits determine the value used by the operation. For example, a 32-bit field of 0xffffffff becomes 0xffffffffffffffff (−1), not positive 4294967295. An out-of-range constant can produce a warning and truncated bits; use a register for a value that cannot be represented by these sign extensions.

NASM normally chooses the short immediate encoding when it preserves the value; a byte qualifier is not required. strict with an immediate size can prevent that shortening.

global _start

section .text
_start:
        mov rax, 12
        mov rbx, 5
        mov rcx, 3
        mov rsi, 9

        xor rax, rbx

        mov rax, 60         ; syscall 60: exit
        xor rdi, rdi
        syscall