| |||||
Technical Support Support Resources
Product Information | A51: VARIABLE ACCESS FROM CInformation in this article applies to:
QUESTIONI have a hybrid program that is half in assembly and half in C. All my global variables are declared in assembly. I access these variables from my C program. Everything compiles and links with no errors. However, when I look at the C listing file, the compiler has generated code that accesses my variables as 2-byte objects even though the variables declared in the assembler are only 1 byte long. What causes this to happen and how can I fix it? ANSWERWhen you declare a variable in assembly that you will use in C, you must ensure that the memory area and data type match exactly. If the variable you declare in assembly is in XDATA memory and it is 1 byte long, the corresponding C data type must be declared as one of the following: char xdata var; unsigned char xdata var; The easiest way to verify that your assembly variable declarations are correct is to declare all global variables in C in a single source file and compile that C source file using the SRC directive for the compiler. The resulting .SRC file will contain the assembly code necessary to declare the variables. You may use the .SRC file to declare your C variables in assembly. Last Reviewed: Friday, August 18, 2006 | ||||
| |||||