Instructions
XOR Instructions
The Exclusive-OR instruction (XOR) differs from InclusiveOR (OR). The difference is that a 1,1 condition of the OR function produces a l , while the 1,1 condition of the Exclusive-OR operation produces a O. The Exclusive-OR operation excludes this condition, while the Inclusive-OR includes it. If the inputs of the Exclusive-OR function are both 0 or both 1, the output is O. If the inputs are different, the output is 1. Because of this, the Exclusive-OR function is sometimes called a comparator.
XOR Instructions
The XOR instruction uses any addressing mode except segment register addressing. Table 5-16 lists several Exclusive-OR instructions and their operations.
XOR Instructions
As with the AND and OR functions, Exclusive-OR can replace discrete logic circuitry in embedded applications. The 7486 quad, 2-input Exclusive-OR gate is replaced by one XOR instruction. The 7486 costs about 40, while the instruction costs less than I/I00 to store in the memory. Replacing the circuitry on the 7486 saves a considerable amount of money, especially if many systems are built.
XOR Instructions
The Exclusive-OR instruction is useful if some bits of a register or memory location must be inverted. This instruction allows part of a number to be inverted or complemented. Figure 5-8 shows how just part of an unknown quantity can be inverted by XOR. Notice that when a 1 Exclusive-ORs with X, the result is X. If a 0 Exclusive-ORs with X, the result is X.
The NOT instruction inverts all bits of a byte, word, or double-word. The NEG instruction two's complements a number, which means that the arithmetic sign of a signed number changes from positive to negative or negative to positive. The NOT function is considered logical, and the NEG function is considered an arithmetic operation.
On positive integers, a logical left shift is equivalent to multiplication by 2 and a logical right shift is equivalent to division by 2. The arithmetic shift extends this operation to negative 2's complement integers.
An arithmetic right shift is similar to a logical right shift, except that the leftmost bits are filled with the sign bit of the original number instead of 0's.
Observe that in 8 bit 2's complement 1000 1011 equals decimal -117 and the result after the arithmetic right shift is 1100 0101, which equals decimal -59.
Shift
Shift a register r (A,B,D) or a memory operand to the left or right one bit. Left: multiplying by 2 Right: dividing by 2 (MSB is replicated)
N, Z, V, C
Rotate a register r (A,B) or a memory operand to the left or right through carry (C) one bit. N, Z, V, C
For example, if EAX = 60000000H and the BSF EBX,EAX instruction executes, the number is scanned from the rightmost bit toward the left. The first I-bit encountered is at bit position 29, which is placed into EBX, and the zero flag bit is set. If the same value for EAX is used for the BSR instruction, the EBX register is loaded with a 30 and the zero flag bit is set.