rcr
Rotate Carry Right
Rotates bits right through Carry Flag.
Details
Rotates the bits of the destination operand right by the number of positions specified in the count operand, with the carry flag inserted at the high end and the low bit shifted into the carry flag. The rotation is through the carry flag, making it part of the rotating chain. All bits including CF participate in a circular rotate. The OF flag is set/cleared based on the most significant bit change on a single-bit rotate; CF is updated to the last bit shifted out.
Pseudocode Operation
count ← (src == 0) ? 1 : src & 0x1F;
temp_cf ← CF;
for i ← 0 to count - 1:
new_cf ← dest & 1;
dest ← (dest >> 1) | (temp_cf << (width - 1));
temp_cf ← new_cf;
CF ← temp_cf;
if count == 1:
OF ← MSB_before_rotate XOR CF;
Example
Encoding
Operands
-
dest
Register or memory operand -
src
8-bit signed immediate
Reference (Intel® SDM)
Instruction Forms
| Opcode | Instruction | Op/En | 64/32-bit Mode | CPUID | Description |
|---|---|---|---|---|---|
| D0 /2 | RCL r/m8, 1 | M1 | Valid Valid | Rotate 9 bits (CF, r/m8) left once. | |
| D2 /2 | RCL r/m8, CL | MC | Valid Valid | Rotate 9 bits (CF, r/m8) left CL times. | |
| C0 /2 ib | RCL r/m8, imm8 | MI | Valid Valid | Rotate 9 bits (CF, r/m8) left imm8 times. | |
| D1 /2 | RCL r/m16, 1 | M1 | Valid Valid | Rotate 17 bits (CF, r/m16) left once. | |
| D3 /2 | RCL r/m16, CL | MC | Valid Valid | Rotate 17 bits (CF, r/m16) left CL times. | |
| C1 /2 ib | RCL r/m16, imm8 | MI | Valid Valid | Rotate 17 bits (CF, r/m16) left imm8 times. | |
| D1 /2 | RCL r/m32, 1 | M1 | Valid Valid | Rotate 33 bits (CF, r/m32) left once. | |
| REX.W + D1 /2 | RCL r/m64, 1 | M1 | Valid N.E. | Rotate 65 bits (CF, r/m64) left once. Uses a 6 bit count. | |
| D3 /2 | RCL r/m32, CL | MC | Valid Valid | Rotate 33 bits (CF, r/m32) left CL times. | |
| REX.W + D3 /2 | RCL r/m64, CL | MC | Valid N.E. | Rotate 65 bits (CF, r/m64) left CL times. Uses a 6 bit count. | |
| C1 /2 ib | RCL r/m32, imm8 | MI | Valid Valid | Rotate 33 bits (CF, r/m32) left imm8 times. | |
| REX.W + C1 /2 ib | RCL r/m64, imm8 | MI | Valid N.E. | Rotate 65 bits (CF, r/m64) left imm8 times. Uses a 6 bit count. | |
| D0 /3 | RCR r/m8, 1 | M1 | Valid Valid | Rotate 9 bits (CF, r/m8) right once. | |
| D2 /3 | RCR r/m8, CL | MC | Valid Valid | Rotate 9 bits (CF, r/m8) right CL times. | |
| C0 /3 ib | RCR r/m8, imm8 | MI | Valid Valid | Rotate 9 bits (CF, r/m8) right imm8 times. | |
| D1 /3 | RCR r/m16, 1 | M1 | Valid Valid | Rotate 17 bits (CF, r/m16) right once. | |
| D3 /3 | RCR r/m16, CL | MC | Valid Valid | Rotate 17 bits (CF, r/m16) right CL times. | |
| C1 /3 ib | RCR r/m16, imm8 | MI | Valid Valid | Rotate 17 bits (CF, r/m16) right imm8 times. | |
| D1 /3 | RCR r/m32, 1 | M1 | Valid Valid | Rotate 33 bits (CF, r/m32) right once. Uses a 6 bit count. | |
| REX.W + D1 /3 | RCR r/m64, 1 | M1 | Valid N.E. | Rotate 65 bits (CF, r/m64) right once. Uses a 6 bit count. | |
| D3 /3 | RCR r/m32, CL | MC | Valid Valid | Rotate 33 bits (CF, r/m32) right CL times. | |
| REX.W + D3 /3 | RCR r/m64, CL | MC | Valid N.E. | Rotate 65 bits (CF, r/m64) right CL times. Uses a 6 bit count. | |
| C1 /3 ib | RCR r/m32, imm8 | MI | Valid Valid | Rotate 33 bits (CF, r/m32) right imm8 times. | |
| REX.W + C1 /3 ib | RCR r/m64, imm8 | MI | Valid N.E. | Rotate 65 bits (CF, r/m64) right imm8 times. Uses a 6 bit count. | |
| D0 /0 | ROL r/m8,2 1 | M1 | Valid Valid | Rotate 8 bits r/m8 left once. | |
| D2 /0 | ROL r/m8, CL | MC | Valid Valid | Rotate 8 bits r/m8 left CL times. | |
| C0 /0 ib | ROL r/m8, imm8 | MI | Valid Valid | Rotate 8 bits r/m8 left imm8 times. | |
| D1 /0 | ROL r/m16, 1 | M1 | Valid Valid | Rotate 16 bits r/m16 left once. | |
| D3 /0 | ROL r/m16, CL | MC | Valid Valid | Rotate 16 bits r/m16 left CL times. | |
| C1 /0 ib | ROL r/m16, imm8 | MI | Valid Valid | Rotate 16 bits r/m16 left imm8 times. | |
| D1 /0 | ROL r/m32, 1 | M1 | Valid Valid | Rotate 32 bits r/m32 left once. | |
| REX.W + D1 /0 | ROL r/m64, 1 | M1 | Valid N.E. | Rotate 64 bits r/m64 left once. Uses a 6 bit count. | |
| D3 /0 | ROL r/m32, CL | MC | Valid Valid | Rotate 32 bits r/m32 left CL times. RCL/RCR/ROL/ROR—Rotate Vol. 2B 4-533 Opcode1 Instruction Op/ 64-Bit Compat/ Description En Mode Leg Mode | |
| REX.W + D3 /0 | ROL r/m64, CL | MC | Valid N.E. | Rotate 64 bits r/m64 left CL times. Uses a 6 bit count. | |
| C1 /0 ib | ROL r/m32, imm8 | MI | Valid Valid | Rotate 32 bits r/m32 left imm8 times. | |
| REX.W + C1 /0 ib | ROL r/m64, imm8 | MI | Valid N.E. | Rotate 64 bits r/m64 left imm8 times. Uses a 6 bit count. | |
| D0 /1 | ROR r/m8, 1 | M1 | Valid Valid | Rotate 8 bits r/m8 right once. | |
| D2 /1 | ROR r/m8, CL | MC | Valid Valid | Rotate 8 bits r/m8 right CL times. | |
| C0 /1 ib | ROR r/m8, imm8 | MI | Valid Valid | Rotate 8 bits r/m16 right imm8 times. | |
| D1 /1 | ROR r/m16, 1 | M1 | Valid Valid | Rotate 16 bits r/m16 right once. | |
| D3 /1 | ROR r/m16, CL | MC | Valid Valid | Rotate 16 bits r/m16 right CL times. | |
| C1 /1 ib | ROR r/m16, imm8 | MI | Valid Valid | Rotate 16 bits r/m16 right imm8 times. | |
| D1 /1 | ROR r/m32, 1 | M1 | Valid Valid | Rotate 32 bits r/m32 right once. | |
| REX.W + D1 /1 | ROR r/m64, 1 | M1 | Valid N.E. | Rotate 64 bits r/m64 right once. Uses a 6 bit count. | |
| D3 /1 | ROR r/m32, CL | MC | Valid Valid | Rotate 32 bits r/m32 right CL times. | |
| REX.W + D3 /1 | ROR r/m64, CL | MC | Valid N.E. | Rotate 64 bits r/m64 right CL times. Uses a 6 bit count. | |
| C1 /1 ib | ROR r/m32, imm8 | MI | Valid Valid | Rotate 32 bits r/m32 right imm8 times. | |
| REX.W + C1 /1 ib | ROR r/m64, imm8 | MI | Valid N.E. | Rotate 64 bits r/m64 right imm8 times. Uses a 6 bit count. |
Description
Operation
(* RCL and RCR Instructions *) SIZE := OperandSize; CASE (determine count) OF SIZE := 8: tempCOUNT := (COUNT AND 1FH) MOD 9; SIZE := 16: tempCOUNT := (COUNT AND 1FH) MOD 17; SIZE := 32: tempCOUNT := COUNT AND 1FH; SIZE := 64: tempCOUNT := COUNT AND 3FH; ESAC; IF OperandSize = 64 THEN COUNTMASK = 3FH; ELSE COUNTMASK = 1FH; FI; (* RCL Instruction Operation *) tempDEST := DEST; WHILE (tempCOUNT ≠ 0) DO tempCF := MSB(tempDEST); tempDEST := (tempDEST ∗ 2) + CF; CF := tempCF; tempCOUNT := tempCOUNT – 1; OD; ELIHW; IF (COUNT & COUNTMASK) = 1 THEN OF := MSB(tempDEST) XOR CF; ELSE OF is undefined; FI; DEST := tempDEST; RCL/RCR/ROL/ROR—Rotate Vol. 2B 4-535 (* RCR Instruction Operation *) tempDEST := DEST; IF (COUNT & COUNTMASK) = 1 THEN OF := MSB(tempDEST) XOR CF; ELSE OF is undefined; FI; WHILE (tempCOUNT ≠ 0) DO tempCF := LSB(SRC); tempDEST := (tempDEST / 2) + (CF * 2SIZE); CF := tempCF; tempCOUNT := tempCOUNT – 1; OD; DEST := tempDEST; (* ROL Instruction Operation *) tempCOUNT := (COUNT & COUNTMASK) MOD SIZE tempDEST := DEST; WHILE (tempCOUNT ≠ 0) DO tempCF := MSB(tempDEST); tempDEST := (tempDEST ∗ 2) + tempCF; tempCOUNT := tempCOUNT – 1; OD; ELIHW; IF (COUNT & COUNTMASK) ≠ 0 THEN CF := LSB(tempDEST); FI; IF (COUNT & COUNTMASK) = 1 THEN OF := MSB(tempDEST) XOR CF; ELSE OF is undefined; FI; DEST := tempDEST; (* ROR Instruction Operation *) tempCOUNT := (COUNT & COUNTMASK) MOD SIZE tempDEST := DEST; WHILE (tempCOUNT ≠ 0) DO tempCF := LSB(SRC); tempDEST := (tempDEST / 2) + (tempCF ∗ 2SIZE); tempCOUNT := tempCOUNT – 1; OD; ELIHW; IF (COUNT & COUNTMASK) ≠ 0 THEN CF := MSB(tempDEST); FI; IF (COUNT & COUNTMASK) = 1 THEN OF := MSB(tempDEST) XOR MSB − 1(tempDEST); ELSE OF is undefined; FI; DEST := tempDEST; RCL/RCR/ROL/ROR—Rotate Vol. 2B 4-536
Flags Affected
For RCL and RCR instructions, a zero-bit rotate does nothing, i.e., affects no flags. For ROL and ROR instructions, if the masked count is 0, the flags are not affected. If the masked count is 1, then the OF flag is affected, otherwise (masked count is greater than 1) the OF flag is undefined. For all instructions, the CF flag is affected when the masked count is non-zero. The SF, ZF, AF, and PF flags are always unaffected.