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
complement (not operation)
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
2. Rotate accumulator right by one bit
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
SWAP
For example,
A=53H (before execution)
SWAP A
A=35H (After execution)
MOV A, #53H //A=53H
SWAP A //A=35H
Post a Comment