We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hello I am using C51 Compiler for AT89C51. How can I Count clock cycle consumption for a Piece of C Code e.g P1=(int)(((sin((2*PI)*(((double) (k++))/MAX))+1)/2)*BYTE); ????????? How many clks it will take ??? ????????
Looking at only the C source code, you can't. Using an emulator or uVision's simulator, set a breakpoint at this C statement and the statement that follows it. Execute up to the first breakpoint and (using uVision's simulator, at least) note the clocks value, then execute up to the next breakpoint and subtract the noted clocks value from the new clocks value and there you have it.
a piece on convoluted code like that will almost certainly not have a single, constant execution time - it will depend on the precise values of the variables involved in each particular calculation!
Keil has a web page where you can get the minimum, average, and maximum times for the floating point function calls. You could add those up to get an idea of how long calculating that expression would take. http://www.keil.com/benchmks/tm_c51_v7_small.asp
"Keil has a web page where you can get the minimum, average, and maximum times..." and if you look at that page, you will see that there can be a 2:1 (or more!) ratio between the minimum and maximum! Like I said earlier: there is not a single, constant answer to this question!