|
|||||||||||
Technical Support Support Resources
Product Information |
C51: Accessing a Pointer in AssemblerInformation in this article applies to:
QUESTIONI have a pointer declared in C that I wish to manipulate in assembler. How do I do it? ANSWERThe best way is to write what you want to do in C then and then use the compiler SRC directive to generate the equivalent assembler. For example, ptr is declared in C as:
The following C code (using an idata pointer):
generates the following assembler:
The address is located in memory where the pointer lives and the value 41H is stored indirectly using that address. The following C code (using an xdata pointer):
generates the following assembler:
For generic pointer things get a little more complex. In order to use a generic pointer calls to library routines have to be made to load and store the pointer. The following C code:
generates the following assembler:
As you can see, the three bytes of the pointer (two for the address and one for the memory space) are placed in R1 to R3. These are then stored in memory where the pointer is located. The value 41H is placed in the Accumulator and the library routine ?C?CSTPTR is called to store the value. Refer to C51: ?C? Load and Store Library Routines for more information on the library routines that are available. From this information you can manipulate pointers in assembler, however the best way to do this is to use the compiler SRC directive to write the assembler for you. MORE INFORMATION
SEE ALSOLast 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.