AngoLinux

80386 Programmer's Reference Manual -- Opcode RCL


RCL/RCR/ROL/ROR -- Rotate

OpcodeInstructionClocks DescriptionExample
D0 /2rclb 1,r/m89/10 Rotate 9 bits (CF,r/m byte) left oncerclb $1,%dl
rclb $1,(%ebx,1)
rclb $1,m8(%ebx,1)
rclb $1,m8(%ebx,%ebp,1)
D2 /2rclb cl,r/m89/10 Rotate 9 bits (CF,r/m byte) left CL timesrclb %cl,%dl
rclb %cl,(%ebx,1)
rclb %cl,m8(%ebx,1)
rclb %cl,m8(%ebx,%ebp,1)
C0 /2 ibrclb imm8,r/m89/10 Rotate 9 bits (CF,r/m byte) left imm8 timesrclb $0x7f,%dl
rclb $0x7f,(%ebx,1)
rclb $0x7f,m8(%ebx,1)
rclb $0x7f,m8(%ebx,%ebp,1)
D1 /2rclw 1,r/m169/10 Rotate 17 bits (CF,r/m word) left oncerclw $1,%cx
rclw $1,(%ebx,1)
rclw $1,(%ebx,2)
rclw $1,(%ebx,%ebp,1)
D3 /2rclw cl,r/m169/10 Rotate 17 bits (CF,r/m word) left CL timesrclw %cl,%cx
rclw %cl,(%ebx,1)
rclw %cl,(%ebx,2)
rclw %cl,(%ebx,%ebp,1)
C1 /2 ibrclw imm8,r/m169/10 Rotate 17 bits (CF,r/m word) left imm8 timesrclw $0x7f,%cx
rclw $0x7f,(%ebx,1)
rclw $0x7f,(%ebx,2)
rclw $0x7f,(%ebx,%ebp,1)
D1 /2rcll 1,r/m329/10 Rotate 33 bits (CF,r/m dword) left oncercll $1,%ecx
rcll $1,(%ebx,2)
rcll $1,(%ebx,4)
rcll $1,(%ebx,%ebp,1)
D3 /2rcll cl,r/m329/10 Rotate 33 bits (CF,r/m dword) left CL timesrcll %cl,%ecx
rcll %cl,(%ebx,2)
rcll %cl,(%ebx,4)
rcll %cl,(%ebx,%ebp,1)
C1 /2 ibrcll imm8,r/m329/10 Rotate 33 bits (CF,r/m dword) left imm8 timesrcll $0x7f,%ecx
rcll $0x7f,(%ebx,2)
rcll $0x7f,(%ebx,4)
rcll $0x7f,(%ebx,%ebp,1)
D0 /3rcrb 1,r/m89/10 Rotate 9 bits (CF,r/m byte) right oncercrb $1,%dl
rcrb $1,(%ebx,1)
rcrb $1,m8(%ebx,1)
rcrb $1,m8(%ebx,%ebp,1)
D2 /3rcrb cl,r/m89/10 Rotate 9 bits (CF,r/m byte) right CL timesrcrb %cl,%dl
rcrb %cl,(%ebx,1)
rcrb %cl,m8(%ebx,1)
rcrb %cl,m8(%ebx,%ebp,1)
C0 /3 ibrcrb imm8,r/m89/10 Rotate 9 bits (CF,r/m byte) right imm8 timesrcrb $0x7f,%dl
rcrb $0x7f,(%ebx,1)
rcrb $0x7f,m8(%ebx,1)
rcrb $0x7f,m8(%ebx,%ebp,1)
D1 /3rcrw 1,r/m169/10 Rotate 17 bits (CF,r/m word) right oncercrw $1,%cx
rcrw $1,(%ebx,1)
rcrw $1,(%ebx,2)
rcrw $1,(%ebx,%ebp,1)
D3 /3rcrw cl,r/m169/10 Rotate 17 bits (CF,r/m word) right CL timesrcrw %cl,%cx
rcrw %cl,(%ebx,1)
rcrw %cl,(%ebx,2)
rcrw %cl,(%ebx,%ebp,1)
C1 /3 ibrcrw imm8,r/m169/10 Rotate 17 bits (CF,r/m word) right imm8 timesrcrw $0x7f,%cx
rcrw $0x7f,(%ebx,1)
rcrw $0x7f,(%ebx,2)
rcrw $0x7f,(%ebx,%ebp,1)
D1 /3rcrl 1,r/m329/10 Rotate 33 bits (CF,r/m dword) right oncercrl $1,%ecx
rcrl $1,(%ebx,2)
rcrl $1,(%ebx,4)
rcrl $1,(%ebx,%ebp,1)
D3 /3rcrl cl,r/m329/10 Rotate 33 bits (CF,r/m dword) right CL timesrcrl %cl,%ecx
rcrl %cl,(%ebx,2)
rcrl %cl,(%ebx,4)
rcrl %cl,(%ebx,%ebp,1)
C1 /3 ibrcrl imm8,r/m329/10 Rotate 33 bits (CF,r/m dword) right imm8 timesrcrl $0x7f,%ecx
rcrl $0x7f,(%ebx,2)
rcrl $0x7f,(%ebx,4)
rcrl $0x7f,(%ebx,%ebp,1)
D0 /0rolb 1,r/m83/7 Rotate 8 bits r/m byte left oncerolb $1,%dl
rolb $1,(%ebx,1)
rolb $1,m8(%ebx,1)
rolb $1,m8(%ebx,%ebp,1)
D2 /0rolb cl,r/m83/7 Rotate 8 bits r/m byte left CL timesrolb %cl,%dl
rolb %cl,(%ebx,1)
rolb %cl,m8(%ebx,1)
rolb %cl,m8(%ebx,%ebp,1)
C0 /0 ibrolb imm8,r/m83/7 Rotate 8 bits r/m byte left imm8 timesrolb $0x7f,%dl
rolb $0x7f,(%ebx,1)
rolb $0x7f,m8(%ebx,1)
rolb $0x7f,m8(%ebx,%ebp,1)
D1 /0rolw 1,r/m163/7 Rotate 16 bits r/m word left oncerolw $1,%cx
rolw $1,(%ebx,1)
rolw $1,(%ebx,2)
rolw $1,(%ebx,%ebp,1)
D3 /0rolw cl,r/m163/7 Rotate 16 bits r/m word left CL timesrolw %cl,%cx
rolw %cl,(%ebx,1)
rolw %cl,(%ebx,2)
rolw %cl,(%ebx,%ebp,1)
C1 /0 ibrolw imm8,r/m163/7 Rotate 16 bits r/m word left imm8 timesrolw $0x7f,%cx
rolw $0x7f,(%ebx,1)
rolw $0x7f,(%ebx,2)
rolw $0x7f,(%ebx,%ebp,1)
D1 /0roll 1,r/m323/7 Rotate 32 bits r/m dword left onceroll $1,%ecx
roll $1,(%ebx,2)
roll $1,(%ebx,4)
roll $1,(%ebx,%ebp,1)
D3 /0roll cl,r/m323/7 Rotate 32 bits r/m dword left CL timesroll %cl,%ecx
roll %cl,(%ebx,2)
roll %cl,(%ebx,4)
roll %cl,(%ebx,%ebp,1)
C1 /0 ibroll imm8,r/m323/7 Rotate 32 bits r/m dword left imm8 timesroll $0x7f,%ecx
roll $0x7f,(%ebx,2)
roll $0x7f,(%ebx,4)
roll $0x7f,(%ebx,%ebp,1)
D0 /1rorb 1,r/m83/7 Rotate 8 bits r/m byte right oncerorb $1,%dl
rorb $1,(%ebx,1)
rorb $1,m8(%ebx,1)
rorb $1,m8(%ebx,%ebp,1)
D2 /1rorb cl,r/m83/7 Rotate 8 bits r/m byte right CL timesrorb %cl,%dl
rorb %cl,(%ebx,1)
rorb %cl,m8(%ebx,1)
rorb %cl,m8(%ebx,%ebp,1)
C0 /1 ibrorb imm8,r/m83/7 Rotate 8 bits r/m word right imm8 timesrorb $0x7f,%dl
rorb $0x7f,(%ebx,1)
rorb $0x7f,m8(%ebx,1)
rorb $0x7f,m8(%ebx,%ebp,1)
D1 /1rorw 1,r/m163/7 Rotate 16 bits r/m word right oncerorw $1,%cx
rorw $1,(%ebx,1)
rorw $1,(%ebx,2)
rorw $1,(%ebx,%ebp,1)
D3 /1rorw cl,r/m163/7 Rotate 16 bits r/m word right CL timesrorw %cl,%cx
rorw %cl,(%ebx,1)
rorw %cl,(%ebx,2)
rorw %cl,(%ebx,%ebp,1)
C1 /1 ibrorw imm8,r/m163/7 Rotate 16 bits r/m word right imm8 timesrorw $0x7f,%cx
rorw $0x7f,(%ebx,1)
rorw $0x7f,(%ebx,2)
rorw $0x7f,(%ebx,%ebp,1)
D1 /1rorl 1,r/m323/7 Rotate 32 bits r/m dword right oncerorl $1,%ecx
rorl $1,(%ebx,2)
rorl $1,(%ebx,4)
rorl $1,(%ebx,%ebp,1)
D3 /1rorl cl,r/m323/7 Rotate 32 bits r/m dword right CL timesrorl %cl,%ecx
rorl %cl,(%ebx,2)
rorl %cl,(%ebx,4)
rorl %cl,(%ebx,%ebp,1)
C1 /1 ibrorl imm8,r/m323/7 Rotate 32 bits r/m dword right imm8 timesrorl $0x7f,%ecx
rorl $0x7f,(%ebx,2)
rorl $0x7f,(%ebx,4)
rorl $0x7f,(%ebx,%ebp,1)

Operation




(* ROL - Rotate Left *)
temp := COUNT;
WHILE (temp <> 0)
DO
   tmpcf := high-order bit of (r/m);
   r/m := r/m * 2 + (tmpcf);
   temp := temp - 1;
OD;
IF COUNT = 1
THEN
   IF high-order bit of r/m <> CF
   THEN OF := 1;
   ELSE OF := 0;
   FI;
ELSE OF := undefined;
FI;
(* ROR - Rotate Right *)
temp := COUNT;
WHILE (temp <> 0 )
DO
   tmpcf := low-order bit of (r/m);
   r/m := r/m / 2 + (tmpcf * 2^(width(r/m)));
   temp := temp - 1;
DO;
IF COUNT = 1
THEN
   IF (high-order bit of r/m) <> (bit next to high-order bit of r/m)
   THEN OF := 1;
   ELSE OF := 0;
   FI;
ELSE OF := undefined;
FI;

Description

Each rotate instruction shifts the bits of the register or memory operand given. The left rotate instructions shift all the bits upward, except for the top bit, which is returned to the bottom. The right rotate instructions do the reverse: the bits shift downward until the bottom bit arrives at the top.

For the RCL and RCR instructions, the carry flag is part of the rotated quantity. RCL shifts the carry flag into the bottom bit and shifts the top bit into the carry flag; RCR shifts the carry flag into the top bit and shifts the bottom bit into the carry flag. For the ROL and ROR instructions, the original value of the carry flag is not a part of the result, but the carry flag receives a copy of the bit that was shifted from one end to the other.

The rotate is repeated the number of times indicated by the second operand, which is either an immediate number or the contents of the CL register. To reduce the maximum instruction execution time, the 80386 does not allow rotation counts greater than 31. If a rotation count greater than 31 is attempted, only the bottom five bits of the rotation are used. The 8086 does not mask rotation counts. The 80386 in Virtual 8086 Mode does mask rotation counts.

The overflow flag is defined only for the single-rotate forms of the instructions (second operand := 1). It is undefined in all other cases. For left shifts/rotates, the CF bit after the shift is XORed with the high-order result bit. For right shifts/rotates, the high-order two bits of the result are XORed to get OF.

Flags Affected

OF only for single rotates; OF is undefined for multi-bit rotates; CF as described above

Protected Mode Exceptions

#GP(0) if the result is in a nonwritable segment; #GP(0) for an illegal memory operand effective address in the CS, DS, ES, FS, or GS segments; #SS(0) for an illegal address in the SS segment; #PF(fault-code) for a page fault

Real Address Mode Exceptions

Interrupt 13 if any part of the operand would lie outside of the effective address space from 0 to 0FFFFH

Virtual 8086 Mode Exceptions

Same exceptions as in Real Address Mode; #PF(fault-code) for a page fault


[Home Page dell'ITIS "Fermi"] [80386 Programmer's Reference Manual Index] [Previous] [Next]