Unary operations require a single operand thus the operations are performed on a single operand. The source, as well as destination for these operations, is Accumulator.

*Unary operations

  • Clear
  • Complement
  • Rotate
  • SWAP 

clear

clear instruction is used to clear the contents of the accumulator, the format of this instruction is

                            CLr A   // clear accumulator, a=00h

complement (not operation)

Generally, complement is used to generate l's complement of the data in an accumulator i.e. All 0s will replaced by 1 and 1s will be replaced by 0.

                        CPL A  // complement A

Rotate

The 8051 has four different rotate instructions as described in the following section.

1. Rotate accumulator left by one bit

2. Rotate accumulator right by one bit

3. Rotate accumulator left through carry by one bit

4. Rotate accumulator right through carry by one bit


1. Rotate accumulator left by one bit

RL A // rotate A one bit position to the left, bit D0 to D1, bit D1 to D2, …, bit D6 to D7 and bit D7 to D0



For example,
MOV A, #43H // A= 0100 0011
RL A // A=1000 0110
RL A // A=0000 1101

2. Rotate accumulator right by one bit

RR A // rotate A one bit position to the right, bit D0 to D7, bit D7 to D6, …, bit D2 to D1 and bit D1 to D0

For example,

MOV A, #35H // A= 0011 0101

RR A // A= 1001 1010


3. Rotate accumulator left through carry by one bit

RLC A // rotate A one bit position to the left through carry flag, bit D0 to D1, bit D1 to D2, …, bit D6 to D7, bit D7 to CY and CY to D0 



For example,

CLR C // CY=0

MOV A, #0D6H // A= 1101 0110, CY=0 

RLC A // A= 1010 1100, CY=1


4. Rotate accumulator right through carry by one bit

RRC A // rotate A one bit position to the right through carry flag, bit D0 to CY, CY to D7, bit D7 to D6,…, bit D2 to D1 and bit D1 to D0


For example,
SETB C // CY=1
MOV A, #62H // A= 0110 0010, CY=1 
RRC A // A= 1011 0001, CY=0


 SWAP 

SWAP A instruction swaps the nibbles of register A i.e. it interchanges the upper nibble with lower nibble of A. This operation is equivalent to 4-bit rotation in either left or right direction. It works only with A register.




For example,

A=53H (before execution)

SWAP A

A=35H (After execution)

MOV A, #53H //A=53H

SWAP A //A=35H

Post a Comment

Previous Post Next Post