Microchip
直播中

张喆

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

* .asm中的地址未在* .c中使用

我有一个初学者的问题,我找不到手册或论坛。我使用汇编程序在一个单独的*.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)

张蕾

2019-4-22 11:20:18
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
 
举报

李维兴

2019-4-22 11:30:22
在您的程序集文件中,这样做:注意领先的下划线。

以上来自于百度翻译


      以下为原文

   
In your assembly file, do this:
global _counter
; ...
banksel _counter
movwf _counter

Notice the leading underscore.
 
举报

张建军

2019-4-22 11:42:04
“您必须在其中一个模块中定义它们,并将它们声明为其他模块上的外部”——我可以仅在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.
 
举报

张建军

2019-4-22 11:47:05
谢谢。我想知道这两种方法是否正确: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.)
 
举报

更多回帖

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