|
|||||||||||
Technical Support Support Resources
Product Information |
C51: Locating Function Tables in Code MemoryInformation in this article applies to:
QUESTIONI have defined a structure that contains an array of function pointers. I then use this to declare a variable. I'm trying to locate the function pointers in code memory, however, I get syntax errors. What am I doing wrong?
ANSWER
Individual struct members can't be assigned to different memories.
This only works for complete objects/variables. The variable functable is then defined using the typedef. This is a variable declaration, so we specify that it is 'const code'. This ensures that the function pointers are located in code memory. We also have to initialize the table right away because it cannot be initialized later. The rest of the code simply calls two functions indirectly to prove all the code is correct and functional.
If you now look at the Symbol Table of Module in the generated .m51 map file, you see that the functions foo and bar are located at, for example, the following locations: foo: 50H bar: 70H You also see that functable is located, in this case, at 9CH in code memory. If you now debug the program in µVision (can be the Simulator) you can double-check that the function pointers really are stored in code memory. Type
into the Command Windows command line to display code memory from location 9CH onwards. You will see the following data:
These are the function pointers. The first byte of each pointer is FFH, which means that the pointer points to code memory. The remaining two bytes are the location of the function. You can see that 0050H and 0070H are the locations of the functions foo() and bar(). Now that you can see that the structure is located in code memory, the function pointers are also located in code memory. If you look through the .m51 file, you may not be able to find the structure name. That is because it was never located in memory. It was simply used as a 'template' for the functable variable. Using these methods, it is easy to double-check where your function pointers are being located, whether they are declared on their own or as part of a structure. MORE INFORMATION
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.