|
|
View previous topic :: View next topic |
Author |
Message |
nazoa
Joined: 09 Feb 2007 Posts: 56
|
Passing array pointer to function |
Posted: Mon Mar 02, 2015 10:03 am |
|
|
Hello,
I am trying to find a way of passing array pointers to a function.
The following code fails to compile at the "POP R0[0]" line. The compiler (V4.14) complains that the expression does not resolve to a constant.
Any suggestions how to fix the code?
Thanks!
Code: | void Read4ADCs(int16 *R0[], *R1[], *M0[], *M1[])
//** Routine to read 4 x ADCs **
{
#WORD REGE = 0xE44
#WORd REGG = 0xE62
while (input(ADSTATUS)) //Ensure ADC is busy before proceeding
{;}
#asm
CheckG0: BTSS REGG,8 //Check conversion done (g8 is high)
goto CheckG0;
NOP
PUSH 0xE32 //Read REF0 and get ready for REF1
BSET REGE,3 //Set E3 (PLD P1) high
NOP
NOP
POP R0[0] |
|
|
|
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
|
Posted: Mon Mar 02, 2015 10:21 am |
|
|
"V4.14" is not a valid version of CCS C, is this V4.140? Is this even CCS C code?
To pass a pointer, whether to an array or not, the syntax would be
void Read4ADCs(int16 *R0, *R1, *M0, *M1). A pointer is a pointer is a pointer: pointers to array elements are indistinguishable from pointers to anything else. Assembler won't index into the array for you, i.e. R0[0] or M1[3], you have to do the calculations. the compiler is telling you that "R0[0]" isn't a constant, such as the "0xE32" you use for the push. it doesn't know how to get the value from the array - you have to do that.
Is this code that you're trying to adapt to do something different to what it was originally written to do? Do you fully understand how it works? Are you aware that almost certainly there's a simpler way to do it using C, and not assembler? It is rare that assembler is needed in CCS C. |
|
|
nazoa
Joined: 09 Feb 2007 Posts: 56
|
|
Posted: Mon Mar 02, 2015 10:54 am |
|
|
Thanks for taking the time to reply. I think I understand
where the problem is now.
Yes, the code needs to be in assembly for speed. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|