|
|||||||||||
Technical Support Support Resources
Product Information |
A51: Calling C Functions From AssemblyInformation in this article applies to:
QUESTIONI wish to call a function written in C from my assembly code. How do I do it? ANSWERThe easiest way to achieve this is to let the C compiler generate the correct assembly code for you. Suppose you have a C function called 'foo' which takes a single unsigned char argument and returns an unsigned char value. In a new C file write a dummy function that calls 'foo'. For example:
#pragma SRC directs the C compiler to generate assembly code when the file is compiled. The extension of the assembly file will be 'src'. If you view the src file you will see how to call the function 'foo' from assembly. It shows the registers or memory locations used to pass the function arguments and which registers or memory locations are used to return a value. In addition it also gives you the correct function naming convention to use, which is essential for interfacing assembly to C. You can then use the src file as a template to write the function call in your own assembly code. Note that you must also include the EXTRN directive for the function, eg:
MORE INFORMATION
SEE ALSOATTACHED FILESRequest the files attached to this knowledgebase article. 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.