Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics 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.

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

Status
Not open for further replies.

thannara123

Advanced Member level 5
Joined
Jan 7, 2010
Messages
1,580
Helped
122
Reputation
244
Reaction score
114
Trophy points
1,353
Location
India
Activity points
10,379
Hello ,
Any way to find out the machine cycles taken each instruction in written in C (Keil) ?


thanks
 

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.
 

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 !)
 
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 picture asm cycle.JPG

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

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.
 
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.
 
Yes right that is am searching ? thanks Thamid for the information .

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

yes!
"Registers" window have all timings:
cycles, 0.12345678us, .....
see bellow this page:
**broken link removed**

p.s.
only if some of micro isn't supported 100% at peripheral level this data can't be viewed!
 
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
 
Ah, that would be the easier way! I didn't realise this existed.
 

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
 

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

Back
Top