Foo
Foo

Reputation: 319

What is the difference between RCR and ROR?

I understand the from the terms that RCR would rotate the bit from the right to left, taking the bit from the carry while ROR will rotate the bit from right to left, taking the bit from the right but is that the only difference between them? If this is so, both of the instructions seem to do the same work. Please help out. Thanks

Upvotes: 12

Views: 23651

Answers (2)

Andrew Cooper
Andrew Cooper

Reputation: 32576

Both instructions rotate bits from left to right (where the left hand bit is the MSB).

RCR rotates the carry flag into the MSB and the LSB to the carry flag.

ROR rotates the LSB to the MSB without going through the carry flag.

+--> CF -->  MSB --> ... -> LSB --+
|                                 |      RCR
+---------------------------------+


+-> CF      +-> MSB --> ... -> LSB --+
|           |                        |      ROR
+------------------------------------+

Upvotes: 10

Paul R
Paul R

Reputation: 212979

RCR includes the carry flag in the rotation, so it's effectively an N+1 bit rotate, whereas ROR does not include the carry flag, so it's just an N bit rotate.

Some nice diagrams from www.c-jump.com:

enter image description here

enter image description here

Upvotes: 39

Related Questions