??? 08/16/06 23:30 Read: times |
#122393 - AsmCallC Responding to: ???'s previous message |
Hi Kuldeep,
KEIL uses R7,R6,R5... to pass data between C functions, v_a?040: DS 2 v_b?041: DS 1 v_d?043: DS 4 is memory locations were C store variables (for underscore question marks and other simbols and passing data by using R7,R6,R5...consult KEIL documentation ASM -> C it is the same)....You have to learn tool to be able to use it so the good start is to read KEIL book C51 Compiler Optimizing 8051 C Compiler and Library Reference... Calling assembler is well documented (in KEIL documentation) but the opposite way not. The opposite way uses same rules. It is more difficult but possible to do the opposite. 1st you don't need to translate your C in SRC. Put your C files at the end of project. 2nd You have to put your assembler on the absolute locations by using directives for example NAME ASSEMBLERSTART ; linker directives CSEG AT 100H after that you need to specify C-functions as EXTRN CODE(CSAMPLE1), if your C functions passes variables in registers R7, R6, R5, R4 the name of function has underscore _CSAMPLE1 otherwise CSAMPLE1 if it is void. any variable what you want to pass from C into ASM you need to use EXTRN DATA, EXTRN PDATA, EXTRN IDATA, EXTRN BIT, startup.a51 file needs to be modified so code will jump on your assembler and not looking for main(), for example: ?C_C51STARTUP SEGMENT CODE ?STACK SEGMENT IDATA EXTRN CODE (ASSEMBLERSTART) RSEG ?STACK DS 1 CSEG AT 0 LJMP STARTUP1 ---------------------------- RSEG ?C_C51STARTUP STARTUP1: MOV SP,#79H LJMP ASSEMBLERSTART END be careful how to handle stack, use DATA for ASM and IDATA for C, check map file to verify memory usage, and it will work, Why you don't let C call ASM and manage code flow? |
Topic | Author | Date |
calling c function from assembly | 01/01/70 00:00 | |
More reading required | 01/01/70 00:00 | |
AsmCallC | 01/01/70 00:00 | |
Absolute addresses?? | 01/01/70 00:00 | |
legacy | 01/01/70 00:00 | |
not really | 01/01/70 00:00 | |
NOREGPARAMS | 01/01/70 00:00 | |
Keil example | 01/01/70 00:00 | |
undefined varibales | 01/01/70 00:00 | |
Wouldnt it be easier... | 01/01/70 00:00 | |
Eh??? | 01/01/70 00:00 | |
inline | 01/01/70 00:00 | |
what I do and recommend![]() | 01/01/70 00:00 |