Rotate Instructions in 8086 Microprocessor – ROL, ROR, RCR & RCL

In the last article, we have seen the shift instructions of the 8086 microprocessor that performs bit-wise shifting of specified byte either to the left or right side. Similar to shift instructions, there are rotate instructions in the 8086 microprocessor where bits of operand are rotated either to the left or right side. There are four rotate instructions in the 8086 microprocessor,

  • ROL (Rotate Left) Instruction,
  • ROR (Rotate Right) Instruction,
  • RCL (Rotate Carry Left) Instruction,
  • RCR (Rotate Carry Right) Rotate Carry Right.

The shift instructions and rotate instructions look similar in operation, but the difference is that, in shift instructions, the bits shifted out of operand are lost. Whereas in the case of rotate instructions the bits shifted out of operand from one end will flow back to the operand from another end.

By using RCL and RCR instructions the bits in the operand are rotated through the carry flag i.e., the operand is extended by the carry flag. In order to execute rotate instructions, the destination operand must be a register or memory operand and it should not be an immediate operand. Let us learn briefly about rotate instructions of the 8086 microprocessor.

ROL Instruction :

This instruction stands for Rotate Left without carry flag. The contents of the operand (register or memory location) are rotated left bit-wise by some number of positions depending on the count value. During this rotation, the most significant bit (MSB) is moved into the carry flag (CF) as well as into the least significant bit (LSB) position. The below shows the operation ROL instruction with count value 2.

Rotate Instructions in 8086 Microprocessor

In the above figure, we can see on shifting of each bit of operand to the left side, the MSB is shifted to CF and to the LSB position. The number of times the bits should be rotated left is given as the count value in the instruction. In case if the count value is two or more than two times, firstly CL register is loaded with the count value, and then CL is mentioned in the instruction (i.e, in place of the count value) as shown in the below examples.

Example for ROL Instruction :

Instruction Explanation
ROL CX, 1 ; bits in CX is rotated 1-bit left
; MSB is shifted to CF and LSB
ROL BL, CL ; bits in BL is rotated 5-bits left (assuming CL = 05H)
; MSB is shifted to LSB for 5 times
; CF contains the last shifted bit from MSB to LSB

ROR Instruction :

This instruction stands for Rotate Right without carry flag. The contents of the operand are rotated right bit-wise by some number of positions depending on the count value. The ROL instruction seen above rotates the bits towards the left side, whereas the ROR instruction rotates the bits towards the right side. Since this instruction rotates the bits right, the least significant bit (LSB) is moved into the carry flag (CF) as well as into the most significant bit (MSB) position. The below shows the operation ROR instruction with count value 2.

Rotate Instructions in 8086 Microprocessor

The number of times the bits should be rotated right is given as the count value in the instruction. In case if the count value is two or more than two times, firstly CL register is loaded with the count value, and then CL is mentioned in the instruction (i.e, in place of the count value) as shown in the below examples.

Example for ROR Instruction :

Instruction Explanation
ROR CX, 1 ; bits in CX is rotated 1-bit right
; LSB is shifted to CF and MSB
ROR BL, CL ; bits in BL is rotated 5-bits right (assuming CL = 05H)
; LSB is shifted to MSB for 5 times
; CF contains the last shifted bit from LSB to MSB

RCR Instruction :

This instruction stands for Rotate Right Through Carry. In this instruction, the contents of the operand (register or memory location) are rotated right bit-wise by some number of positions along with the carry flag. During the rotation the least significant bit (LSB) is moved to carry flag, and the carry flag is moved into the most significant bit (MSB). The below shows the operation RCR instruction with count value 2.

Rotate Instructions in 8086 Microprocessor

In the above figure, we can see that the carry flag is also been the part of the rotation of bits to the right. In the previous two instructions i.e., ROR and ROL, the carry flag` is not considered while rotating bits, but it is filled with bit moved from LSB in case of ROR and MSB in case of ROL.

In RCR instruction, during the first rotation, the bit which is already present in the carry flag is moved to MSB, and LSB is moved to carry flag. Similar to ROL and ROR, CL is used, if the rotation of bits is more than one time as shown in the below examples.

Example for RCR Instruction :

Instruction Explanation
RCR CX, 1 ; bits in CX is rotated 1-bit right
; LSB is shifted to CF and CF is shifted to MSB
RCR BL, CL ; bits in BL is rotated 5-bits right (assuming CL = 05H)
; LSB is shifted to CF and CF is shifted to MSB for 5 times

RCL Instruction :

This instruction stands Rotate Left Through Carry. This instruction is similar to RCR instruction, but in this, the contents of the operand will be rotated bit-wise left with the carry flag involved in the rotation. The below shows the operation RCL instruction with count value 2.

Rotate Instructions in 8086 Microprocessor

Since the bits are rotated left in RCL instruction, the CF is shifted to LSB, and MSB is shifted to CF and CL register is used in the instruction for rotating the bits more than one time as shown in the below examples.

Example for RCL Instruction :

Instruction Explanation
RCL CX, 1 ; bits in CX is rotated 1-bit left
; MSB is shifted to CF and CF is shifted to LSB
RCL BL, CL ; bits in BL is rotated 5-bits left (assuming CL = 05H)
; MSB is shifted to CF and CF is shifted to LSB for 5 times

Leave a Comment