This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hello,
I am working on a project which includes C as well as Assembly code.
I have a function declarations as follows
#define USE_FUNCTION 1 int function1(void); int function2(void); #if USE_FUNCTION #define _FUNCTION function1 #else #define _FUNCTION function2 #endif
I have to call these function from assembly routines as per the definition of FUNCTION the code snippet as follows,
LCR #_FUNCTION
if I call it the following way "assembler/compiler" throws error :
The following symbols are undefined: FUNCTION
(I have included the header file of function definition in .asm code.)
So, questions :
1. I have to use FUNCTION in C as well as Assembly, How can I successfully call FUNCTION from the assembly.
Rahul Birari91 said:(I have included the header file of function definition in .asm code.)
How do you do that? Do you use the .cdecls directive and include the same header file as the C code? If you do anything else, that is likely the problem. If you do use .cdecls, then I need a test case that allows me to reproduce the same behavior.
Thanks and regards,
-George
Hi George, Yes I have used cdelcs directive to include the same header file where prototypes for function1 and function2 compile time switch is defined as in my first post.
Also, Initially I was just using function1 from assembly and it was building successfully.
.cdecls C,LIST ,"header.h"
Hello David, I have tried that as well, in that case I had to change definitions of function1 and function2 and the instances of FUNCTIONS as well. For some reason it didn't work.
Also, I noticed in assembly file when I defined
.define _function1, _FUNCTION
It works, I am not sure how to include compile time conditional switches though, Any help will be appreciated.
Thanks
Rahul
I am unable to work with small pieces of code. I need a test case which allows me to reproduce the same behavior. Then I can probably explain what is wrong and how to fix it.
Thanks and regards,
-George
Rahul, George,
I think the 'problem' is that #define (and the assembly equivalent .define) only match whole symbols, not partial symbols. Suppose you did the following:
#define abc 123;
int x;
x = abc;
The above works. But if you tried to do this:
#define abc 123;
int x;
x = abc4;
you get a symbol 'abc4' undefined error. The leading underscore that Rahul uses in his assembly code is just another character, and the parser is looking to replace _FUNCTION, not FUNCTION.
------------------------------------
The solution here for Rahul is to incorporate the underscore into the #define macro:
The above works. I tested.
Regards,
David
Thanks a lot David,
I noticed it cant be used in both assembly and C. I had to define different #defines for C and assembly.
#define USE_FUNCTION 1 int function1(void); int function2(void); #if USE_FUNCTION #define FUNCTION_C function1 #else #define FUNCTION_C function2 #endif #if USE_FUNCTION #define FUNCTION_ASM _function1 #else #define FUNCTION_ASM _function2 #endif
Thanks,
Rahul
Rahul,
One more thing. I notice that your
#if USE_FUNCTION
is not complete. It needs to be:
#if USE_FUNCTION == 1
If you don't use the ==, you always get function1.
Regards,
David