ROR (ROtate Right)¶
[operand] = [operand] >> 1 + C << 7
ROR shifts all the bits of an operand one place to the right, and sets the most significant bit to the value of the Carry flag. The Carry flag is then set to the value of the least significant bit before it is shifted out.
ROR can operate on both memory locations and the accumulator register (A). When used on memory, the operand is the value stored at the specified memory address.
Addressing Modes¶
ROR supports the following addressing modes:
Mode |
Syntax |
Bytes |
Cycles |
---|---|---|---|
Implied |
ROR A |
|
2 |
Zero Page |
ROR zp |
|
5 |
Zero Page + X |
ROR zp,X |
|
6 |
Absolute |
ROR addr |
|
6 |
Absolute + X |
ROR addr,X |
|
7 |
Flags Affected¶
N (Negative) – Set if the result has the most significant bit set (i.e., is negative); otherwise, it is cleared.
Z (Zero) – Set if the result is zero; otherwise, it is cleared.
C (Carry) – Set to the value of the least significant bit before it is shifted out.
Examples¶
Rotate Accumulator Right¶
LDA #85 ; load A with binary 01010101
CLC ; clear carry flag
ROR A ; A now contains binary 00101010, C is set to 1
Rotate Memory Right¶
LDX #$10 ; load X with 16
ROR $00,X ; Rotate the value at address $0010 right
See Also¶
ASL (Arithmetic Shift Left)
LSR (Logical Shift Right)
ROL (ROtate Left)