Section 03 Part 04 – The EOR Instruction (XOR)

 

An action doesn't have to be wrong just because it is not logical. It doesn't have to be right just because it has its logic. ~Lion Feuchtwanger

 

 

 

Introduction

 

EOR – Exclusive OR logical

 

This instruction will perform XOR logical between the source operand and destination operand, the result is saved to the destination operand.

 

So what is XOR logical?

 

Let us take two bits, one from the source operand and one from the destination operand, and perform XOR logical:

 

source operand

 

destination operand

 

Result

 

 

 

 

 

0

XOR

0

=

0

0

XOR

1

=

1

1

XOR

0

=

1

1

XOR

1

=

0

 

The idea is that only one has to be 1 for the result to be 1.  To understand further, once again, pretend 0 is false, and 1 is true:

 

source operand

 

destination operand

 

Result

 

 

 

 

 

False

XOR

False

=

False

False

XOR

True

=

True

True

XOR

False

=

True

True

XOR

True

=

False

 

 

They must be the opposite of each other for the result to be true.

 

The name that most other instruction sets use is XOR, the 68k uses the mnemonic EOR instead.  They have the same meaning and are the same thing, but I’m writing it here just so we’re clear on the situation.

 

 

 

Examples

 

So, here is an example (we’ll pretend that d0 contains 01234567 again):

 

          eori.b    #$E2,d0

 

This instruction will “XOR” the byte E2 with the byte 67 inside d0.  E2 and 67 in binary is 1110 0010 and 0110 0111.

 

E2

1

1

1

0

0

0

1

0

 

 

 

 

 

 

 

 

 

XOR

XOR

XOR

XOR

XOR

XOR

XOR

XOR

XOR

 

 

 

 

 

 

 

 

 

67

0

1

1

0

0

1

1

1

 

 

 

 

 

 

 

 

 

=

=

=

=

=

=

=

=

=

 

 

 

 

 

 

 

 

 

85

1

0

0

0

0

1

0

1

 

As you see above, the source and the destination must not match for the result to be 1, if they match, the result is 0.

 

E2 XOR 67 = 85

 

85 is saved into d0, d0 now contains 01234585.

 

Just like the “AND” and “OR” instructions, EOR has the same abilities, with an exception.  You can EOR one register to another:

 

          eor.w     d0,d1

 

You can EOR on memory in various ways:

 

          eori.w    #$07FF,$00004000

          eor.w     d0,$00004000

 

And you can EOR on memory using the address registers:

 

          eori.w    #$07FF,(a1)

          eor.w     d0,(a3)

 

For EOR, the source operand cannot be a memory address, or memory using an address register:

 

          eor.w     $00020000,d0

          eor.b     (a0),d0

 

Additionally, you cannot EOR onto address registers directly:

 

          eori.w    #$0042,a0

 

 

 

EOR Immediate

 

If the source operand is “immediate”, you must use the instruction “eori” instead of “eor”:

 

          eori.w    #$E003,d0

 

The assembler will turn “eor” into “eori” for you, when it assembles your code, if you use “eor” instead by mistake.

 

 

 

Previous Part

Main Page

Next Part