View previous topic :: View next topic |
Author |
Message |
Arakel
Joined: 06 Aug 2016 Posts: 107 Location: Moscow
|
How to count the instructions of functions/code? |
Posted: Sat Apr 06, 2019 7:49 am |
|
|
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: 9270 Location: Greensville,Ontario
|
|
Posted: Sat Apr 06, 2019 9:00 am |
|
|
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
|
|
Posted: Sat Apr 06, 2019 9:03 am |
|
|
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: 9270 Location: Greensville,Ontario
|
|
Posted: Sat Apr 06, 2019 11:08 am |
|
|
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
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9270 Location: Greensville,Ontario
|
|
Posted: Sat Apr 06, 2019 12:38 pm |
|
|
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
|
|
Posted: Sun Apr 07, 2019 7:36 am |
|
|
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 |
|
|
|