* better
[mascara-docs.git] / hw / i386.reference / RCL.htm
blob97e5d8be0c9e3ff5ebc25de69c17d263eda10ff6
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
2 <HTML>
3 <HEAD>
4 <TITLE>80386 Programmer's Reference Manual -- Opcode RCL</TITLE>
5 </HEAD>
6 <BODY>
7 <B>up:</B> <A HREF="c17.htm">
8 Chapter 17 -- 80386 Instruction Set</A><BR>
9 <B>prev:</B><A HREF="PUSHF.htm"> PUSHF/PUSHFD Push Flags Register onto the Stack</A><BR>
10 <B>next:</B><A HREF="REP.htm"> REP/REPE/REPZ/REPNE/REPNZ Repeat Following String Operation</A>
11 <P>
12 <HR>
13 <P>
14 <H1>RCL/RCR/ROL/ROR -- Rotate</H1>
17 <PRE>
18 Opcode Instruction Clocks Description
20 D0 /2 RCL r/m8,1 9/10 Rotate 9 bits (CF,r/m byte) left
21 once
22 D2 /2 RCL r/m8,CL 9/10 Rotate 9 bits (CF,r/m byte) left CL
23 times
24 C0 /2 ib RCL r/m8,imm8 9/10 Rotate 9 bits (CF,r/m byte) left
25 imm8 times
26 D1 /2 RCL r/m16,1 9/10 Rotate 17 bits (CF,r/m word) left
27 once
28 D3 /2 RCL r/m16,CL 9/10 Rotate 17 bits (CF,r/m word) left
29 CL times
30 C1 /2 ib RCL r/m16,imm8 9/10 Rotate 17 bits (CF,r/m word) left
31 imm8 times
32 D1 /2 RCL r/m32,1 9/10 Rotate 33 bits (CF,r/m dword) left
33 once
34 D3 /2 RCL r/m32,CL 9/10 Rotate 33 bits (CF,r/m dword) left
35 CL times
36 C1 /2 ib RCL r/m32,imm8 9/10 Rotate 33 bits (CF,r/m dword) left
37 imm8 times
38 D0 /3 RCR r/m8,1 9/10 Rotate 9 bits (CF,r/m byte) right
39 once
40 D2 /3 RCR r/m8,CL 9/10 Rotate 9 bits (CF,r/m byte) right
41 CL times
42 C0 /3 ib RCR r/m8,imm8 9/10 Rotate 9 bits (CF,r/m byte) right
43 imm8 times
44 D1 /3 RCR r/m16,1 9/10 Rotate 17 bits (CF,r/m word) right
45 once
46 D3 /3 RCR r/m16,CL 9/10 Rotate 17 bits (CF,r/m word) right
47 CL times
48 C1 /3 ib RCR r/m16,imm8 9/10 Rotate 17 bits (CF,r/m word) right
49 imm8 times
50 D1 /3 RCR r/m32,1 9/10 Rotate 33 bits (CF,r/m dword) right
51 once
52 D3 /3 RCR r/m32,CL 9/10 Rotate 33 bits (CF,r/m dword) right
53 CL times
54 C1 /3 ib RCR r/m32,imm8 9/10 Rotate 33 bits (CF,r/m dword) right
55 imm8 times
56 D0 /0 ROL r/m8,1 3/7 Rotate 8 bits r/m byte left once
57 D2 /0 ROL r/m8,CL 3/7 Rotate 8 bits r/m byte left CL
58 times
59 C0 /0 ib ROL r/m8,imm8 3/7 Rotate 8 bits r/m byte left imm8
60 times
61 D1 /0 ROL r/m16,1 3/7 Rotate 16 bits r/m word left once
62 D3 /0 ROL r/m16,CL 3/7 Rotate 16 bits r/m word left CL
63 times
64 C1 /0 ib ROL r/m16,imm8 3/7 Rotate 16 bits r/m word left imm8
65 times
66 D1 /0 ROL r/m32,1 3/7 Rotate 32 bits r/m dword left once
67 D3 /0 ROL r/m32,CL 3/7 Rotate 32 bits r/m dword left CL
68 times
69 C1 /0 ib ROL r/m32,imm8 3/7 Rotate 32 bits r/m dword left imm8
70 times
71 D0 /1 ROR r/m8,1 3/7 Rotate 8 bits r/m byte right once
72 D2 /1 ROR r/m8,CL 3/7 Rotate 8 bits r/m byte right CL
73 times
74 C0 /1 ib ROR r/m8,imm8 3/7 Rotate 8 bits r/m word right imm8
75 times
76 D1 /1 ROR r/m16,1 3/7 Rotate 16 bits r/m word right once
77 D3 /1 ROR r/m16,CL 3/7 Rotate 16 bits r/m word right CL
78 times
79 C1 /1 ib ROR r/m16,imm8 3/7 Rotate 16 bits r/m word right imm8
80 times
81 D1 /1 ROR r/m32,1 3/7 Rotate 32 bits r/m dword right once
82 D3 /1 ROR r/m32,CL 3/7 Rotate 32 bits r/m dword right CL
83 times
84 C1 /1 ib ROR r/m32,imm8 3/7 Rotate 32 bits r/m dword right imm8
85 times
86 </PRE>
89 <H2>Operation</H2>
91 <PRE>
92 (* ROL - Rotate Left *)
93 temp := COUNT;
94 WHILE (temp <> 0)
96 tmpcf := high-order bit of (r/m);
97 r/m := r/m * 2 + (tmpcf);
98 temp := temp - 1;
99 OD;
100 IF COUNT = 1
101 THEN
102 IF high-order bit of r/m <> CF
103 THEN OF := 1;
104 ELSE OF := 0;
106 ELSE OF := undefined;
108 (* ROR - Rotate Right *)
109 temp := COUNT;
110 WHILE (temp <> 0 )
112 tmpcf := low-order bit of (r/m);
113 r/m := r/m / 2 + (tmpcf * 2^(width(r/m)));
114 temp := temp - 1;
116 IF COUNT = 1
117 THEN
118 IF (high-order bit of r/m) <> (bit next to high-order bit of r/m)
119 THEN OF := 1;
120 ELSE OF := 0;
122 ELSE OF := undefined;
124 </PRE>
126 <H2>Description</H2>
128 Each rotate instruction shifts the bits of the register or memory operand
129 given. The left rotate instructions shift all the bits upward, except for
130 the top bit, which is returned to the bottom. The right rotate instructions
131 do the reverse: the bits shift downward until the bottom bit arrives at
132 the top.
134 For the RCL and RCR instructions, the carry flag is part of the rotated
135 quantity. RCL shifts the carry flag into the bottom bit and shifts the top
136 bit into the carry flag; RCR shifts the carry flag into the top bit and
137 shifts the bottom bit into the carry flag. For the ROL and ROR
138 instructions, the original value of the carry flag is not a part of the
139 result, but the carry flag receives a copy of the bit that was shifted from
140 one end to the other.
142 The rotate is repeated the number of times indicated by the second
143 operand, which is either an immediate number or the contents of the CL
144 register. To reduce the maximum instruction execution time, the 80386
145 does not allow rotation counts greater than 31. If a rotation count greater
146 than 31 is attempted, only the bottom five bits of the rotation are used.
147 The 8086 does not mask rotation counts. The 80386 in Virtual 8086 Mode does
148 mask rotation counts.
150 The overflow flag is defined only for the single-rotate forms of the
151 instructions (second operand := 1). It is undefined in all other cases. For
152 left shifts/rotates, the CF bit after the shift is XORed with the
153 high-order result bit. For right shifts/rotates, the high-order two bits of
154 the result are XORed to get OF.
156 <H2>Flags Affected</H2>
158 OF only for single rotates; OF is undefined for multi-bit rotates; CF as
159 described above
161 <H2>Protected Mode Exceptions</H2>
163 #GP(0) if the result is in a nonwritable segment; #GP(0) for an illegal
164 memory operand effective address in the CS, DS, ES, FS, or GS
165 segments; #SS(0) for an illegal address in the SS segment; #PF(fault-code)
166 for a page fault
168 <H2>Real Address Mode Exceptions</H2>
170 Interrupt 13 if any part of the operand would lie outside of the effective
171 address space from 0 to 0FFFFH
173 <H2>Virtual 8086 Mode Exceptions</H2>
175 Same exceptions as in Real Address Mode; #PF(fault-code) for a page
176 fault
180 <HR>
182 <B>up:</B> <A HREF="c17.htm">
183 Chapter 17 -- 80386 Instruction Set</A><BR>
184 <B>prev:</B><A HREF="PUSHF.htm"> PUSHF/PUSHFD Push Flags Register onto the Stack</A><BR>
185 <B>next:</B><A HREF="REP.htm"> REP/REPE/REPZ/REPNE/REPNZ Repeat Following String Operation</A>
186 </BODY>