xor
Bitwise XOR (exclusive OR)
Sets $t1 to $t2 XOR $t3, or an immediate, so each result bit is 1 where the inputs differ.
Used in
- Arithmetic, logic and bitsMIPS assembly
- The snake gameMIPS assembly
- Flappy birdMIPS assembly
Forms
xor , ,
Pseudo-instructions
The assembler turns these into one or more real instructions.
-
Set $t1 to ($t2 bitwise-exclusive-OR 16-bit unsigned immediate)
-
Set $t1 to ($t1 bitwise-exclusive-OR 16-bit unsigned immediate)
Operands
$t1- Any general-purpose register,
$0to$31, using its numeric or named spelling, such as$8or$t0($zerois$0;$rais$31). $t2- A general-purpose register. It may be the same register as
$t1. $t3- A general-purpose register. It may be the same register as
$t1. uimm16- An unsigned 16-bit immediate,
0to65535.
Each bit of $t1 is 1 if the corresponding bits in $t2 and $t3 differ. Used to toggle specific bits, detect differences, or implement simple encryption/checksums.
# Initialize both inputs, then execute xor with initialized inputs. Inspect $t2: 4.
li $t0, 7
li $t1, 3
xor $t2, $t0, $t1