5. Exclusive OR Instructions

Having dealt with the inclusive or instructions above, it is now time for the exclusive or instructions. This has the format :

EOR.size Dn,destination

Where size can be byte, word or long. Notice this time that EOR source,Dn is not permitted ? I wonder why ? (I don't know - does anyone ?)

This instruction also sets the flags as per the NOT instruction. In the truth table for inclusive or, there was a 1 bit set in the result when there was a 1 in either the source or destination or both. Exclusive or is different and only allows a 1 in the result when there is a single 1 in either the source or destination. As follows :

Table 4.3. Truth Table for Logical EOR

Source bitDestination BitResulting Bit
000
011
101
110

Using the same example as OR and AND above we now have the following :

D0.W contains $AAAA and D1.W contains $6543 the instruction

EOR.W D0,D1

Will result in D1.W being set to $CFE9 and D0 will remain unchanged. How does this work ? Once again, in binary :

D0 = $AAAA = 1010 1010 1010 1010
D1 = $6543 = 0110 0101 0100 0011

So using the truth table above, the result will be :

D1 = $CFE9 = 1100 1111 1110 1001

One feature of EOR is that if you EOR the result of a previous EOR with the same value again, you get back to the original value. Using this code :

MOVEQ #$AAAA,D0
MOVEQ #$6543,D1
EOR.W D0,D1
EOR.W D0,D1

Wil return us to the state we were in before the first EOR, in that D1 will once again hold the value $6543. Try to work it out for yourselves using the example above as a guideline.

This can be used in a sort of 'Pretty Bad Privacy' program where data is encrypted using EOR. The following small program demonstrates this.

Example 4.1. Pretty Bad Privacy Example

START      MOVEQ     #7,D0
           LEA       DATA_STUFF,A1 
           MOVEQ     #100-1,D1
LOOP       EOR.B     D0,(A1)+
           DBRA.S    D1,LOOP
           RTS

DATA_STUFF           Put 100 bytes of data here !

The LEA instruction is a new one and will be discussed soon. Suffice to say that it simply loads the address of the label 'data_stuff' into the address register named. This must be used in QL programs as they have to be able to run at any memory address. The LEA instruction allows this.

The above code is very simple and assumes that there is exactly 100 bytes of data stored in memory at the location labelled 'data_stuff' To encrypt the data, simply call the routine at label 'start' and 100 bytes will be encrypted. To decrypt it, simply call 'start' again and the data will be restored. This is easily cracked because of the use of a single byte to encrypt the data so don't go using it for anything you value !!!!

EOR has the usual variations :

EORI #data,destination

You will notice the absence of EORI source,Dn as mentioned above.

EORI #data,CCR

EORI #data,CCR is an instruction that is used to change some or all of the flags in the user byte of the status register. The flags are changed as follows :

EORI #data,SR

EORI #data,SR works upon the entire status register.

As above, the flags are changed according to the data - bits 0 to 4. The rest of the status register is changed as follows :

The value in bits 10, 9 and 8 is EOR'd with the current value in the interrupt level bits of the SR and the new value becomes the new interrupt level mask.