The XOR instruction
Logical bitwise exclusive OR.
The XOR instruction format
| Instruction | Description |
|---|---|
| XOR AL, imm8 | AL XOR imm8. |
| XOR AX, imm16 | AX XOR imm16. |
| XOR reg/mem8, imm8 | reg/mem8 XOR imm8. |
| XOR reg/mem16, imm16 | reg/mem16 XOR imm16. |
| XOR reg/mem16, imm8 | reg/mem16 XOR imm8 (sign-extended). |
| XOR reg/mem8, reg8 | reg/mem8 XOR reg8. |
| XOR reg/mem16, reg16 | reg/mem16 XOR reg16. |
| XOR reg8, reg/mem8 | reg8 XOR reg/mem8. |
| XOR reg16, reg/mem16 | reg16 XOR reg/mem16. |
Performs a bitwise exclusive OR (XOR) operation on the destination (first) and source (second) operands and stores the result in the destination operand location. The source operand can be an immediate, a register or a memory location; the destination operand can be a register or a memory location. (However, two memory operands cannot be used in one instruction.) Each bit of the result is 1 if the corresponding bits of the operands differ; each bit is 0 if the corresponding bits are the same.
This instruction can be used with the lock prefix to allow the instruction to be executed atomically.
Usage example
title .model small .stack 100h code segment public ; Start of the code segment assume cs:code main proc ; Start of the main procedure mov ax, 18 ; Copy the value 18 into the ax register xor ax, ax ; Clear the ax register. This is one byte shorter and faster than mov ax, 0 mov ax, 4C00h ; Copy the process termination function number into ah and the value into al int 21h ; Call the interrupt main endp ; End of the main procedure code ends ; End of the code segment end main ; End of file. The main procedure is the entry point
Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".
Processor status flags
CF
0PF
YesAF
?ZF
YesSF
YesTF
NoIF
NoDF
NoOF
0