Oh man, It was extremely hard trying to understand how these worked. I had to do a ton of testing.
I'm 90% sure this is wrong, but these are the results I got while testing these instructions in dolphin.
These instructions work in a very oddly specific way.
AND
AND means "If both values are true (equal), the result is true".
AND takes the values from Register B and C and compares them, the result of the operation is put in Register A
EXAMPLE:
# Assume that Register 0 and Register 1 both hold the value "3"
and r2, r0, r1
cmpwi r2, 3
beq function2
# This code will compare the values of Registers 0 and 1 to see if they are both equal to 3, in this case they are, so the code jumps to "function2"
- If both the values are the same, the resulting value is the same as the intial value
- If one value is different than the other, the resulting value is
0 (false)
OR
OR means "If at least one value is true (equal), the result is true.
OR takes the values from Register B and C and compares them, the result of the operation is put in Register A
EXAMPLE:
# Assume that Register 0 holds the value "2" and Register 1 holds the value "3"
or r2, r0, r1
cmpwi r2, 3
beq function2
cmpwi r2, 5
beq function2
# You might be wondering why the resulting register is being checked for the value "5".
# If only one of the values is "true", the resulting value is made up of both values added together, which in this case would be "5"
# The code checks to see if either 1 value was "true" (if r2 = 0x5),
or if both of them were (if r2 = 0x3). If one of those conditions are met, the code jumps to "function2"
- If both the values are the same, the resulting value is the intial value
- If 1 value is different, the resulting value is the sum of both values added together
XOR
XOR means "Only one value can be true, otherwise the result is false".
XOR takes the values from Register B and C and compares them, the result of the operation is put in Register A
EXAMPLE:
# Assume that Register 0 holds the value "2" and Register 1 holds the value "3"
xor r2, r0, r1
cmpwi r2, 5
beq function2
# Assume that you want your code to jump to "function2" if only 1 of the values in Register 0 and Register 1 is "true"
# I can't think of a good way to explain this.....
# Basically, the xor instruction adds both values from both registers together if one of them is different from the other.
# Let's assume that in this context, you wanted to check to see if Register 0 or Register 1 held the value "2", as the code above shows.
# Register 0 holds the value "2", and Register 1 holds the value "3"
# The resulting value is "5", and the operation result was "true"
# Do you know why the result was true?
#Because "2" was one of the values that was needed to make the result value.
That's the best way I can possibly explain it.
- If both the values are the same, the resulting value is 0 (false)
- If 1 value is different, the resulting value is the sum of both values added together