Microchip
直播中

张东群

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

怎么在16F1937的C代码中使用asm

大家好,我在使用16F1937处理器的C项目中遇到了一些困难。我的开发工具实际上是带有XC 8编译器V1.42,免费模式的MPLAB X V3.61。在我的项目中,刚刚从ASM移植到C,我需要一个具有16位结果的快速乘法8位×8位。就像原来的ASM项目一样。C移植完成后,由于C的缓慢乘法,我看到了一些执行延迟,只是想一个想法C函数的持续时间大约是ASM函数的2.5倍。说,我决定只用ASM中的乘法运算,现在一切都很好,但是我花了很多。在阅读大量文章和XC8用户指南的时候,在我看来,对于C代码中包含的ASM没有详细的说明。对于我来说,编写的代码不是那么“漂亮”,但实际上是找到的唯一方法,而且没有XC8C的抱怨。OMPELER。这是使用的代码,希望对其他人有用。EMANUELE。

以上来自于百度翻译


      以下为原文

    Hello everybody, I've had some difficulties using assembly code inside a C project with 16F1937 processor.
My development tool is actually MPLAB X V3.61 with XC 8 Compiler V1.42, free mode.
In my project, just now ported from asm to C, I need a fast multiplication 8 bit * 8 bit with a 16 bit result, as it was in original asm project. Once the C porting was completed, I see some delays in execution due to the slow multiplication introduced by C, just to have an idea C function has a duration of about 2.5 times asm function.
Said that, I've decided to use only multiplication in asm, and now everything works fine, but I spend a lot of time to find something that really works after reading a lot of posts and the XC8 user guide, that, in my opinion, is not properly detailed about asm included in C code.
The code written is not so 'beautiful' for me, but actually is the only way found that works and gives no complains from XC8 compiler.
This is the code used, I hope it will be useful for someone else.

Emanuele.
   Attachment(s)

Multiply8by8.c (1.56 KB) - downloaded 195 times

回帖(19)

杨叶

2019-2-27 12:33:39
HI,除非您只有两个汇编行(内联汇编),否则最好将(更容易)的程序文件添加到您的项目中。内联汇编语法非常有限,复杂且妨碍了C源代码的优化……请看这个目录:C:Project文件(x86)Microchip xC8。v1.42DOCSMPLABOXXC8YCCOMPILRIL USER指南

以上来自于百度翻译


      以下为原文

    Hi,
 
Unless you only have a couple of assembly lines (inline assembly), it is better (and much easier) to add an assembly file to your project.
Inline assembly syntax is very limitative, complex and prevents optimization in C source code....
Look in this directory : c:Program Files (x86)Microchipxc8v1.42docsMPLAB_XC8_C_Compiler_User_Guide.pdf
section 5.12
 
Regards
举报

罗茵

2019-2-27 12:49:10
此外,如何在章节3.4.7汇编代码中帮助您找到用户Guide.Jeff的方法。

以上来自于百度翻译


      以下为原文

   
Plus the How Tos in Section 3.4.7 Assembly Code might help you find your way around the User's Guide.
 
Jeff.
举报

李维兴

2019-2-27 13:05:07
可以使用C函数或汇编文件UUL8AS:

以上来自于百度翻译


      以下为原文

    You can use either a C function:
void Umul8(void)
{
    #asm
        movf    _mult1,w    // w = mult1
        clrf    _res16hi    // Clear product hi
        clrf    _res16lo    // Clear product lo
        clrc                // Clear carry flag
    irp bit,0,1,2,3,4,5,6,7
        btfsc   _mult2,bit
        addwf   _res16hi,f
        rrf     _res16hi,f
        rrf     _res16lo,f
    endm
    #endasm
}
or an assembly file umul8.as:
#include
global _Umul8,_mult1,_mult2,_res16hi,_res16lo
psect   umul8,local,class=CODE,delta=2
_Umul8:
        movf    _mult1,w
        clrf    _res16hi
        clrf    _res16lo
        bcf     CARRY
    irp bit,0,1,2,3,4,5,6,7
        btfsc   _mult2,bit
        addwf   _res16hi,f
        rrf     _res16hi,f
        rrf     _res16lo,f
    endm
        return
举报

陈萍

2019-2-27 13:23:36
非常感谢大家的建议和例子,特别是对1AN0的代码,比我的更优雅,也适当的工作。

以上来自于百度翻译


      以下为原文

    Thanks a lot to everyone for suggestions and examples, in particular to 1and0 for code, more elegant than mine and also properly working.
 
Emanuele.
举报

更多回帖

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