This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Passing > 4 Parameters to Function

Greetings:

Here is an odd one that I hope someone can point out the obvious thing I am doing wrong. In the accompanying extremely simplified source code, compiled with uVision3 V3.12a, I am just calling a function with six parameters. Nothing earth shattering about that, and running this code under the simulator it works fine. Prior to the function call the first four parameters are loaded into registers and the fifth and sixth are pushed on the sack, as other forum discussions state that it should. The function returns the sum of the parameters, as expected. When I run this on the target environment, however, the processor pushes zeros onto the stack instead of the fifth and sixth parameter and, of course, the return value is wrong.

//* Main.c **********************************

#include <LPC22XX.H>
unsigned char Param6Test ( char, char, char, char, char, char );

//*******************************************
void main ( void )
{
    char Param1;
    char Param2;
    char Param3;
    char Param4;
    char Param5;
    char Param6;
    char RetVal;

    Param1 = 1;
    Param2 = 2;
    Param3 = 3;
    Param4 = 4;
    Param5 = 5;
    Param6 = 6;

    while ( 1 )
    {
        RetVal = Param6Test ( Param1,  Param2, Param3, Param4, Param5, Param6 );
        if ( RetVal == 1 )
            Param1++;
    }
}

//*******************************************

char Param6Test ( char x1, char x2, char x3, char x4, char x5, char x6 )
{
    char    charRetval;

    charRetval = x1;
    charRetval = charRetval + x2;
    charRetval = charRetval + x3;
    charRetval = charRetval + x4;
    charRetval = charRetval + x5;
    charRetval = charRetval + x6;

    return ( charRetval );
}

//*******************************************

Obviously, this is a "do nothing" simplification of my original problem, and I have observed the compiler does try very hard to optimize things (which makes debugging a bit more challenging), yet I have been unable to pass more than four parameters via a function call while running on hardware. There must be something fundamental I have overlooked. Any ideas?

Thanks,
Doug

0