您好,XC8编译器使用的是哪种许可证?自由模式或Pro模式。在自由模式下有很多优化,如果你还没有做过的话,有可能尝试2个月的最大优化。你不必在程序集中编写所有代码,只需要那些真正重要的部分。你可以完全编写一个函数。程序集,你可以在C中写一个函数条目和完成,并用一大块汇编代码填充它,或者你可以在C代码中加入汇编指令。注意,在C代码中加入汇编指令,如果没有C编译器知道发生了什么,可能会导致错误。例如改变FSR寄存器。R内容,而不是恢复原始值,可能会导致以下代码中的错误。这里是一个在C函数中封装的汇编代码的例子,它已经用于连接的交流测量和PIC16和PIC18上的RMS平均计算。
以上来自于百度翻译
以下为原文
Hi,
Which kind of license for XC8 compiler are you using? Free or Pro mode.
There are a lot of optimizations not done in Free mode,
There is a possibility to try out maximum optimizations for 2 months, if you haven't done so already.
You don't have to write all the code in assembly, only those parts where it really matter.
You may write a function entirely in assembly,
You may write a function entry and completion in C and fill it with a big block of assembly code,
or you may put in assembly instructions in C code.
Be careful, putting in assembly instructions in C code, without C compiler knowing what is going on,
may cause errors.
E.g. changing FSR register contents, and not restoring the original value, may cause error in following code.
Here is an example of assembly code wrapped in a C function, it have been used in connection AC measurements and RMS average calculations on PIC16 and PIC18.:
/*
* PIC16, PIC18
* Calculate average from a running accumulator Avg = Avg >> 10;
* Modified from code contributed on Microchip forum by "co_worker"
* containing suggestions from "1and0" and "andig"
* Microchip Forum http://www.microchip.com/forums/FindPost/848067
*/
#include
#include
#define IN_ASM
#ifndef Avgshift
#define Avgshift 10
#endif
/*
* Unsigned integer shift
*
* Result = Arg >> 10;
*
* Parameters:
* a = 24-bit unsigned integer accumulating samples.
*
* Return Value:
* The function returns a 16-bit unsigned integer Result.
*
* Program Memory:
* 20 instructions including call and return
*
* Execution Time:
* 14 cycles excluding the call (prolog) and return (epilog).
*
* Remarks:
*
*
* History:
* 2016-05-04 - by Arne Bergseth "Mysil"
*/
uint16_t uShift_24_10(uint24_t Arg)
{
uint16_t Result = 0; /* Zero to make compiler happy, */
/* zeroing may be omitted if compiler warning is acceptable. */
#if defined(IN_C)
result = a >> avgshift;
#endif
#if defined(IN_ASM) /* ? instructions, ? cycles, ? avg ? to be tested. */
/*
* Ma.
*
* rh:rl = (au:ah:al >> 10)
*
*/
#asm
#ifdef _PIC18
#define rh (uShift_24_10@Result+1)
#define rl (uShift_24_10@Result)
#define au (uShift_24_10@Arg+2)
#define ah (uShift_24_10@Arg+1)
#define al (uShift_24_10@Arg)
#elif _PIC14 || _PIC14E
#define rh (uShift_24_10@Result+1)&0x7F
#define rl (uShift_24_10@Result)&0x7F
#define au (uShift_24_10@Arg+2)&0x7F
#define ah (uShift_24_10@Arg+1)&0x7F
#define al (uShift_24_10@Arg)&0x7F
#endif
BANKSEL(uShift_24_10@Arg)
/* rh:rl = au:ah >> 1 Do 8 bit shift by picking bytes
* then 1 bit shift by instruction */
bcf STATUS,0 /* clear the carry bit. */
#if (Avgshift == 8) /* Do 8 bit shift by picking bytes . */
movf au,W
movwf rh
movf ah,W
movwf rl
#elif (Avgshift > 8) /* then 1 bit shift by instruction. */
rrcf au,W /* Move from Au into W */
movwf rh /* store in Rh */
rrcf ah,W
movwf rl
#endif
#if (Avgshift == 10) /* ru:rh:rl = ru:rh:rl >> 1 */
clrc /* one more rotation for 10 bit shift */
rrcf rh,F
rrcf rl,F /* Shift into rl from the carry bit */
// rrcf rl,W ;/* may use W for this. */
#else
movf rl,W /* start with low byte */
#endif
#endasm
#endif
return Result;
}
Regards,
Mysil
您好,XC8编译器使用的是哪种许可证?自由模式或Pro模式。在自由模式下有很多优化,如果你还没有做过的话,有可能尝试2个月的最大优化。你不必在程序集中编写所有代码,只需要那些真正重要的部分。你可以完全编写一个函数。程序集,你可以在C中写一个函数条目和完成,并用一大块汇编代码填充它,或者你可以在C代码中加入汇编指令。注意,在C代码中加入汇编指令,如果没有C编译器知道发生了什么,可能会导致错误。例如改变FSR寄存器。R内容,而不是恢复原始值,可能会导致以下代码中的错误。这里是一个在C函数中封装的汇编代码的例子,它已经用于连接的交流测量和PIC16和PIC18上的RMS平均计算。
以上来自于百度翻译
以下为原文
Hi,
Which kind of license for XC8 compiler are you using? Free or Pro mode.
There are a lot of optimizations not done in Free mode,
There is a possibility to try out maximum optimizations for 2 months, if you haven't done so already.
You don't have to write all the code in assembly, only those parts where it really matter.
You may write a function entirely in assembly,
You may write a function entry and completion in C and fill it with a big block of assembly code,
or you may put in assembly instructions in C code.
Be careful, putting in assembly instructions in C code, without C compiler knowing what is going on,
may cause errors.
E.g. changing FSR register contents, and not restoring the original value, may cause error in following code.
Here is an example of assembly code wrapped in a C function, it have been used in connection AC measurements and RMS average calculations on PIC16 and PIC18.:
/*
* PIC16, PIC18
* Calculate average from a running accumulator Avg = Avg >> 10;
* Modified from code contributed on Microchip forum by "co_worker"
* containing suggestions from "1and0" and "andig"
* Microchip Forum http://www.microchip.com/forums/FindPost/848067
*/
#include
#include
#define IN_ASM
#ifndef Avgshift
#define Avgshift 10
#endif
/*
* Unsigned integer shift
*
* Result = Arg >> 10;
*
* Parameters:
* a = 24-bit unsigned integer accumulating samples.
*
* Return Value:
* The function returns a 16-bit unsigned integer Result.
*
* Program Memory:
* 20 instructions including call and return
*
* Execution Time:
* 14 cycles excluding the call (prolog) and return (epilog).
*
* Remarks:
*
*
* History:
* 2016-05-04 - by Arne Bergseth "Mysil"
*/
uint16_t uShift_24_10(uint24_t Arg)
{
uint16_t Result = 0; /* Zero to make compiler happy, */
/* zeroing may be omitted if compiler warning is acceptable. */
#if defined(IN_C)
result = a >> avgshift;
#endif
#if defined(IN_ASM) /* ? instructions, ? cycles, ? avg ? to be tested. */
/*
* Ma.
*
* rh:rl = (au:ah:al >> 10)
*
*/
#asm
#ifdef _PIC18
#define rh (uShift_24_10@Result+1)
#define rl (uShift_24_10@Result)
#define au (uShift_24_10@Arg+2)
#define ah (uShift_24_10@Arg+1)
#define al (uShift_24_10@Arg)
#elif _PIC14 || _PIC14E
#define rh (uShift_24_10@Result+1)&0x7F
#define rl (uShift_24_10@Result)&0x7F
#define au (uShift_24_10@Arg+2)&0x7F
#define ah (uShift_24_10@Arg+1)&0x7F
#define al (uShift_24_10@Arg)&0x7F
#endif
BANKSEL(uShift_24_10@Arg)
/* rh:rl = au:ah >> 1 Do 8 bit shift by picking bytes
* then 1 bit shift by instruction */
bcf STATUS,0 /* clear the carry bit. */
#if (Avgshift == 8) /* Do 8 bit shift by picking bytes . */
movf au,W
movwf rh
movf ah,W
movwf rl
#elif (Avgshift > 8) /* then 1 bit shift by instruction. */
rrcf au,W /* Move from Au into W */
movwf rh /* store in Rh */
rrcf ah,W
movwf rl
#endif
#if (Avgshift == 10) /* ru:rh:rl = ru:rh:rl >> 1 */
clrc /* one more rotation for 10 bit shift */
rrcf rh,F
rrcf rl,F /* Shift into rl from the carry bit */
// rrcf rl,W ;/* may use W for this. */
#else
movf rl,W /* start with low byte */
#endif
#endasm
#endif
return Result;
}
Regards,
Mysil
举报