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

compilation option

Hello all,
I have one project in microvision keil2.
It is of 89v51rd2 and sst89e516rd2 controller.
I am compiling code in keil2, somehow I am finding short of memory while compiling the code as my variable usage exceeds the capacity.
So I declared memory model of large i.e variable in XDATA under target option.

I am able to compile the code successfully, but some of my data are code, idata.
so I have query whether my variables assigned as code, idata will perform properly even if memory model is XDATA.

Thanks and regards

  • Note that the memory model controls default storage.

    It's normally better to manually specify that a few large variables should be stored in XDATA than to jump all the way and request that the default is to use XDATA.

    If you add an attribute to store a variable in a different memory region, then the code will be fine with that. If the tools themselves decides a specific memory region, then the tools will produce code adapted to that.

  • It's normally better to use the small model and manually specify that a few large variables should be stored in XDATA than to jump all the way and request that the default is to use XDATA.

  • Hello all,
    Thanks for reply.
    but what if memory model is used xdata and function variable i.e local variable is declared as idata and global variable declared as xdata? will they create problem when used?
    regards

  • Each access to a variable happens based on the attribute that is "glued" to the variable.

    In some situations, you will explicitly associate a storage attribute to the variable. In some situations, the compiler will associate the storage attribute - based on where you declared the variable or memory model or if there are specific type information. So for example if the data is "const", the compiler can decide to associate a storage attribute to place the variable in the code space.

    All code generation will take into account this attribute when deciding what instructions to use when accessing the variable.

    So it's only when you do own creative designs that you may get into troubles. The compiler itself will not associate any storage attributes that it can't generate correct code for. And it will complain about incompatible attributes resulting in impossible combinations.

  • So for example if the data is "const", the compiler can decide to associate a storage attribute to place the variable in the code space.
    not using Keil right now (doing Renesas with IAR) I can't check, but I recall that Keil does not (always?) put 'const' in the code memory. use the 'code' keyword to guarantee that such 'variables' (variables that can't vary eh?) goes in code memory

  • The important thing here is "can decide to".

    "code" will force data into that specific memory space, while "const" or "static const" can be used as a hint to the compiler that since the data may not be modified it has the option to consider not copying the data into RAM.

  • the option to consider not copying the data into RAM
    but when you are short of memory you want to force that decision and thus use 'code'