RRA (Right Rotate then Add with Carry)

[operand] -> [operand] >> 1 -> C -> [operand] + A -> A

RRA performs a right rotation on an operand, and then adds the result with the accumulator register (A) and the Carry flag. The result is then stored in the accumulator. The Carry flag is set if the unsigned result exceeds 255, otherwise it is cleared.

RRA is an illegal opcode, and its behavior is not well-defined on the 6502. However, on some versions of the chip, RRA behaves similarly to ADC, except that it first performs a right rotation on the operand. This can be useful for certain operations, such as implementing a sound generator.

Addressing Modes

Mode

Syntax

Bytes

Cycles

ZeroPage

+RRA zp

67 nn

5

ZeroPage+X

+RRA zp,x

77 nn

6

Absolute

+RRA addr

6F ll hh

6

Absolute+X

+RRA addr,x

7F ll hh

7

Absolute+Y

+RRA addr,y

7B ll hh

7

(Indirect+X)

+RRA (zp,x)

63 nn

8

(Indirect)+Y

+RRA (zp),y

73 nn

8

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 if the unsigned result is too large to fit in 8 bits; otherwise, it is cleared.

  • V (Overflow) – Set if the two values being added have the same sign but the result has the opposite sign; otherwise, it is cleared.

Examples

As RRA is an illegal opcode with undefined behavior, examples cannot be provided.

See Also

  • ADC (ADd with Carry)

Comments