|
|||||||||||
|
Technical Support Support Resources
Product Information |
C51: Adding C Functions to Existing Assembler CodeInformation in this article applies to:
QUESTIONI'm using the Keil C51 Tools and have successfully written 8051 programs only in assembly language. Now I need add C code to my assembly program. I want to keep as much as possible of my existing assembly code. Are there some guidelines on how to mix assembly and C code using the Keil C51 compiler? How can I access memory locations from my C programs that I have reserved in assembly code? ANSWERThe Keil C51 Compiler generates relocatable object files that can interface easily to relocatable assembler programs. The file Keil_v5\C51\ASM\TEMPLATE.A51 shows you how to structure relocatable assembly modules. This file defines several variables, for example:
You access these variables in your C code with:
To reduce data RAM requirements of your application, the BL51/Lx51 Linker/Locater performs call tree analysis of the complete application program. Therefore, the linker needs to be able to distinguish between constants and program code and it must also be able to determine the local data segments for your program code. For this reason you should change the segment naming conventions of your assembler program to the segment names used by the C51 Compiler. Detailed information can be found in Application Note 149: Data Overlaying and Code Banking with A51 Assembler Modules. For each interrupt function written in assembly, you must create a separate segment for the interrupt vector using CSEG AT.
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.