Question on variable values in register(more than 255)

Thread Starter

eddy123456

Joined Feb 4, 2008
7
Hi guys,

Ive found out that the only way to have a value larger than 255(for a variable) is by increasing the value of another variable every time the first variable overflow. By the way im using pic16f84 and im currently learning how to program in assembly language.

Example, "counta" for values from 0-256 and "countb" is for overflow of "counta".

This is an example code that i found which shows the calculation of numbers more than 256. The result will correspond to an address in a map.

rpmhi=counter overflow for rpmlow.
value of rpm : 74<(rpmhi+rpmlow)<600

Code:
Rich (BB code):
        ; the formula to get the data stored in the map is as follows
        ;
        ;                (rpmhi+rpmlow count)  -  74
        ;    131   -    ----- ----------------------
        ;                           4
        ;
caladv  movlw d'74'          ; (rpmhi+rpmlow count) - 74
        subwf rpmlo,F      ; rpmlo = rpmlo - 74
        btfss STATUS,C
        decf rpmhi,F
        ;
        ; divide result by 4
        ;
        bcf STATUS,C
        rrf rpmhi,F
        rrf rpmlo,F        ; / 2
        ;
        bcf STATUS,C
        rrf rpmhi,F
        rrf rpmlo,F        ; / 4
        ;
        movlw .131         ; 131 entries in map list
        movwf math
        ;
        movf rpmlo,W
        subwf math,W       ; W = 131 - result
        ;
        bcf PCLATH,0      ; be sure to go h'200'
        bsf PCLATH,1      ; where is the map.
        call map      ; read map
        movwf rtdset       ; come back with new retard value


Im not sure how the codes work.Ive tried the logic, and it seems fine for numbers <256,

example :

say value of rpm : (rpmhi+rpmlow)=240

where rpmhi=0 and rpmlow=d'240'

ive done 2 different approach :
a) using calculator =41.5
b) using the logic operator (subwf,rrf) =41


But when rpm value > 256, say (rpmhi+rpmlow)=496

where rpmhi=1 and rpmlow=d'240'

same approach as above:
a) using calculator =105.5
b) using the logic operator (subwf,rrf) =41

or am i missing something here..:confused:
 

n9352527

Joined Oct 14, 2005
1,198
Taking your example value:

rpm = 240
rpmhi = 0x00, rpmlo = 0xF0

value = (0xF0 - 0x4A)/0x04
value = 0x29


rpm = 496
rpmhi = 0x01, rpmlo = 0xF0

after being subtracted by 0x4A, rpmlo would be 0xA6.
after the first rrf, rpmhi would be 0x00, and the C would be 1.
after the second rrf, rpmlo would be 0xD3.
after the third rrf, rpmhi wold stay at 0x00, and the C would be 0.
after the fourth rrf, rpmlo would be 0x69.

so, the value would be 0x69, which is the right value of 105.

The thing that you seemed to miss was that rrf is a rotate right through carry instruction. Which means that the C bit is inserted at MSB and the LSB is shifted to C.
 

Thread Starter

eddy123456

Joined Feb 4, 2008
7
oh! now i get it, C is used to divide the 8 bit binary as if it were a 16 bit :

rrf 00000001 11110000

is the same as

bcf
rrf 00000001
rrf 11110000

Thanks a lot!
 
Top