on Sunday, 15 September 2013
This is our last post regarding Instruction set of 8051. In this post we will look at the Logical Instructions and they are pretty much easy to use.


ANL: ANL is the Logical AND instruction. We have seen the AND operation in our previous posts. Now we will look  how we make use this Instruction.
ANL destination, source

Data of destination register/address data will be Logically AND with source data.
Do you remember the AND operation, the output will be 1 only when both the inputs are 1.

Write a program to perform logical AND on 34h and 0Fh
Mov A,#34h
ANL A,#0Fh

                  0011 0100 =34
                  0000 1111 =0F
                  0000  0100 = 04

Result 04 will be saved in 'A'
Note, it is also an example for masking the higher nibble. i.e we are making the MSB first 4 bits to zero.

We have seen OR operation in our previous post. Do you remember, the output of OR will be 1 if any one of the input is 1.
ORL destination, source


Mov A,#01h
ORL A,#20h

                0000 0001
                0010 0000
                0010 0001
Result " 21" h will be saved in register 'A'
Note , it is also an example for merging(combining) i.e 01 and 20 =21.

Do you remember the XOR operation, when both the inputs are same then output will be 0 if not 1
XRL destination, source

Example:Write a program to check whether the value in R0 and R1 are equal, if equal then store '1' in R4 if not with '2'

ORG 00h
Mov A,R0
XRL A,R1 ; if A=R1 then result A=0 if not anyother
CJNE A,#0h, xyz ;check if A=0 if not equal jump to xyz
Mov R4,#1h ;equal then store R4=1
SJMP END; short jump to end
xyz: Mov R4,#2h ; if not equal then R4=2


Rotate Right: The bits in the register A will be rotated right i.e MSB will be shifted to LSB one position.

Let A = 0010 100
After RR A  then value of A will be A = 1001 0100
Again RR A then A= 0100 1010
Note, we can only use register A for this purpose.

Rotate Left: The bits in the register A will be rotated left i.e LSB will be shifted to MSB one position. Its opposite to Rotate Right operation.

If A= 0110 0011
After RL A , then A will be 1100 0110

Rotate Right With Carry: 
The bits in the register A will be rotated right along with carry i.e Carry to MSB and MSB to LSB one position and LSB to Carry.

Lets say C=0 and A= 0110 0011
After RRC A , C=1 and A=0011 0001
Again after RRC A , C=1 and A=1001 1000

Rotate Left With Carry:
The bits in the register A will be rotated left along with Carry.

Lets say C=0 and A= 1010 0011
RLC A then C = 1 and A=0100 0110
RLC A then C = 0 and A=1000 1101

Let us look at the last instruction SWAP A :
This instruction shifts the lower nibble to higher nibble and higher nibble to lower nibble.

If A= 1111 0000
After SWAP A , A= 0000 1111

Let us look at other example

If A = 0111 0010 then after SWAP A , A= 0010 0111

We have completed all important instructions of 8051, let us look at addressing modes of 8051 with few examples in our next post.



Post a Comment