I am calling an assembly function from C. The prototype explicitly declares a xdata pointer parameter, foo(unsigned char xdata *buffer). Likewise the definition explicitly declares xdata pointer parameter. However, when it is compiled, the pointer is passed as a generic pointer. This is a problem because memory-specific pointer is passed in registers R6/R7 while generic is passed in R1/R2/R3.
Has anybody heard of this happening before.
My C Compiler is C51.exe V8.12
The Cx51 Compiler passes up to three function arguments in MCU registers. This mechanism significantly improves system performance as arguments are not written to and read from memory. Argument or parameter passing can be controlled by the REGPARMS and NOREGPARMS directives.
So you should check content of R1. If R1==0x01, it means access xdata; If R1==0xFE, it means access pdata; If R1==0xFF, it means access code.
For an example,
Address+0 Address+1 Address+2 Content 0x01 0x87 0x65
means a pointer to xdata 0x8765.
Oh, it is really odd. With your declaration it should arrange R6/R7 for memory-specific pointer. Sorry for me recklessness. I've test with a small program and it does occupy R6/R7 for this xdata pointer. In C program (main.c):
... extern void testasm(unsigned char xdata* pEBI); ... testasm((unsigned char xdata*)0x4321); ...
The assembler code (testasm.a51):
?PR?TESTASM?MAIN SEGMENT CODE PUBLIC _testasm RSEG ?PR?TESTASM?MAIN _TESTASM: MOV A, R6 MOV B, R7 MUL AB RET END