Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

Any way to find out the machine cycles taken each instruction in Keil written in C

Status
Not open for further replies.

sky_123

Advanced Member level 4
Joined
Feb 26, 2011
Messages
1,170
Helped
279
Reputation
566
Reaction score
273
Trophy points
1,363
Activity points
9,599
Hi,

You can probably enable assembler listing generation (I don't use Keil, but I'm sure it must be possible).
Interspersed with code, it will look like something like this:
Code:
      9            unsigned int i;
     10            for (i=0; i<30000; i++)
   \                     mydelay:
   \   00000000   0x....             LDR      R0,??DataTable1  ;; 0x7530
     11            {
     12              __no_operation();
   \                     ??mydelay_0:
   \   00000002   0x46C0             Nop      
     13            }
   \   00000004   0x1E40             SUBS     R0,R0,#+1
   \   00000006   0xD1FC             BNE      ??mydelay_0
     14          }
   \   00000008   0x4770             BX       LR               ;; return
Then, you can directly look up the machine instructions in the specific microcontroller data sheet, to
see how long they take to execute.
 

Jigar 4 Electronics

Full Member level 5
Joined
Apr 28, 2011
Messages
313
Helped
40
Reputation
80
Reaction score
38
Trophy points
1,318
Location
Hamilton, ON, Canada
Activity points
3,390
after you click on debug in keil, a sub window will be there in background of the main program window.
main program Tab has program in C, & other Tab will be of ASM language... that will be equivalent to the C program & so we can
judge the no. of cycles for 1 instruction of C by step execution.
But I've experienced that if we have used 3 for loop (even if all of them are same !) all of them will occupy diff. no. of Machine Cycles. (Don't know why !)
 

thannara123

Advanced Member level 4
Joined
Jan 7, 2010
Messages
1,455
Helped
120
Reputation
240
Reaction score
110
Trophy points
1,353
Location
God's Own country India, India
Activity points
9,424
thanks for replay ?
one doubt How to calculate how much cycles take each instruction ?
is it according with bit operation ? please can you explain how it ?

for example take from the pictureasm cycle.JPG

what is the relation between bit operation and cycles ?
 
Last edited:

sky_123

Advanced Member level 4
Joined
Feb 26, 2011
Messages
1,170
Helped
279
Reputation
566
Reaction score
273
Trophy points
1,363
Activity points
9,599
You can see from your screenshot that the "P2=0x00" command was translated into two instructions:
CLR A
MOV PPAGE_SFR(0x00),A


Then, you can see that the "P3=0x00" command was translated to one instruction:
MOV P3(0xB0),A

You can check the microcontroller data sheet to see how many clock cycles these instructions take. Maybe it is 1 clock cycle each for a PIC (I don't know).
Then, you can check the microcontroller clock cycle period (depends on your crystal) and multiply by the number of clock cycles.
So, the P2=0x00 command took twice as long as the P3=0x00 command, because the "CLR A" instruction was used for both (it basically sets register A to zero).
A total of 3 machine instructions for the two source code lines. So, for those two source code lines, the amount of time was 1.5 machine instructions each.
 

Tahmid

Advanced Member level 5
Joined
Jun 17, 2008
Messages
4,758
Helped
1,791
Reputation
3,574
Reaction score
1,650
Trophy points
1,393
Location
Silicon Valley, California, USA (from Dhaka, Bangl
Activity points
30,545
Isn't there a stopwatch in Keil that you can use to move through the code while debugging and check the time taken for each instruction written? I haven't used Keil, so I don't know. But a stopwatch is present in many other IDEs.
 

thannara123

Advanced Member level 4
Joined
Jan 7, 2010
Messages
1,455
Helped
120
Reputation
240
Reaction score
110
Trophy points
1,353
Location
God's Own country India, India
Activity points
9,424
Yes right that is am searching ? thanks Thamid for the information .

But i goggled but nothing about stop watch in Keil please help me
 

alexan_e

Administrator
Joined
Mar 16, 2008
Messages
11,895
Helped
2,021
Reputation
4,158
Reaction score
2,031
Trophy points
1,393
Location
Greece
Activity points
64,377
There is a stopwatch at the lower right corner of uvision
uvision_stopwatch.gif

There is also a cycle counter in the left side panel
uvision_cycles.gif
 

sky_123

Advanced Member level 4
Joined
Feb 26, 2011
Messages
1,170
Helped
279
Reputation
566
Reaction score
273
Trophy points
1,363
Activity points
9,599
Ah, that would be the easier way! I didn't realise this existed.
 

kodi.sudar

Member level 5
Joined
Dec 21, 2009
Messages
92
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
india
Activity points
1,849
There is a stopwatch at the lower right corner of uvision
View attachment 84155

There is also a cycle counter in the left side panel
View attachment 84156
I heard that it is possible to use logic analyzer to measure the execution time in Uvision4 . but i don't know to verify that any idea to achieve that ?

Thanks

- - - Updated - - -

There is a stopwatch at the lower right corner of uvision
View attachment 84155

There is also a cycle counter in the left side panel
View attachment 84156
I heard that it is possible to use logic analyzer to measure the execution time in Uvision4 . but i don't know to verify that any idea to achieve that ?

Thanks
 

alexan_e

Administrator
Joined
Mar 16, 2008
Messages
11,895
Helped
2,021
Reputation
4,158
Reaction score
2,031
Trophy points
1,393
Location
Greece
Activity points
64,377
I think by using a dummy variable that is changed in the program and then view that variable in the integrated logic analyzer of uvision to measure the time between the variable state changes
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top