RRF Bit Operations
Rotate a register one bit right through the carry flag.
| Syntax | RRF f, d |
|---|---|
| Operands | f: register address 0-127 (bank bits come from STATUS); d: 0 or w puts the result in W, 1 or f puts it back in f |
| Operation | rotate f right through C: C → bit 7, bit 0 → C |
| Status bits | C |
| Words / cycles | 1 word, 1 cycle |
| Encoding | 00 1100 dfff ffff |
How it works
RRF shifts register f one place right. The old C enters bit 7 and the old bit 0 goes into C. With C cleared first, RRF divides an unsigned value by 2, and C holds the remainder.
Example
; RRF example from picsimulator.com/instructions/rrf.html
list p=16f84a
include <p16f84a.inc>
org 0
bcf STATUS, C
movlw 0x03
movwf 0x20
rrf 0x20, f ; 0x20 = 0x01, C = 1
3 shifted right is 1, and the bit shifted out (1) is in C.
Open this example in the simulator
Watch out for
- Like RLF, RRF rotates through C. For an unsigned divide by 2, clear C first.