Home     Forum     Projects     Experiments     Circuits     Theory     BLOG     PIC Tutorials     Time for Science

### Author Topic: RRF instruction 18F2550  (Read 9702 times)

0 Members and 1 Guest are viewing this topic.

#### fredf

• Posts: 1
##### RRF instruction 18F2550
« on: November 12, 2012, 19:18:05 PM »
Dear Gurus   I don't get consistent div by 2 results using RRCF. or should it be RRNCF?
I attach  the assembler code snippet

The example msb 43 3B 05 lsb  div/2 should give an output of  hex 21 9D 82 in the
temp3, temp2, temp1   registers.
This number does but others with F seem to produce rubbish  div /2 results.

Obviously the code is precarious and I would appreciate  comment on chaining registers to get consistent  div/2 results.

Bye and thanks
Fred

In case the jpeg doesn't get through the code is:-

RRFtest:

clrf temp4
clrf temp3
clrf temp2
clrf temp1

movlw 0x43  ; Dummy infoMSB 0x43,0x3B,0x05
movwf temp3 ; to  try and isolate the problem
movlw 0x3B
movwf temp2
movlw 0x05
movwf temp1

Divby2startshere:

rrcf   temp3,f,1
btfsc STATUS,C
nop
nop

rrcf   temp2,f,1
btfsc STATUS,C
nop
nop

rrcf   temp1,f,1
nop
nop

#### kam

• Hero Member
• Posts: 1849
##### Re: RRF instruction 18F2550
« Reply #1 on: November 13, 2012, 08:01:01 AM »
So, you have a 3x8bit number temp3:temp2:temp1 and you want to divide this by 2:

bcf carry (make sure the carry is clear)
rrf temp3,f
rrf temp2,f
rrf temp1,f

.end

#### _pike

• Full Member
• Posts: 182
##### Re: RRF instruction 18F2550
« Reply #2 on: November 15, 2012, 09:23:43 AM »
Fist of all this numbers are not integers so i think that numbers won't be the expected.Would be more or less.Second try kam's solution.Also i cant understand how you use the code...

rrcf   temp3,f,1     -----rotate temp3 register right place the result on temp3 reg and the BSR is used to select the GPR bank
btfsc STATUS,C    -----If carry is 0 then jump next instruction...  (why?)What happens if a number has a 0 on it???Stop rotating perhaps?
nop                     -----Do nothing
nop                     -----Do nothing

rrcf   temp2,f,1
btfsc STATUS,C
nop
nop

rrcf   temp1,f,1
nop
nop
« Last Edit: November 15, 2012, 09:26:48 AM by _pike »