Logical Instructions in AVR Microcontroller

Logical Instructions are the instructions which perform basic arithmetic operations such as AND, OR, XOR, etc. In AVR micro-controller, the destination operand is always a register.

The following table shows the logical instructions :

Instruction Operand Explanation Example
AND D, S D = D AND S
Performs a AND operation on the operands
and stores the result in the left hand operand
AND D, S
ANDI D, k(constant) D = D AND k
Performs a AND operation on the operands
and stores the result in the left hand operand with the right hand operand being a constant
ANDI D, k
OR D, S D = D OR S
Performs a OR operation on the operands
and stores the result in the left hand operand
OR D, S
ORI D, k D = D OR k
Performs a OR operation on the operands
and stores the result in the left hand operand with the right hand operand being a constant
ORI D, k
EOR D, S D = D XOR S
Performs a EX-OR operation on the operands
and stores the result in the left hand operand
EOR D, S
COM D. D = 1’s complement of D
The complement action changes ‘1’s to ‘0’s
and ‘0’s to ‘1’s
COM D
NEG D D = 2’s complement of D
This instruction takes the 2’s complement
NEG D
CP D, S Compares D and S
This instruction is really a subtraction action.
The only difference is that the values of registers don’t change
CP D, S
CPI D, k Compares D and k
The only difference between CP an CPI is that
CPI has one of the operands as a constant
CP D, k

Note :
D and S are Destination and Source respectively. Both are registers. k is a constant.

Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.