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

XOR

From 0x10c Wiki
(Difference between revisions)
Jump to: navigation, search
(Added mnemonic)
(Usage: added truth table)
 
Line 6: Line 6:
  
 
<code>XOR</code> performs a bitwise Exclusive-OR on <code>arg1</code> with <code>arg2</code> and stores the result in <code>arg1</code>. That is, only the bits different between <code>arg1</code> and <code>arg2</code> become 1 in the result; all other bits are set to 0.
 
<code>XOR</code> performs a bitwise Exclusive-OR on <code>arg1</code> with <code>arg2</code> and stores the result in <code>arg1</code>. That is, only the bits different between <code>arg1</code> and <code>arg2</code> become 1 in the result; all other bits are set to 0.
 +
 +
{| class="wikitable"
 +
|+ 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
 +
|}
  
 
===Example===
 
===Example===

Latest revision as of 20:11, 13 July 2012

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

Contents

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

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.

Signing dependence

XOR works correctly with both signed and unsigned numbers.

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.

References

Personal tools
Namespaces
Variants
Actions
Navigation
Community
Toolbox