Assembly Language Programming

Rotate Operations

The ARM processor has two rotate operations, ROR (Rotate Right) and RRX (Rotate Right with Extend).

ROR behaves much like LSR in that bits are moved between 0 and 32 places to the right. However, whereas the rightmost bits in a LSR operation fall off the register, in a ROR operation, these bits are used to fill the vacated slots at the most significant end of the register. In this way the bits "rotate". If the degree of the rotation is 32 places, then the output is identical to the input as all the bits will have returned to their original location.

ROR can be used with a literal or by sourcing the rotation from a register.

MOV r0, r0, ROR #3 ; rotate value in r0 3 places and put result in r0
MOV r2, r0, ROR r1 ; rotate r0 by value of places in r1 and put result in r2

Rotation

RRX is a ROR operation with a crucial difference. It rotates the number to the right by one place but the original bit 31 is filled by the value of the Carry flag and the original bit 0 is moved into the Carry flag. This allows a 33-bit rotation by using both the register and the carry flag.

MOV r0, r0, RRX ; rotate right extended and put result back into r0

Rotation Right extended one place