Logical instructions of 8051

As there were 24 arithmetic instruction sets,and there are 25 logical instructions in 8051. AND , OR, XOR , NOT …. These instructions come under logical instructions.

ANL A, #14H :

This is AND instruction performed between the data of register A, and the 14H

A ← A *14H ,  the result is stored in A register, * is the symbol of and operation.

ABA*B
000
010
100
111

The AND table shows that 

  1. AND operation between any bit and zero is always zero.
  2. AND operation between any bit and one is the bit itself the result.

Applications of AND operation.

  1. Reset the lower nibble without affecting higher nibble of a register A ( 0100 1011 ). Then we do an AND operation with A register. The bits we wanted to RESET should be AND with 0. The bits we wanted to keep unchanged , do AND operation with 1.
logical-instructions-of-8051

ANL A, R0 :

This is AND instruction similar to above, but this is AND operation between A register and R0 register. The result is stored in A register. 
A ← A *R0

ANL A, 14H :

A ← A + [ 14H ]

Here the AND is performed between A register content and content of 14H location. The result is stored in A register. 
A ← A *[ 14H ]

ANL A, @R0 :

Here @R0 stands for the data of the location , stored in R0

ANL 14H, A :

This is the same to ANL A, 14H , but in this instruction the final result is stored in 14H location.

[ 14H ]  ← A * [ 14H ]

ANL 14H , #14H :

[ 14H ]  ← 14H + [ 14H ] ; both are different here.

ORL A, #14H
ORL A, R0
ORL A, 14H
ORL A, @R0
ORL 14H, A
ORL 14H , #14H

These all are OR instructions, and all are similar to AND instruction types.

ABA+B
000
011
101
111

The OR table shows that 

  1. OR operation between any bit and zero is the bit itself the result.
  2. OR operation between any bit and one is always one.

Applications of OR operation.

  1. SET the lower nibble without affecting higher nibble of a register A ( 0100 1011 ). Then we do an OR operation with A register. The bits we wanted to SET should be OR with 1. The bits we wanted to keep unchanged , do OR operation with zero.
logical-instructions-of-8051

XRL A, #14H
XRL A, R0
XRL A, 14H
XRL A, @R0
XRL 14H, A
XRL 14H , #14H

This is X-OR operation, and the instruction are similar 

ABA xor B
000
011
101
110

The XOR table shows that 

  1. XOR operation between any bit and zero is the bit itself the result.
  2. XOR operation between any bit and one is the complement of the bit.

ROTATE INSTRUCTIONS:

These rotate instructions are important part of logical instructions of 8051, and these rotate instructions are classifies as

RL A

This instruction is to shift all the bits from LSB to all the way left of it. Thus named rotate left.

logical-instructions-of-8051

From the above figure, rotating left goes all up to MSB, and MSB value is assigned to LSB as well as Carry Flag, where the CF has lost its value. 

RR A

This instruction is to shift all the bits from MSB to all the way right of it. Thus named rotate right.

logical-instructions-of-8051

From the above figure, rotating right goes all up to LSB, and LSB value is assigned to MSB as well as Carry Flag, where the CF has lost its value. 

RLC A

This instruction is to shift all the bits from LSB to all the way left of it including the carry flag in it. Thus named rotate left with carry.

logical-instructions-of-8051

From the above figure, rotating left goes all up to CF, and then the value of CF is assigned to LSB. Here we don’t lose the data of the CF flag register. 

RRC A

This instruction is to shift all the bits from MSB to all the way left of it including the carry flag in it. Thus named rotate right with carry.

logical-instructions-of-8051

From the above figure, rotating right goes all up to CF, and then the value of CF is assigned to MSB. Here we don’t lose the data of the CF flag register. 

Application of rotate instructions:

Find whether a byte is even or odd?
To find this , we have to determine the value of LSB ( all other bits are multiple of 2 ) , if LSB is 1 then its odd number or else it’s even number.
Rotate left and let LSB come in CF, access the CF.
Then rotate back right to get actual data. To get the original value of CF use RRC and RLC.

Find any bit in a register !
Then rotate the bits, until the required bit gets in CF. access the CF. 

CF is a part of the flag register which is SFR, and all the bits of CF are given or accessed by the programmer.

Swap higher nibble and lower nibble. 
Rotate 4 times. Exclude CF in the loop.

CLR A:

Clears the each and every bit of A register.

A ← 00H

CPL A:

It gives back the complement of the bit.

A ← A ( A bar )

SWAP A:

It swaps the higher nibble of the byte with lower nibble.

ALower nibble  ↔ AHigher nibble

These were 25 logical instruction sets of logical groups. 

NOP 

This is no operation, which means 8051 takes the instructions, decodes it and then analyzes it’s a null operation. This whole process consumes 1µ second. We can keep this time waste in a loop and increase it upto few seconds. This instruction can be used as a delay in 8051. And this is the software delay type.

Related Topics:
Logical instructions in 8086

Spread knowledge

Leave a Comment

Your email address will not be published.