ARM Technical Support Knowledge Articles

EXTERN VARS AND INLINE ASSEMBLY

Applies to: C51 C Compiler

Answer


Information in this article applies to:


QUESTION

I am using inline assembly. Included in the C file in which the inline assembly resides is a header file (.H) that contains EXTERN declarations for variables declared in other modules. When I try to build the project, I receive either UNDEFINED SYMBOL or REDEFINED SYMBOL errors pointing to the EXTERNS. Is there an example of the correct way to accomplish this?

ANSWER

Yes.

  1. Create a project with the following files:


    MAIN.CM

      #pragma SRC(MAIN.A51)
      #include "xdatinc.h"
    
      void main(void) {
         ioport=0x55;
    
         while(1) {
           ioport+=2;
           #pragma asm
             inc r0  // this is just here to add inline asm to the mix..
           #pragma endasm
         }
      }
    


    INCFILE.H

      extern xdata unsigned char ioport;
    


    INCFILE.C

      xdata unsigned char ioport _at_ 0x8000
    
  2. Create a project file and add the following files in the following order.
    • MAIN.C
    • MAIN.A51 (create when MAIN.C is compiled)
    • INCFILE.C
  3. Turn off the "Include in Link/LIB" checkbox for MAIN.C. Turn ON the "Always Build" checkbox for both MAIN.C AND MAIN.A51
  4. Build the project. There should be no errors.

Article last edited on: 2005-07-09 12:37:08

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential