完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我有一个初学者的问题,我找不到手册或论坛。我使用汇编程序在一个单独的*.ASM文件中,主程序在一个*.c文件中。当我在*.ASM文件中写入一个特定的地址时,例如:计数器-0x20……MOVWF反拨器,我能确保这个地址(0x20)没有被C编译器分配给*.c文件中定义的一些局部变量或全局变量,并且我可以意外地覆盖现有变量吗?编译器是否如此聪明以致于这不会发生?或者我需要在*.c文件中声明:静态char计数器@ 0x20;以确保这个地址是保留的吗?
以上来自于百度翻译 以下为原文 I have a beginner's question which I couldn't find in manuals or forums. I use assembler routines that are in a separate *.asm file and the main program is in a *.c file. When I write to a specific address in the *.asm file, for example: COUNTER equ 0x20 ... movwf COUNTER how can I make sure that this address (0x20) is not being allocated by the C compiler for some local or global variables defined in the *.c file and I could accidentally overwrite an existing variable? Is the compiler so clever that this does not happen? Or do I need to declare in the *.c file: static char counter @ 0x20; to make sure that this address is reserved? |
|
相关推荐
7个回答
|
|
Hiu根本不使用这种地址定义,它只适用于“绝对”程序集。为了有一个混合的“C”ANSD“ASM”程序,你的“ASM”代码必须是可重新定位的类型,因此链接器可以加入所有的片段。在其中一个模块中定义它们,并在其他模块上声明它们为外部。
以上来自于百度翻译 以下为原文 Hi You simply don't use that kind of address definition, its only for "absolute" assembly. In order to have a mixed "C" ansd "ASM" program your "ASM" code must be of the relocatable type so the linker can join all the pieces. To share variables between different source modules ("C" or "ASM") you must define them in one of the modules, and declare them as external on the other modules. HIH Best regards Jorge |
|
|
|
在您的程序集文件中,这样做:注意领先的下划线。
以上来自于百度翻译 以下为原文 In your assembly file, do this: global _counter ; ... banksel _counter movwf _counter Notice the leading underscore. |
|
|
|
“您必须在其中一个模块中定义它们,并将它们声明为其他模块上的外部”——我可以仅在ASM中定义它,而不在C中使用它吗?或者我需要在C中定义它,虽然我不会在C中使用它吗?我不想创建一个共享变量,只需要在ASM中使用一个地址。正如我所知道的,“计数器=0x20”不分配任何空间,它只是在编译前用一个数字替换这个字。
以上来自于百度翻译 以下为原文 "you must define them in one of the modules, and declare them as external on the other modules" - can I define it only in ASM and not use it in C at all? Or do I need to define it in C although I won't be using it in C? I don't want to create a shared variable, just to use an address in ASM. As I know, "COUNTER equ 0x20" doesn't allocate any space, it just replaces the word by a number before compilation. |
|
|
|
谢谢。我想知道这两种方法是否正确:1)在C:无符号字符计数器;在ASM:Global O-RAD2中:无符号char A(32)@ 0x20;在AS:StasyOfFixSoC 0x20(有时我只使用一个字节,我不需要知道地址),但有时我需要一个数组,我和BETW共享这个地址。EN C和ASM)
以上来自于百度翻译 以下为原文 Thanks. I would like to know if both ways are correct: 1) In C: unsigned char counter; In ASM: global _counter 2) In C: unsigned char a[32] @ 0x20; In ASM: start_of_array equ 0x20 (Sometimes I use just one byte for which I don't need to know the address, but sometimes I need the address for an array that I share between C and ASM.) |
|
|
|
是的,这就是绝对代码的问题;-你真的应该得到可重新定位的汇编代码的想法。链接器将负责您的变量。变量必须在其中一个模块中定义。在其他方面,它们被声明为Extn。也许第5.123章XC8用户指南中的汇编和C代码之间的交互帮助
以上来自于百度翻译 以下为原文 Yes, that's the problem with that absolute code ;-) You really should get the idea of relocatable assembly code. The linker will take care of your variables then. The variables have to be defined in one of the modules only. In the others they are declared as extern. Maybe chapter 5.12.3 Interaction between Assembly and C Code in the XC8 user guide helps |
|
|
|
HI,虽然可以在汇编中定义变量并使它们在汇编和C中都使用,但建议在C代码中定义它们。一旦定义了全局可访问变量,就可以在汇编代码中使用全局指令来链接到它的符号。这个符号将是一个带有下划线的C名字。在第二个示例中,可以使用符号γA(加上偏移量以获得每个元素)。如果你设置相等,就像在那个例子中,你将负责维护它们。但一如既往,尽量做到尽可能多的C。你在装配中的越多,你所需要的工作和心痛就越多。杰夫。
以上来自于百度翻译 以下为原文 Hi, Although it is possible to define variables in assembly and have them used in both assembly and C, it is thoroughly recommended that you define them in C code. Once a globally-accessible variable is defined, you can then use the GLOBAL directive in assembly code to link into its symbol. This symbol will be the C name with a leading underscore. In your second example, you can use the symbol _a (plus an offset to get to each element). If you set up equates, as in that example, you will be responsible for maintaining them. But as always, try to do as much as you can in C. The more you have in assembly, the more work and heartache you will need to endure. Jeff. |
|
|
|
如上所述,我建议学习如何告诉XC8你想要变量在哪一个银行,以及如何告诉XC8实际做你所要求的。提示:第168页。5.4.84BAND0、BANG1、BANG2和BANG3型限定符“第103页”。4.815- ADDQUAL:将编译器响应设置为内存限定符
以上来自于百度翻译 以下为原文 As above. I would recommend learning how to tell XC8 which bank you want the variable to be in, and how to tell XC8 to actually do what you asked. ;) Hint: Page 168. "5.4.8.4 BANK0, BANK1, BANK2 AND BANK3 TYPE QUALIFIERS" Page 103. "4.8.15 --ADDRQUAL: Set Compiler Response to Memory Qualifiers" |
|
|
|
只有小组成员才能发言,加入小组>>
5238 浏览 9 评论
2028 浏览 8 评论
1950 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3204 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2253 浏览 5 评论
778浏览 1评论
666浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
595浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
677浏览 0评论
576浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-23 10:47 , Processed in 1.537071 second(s), Total 89, Slave 72 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号