Wednesday, March 23, 2016

8051 Rotate Accumulator

Bit Shifting
In many applications there is a need to perform a bitwise rotation of an operand. 8051 allow a program to rotate the accumulator right or left. In the 8051, to rotate a byte the operand must be in register A.

Rotate Accumulator Right – RR A
The eight bits in the Accumulator are rotated one bit to the right. Bit 0 is rotated into the bit 7 position. No flags are affected.

Encoding: 0 0 0 0 0 0 1 1

The Accumulator holds the value 0C5H (11000101B). The following instruction,

RR A

leaves the Accumulator holding the value 0E2H (11100010B) with the carry unaffected.

ORG 0H
MOV A, #0C5H; A = 11000101B
RR A ; A = 11100010B
END; end of asm source file


Rotate Accumulator Right through Carry flag – RRC A
The eight bits in the Accumulator and the carry flag are together rotated one bit to the right. Bit 0 moves into the carry flag; the original value of the carry flag moves into the bit 7 position. No other flags are affected.

Encoding: 0 0 0 1 0 0 1 1

The Accumulator holds the value 0C5H (11000101B), the carry is zero. The following instruction,

RRC A

leaves the Accumulator holding the value 62 (01100010B) with the carry set.

ORG 0H
MOV A, #0C5H; A = 11000101B
RRC A; A = 01100010B, C = 1
END; end of asm source file


Rotate Accumulator Left – RL A
The eight bits in the Accumulator are rotated one bit to the left. Bit 7 is rotated into the bit 0 position. No flags are affected.

Encoding: 0 0 1 0 0 0 1 1

The Accumulator holds the value 0C5H (11000101B). The following instruction,

RL A

leaves the Accumulator holding the value 8BH (10001011B) with the carry unaffected.

ORG 0H
MOV A, #0C5H; A = 11000101B
RL A; A = 10001011B
END; end of asm source file


Rotate Accumulator Left through the Carry flag – RLC A
The eight bits in the Accumulator and the carry flag are together rotated one bit to the left. Bit 7 moves into the carry flag; the original state of the carry flag moves into the bit 0 position. No other flags are affected.

Encoding: 0 0 1 1 0 0 1 1

The Accumulator holds the value 0C5H(11000101B), and the carry is zero. The following instruction,

RLC A

leaves the Accumulator holding the value 8AH (10001010B) with the carry set.

ORG 0H
MOV A, #0C5H; A = 11000101B
RLC A; A = 10001010B, C = 1
END; end of asm source file


Serializing Data:
Serializing data is a way of sending a byte of data one bit at a time through a single pin of microcontroller. There are two ways to transfer a byte of data serially:
  • Using serial port
  • Transferring data one bit at a time through a single pin

Serializing data is one of the most widely used applications of the rotate instruction. Using that concept and the rotate instruction, we transfer a byte of data serially (one bit at a time).

ORG 0H
MOV A, #0C5H
MOV R7, #8
LOOP : RRC A ; move bit to carry
MOV P0.1, C ; send bit on data pin
DJNZ R7, LOOP
END; end of asm source file



Related topics:
8051 Complement Accumulator and Bit   |   8051 Set Bit   |   8051 Clear Accumulator and Bit   |   8051 Swap Nibble   |   8051 Exchange Accumulator   |   8051 Exchange Digit   |   8051 Push and Pop   |   8051 No Operation

List of topics: 8051

No comments:

Post a Comment