總是習慣性的使用* or / or %
卻忘了正在使用的MCU特性是如何
你真的是個軔體工程師嗎?
還是只是個用高階語言寫MCU的工程師
UTC = 0x12345;
/* for(i=5;i>=0;i--) //1
{
dec_temp[i] = UTC % 10;
UTC /= 10;
} */
/* va = 100000; //2
for(i=0;i<5;i++)
{
while (UTC>=va)
{
UTC -= va;
dec_temp[i]++;
}
va /= 10;
}
dec_temp[5]=UTC; */
/*va = 100000; //3
while (UTC>=va)
{
UTC -= va;
dec_temp[0]++;
}
va = 10000;
while (UTC>=va)
{
UTC -= va;
dec_temp[1]++;
}
va = 1000;
while (UTC>=va)
{
UTC -= va;
dec_temp[2]++;
}
va = 100;
while (UTC>=va)
{
UTC -= va;
dec_temp[3]++;
}
va = 10;
while (UTC>=va)
{
UTC -= va;
dec_temp[4]++;
}
dec_temp[5]=UTC; */
/* va = 100000; //4
for(i=0;i<5;i++)
{
dec_temp[i]=UTC/va;
UTC -= (dec_temp[i]*va);
va /=10;
}*/
/*dec_temp[0]=UTC/100000; //5
UTC = UTC-(dec_temp[0]*100000);
dec_temp[1]=UTC/10000;
UTC = UTC-(dec_temp[1]*10000);
dec_temp[2]=UTC/1000;
UTC = UTC-(dec_temp[2]*1000);
dec_temp[3]=UTC/100;
UTC = UTC-(dec_temp[3]*100);
dec_temp[4]=UTC/10;
dec_temp[5]=UTC-(dec_temp[4]*10); */
/*dec_temp[0]=UTC/100000; //6
UTC = UTC%100000;
dec_temp[1]=UTC/10000;
UTC = UTC%10000;
dec_temp[2]=UTC/1000;
UTC = UTC%1000;
dec_temp[3]=UTC/100;
UTC = UTC%100;
dec_temp[4]=UTC/10;
dec_temp[5] =UTC%10;*/
有編號的6個程式碼
所做的事情都一樣
只是把hex to bcd
但如果今天使用的是8bit MCU
雖然結果都是相同的
但程式所執行的時間
和程式的大小可是有很大的差別的
8051:
original code:1205
1.CPU_time:0.00181350 code:1544
2.CPU_time:0.00111800 code:1605
3.CPU_time:0.00034800 code:1534
4.CPU_time:0.00167875 code:1680
5.CPU_time:0.00080250 code:1830
6.CPU_time:0.00146450 code:1703
6502:
original code:655
1.CPU_time:0.0199435 cpu_cycle:39887 code:1049
2.CPU_time:0.008923 cpu_cycle:17846 code:1125
3.CPU_time:0.000409 cpu_cycle:818 code:1317
4.CPU_time:0.0177185 cpu_cycle:35437 code:1249
5.CPU_time:0.0088335 cpu_cycle:17667 code:1702
6.CPU_time:0.016546 cpu_cycle:33092 code:1489
沒有留言:
張貼留言