X86 Assembly/Logic

Logical instructions
The instructions on this page deal with bit-wise logical instructions. For more information about bit-wise logic, see Digital Circuits/Logic Operations.

All logical instructions presented in this section are executed in the, as the name already suggests, the arithmetic logic unit.

binary operations
These instructions require two operands.

operation
performs a bit-wise  of the two operands, and stores the result in destination.

side effects
See below.

application

 * An  can be used to calculate the intersection of two “sets”, or a value representing a “mask”. Some programming language require that Boolean values are stored exactly as either   or  . An   will ensure only the LSB is set, or not set.
 * If partial register addressing is not available in the desired size, an  can be used for a $$\text{destination}\!\!\!\!\mod\text{mask}$$ operation, that is the remainder of integer division. For that, mask has to contain the value $$2^n-1$$ (i. e. all lower bits set until a certain threshold), where $$2^n$$ equals your desired divisor.

operation
The  instruction performs a bit-wise   of the two operands, and stores the result in destination.

side effects
See below.

application

 * An  can be used to calculate the union of two “sets”, or a value representing a “mask”.

operation
Performs a bit-wise  of the two operands, and stores the result in destination.

side effects
See below.

application

 * (or any GPR twice) will clear all bits. It is a specially recognized word. However, since  affects flags it might introduce bogus dependencies.

side effects for,, and

 * OF ≔ 0
 * CF ≔ 0
 * SF becomes the value of the most significant bit of the calculated result
 * ZF ≔ result = 0
 * PF is set according to the result

operation
Performs a bit-wise inversion of argument.

side-effects
None.

application

 * is frequently used to get a register with all bits set.