RCR rotates right through the carry flag. The operand and CF form a ring of 9 bits (byte) or 17 bits (word). Each step, every bit moves one place right, the old CF enters the top bit, and the old bit 0 becomes the new CF.
+-> CF -> b7 b6 b5 b4 b3 b2 b1 b0 --+| |+------------------------------------+CF=1 0000 0010RCR 1 CF=0 1000 0001
Forms and flags
Register or memory operand; count 1 or CL on the 8086. Only CF and OF are changed; SF, ZF, PF and AF are left as they were. With a count of 1, OF is set when the two highest bits of the result differ (the old CF and the old top bit were different). For other counts OF is undefined. Clear or set CF first (CLC, STC) if the bit coming in matters.
Multi-word shifts
To shift a wide value right by one bit, start at the highest part and work down: shift the top part, then RCR each lower part so the bit leaving one part enters the top of the next. For an unsigned 32-bit number in DX:AX, which divides it by 2:
SHR DX, 1 ; high word: bit 0 into CFRCR AX, 1 ; low word: CF into bit 15; signed value: use SAR DX, 1 instead of SHR
After the pair, CF holds the bit that dropped off the whole value, the remainder of the division. Left shifts go the other way round: SHL on the lowest part, then RCL upward.
RCR is also a way to put CF into the top bit of a register: STC then RCR AL, 1 sets bit 7 and moves the rest down.
MOV BH, 03h ; high byte 0000 0011MOV BL, 08h ; low byte 0000 1000: 0308h = 776SHR BH, 1 ; high byte first: bit 0 -> CFRCR BL, 1 ; CF enters bit 7 of the low byteMOV AL, BHCALL SHOWBIN ; 0000 0001MOV AL, BLCALL SHOWBIN ; 1000 0100: 0184h = 388CALL SHOWCF ; nothing left overSHOWBIN PROC NEAR ; print AL as 8 binary digits and a spacePUSHF ; keep the caller's flagsPUSH AXPUSH BXPUSH CXPUSH DXMOV BL, ALMOV CX, 8NEXTBIT:SHL BL, 1 ; the top bit falls into CFMOV DL, "0"ADC DL, 0 ; "0" + CF = "0" or "1"MOV AH, 02hINT 21hLOOP NEXTBITMOV DL, " "MOV AH, 02hINT 21hPOP DXPOP CXPOP BXPOP AXPOPFRETSHOWBIN ENDPSHOWCF PROC NEAR ; print "CF=0" or "CF=1" and a spacePUSHFPUSH AXPUSH DXMOV DL, "0"ADC DL, 0 ; "0" + CF, before anything changes CFPUSH DXMOV AH, 09hMOV DX, OFFSET CFTXTINT 21hPOP DXMOV AH, 02hINT 21hMOV DL, " "MOV AH, 02hINT 21hPOP DXPOP AXPOPFRETSHOWCF ENDPCFTXT DB "CF=$"
Later CPUs
The 8086 uses all 8 bits of CL as the count. The 80186 and later mask the count to 5 bits and accept an immediate count, as in RCR AX, 2.