The binary AND operation has two inputs and one output. It is like the ADD operation which takes two arguments (two inputs) and produces one result (one output).
The inputs to a binary AND operation can only be 0 or 1 and the result can only be 0 or 1
The binary AND operation (also known as the binary AND function) will always produce a 1 output if both of its inputs are 1 and will produce a 0 output if one or both of its inputs are 0.
If we call the inputs A and B and the output C we can show the AND function as:
A B C 0 AND 0 -> 0 0 AND 1 -> 0 1 AND 0 -> 0 1 AND 1 -> 1
The PIC machine code AND instruction operates on 8 sets of inputs and outputs in parallel.
If we AND two input bytes together on the PIC we get an output byte. If we give each bit within a byte a number we can see that each bit in the output is the result of the AND function on two corresponds bits of the input
i.e.So if we have two binary numbers 00100100 and 00100001 we can see the effect of ANDing these two sets of 8 bits in parallel.
A7 A6 A5 A4 A3 A2 A1 A0 B7 B6 B5 B4 B3 B2 B1 B0 C7 C6 C5 C4 C3 C2 C1 C0e.g.
argument 1 0 0 1 0 0 1 0 0 argument 2 0 0 1 0 0 0 0 1 result 0 0 1 0 0 0 0 0
The input bits A5 and B5 and the output bit C5 are here shown in red
The input bits A2 and B2 and the output bit C2 are here shown in green
The input bits A1 and B1 and the output bit C1 are here shown in yellow
The input bits A0 and B0 and the output bit C0 are here shown in blue
In XCSB the binary AND operator works in the same way, operating in parallel on sets of inputs and outputs within a variable or constant.
If we assign the value 0x24 to the variable J, which is the hexadecimal equivalent of the binary value 00100100, the value 0x21 to the variable K which is the hexadecimal equivalent of the binary value 00100001 and then perform the XCSB AND operation on J and K and assign the result to M. The value stored in M will be 0x20 which is the hexadecimal equivalent of the binary value 00100000
Written as XCSB source code this would be:J = 0x24 K = 0x21 M = J & K