# RRF and RLF instruction in ASM

Status
Not open for further replies.

#### birdman0_o

##### Active Member
Hey guys,

I have a question regarding the asm instructions RRF (rotate right through carry) and RLF (rotate left through carry).

Whenever I use these instructions what happens is that the original register gets modified if I use this instruction multiple times.

For example, when I use it with my 74HC595 serial - parallel shift register and I shift it 8 times, it isn't restored to what it originally was. I am showing a, lets say for the sake of argument 3 at first, it displays, but when the loop gets to showing the 3 again, its completely changed.

I've always used the 16f628a, perhaps it is only a problem with this uC.

Anybody have any similar experience?

#### birdman0_o

##### Active Member
Ok I have a lead that a friend mentioned, perhaps I modify the C register before shifting but while looking through my code I do not see anywhere where that could be happening!

Code:
HC595 MACRO Var,Var1

Local Loop		; Local Label
MOVLW .8		; Transfer 8 bits
MOVWF Var1		; Initializing counter

Loop
RLF Var,f	; Rotate "Var" one place to the left
BTFSS STATUS,C	; Is carry 1?
BCF Bits		; If not set data line to 0
BTFSC STATUS,C	; Is carry 0?
BSF Bits		; If not set data line to 1

BSF Clock		; Generate one clock
BCF Clock		;

DECFSZ Var1,f	; Has 8 bits been sent?
GOTO Loop		; If not, repeat

BSF Latch		; If all 8 bits have been sent, set latch
BCF Latch

ENDM

#### Mike - K8LH

##### Well-Known Member
Hi Mike,

I think you'll find that if you do one additional rlf Var,f instruction at the end of your macro then Var will contain the orignal value. I would suggest watching the Var variable and single stepping through the loop using the MPLAB Simulator so you can see what's going on but I don't think the Simulator will single step through a macro.

You might also consider using a pair of rlf instructions to rotate the b7 bit into the b0 position;

Code:
        movlw   8               ;
movwf   Var1            ;
Loop
[COLOR=Magenta]        rlf     Var,W           ; pseudo RLNCF instruction
rlf     Var,F           ;
[/COLOR]        bcf     Bits            ;
skpnc                   ;
bsf     Bits            ;
bsf     Clock           ;
bcf     Clock           ;
decfsz  Var1,F          ; all 8 bits sent?
goto    Loop            ; no, branch, else
bsf     Latch           ;
bcf     Latch           ;

#### birdman0_o

##### Active Member
It's people like you who deserve a big hug
The extra RLF did the trick
Many thanks

Status
Not open for further replies.

Replies
10
Views
3K
Replies
2
Views
888
Replies
1
Views
2K
Replies
1
Views
1K
Replies
11
Views
1K