11

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

CodingWithSpike
  • 42,906
  • 18
  • 101
  • 138
Foo
  • 309
  • 2
  • 5
  • 10
  • 2
    One uses an extra bit (carry), the other doesn't, as you've stated. How does that make them "do the same work"? – Mat May 01 '12 at 08:04

2 Answers2

38

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

Paul R
  • 208,748
  • 37
  • 389
  • 560
  • Oh, alright. I was actually thinking that the carry flag would be containing the same thing in both the instructions. Thanks for clearing out. – Foo May 01 '12 at 08:08
10

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
+------------------------------------+
Andrew Cooper
  • 32,176
  • 5
  • 81
  • 116
  • `RCR rotates the carry flag into the MSB and the LSB to the carry flag.` I am sorry if I am wrong but should't the LSB first move to CF and then CF moves to the MSB? – Foo May 01 '12 at 08:13
  • 1
    No, that's the point. RCR effectively works like an N+1 bit ROR. So the od value of the CF goes to the MSB and the old value of the LSB goes to the CF. So, given the same initial conditions both instructions will give the same result in the CF, but the new value of the MSB may differ. – Andrew Cooper May 01 '12 at 13:04