Reading variables - more clock cycles?


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2007
    Posts
    67

    Default Reading variables - more clock cycles?

    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....


    Code:
    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".....

    Code:
    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?

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    They are all equal.

    TMR1H = %01010101
    TMR1L = %11110001

    Produces;
    Code:
       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;
    Code:
       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.
    Last edited by Bruce; - 23rd February 2008 at 20:15. Reason: Example
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Similar Threads

  1. PBP instruction clock cycles
    By MOUNTAIN747 in forum General
    Replies: 4
    Last Post: - 31st January 2009, 02:53
  2. EM4095 Chip, get Clock and Data signals?
    By mindthomas in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 19th August 2008, 06:27
  3. Shiftout/in
    By BobEdge in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 23rd August 2007, 11:48
  4. Help with sound command in 2 programs
    By hyperboarder in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th July 2007, 20:36
  5. Reading Array values into variables
    By Tom Gonser in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 21st March 2005, 10:30

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts