EOR (bitwise Exclusive OR)

A = A ^ [operand]

EOR performs a bitwise exclusive OR operation between the accumulator register (A) and an operand. The result is stored in the accumulator.

Addressing Modes

Mode

Syntax

Bytes

Cycles

Immediate

EOR #const

49 nn

2

ZeroPage

EOR zp

45 nn

3

ZeroPage+X

EOR zp,x

55 nn

4

Absolute

EOR addr

4D ll hh

4

Absolute+X

EOR addr,x

5D ll hh

4-5

Absolute+Y

EOR addr,y

59 ll hh

4-5

(Indirect+X)

EOR (zp,x)

41 nn

6

(Indirect)+Y

EOR (zp),y

51 nn

5-6

Flags Affected

  • N (Negative) – Set if the result has the most significant bit set (i.e., is negative); otherwise, it is cleared.

  • Z (Zero) – Set if the result is zero; otherwise, it is cleared.

Examples

Simple Exclusive OR with a Constant

    LDA #0x55  ; load A with 01010101b
    EOR #0xAA  ; perform exclusive OR with 10101010b
               ; A now contains 11111111b

Exclusive OR with a Memory Location

    LDA $12    ; load A with the value at memory location $12
    EOR #$FF   ; perform exclusive OR with constant FFh
               ; A now contains the bitwise complement of the value at $12

Exclusive OR with a Memory Location using Zero Page Addressing

    LDA $04    ; load A with the value at memory location $04
    EOR $05    ; perform exclusive OR with the value at memory location $05
               ; A now contains the result of the bitwise exclusive OR operation

Exclusive OR with a Memory Location using Zero Page Addressing with Indexing

    LDX #$02   ; load X with 2
    LDA $05,X  ; load A with the value at memory location $07
    EOR #$FF   ; perform exclusive OR with constant FFh
               ; A now contains the bitwise complement of the value at $07

Exclusive OR with a Memory Location using Absolute Addressing

    LDA $1234  ; load A with the value at memory location $1234
    EOR #$AA   ; perform exclusive OR with constant AAh
               ; A now contains the result of the bitwise exclusive OR operation

Exclusive OR with a Memory Location using Absolute Addressing with Indexing

    LDY #$02   ; load Y with 2
    LDA $1234,Y ; load A with the value at memory location $1236
    EOR #$0F   ; perform exclusive OR with constant 0Fh
               ; A now contains the result of the bitwise exclusive OR operation

Exclusive OR with a Memory Location using Indirect Addressing with Indexing

asmCopy code    LDX #$01    ; load X with 1
    LDA ($10,X) ; load A with the value at the address contained in $11
    EOR #$55    ; perform exclusive OR with constant 55h
                ; A now contains the result of the bitwise exclusive OR operation

Exclusive OR with a Memory Location using Indirect Addressing with Indexing

    LDY #$01      ; load Y with 1
    LDA ($10),Y   ; load A with the value at the address contained in $11
    EOR #$FF      ; perform exclusive OR with constant FFh
                  ; A now contains the bitwise complement of the value at $11

Note: These examples are for illustrative purposes only and may not be suitable for use in actual programs.

See Also

  • ORA (bitwise OR with accumulator)

  • AND (bitwise AND with accumulator)

Comments