# Doubt in the rotation asm pic16F

#### massanetabr

Joined Jun 3, 2019
44
Guys, I'm a beginner and I'm in doubt in the RRF Rotation instruction. Assuming I have this value

0000 0011 0011 1100
AH = 0000 0011
AL = 0011 1100

Did I do that?

RRF AH, F
RRF AL, F
RRF AH, F
RRF AL, F

Will the result be?

AH = 0000 0000
AL = 1100 1111

#### AlbertHall

Joined Jun 4, 2014
12,293
That's what I make it.

#### Beau Schwabe

Joined Nov 7, 2019
147
Clear the carry bit before each AH shift or else you could end up with unknown values of "C" being shifted into the MSB

#### AlbertHall

Joined Jun 4, 2014
12,293
Clear the carry bit before each AH shift or else you could end up with unknown values of "C" being shifted into the MSB
It would be a good idea to clear C before the first AH shift, but if a 16 bit rotate is required as the TS result suggests then that should be the only time C is cleared.

#### Beau Schwabe

Joined Nov 7, 2019
147
" that should be the only time C is cleared. " ... but he is shifting the entire 16 bit (word) twice, so No ... Clear the "C" flag ONLY before each AH shift.

Some assembly variants allow for a LOGICAL shift, which shifts in a ZERO regardles of what C is...

bcf STATUS,C ; Clear C flag
RRF AH, F
RRF AL, F
bcf STATUS,C ; Clear C flag
RRF AH, F
RRF AL, F

.... OR ....

RLF AH, F ; Rotate LOGICAL right
RRF AL, F
RLF AH, F ; Rotate LOGICAL right
RRF AL, F

Last edited:

#### AlbertHall

Joined Jun 4, 2014
12,293
but he is shifting the entire 16 bit (word) twice
Or is the desired result a 16 bit rotation, as suggested by the TS suggested result?

Joined Jul 18, 2013
28,028
Use the debugger tool to step through the program and monitor the registers.

#### MrChips

Joined Oct 2, 2009
29,829
There is a difference between shift operation and rotate operation. Learn the difference and choose the one you want.
Also know the difference between arithmetic shift and logical shift.