Microchip
直播中

赵护林

7年用户 240经验值
私信 关注
[问答]

C代码的指令周期计算需要多少时间

海佬。我想知道我的代码执行我的程序需要多少时间。假设我写了一个简单的代码,用于LED闪烁在MPLAB IDE和HTC编译器的PIC16F87A使用4兆赫。因此,一个指令的执行时间是1US。从上面的C代码中,除了方括号之外,还有16行代码,延迟函数由9行代码组成。这意味着我要把它作为9条指令吗?????!我说的对吗????我想知道的是这个程序包含多少指令?我的意图是我应该说有多少指令是通过看到C代码编写的。

以上来自于百度翻译


      以下为原文

    Hai guys.  I want to know how much time my code take to execute my program. Suppose i write a simple code for led blinking in MPLAB IDE & HTC Compiler for PIC16F877A using 4 MHz. So, Execution Time for One Instruction is 1us.



#include

#define _XTAL_FREQ 4e6

__CONFIG(0x3F3A);

void main()

{

PORTD=0x00;

TRISD=0x00;

while(1)

{

RD0=1;

__delay_ms(500);

RD0=0;

__delay_ms(500);

}

}




From the above c code consists 16 lines of code apart from square brackets, delay function it consists 9 lines of code.

That means shall i take it as 9 instructions????! am i right????

what i want to know is how much instruction this program consists of? My intention is i should say how many instructions is written by just seeing c code.

回帖(12)

蒋喜玲

2018-12-5 14:54:16
不可能。您需要查看拆卸视图或列表文件来确定。用一个非常小的简单程序,你可以猜得相当好,但是随着代码变得越来越大,越来越复杂,它不值得付出努力。编译代码告诉你它有多大。

以上来自于百度翻译


      以下为原文

    Not really possible. You need to look at the disassembly view or listing file to determine that. With a very small simple program you might be able to guess reasonably well, but as the code gets bigger and more complex it's not worth the effort. Compiling the code tells you how big it is.
举报

陈晨

2018-12-5 15:12:20
这不可能是9条指令。但是一些C语句是一对一将是一个操作码。然而大多数不是。

以上来自于百度翻译


      以下为原文

    That is not likely to be 9 instruction. But some C statements are one to one will an an opcode. However most are not.
举报

吴键洪

2018-12-5 15:27:23
不完全错。你不允许PoIC1F架构所需要的银行选择指令。正如其他人建议的,你需要检查编译的代码来了解它是如何做的。查看你的项目文件夹中的.LST文件。如果你使用的话,它也会有很大的不同。在自由模式或PRO模式下编译。

以上来自于百度翻译


      以下为原文

   
No. Completely wrong.
You're not allowing for bank selecting instructions required by POIC1F architecture, etc.
As others suggested, you need to examine the compiled code to get an idea of how it does it.
Look in the .LST file in your project folder.
It also makes a HUGE difference if you are using the compiler in FREE mode or PRO mode.
 
举报

李思昊

2018-12-5 15:34:55
好了,伙计们!谢谢你的建议MrBuff宁,Nkurzman和Qub。

以上来自于百度翻译


      以下为原文

    Ok guys! Thank u for the suggestions mbrowning, Nkurzman and qub.
举报

更多回帖

发帖
×
20
完善资料,
赚取积分