The EOR operator

The instruction EOR ("exclusive or") will return a true value (1) if one, and only one, of the bits in the pair being tested is a 1. The following turth table is for the EOR operator.

Truth Table for "EOR"

0 110

The EOR instruction is often used for comparing bytes to determine if they are identical, since if any bit in two bytes is different, the result of a comparison will be non-zero. Here is an illustration of that comparison.

Example 1 Example 2

1011 0110 1011 0110 EOR 10110110 But: EOR 10110111

0000 0000 0000 0001

In Example 1, the bytes being compared are identical, so the result of the comparison is zero. In Example 2, one bit is different, so the result of the comparison is non-zero. The EOR operator is also used to complement values. If an 8-bit value is used with $FF, every bit in it that's a 1 will be complemented to a 0, and every bit that's a 0 will be complemented to a 1.

1110 0101 (in accumulator) EOR 1111 1111

0001 1010 (new value in accumulator)

Still another useful characteristic of the EOR instruction is that when it is performed twice on a number using the same operand, the number will be first be changed to another number, and then restored to its original value. This is shown in the following example.

1110 0101 (in accumulator) EOR 0101 0011

1011 0110 (new value in accumulator) EOR 0101 0011 (same operand as above)

1110 0101 (original value in accumulator restored)

This capability of the EOR instruction is often used in high resolution graphics to put one image over another without destroying the one underneath. (Yes, that's how its done!)

The "BIT" operator

That brings us to the BIT operator, an instruction even more esoteric than AND, ORA, or EOR. The BIT instruction is used to determine the state of a specific bit — or specific bits — of a binary value stored in memory. When the BIT instruction is used in a program, bits 6 and 7 of the value being tested are transferred directly to bits 6 and 7 (the sign and overflow bits) of the processor status register. Then an AND ojèplration is performed with the accumulator and the value in memory. The result of this AND operation is stored in the Z (zero) flag of the P register. If there is a 1 in both the accumulator and the value in memory at the same bit position, the result is non-zero and the Z flag is cleared. If the bits are different or both zero, the result is zero and the Z flag is set. The most important aspect here is that after all of this takes place, the values in the accumulator and the memory location remain unchanged.

0 0

Post a comment

  • Receive news updates via email from this site