1

My EAX register contains the xxxxxx9D value and I have the following assembly code:

C0C8 14 --> ROR AL,14

To me, it means that the last 8 bits of the EAX's 32 bits value are rotated bitwise by 14 mod 8 = 6 positions

0x9D = b1001 1101

will be transformed into

b0111 0110 = 0x76

However, OllyDbg tells me that EAX = xxxxxxD9, which means EAX has been rotated bitwise by 4 bits!

Where am I wrong?

Bernard Rosset
  • 4,523
  • 6
  • 27
  • 29
  • 2
    That's 14 hex which is 20 decimal. – Igor Skochinsky Apr 06 '12 at 19:35
  • For the record: best-practices for expressing rotates in a compiler-friendly way, avoiding undefined behaviour: http://stackoverflow.com/questions/776508/circular-shift-rotate-operations-in-c. That answer has code that will get gcc and clang to produce a single `ror` instruction. – Peter Cordes Aug 17 '15 at 17:41

2 Answers2

6

You are trying to rotate an 8-bit register by 20 positions. That's a bit much, rotating by 8 produces the same value. Rotating by 9 is the same as rotating by 1. Etcetera. The processor will thus rotate by 20 mod 8 = 4 positions.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
1

Post your complete code, with this:

mov     al,$9d
ror     al,14

I get 76 as expected.

Edit If you rotate by $14 positions, you will get d9.

Jens Björnhager
  • 5,632
  • 3
  • 27
  • 47