Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 05, 2016, 09:23:25 09:23


Login with username, password and session length


Pages: [1]
Print
Author Topic: Counting number of instructions in CCS C  (Read 1992 times)
0 Members and 1 Guest are viewing this topic.
vsmGuy
Junior Member
**
Offline Offline

Posts: 35

Thank You
-Given: 11
-Receive: 7


« on: July 10, 2010, 07:37:29 19:37 »

I would like to find out, *without* opening the assembly listing, the number of instructions for a line ( or a number of lines ) in CCS C.

Is this possible ( even in conjuction with tools like MPLAB using the plugin )?

For example,

1. I want to find out how many instructions

Code:
delay_us(200);

generates

2. I want to find out how many instructions

Code:
set_timer1(0);
delay_us(200);

generates

3. Then, I would like to count the number of clock cycles it took to execute each function,  *without* opening the assembly listing
Logged
oldvan
V.I.P
Senior Member
*****
Offline Offline

Posts: 375

Thank You
-Given: 152
-Receive: 106


If the van is a Rockin'...


WWW
« Reply #1 on: July 11, 2010, 12:15:29 00:15 »

1.1) 
Code:
       delay_us(200);
Compile.  Note the number of bytes of ROM used.

1.2) 
Code:
//     delay_us(200);
Compile.  Note the number of bytes of ROM used.

1.3) Subtract.


2)  See example given in 1).


3)  ?? Maybe asking a bit much there.
Logged

Give a man a fish and you feed him for a day.
Teach a man to fish and he will sit around in a boat drinking beer all day.
rajudp
Newbie
*
Offline Offline

Posts: 28

Thank You
-Given: 1
-Receive: 2


« Reply #2 on: July 11, 2010, 07:38:52 07:38 »

check the sta file
Logged
TomJackson69
V.I.P
Active Member
*****
Offline Offline

Posts: 221

Thank You
-Given: 23
-Receive: 63


« Reply #3 on: July 11, 2010, 08:04:30 20:04 »

Hello,

Without read the assembly listing for counting the number of instructions is only guessing. Each programmer write program difference from each other, therefore, one suggestion may not be other want.

For calculate (or guessing) number of instruction during RUN TIME. One could use a TIMER to count the clock cycles for a function being executed and find the number of instructions according to the frequency of the uP running. This way one could get the number of instructions very close to real (error account by some instructions like MOVFF …).

For example:

Define a variable “NUMBER_OF_INSTRUCTION” large enough to hold the counting.

Your function()
{
   Initial TIMER      // to start timer counter
   …
   …         // function body
   …
   Read the timer      // *** make sure the timer don’t roll over *** see note below

Here one could calculate the number of instruction and put it in NUMBER_OF_INSTRUCTION variable. And print out on the LCD or use debug to watch the NUMBER_OF_INSTRUCTION variable.

// remember, this method only gives a proximate number of instruction but one does not have to open the assembly listing to count. If you call another function in your function, the number of instruction still count.
}

One caution should be note: If the function is too long, make sure you know when the TIMER over flow, that way you don’t miss the counter. You could use TIMER INT.

Remember to remove the TESTING instructions from your routine after test.

Tom
« Last Edit: July 11, 2010, 08:06:57 20:06 by TomJackson69 » Logged

Con Rong Chau Tien
vsmGuy
Junior Member
**
Offline Offline

Posts: 35

Thank You
-Given: 11
-Receive: 7


« Reply #4 on: July 12, 2010, 02:29:15 02:29 »

I appreciate your post TomJackson69!

In fact, you got the concept bang on - only thing is - in MPLAB you can set up a instruction timer without adding any code to your firmware. I had forgotten how to set it up but found it again on the net.
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC