We're looking for your comments on how to best organize the wiki's content.

XOR

From 0x10c Wiki
Jump to: navigation, search

XOR (Exclusive OR) is one of the opcodes in the DCPU-16 specification. It represents a bitwise Exclusive-OR operation.

Contents

[edit] Usage

 XOR arg1, arg2

XOR performs a bitwise Exclusive-OR on arg1 with arg2 and stores the result in arg1. That is, only the bits different between arg1 and arg2 become 1 in the result; all other bits are set to 0.

Truth table for Y(A, B) = A XOR B
Input A Input B Output Y
0 0 0
0 1 1
1 0 1
1 1 0

[edit] Example

SET A, 3 ; 0b0011
XOR A, 5 ; 0b0101
; A is now 0b0110, or 6

In the above program, each bit of each argument to XOR is compared to each other. Starting from the rightmost, least significant bit:

  1. 1 equals 1, so the LSB of A is set to 0
  2. 1 is not equal to 0, so the next bit of A is set to 1
  3. 0 is not equal to 1, so the next bit of A is set to 1
  4. 0 is not equal to 0, so the next bit of A is set to 0
  5. Same for the high 12 bits of the arguments - all are 0, so the high 12 bits of A are set to 0.

[edit] Signing dependence

XOR works correctly with both signed and unsigned numbers.

[edit] Processing

In binary machine code, this Basic opcode's five-bit representation is: 0b0 1100 (0x0c)

The instruction has a takes one cycle to execute, plus any additional cycles necessary to evaluate the arguments.

[edit] References

Personal tools
Namespaces
Variants
Actions
Navigation
Community
Toolbox