PDA

View Full Version : Reading variables - more clock cycles?



kevj
- 23rd February 2008, 19:19
If I want to keep a particular loop as fast as possible (fewest cycles), does it add more time to reference a value by it's variable name?

For example, do these two code blocks take the same number of cycles to execute....




EXAMPLE 1:

myVar = 273


EXAMPLE 2:
(assuming SomeNum is already defined as a BYTE and loaded with the value "273")

myVar = SomeNum



And more specifically, when loading the registers of a 16-bit timer... let's say I already have the value "%01010101" loaded into a BYTE variable named "HighTimes" and "%11110001" loaded into a BYTE variable named "LowTimes".....



EXAMPLE 1:

TMR1H = %01010101
TMR1L = %11110001

EXAMPLE 2:

TMR1H = HighTimes
TMR1L = LowTimes


Does this second example take longer to execute because it must go look up the value of the variable before the copy to the register?

Bruce
- 23rd February 2008, 19:53
They are all equal.

TMR1H = %01010101
TMR1L = %11110001

Produces;


MOVLW 0x55
MOVWF TMR1H
MOVLW 0xf1
MOVWF TMR1L


HighTimes = 10
LowTimes = 20 ' loading these vars is the only real time difference

TMR1H = HighTimes
TMR1L = LowTimes

Produces;


MOVF _HighTimes, W
MOVWF TMR1H
MOVF _LowTimes, W
MOVWF TMR1L

The 2nd version of course depends on which bank your vars are in.
Could take more code if they're not in bank0.