完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
大家好,我在使用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个回答
|
|
|
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 |
|
|
|
|
|
此外,如何在章节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. |
|
|
|
|
|
可以使用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 |
|
|
|
|
|
非常感谢大家的建议和例子,特别是对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. |
|
|
|
|
|
我刚刚意识到伪指令“CLRC”在程序集文件中悄无声息地生成代码。如果XC8给我们一个警告或错误,或者修复它,那将是很好的。无论如何,包括.lc:lc.Inc>并使用一个“实际”指令来清除进位位——在前一篇文章中编辑我的代码。
以上来自于百度翻译 以下为原文 I just realized the pseudo-instruction "clrc" silently generates no code in the assembly file. It would be nice if XC8 throw us a warning or error, or fix this. Anyway, #include |
|
|
|
|
|
它不是真的坏了。为了在编写时与流行的汇编程序兼容,PIC汇编程序允许您定义没有冒号的标签。这个方案的问题是没有操作数的任何未被识别的指令被解释为标签。它可以被改变,但这需要改变客户的项目。这仅适用于非PIC18设备,如在62.65符号LABELS.Jeff中所描述的。
以上来自于百度翻译 以下为原文 It's not really broken. To be compatible with the popular assembler at the time it was written, the PIC assembler allowed you to define labels without a colon. The problem with this scheme is that any unrecognised instruction without operands is interpreted as a label. It could be changed, but that would require changes to customers' projects. This only applies to non-PIC18 devices, as described in 6.2.6.5 SYMBOLIC LABELS. Jeff. |
|
|
|
|
|
我怀疑它可能被视为一个标签,但我认为XC8需要一个冒号的标签-学到了一些新的东西。无论如何,我的投票是改变和修复它,因为它被假定为“与当时流行的汇编程序兼容”,我假设它是MPASM);MPASM支持伪指令,如CLRC、CLRZ、SETC、SETZ等。
以上来自于百度翻译 以下为原文 I suspected it might be treated as a label, but I thought XC8 requires a colon for a label -- learned something new. Anyway, my vote is to change and fix it, since it is supposed "to be compatible with the popular assembler at the time" which I assume is MPASM ;) ... and MPASM supports pseduo-instructions such as clrc, clrz, setc, setz, etc. |
|
|
|
|
|
为什么不让所有的设备强制冒号?也就是说,冒号对于所有设备都是可选的MPASM。
以上来自于百度翻译 以下为原文 Why not make the colon mandatory for all the devices? That said, the colon is optional with MPASM for all devices. |
|
|
|
|
|
其中一个可怕的标准没有任何理由坚持下去。标签上的强制性冒号在很多年前会有这么大的意义。
以上来自于百度翻译 以下为原文 One of those horrible standards that persisted for no good reason. Mandatory colons on labels would have made so much sense many, many years ago. |
|
|
|
|
|
这样做会触发对不使用冒号的现有代码的许多错误。这对很多人来说都是一个粗鲁的打击,但这是可能的。-杰夫。
以上来自于百度翻译 以下为原文 Doing so would trigger many errors for existing code that does not use the colon. That would be a rude shock to a lot of people, but is is possible. Yup. :-) Jeff. |
|
|
|
|
|
亲爱的,看着.LST文件,“CLRC”没有,和其他指令一样,但是我不知道这是否意味着没有真正生成代码。对我来说奇怪的是,即使没有ASMAS/Y内插线,即使代码被正确编译和链接,编辑器也会显示错误。伴随着ASM/Y-EnASTM所有的“红色标记”,你可以在附件中神奇地消失。
以上来自于百度翻译 以下为原文 Dear all, looking to .lst file, 'clrc' has no ;# like other instructions, but I don't know if this means that no code is really generated. Another thing that is strange for me is that without _asm / _endasm lines the editor indicates error even if the code is properly compiled and linked. With _asm / _endasm all the 'red marks' that you can see in the attachment magically disappear. Emanuele. Attached Image(s) Attachment(s) Umul8_Lst.txt (2.29 KB) - downloaded 87 times |
|
|
|
|
|
是的,这意味着没有生成代码,因为它被视为“标签”。这是文章最后一页的讨论。只是另一个MPLABX编辑器怪癖让你恼火。
以上来自于百度翻译 以下为原文 Yes, it means no code was generated, because it was treated as a "label". That's what the last page of posts has been discussing. Just another MPLABX editor quirk to keep you annoyed. |
|
|
|
|
|
在我的环境中,使用C函数和编译器抱怨无法识别亲爱的1'0'BCF进位。我写了“BCF状态,0”,即使我不确定CLRC不是真正的进程。
以上来自于百度翻译 以下为原文 Dear 1and0 'bcf CARRY' is not recognized in my environment using 'C function' and compiler complains. I wrote 'bcf STATUS,0' instead, even if I'm not sure that clrc is not really processed. Emanuele. |
|
|
|
|
|
您是否包含了lc.xc.Inc & gt,如在1&0代码开始时所示?如果你这样做,那就包括PIC16F1937.In,它将定义“进位”为“银行面罩(状态),0”,这与你的“BCF状态,0”实际上是一样的。
以上来自于百度翻译 以下为原文 Did you #include If you did, that would have included pic16f1937.inc which would have defined "CARRY" to be "BANKMASK(STATUS), 0" which is effectively the same as your "bcf STATUS,0" |
|
|
|
|
|
亲爱的QHB谢谢你的回答,但我不清楚它的含义;^,这是我第一次使用MPLAB X和XC8。在我看来,可怕的是,即使是正确的,即使是在ASM/AYEX-EnASM指令中被正确地包含在内,正确的指令也会成为一个没有任何警告的标签。尤勒
以上来自于百度翻译 以下为原文 Dear qhb thanks for your answer, but it was not clear for me the meaning of ;#, it's the first time I use MPLAB X and XC8. In my opinion the horrible thing is that something that was a correct instruction becomes a label without any warning even if included correctly in #asm / #endasm directive. Emanuele. |
|
|
|
|
|
亲爱的QHB,如果你看一看前面所附的图像,你就可以正确地写,但是它不起作用。它可能不被识别,因为写在“C”中的“μ”ASM/YEX-EASASM而不是直接在ASM文件中。我可以试试…EMANUELE。
以上来自于百度翻译 以下为原文 Dear qhb if you take a look to the image attached before, #include It's possible that it is not recognized because written inside #asm / #endasm in 'C' instead of directly in asm file ? I can try... Emanuele. |
|
|
|
|
|
是的,这意味着没有生成代码,因为它被视为“标签”。这就是文章最后一页的讨论。不,“CLRC”在函数内的μas/yixEnthAm之间使用时生成代码。下面是.LST文件的摘录:其中0x07C6是地址,0x1003是BCF状态的操作码,C。然而,汇编文件中的汇编代码在.LST文件中显示了{NoTo},并且我认为.LST文件假定是完整的。杰夫?
以上来自于百度翻译 以下为原文 Yes, it means no code was generated, because it was treated as a "label". That's what the last page of posts has been discussing. NOpe, "clrc" works and generates code when used between #asm/#endasm inside a function. Here's excerpt from .lst file: 434 ;psect for function _fUmul8 435 07C3 _fUmul8: 436 437 ;incstack = 0 438 ; Regs used in _fUmul8: [] 439 07C3 0870 movf _mult1,w ;# 440 07C4 01F3 clrf _res16hi ;# 441 07C5 01F2 clrf _res16lo ;# 442 07C6 1003 clrc 443 07C7 1871 btfsc _mult2,0 ;# where 0x07C6 is the address and 0x1003 is the opcode for BCF STATUS,C. However, the assembly code from the assembly file does _NOT_ show up in the .lst file, and I thought the .lst file supposes to be complete. Jeff? |
|
|
|
|
|
'CLRC '的工作是在μASM/γ端内。尝试这个或这个& lt;编辑& gt;如果你包含了& lt;xc.Inc & gt;在yasyASM之后,运载将工作;即现在,你应该知道,从.lc.xc.h & gt提供了StastUsSuxCpSn和CARRYY位,并且运载是从L.X.Inc&Gt提供的。
以上来自于百度翻译 以下为原文 The 'clrc' works inside #asm/#endasm. Try either this bcf STATUS,_STATUS_C_POSN or this bcf CARRY_bit #asm #include bcf CARRY By now, you should have figured out that _STATUS_C_POSN and CARRY_bit are provided from |
|
|
|
|
|
|
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
473 浏览 0 评论
5793 浏览 9 评论
2334 浏览 8 评论
2224 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3530 浏览 3 评论
1124浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1097浏览 1评论
我是Microchip 的代理商,有PIC16F1829T-I/SS 技术问题可以咨询我,微信:A-chip-Ti
873浏览 1评论
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
475浏览 0评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-2 07:49 , Processed in 1.274794 second(s), Total 78, Slave 71 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
1513