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

function parameter error

1.I have defined a function as follow:
char str_cmp(const char*str1,const char*str2);
but the two parameter str1 and str2 have the same value(0x1206) after enter this function although they are different(0x0100,0x1206) in the caller.

2.another problem is the compiler locate the
explicit xdata parameter in data memory,as follow:
int xdata i;
i is located in 0x06 and I can't change the value of i with the following statment,i=10;
but if I define i as long,it is located in xdata.

Parents
  • Please use the < pre > and < /pre > HTML tags when posting souce code.

    Regarding your first question. Have you taken into account the fact that these are generic pointers? Just a thought. How are you getting at the value of the variables, the C51 optimisations can leave the debugger confused. To be sure of what is going on, you may need to step through each disasembly instruction.

    Your question says:
    2.another problem is the compiler locate the
    explicit xdata parameter in data memory,as follow:
    int xdata i;
    i is located in 0x06 and I can't change the value of i with the following statment,i=10;
    but if I define i as long,it is located in xdata.


    However, in your source code you have:

    char str_cmp(const char* str1,const char* str2)
    {
        int i=0;
        ....
    }
    
    When compiling with the large memory model, C51 will put automatic variables into registers if it can and will otherwise place them in the memory specified by the memory model. This is what has happened in this case: address 0x06 is the address of register R6 in bank 0. There are enough free registers for an int, but too few for a long. If you explicitly place the variable (using the syntax indicated in your question) you should find that the variable turns up in xdata.

Reply
  • Please use the < pre > and < /pre > HTML tags when posting souce code.

    Regarding your first question. Have you taken into account the fact that these are generic pointers? Just a thought. How are you getting at the value of the variables, the C51 optimisations can leave the debugger confused. To be sure of what is going on, you may need to step through each disasembly instruction.

    Your question says:
    2.another problem is the compiler locate the
    explicit xdata parameter in data memory,as follow:
    int xdata i;
    i is located in 0x06 and I can't change the value of i with the following statment,i=10;
    but if I define i as long,it is located in xdata.


    However, in your source code you have:

    char str_cmp(const char* str1,const char* str2)
    {
        int i=0;
        ....
    }
    
    When compiling with the large memory model, C51 will put automatic variables into registers if it can and will otherwise place them in the memory specified by the memory model. This is what has happened in this case: address 0x06 is the address of register R6 in bank 0. There are enough free registers for an int, but too few for a long. If you explicitly place the variable (using the syntax indicated in your question) you should find that the variable turns up in xdata.

Children
No data