Keil Logo

C166: Using the MVAR Macro for Fixed Variable Location


Information in this article applies to:

  • C166 All Versions

QUESTION

I have a question about locating variables at absolute memory addresses using the C166 compiler. With the C51 compiler, it was no problem to define a variable at an absolute memory address (int x _at_ 0x1234).

I need to make sure that all my variables are at absolute memory addresses, because after a reset or even a program update, I need to access all values as they were when the machine was turned off. The C166 manual says either to use the linker controls to locate variables or to use the MVAR macro to access the memory.

It seems that the MVAR macro would make it very "painful" to write a program (if you must use MVAR whenever you access a variable). Using the linker sounds better, but for a couple of hundred variables this may be too long for a link command. Any help will be appreciated.

ANSWER

There is an easy way to use the MVAR macro for your application. In the following code, you can define variables using #define...

#include

#define x MVAR (unsigned char, 0x100000)
#define y MVAR (unsigned int, 0x100010)
#define z MVAR (long, 0x100020)

void main (void)
{
x = 1;
y = 1000;
z = 1000000;
}

Then, when you use the defined variable name (x, y, or z in this case) the MVAR macro accesses the correct memory location. This should help and it only requires that you write "special" code for the variable "declaration" or definition as it is in this case.

MORE INFORMATION

  • Refer to HVAR in the C166 User's Guide.

Last Reviewed: Thursday, February 25, 2021


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.