|
|||||||||||
Technical Support Support Resources
Product Information |
C51: Correctly Declaring Variables with Memory SpacesInformation in this article applies to:
QUESTIONWhen I declare a variable with a memory space, what format should I use?
or
ANSWEREither way is acceptable (see below for more information). For example:
both declare an integer in the data memory space. The place to be careful is in complex declarations involving pointers where multiple memory spaces may be required. For example:
is a generic pointer to an integer. The integer may be in any memory space, but the pointer is stored in the data memory space.
is a memory-specific pointer to an integer in the data memory space. The pointer is stored in the default memory space.
is a pointer (stored in xdata) that points to an integer (stored in data). Note that the older method of declaring variables:
may not be supported in future versions of the compiler. For this reason,
is the preferred method of declaring variables and
is the preferred method of declaring pointers. For example:
is a pointer (stored in xdata) that points to an integer (stored in data) using the new format. The following example code:
when compiled, yields the following:
As you can see, the compiler loads the address of p (the pointer) into the DPTR register and uses the MOVX instruction to access p. SEE ALSO
Last Reviewed: Thursday, February 25, 2021 | ||||||||||
|
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.