CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

asm time question

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
umka



Joined: 28 Aug 2007
Posts: 99
Location: New Zealand

View user's profile Send private message

asm time question
PostPosted: Tue Jul 27, 2010 3:53 pm     Reply with quote

I have been trying to optimize a piece of code I wrote by looking at the asm output of ccs but have a question about how long it will take to execute a piece of code.

1) With the " if (Servo_flag[1] == false) " it takes two lines of asm does that mean it takes 2 clock cycles to get through that statement if it doesnt match?

2) Because the second line is a goto does that mean it only takes 1 cycle if the statement is true?

3)If servo_flag 1 and servo_flag 2 are true how many cycles does it take to get thorught the code.

4) if servo_flag1 and 2 are false but the servo counts < val how many cycles does it take to get through the code?

Code:
....................                     
....................                if (Servo_flag[1] == false)   
00C1:  BTFSC  2C.1
00C2:  GOTO   0CC
....................                { if(val >= Servo_Count[1])
00C3:  MOVF   29,W
00C4:  SUBWF  2F,W
00C5:  BTFSS  03.0
00C6:  GOTO   0CC
....................                   {  output_low(Servo1); Servo_flag[1] = true;}}
00C7:  BSF    03.5
00C8:  BCF    06.1
00C9:  BCF    03.5
00CA:  BCF    06.1
00CB:  BSF    2C.1
....................                     
....................                if (Servo_flag[2] == false)   
00CC:  BTFSC  2C.2
00CD:  GOTO   0D7
....................                { if(val >= Servo_Count[2])
00CE:  MOVF   2A,W
00CF:  SUBWF  2F,W
00D0:  BTFSS  03.0
00D1:  GOTO   0D7
....................                   {  output_low(Servo2); Servo_flag[2] = true;}}
00D2:  BSF    03.5
00D3:  BCF    06.2
00D4:  BCF    03.5
00D5:  BCF    06.2
00D6:  BSF    2C.2
....................
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jul 27, 2010 4:08 pm     Reply with quote

Use the Stopwatch feature of the MPLAB simulator to count the instruction
cycles in your code. Put a breakpoint on the first if() statement in the
program below, and also put one on the while(1) line at the end
"Run" the program to the first breakpoint. Zero the Stopwatch. "Run"
the program to the 2nd breakpoint. Look at the number of usec that
it took to execute the code between those two breakpoints, by looking
in the Stopwatch window. Follow the instructions in this post:
http://www.ccsinfo.com/forum/viewtopic.php?t=38351
Remember to set the correct clock frequency in the Debugger Settings
menu. It must be the same as your #use delay() statement.

Notice how I have setup the desired test conditions by setting both
variables to "TRUE" before the if() code is entered. You can set them
to whatever you want, based on which part of the code you wish
to check the execution time for.
Code:

#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

#define Servo1  PIN_B1
#define Servo2  PIN_B2

//===========================
void main()
{
int8 Servo_flag[10];
int8 Servo_Count[10];
int8 val;   

Servo_flag[1] = TRUE; 
Servo_flag[2] = TRUE; 


if(Servo_flag[1] == FALSE)   
  {
   if(val >= Servo_Count[1])
     {
      output_low(Servo1);
      Servo_flag[1] = TRUE;
     }
  }   

if(Servo_flag[2] == FALSE)   
  {
   if(val >= Servo_Count[2])
     {
      output_low(Servo2);
      Servo_flag[2] = TRUE;
     }
  }   


while(1);
}
 
 
 
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group