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

How to count the instructions of functions/code?

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



Joined: 06 Aug 2016
Posts: 107
Location: Moscow

View user's profile Send private message Visit poster's website AIM Address

How to count the instructions of functions/code?
PostPosted: Sat Apr 06, 2019 7:49 am     Reply with quote

Hi again!
I know that normally there should be a separate topic for each question so I create 2 more.

How to count the instructions in CCS. I know that every function has its own built-in implementation, is there any way to count how many processor cycles takes 1 a part of my code?
_________________
Yo! I love learning and technology! I just do not have experience so do not be angry if I ask a stupid question about a detail! From so much to remember sometimes I forget the details in order to remember the big problems!
temtronic



Joined: 01 Jul 2010
Posts: 9174
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Apr 06, 2019 9:00 am     Reply with quote

Basic 'how to do it'
Simply print the listing file (projectname.lst) and you'll see all the machine code.
For most PICs, a 4MHz clock results in a 1us/instruction time, except for branches which take 2. The datasheet will have the instruction set and # of cycles for each.
If the listing doesn't show some code, you'll have to comment out the '#nolist' at the top of the function.

Others will reply with better directions....as I only program PICS for fun these days.

Jay
Arakel



Joined: 06 Aug 2016
Posts: 107
Location: Moscow

View user's profile Send private message Visit poster's website AIM Address

PostPosted: Sat Apr 06, 2019 9:03 am     Reply with quote

Seems like a lot of work :D.

I am using the CCS ide. I know its possible with MPLAB, but I want to avoid installing MPLAB.
_________________
Yo! I love learning and technology! I just do not have experience so do not be angry if I ask a stupid question about a detail! From so much to remember sometimes I forget the details in order to remember the big problems!
temtronic



Joined: 01 Jul 2010
Posts: 9174
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Apr 06, 2019 11:08 am     Reply with quote

Not really. You don't need MPLAB. CCS makes the listing file. Take that and 2-3 pages from the datasheet of your PIC. Depending on how complex your program is, it'll take 10 minutes or 10 days to complete the task.
The PIC has less than 40 instructions so decoding is easy.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Apr 06, 2019 11:40 am     Reply with quote

The MPLAB vs. 8.92 Stopwatch feature can be used to measure how
many cycles (in microseconds) it takes to execute a block of code:
http://www.ccsinfo.com/forum/viewtopic.php?t=38351

MPLAB vs. 8.92 download (from Microchip website) without having
to sign up and register:
http://ww1.microchip.com/downloads/en/DeviceDoc/MPLAB_IDE_8_92.zip

Mplab X stopwatch:
https://www.youtube.com/watch?v=zt44UxcpUlc

But of course, you don't tell us your PIC, so we don't know for sure
if MPLAB 8.92 will support your PIC for Stopwatch.
temtronic



Joined: 01 Jul 2010
Posts: 9174
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Apr 06, 2019 12:38 pm     Reply with quote

While the 'stopwatch' feature will tell you execution time, it doesn't count the actual lines of machine code. To do that, 'count the instructions', you need to dump the listing and see the code.
Now depending on 'how' the code was 'optimized' by the compiler's creator, it may be shorter or longer than what you think it should be. You can optimize for speed or size or go 'inbetween'. Also some programmers, not brought up on PIC assembler, may not know about the great instructions that excute in 1 cycle, relying instead of 5-8 lines of code where 1 will do the same operation.

Jay
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sun Apr 07, 2019 7:36 am     Reply with quote

Or take the direct hardware route.

Depends on your code.

1) Simple repeating loop. Create a pulse on a spare pin, somewhere in the loop. Measure time interval between pulses. (Or you could simply toggle the pin)

2) To measure complex intervals, use different pins in different parts of code.

Mike
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