//main C code---------------------- extern void a(dptr); main() { a(dptr); } //assemble code-------------------- public a a: mov a,#dptr ............ I want to take dptr in a(dptr); My question is how a(dptr); in C code can work fine. Thanks
Unfortunately your answer is incomprehensible. Can you try and explain more clearly? Stefan
It seems we all do not understand each other due use two languages ((=
The C51 Users' Guide has a section entitled "Interfacing C Programs to Assembler" that, among other things, describes the calling conventions for C functions. Everything you need is there. A function that takes a single 16-bit argument will have that argument passed in R6/R7. Most likely, a value that you want to wind up in the DPTR would be a pointer in C. If the memory type is explicitly declared, it would be a 16-bit pointer.
extern void a(XdataObject xdata* obj); a(&myXdataObject);
extern void a(U8* obj); // no memory type specified a(&someVarSomewhere);
I has little sense about the solution. Because my code is calling a assemble function from C,using "public" in assemble code but how to program assemble code let C can call it with argument(R6 and R7) //assemble code-------------------- public a a: mov a,#dptr ........... //---------------------------------- func1 (int a) The first and only argument, a, is passed in registers R6 and R7.
In your C code, you will want a prototype for the function. extern func1 (int a); This tells the compiler about the name of the function, and its parameters. In your assembler code, you will have a "public" declaration. Note that the actual names of C functions as seen by the linker traditionally have a leading underscore. Your assembler function will have to be named to match. PUBLIC _func1 _func1: The C compiler will place its parameters as described in the calling conventions in the C manual. For a single 16-bit argument, that does indeed happen to be R6/R7. The assember code must be written with knowledge of where the C compiler is going to put the arguments. The assembler does not tell the compiler where the arguments go; rather, the programmer writing the assembler code knows what the C compiler conventions are, and writes the assembler code accordingly. Knowing that the parameter will be passed in R6/R7, you can then do with the parameters as you wish. To put it into the DPTR, you'd do something like: func1: mov DPH, R6 mov DPL, R7 If you want to pass parameters as global variables, then your assembler code should have PUBLIC symbols for appropriately sized areas of storage, and your C code would then have extern references to variables. The function would have no formal parameters at all. extern int a; // global needed by assembly a = 100; func1();
Thanks for your detail description. deeply appreciated.