Doubt in the rotation asm pic16F

Thread Starter

massanetabr

Joined Jun 3, 2019
26
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
11,506
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
100
" 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:

MrChips

Joined Oct 2, 2009
24,237
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.
 
Top