Jump to content
  • 0

Mehdim

Question

Hello everyone;

 

I am using Zybo board with standalone OS using Xilinx SDK.

 

I wonder to know if there is any library or board support package that I can get the value of PC (Program Counter).

 

The reason I am looking for that, is that I want to measure how much clock cycle does a portion of my code take (by calculating difference between  PCs at two test points of the code).

 

Appreciate your comments.

 

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

Mehdim,

As for getting the PC, it might be possible to write a small piece of assembly code that returns its own return address. I haven't tried this on Zybo before, so I'm not sure if assembly level programming possible, or what version of assembly it would be in.

For measuring clocks over a piece of code. Depending on your code structure, taking the difference between two program counters is not the best way to do this. If there are any function calls, then it is likely that the compiler would turn those into jumps or branches, which would move the PC to a different section of code entirely, what this would mean is that your change in PC would only show the length of the contiguous code segment your get PC functions were placed in, it would ignore the length of any functions that were called within that block.

So, alternative solutions, the C time.h library *could* work, getting the timestamp before and after your block of code, taking the difference, exactly how a getPC function would work. The issue with this is that, if I recall correctly, the timestamps are measured in milliseconds, which is not nearly a fine enough measurement for what you need. It should also be possible to implement a counter module in the Zybo's FPGA fabric, and to set up a function to zero it out and turn it on from within your code, then once done executing that code, turn it off and fetch the count -- I would prefer this solution, while more complicated, it gives you the most control over the resolution/units of your result. I can expand on these if needed.

Thanks,

Arthur

Link to comment
Share on other sites

Thanks for the prompt reply;

Actually I am looking to measure this distance in number of clock cycles. This measurement can be use to fairly estimate power consumption of each function based on clock cycles. I agree that calling a function to return PC value may cause some unexpected value to the PC.

I will search for some technical paper on this issue and share it if I find the solution.

Thanks for sharing your knowledge.

Link to comment
Share on other sites

I think i have found a solution.

I read R15, which is PC register and store it on a memory location to use it as a variable;

here is my code:

            asm("MOV R0,R15");
            asm("LDR R1,=0x118a60");
            asm("STR R0,[R1]");

 

in-which   refers to a memory address of a variable.

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...