Vol. 1 7-13
PROGRAMMING WITH GENERAL-PURPOSE INSTRUCTIONS
7.3.6.3
Rotate Instructions
The ROL (rotate left), ROR (rotate right), RCL (rotate through carry left) and RCR (rotate through carry right)
instructions rotate the bits in the destination operand out of one end and back through the other end (see
Figure 7-10). Unlike a shift, no bits are lost during a rotation. The rotate count can range from 0 to 31.
The ROL instruction rotates the bits in the operand to the left (toward more significant bit locations). The ROR
instruction rotates the operand right (toward less significant bit locations).
The RCL instruction rotates the bits in the operand to the left, through the CF flag. This instruction treats the CF
flag as a one-bit extension on the upper end of the operand. Each bit that exits from the most significant bit loca-
tion of the operand moves into the CF flag. At the same time, the bit in the CF flag enters the least significant bit
location of the operand.
The RCR instruction rotates the bits in the operand to the right through the CF flag.
For all the rotate instructions, the CF flag always contains the value of the last bit rotated out of the operand, even
if the instruction does not use the CF flag as an extension of the operand. The value of this flag can then be tested
by a conditional jump instruction (JC or JNC).
7.3.7
Bit and Byte Instructions
These instructions operate on bit or byte strings. For the purpose of this discussion, they are further divided into
subordinate subgroups that:
•
Test and modify a single bit
•
Scan a bit string
•
Set a byte given conditions
•
Test operands and report results
Figure 7-10. ROL, ROR, RCL, and RCR Instruction Operations
Destination (Memory or Register)
CF
31
0
Destination (Memory or Register)
CF
0
31
Destination (Memory or Register)
CF
31
0
Destination (Memory or Register)
CF
31
0
ROL Instruction
RCL Instruction
RCR Instruction
ROR Instruction