XC8用户指南在第5.8节中描述了一种方法,该方法允许C代码调用汇编函数,通过定义参数块的基地址而不是将其放置在编译堆栈上,因此不需要通过单独设置的全局变量传递值,如写F。在指南中,我不能让它工作,因为链接器总是抱怨符号。“A asMyTest'”被定义不止一次。我用两个文件创建了一个测试项目(独立的18F13K50,所有其他选项),一个包含“Meal'”并调用汇编函数的C程序和一个包含测试函数的程序集:根据我对该部分的理解,编译器应该注意到用于“ASMyTest'函数的参数块的REST已经设置为重叠‘APIIPARAM1’变量,而不是重新定义它。但它没有这样做,所以我只看到三个选项,或者我做错了什么,向导是错误的,或者这只是在PRO模式下工作。有什么想法吗?
以上来自于百度翻译
以下为原文
The XC8 User Guide describes, on sec
tion 5.8.2, a method that should allow C code to call into assembly functions, by defining the base address of the parameter block instead of placing it on the compiled stack, thus not requiring passing values through global variables set separately, as written further on in the Guide.
But I can't get it to work as the linker always complains about the symbol ('?_asm_test') being defined more than once. I created a test project (Standalone, 18F13K50, all other options left alone) with two files, a C one that contains 'main' and calls the assembly function and an assembly one containing the test function:
// C
#include
extern unsigned char asm_test(unsigned char p1, unsigned char p2);
void main(void)
{
#asm
extrn api_param1
global ?_asm_test
?_asm_test equ api_param1
#endasm
asm_test(1,2);
while(1);
}
; ASM
psect vars,class=COMRAM,abs,ovrld
org 0x0000
global api_param1
api_param1: ds 1
psect asm,class=CODE,reloc=2
signat _asm_test, 8313
global _asm_test
_asm_test: ADDWF api_param1, W, C
RETURN
According to my understanding of that section this should make the compiler notice that the address for the parameter block for the 'asm_test' function was already set to overlap the 'api_param1' variable and not redefine it. But it is not doing it.
So I see only three options; either I've done something wrong, the Guide is wrong or this only works on PRO mode. Any thoughts on which is it?