XOR
When we use logical bitwise XOR we are making a bit-to-bit comparison of two 8-bit values. Each bit is compared within the same position. Unlike OR, if both match 1 then 0 is the result. This is because there needs to be an exclusive value between the comparision. See logic table below for further illustration.
This operation is particularly useful for masking bits. Certain bits are preserved or cleared based on the mask used.
Note, it is possible to include A as the first parameter but this can be ommitted due to it only ever supporting A. i.e. XOR B and XOR A, B are the same.
| A | ? | Result |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
| Example | ||
| A | B | Result |
| 10010011 | 10101110 | 00111101 |
We can think of the logic of XOR easily in the perspectives of other programming languages as XOR is usually available. Take the following psuode code for example:
- if( false XOR false ) this will never fire
- if( false XOR true ) then do this
- if( true XOR false ) then do this
- if( true XOR true ) this will never fire
| Instruction | Description | Opcode |
|---|---|---|
| XOR A | Compare A with itself | AF |
| XOR B | Compare the 8-bit number in B register with value in A register | A8 |
| XOR C | Compare the 8-bit number in C register with value in A register | A9 |
| XOR D | Compare the 8-bit number in D register with value in A register | AA |
| XOR E | Compare the 8-bit number in E register with value in A register | AB |
| XOR H | Compare the 8-bit number in H register with value in A register | AC |
| XOR L | Compare the 8-bit number in L register with value in A register | AD |
| XOR {??} | Compare the 8-bit immediate number with value in A register | EE {??} |
| XOR (HL) | Compare the 8-bit number at memory address HL with value in A register | AE |
| XOR (IX+displacement) | Compare the 8-bit value in IX with value in A register | DDAE ?? |
| XOR (IY+displacement) | Compare the 8-bit value in IY with value in A register | FDAE ?? |