INSTRUCTION SET PART3

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.

LOGICAL INSTRUCTIONS:

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.

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

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.

ORL:
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

Example:

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.

XOR:
Do you remember the XOR operation, when both the inputs are same then output will be 0 if not 1XRL 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 endxyz: Mov R4,#2h ; if not equal then R4=2
END

ROTATE INSTRUCTIONS

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

Let A = 0010 1001
After RR A then value of A will be A = 1001 0100
Again RR A then A= 0100 1010Note, 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.RL A

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.
RRC A

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.RLC A

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 1101Let 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.