This is more of a just for fun question. I’m working on a SC61860 CPU, which is an 8-bit CPU for a Sharp PC-1360 Pocket Computer from 1987 (also used in PC-1401 & 1403’s). Its instruction set doesn’t actually include an XOR. It does have AND, OR, compare, subtraction and addition instructions.
I have tried a few variations of ANDing and ORing values to get result that XOR would produce, but no luck. I was hoping to avoid comparing, but it looks like I don’t have a choice.
If you're interested, you can check out the instruction set.
BTW, this CPU has been great to learn assembly on. Nice and simple, and slow enough (768kHz) that machine language is noticeably faster then using the computers built in BASIC ;) I usually program in C/C++/Java. Assembly has been a breath of fresh air.
This means that any value XOR'd with zero is left unchanged. This means that any value XOR'd with itself gives zero.
logical xor EditPerforms a bit-wise xor of the two operands, and stores the result in destination .
The XOR instruction performs a bit wise Exclusive OR operation between corresponding bits in the two operands and places the result in the first operand. reg, mem, and immed can be 8, 16, or 32 bits. The XOR instruction can be used to reverse selected bits in an operand while preserving the remaining bits.
While the x86/x64 architectures do not have an architectural zero register it seems likely that the Sandybridge processor has a physical zero register. When the renamer detects one of these special instructions it just renames the architectural register to point at the zero register.
From boolean algebra we know that:
A XOR B = (NOT(A) AND B) OR (A AND NOT(B))
Update:
Thank @Brett Hale, @slebetman, as the CPU surprisingly not supporting the NOT
instruction, it can be emulated by arithmetic negation and subtraction, assuming 2's complement negatives representation):
NOT(A) = (-1) - A
Or in case of different negative representation the -1
can be replaced by the corresponding storage type maximum value (i.e. 255 for 8 bit registers or 65565 for 16 bit registers).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With