This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to access global variables of C into Assembly

Hi Forum Members,
I am using Keil uVision2 for P89C51RD2HBP.
I want to access the "global variables defined in C" in assembly routine. The format of my program is as below:

#include <stdio.h>

unsigned char Var1;

void Func1 (void)
{
...
...
#pragma asm
  mov  a,Var1
#pragma endasm
...
...
}
When I compile this program it says
"error A45: UNDEFINED SYMBOL (PASS-2)"

How do I solve this problem ?

Thanking you in advance,
Mr. Kiran V. Sutar

  • Hi Forum Members,
    I also would like to know how to deal with a similar problem in the following code :


    /* The Model used is Large */
    #include <stdio.h>
    
    unsigned char Var1;
    
    void Func1 (void) interrupt 1 using 2
    {
    ...
    ...
    #pragma asm
      mov  a,Var1
    #pragma endasm
    ...
    ...
    }
    
    
    Thanks again.

    Kiran V. Sutar

  • For interfacing C51 to Assembler, Please read the manual: http://www.keil.com/support/man/docs/c51/c51_ap_ctoasm.htm

    "When I compile this program it says
    'error A45: UNDEFINED SYMBOL (PASS-2)'"


    It also tells you which symbol is undefined.

    "How do I solve this problem ?"

    Provided a definition for the symbol!

    We can't help you further without that vital piece of information!

  • "a similar problem"

    Simlar?
    It looks exactly the same to me!

    Are you two guys in the same class?!

  • It looks exactly the same to me!

    It's different in the interrupt and using options chosen --- but those are quite irrelevant for the problem at hand, which of course is that the OP didn't bother to read the docs.

    Are you two guys in the same class?!

    Worse --- they're the same guy, actually ;-)

  • To Forum Members,
    Thanks for your replies.
    After Long hours of reading the manuals and references applications, I got the solution to my problems.

    To Mr. Andy Neil,
    I am the same guy, who wrote the two queries. Because, After sending the first query, I realized, this problem will rise again later, when I write the interrupt routine, hence I posted 2 different messages. If that has caused some problem with the forum members, then I am sorry for the trouble.

    As for the solution to the following problem:

    "When I compile this program it says
    'error A45: UNDEFINED SYMBOL (PASS-2)'"

    It also tells you which symbol is undefined.


    The solution is to name the symbol with proper format as ?DT?SymbolName?Module.

    I had sent this query on this forum, so that I can get a quick solution; rather than going through tons of documentation and app.notes. And I (and almost everybody) am always working against time.

    I am using Avocet C-Compiler for the last 10 years, and am very much used to it. Only thing is I did not know the method for mixed coding in Keil.
    Well Reading the manuals has solved my problems. There are still some more problems but I think, I would rather read the manuals and get them to work, rather than wasting the valuable time of the forum members (and mine) in solving my queries on the forum.

    Well Thanks again to all of you.

    From Kiran V. Sutar.