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 use a variable declared using C syntax in Assembly file

I am using keil and 8051 microcontroller.
I want to convert a part of my code written in C into assembly.
So for that I wanted to use a variable declared in C file in assembly file.How can I use?
I have checked in keil manual also ,there they have given one example code ,in that they have used the variable declared in asm file but not in C.
So now how can I do that?

Parents Reply Children
  • "I want to convert second if condition into assembly"

    Do you mean:

    void fun(void)
    {
      data byte var1;
    
       if(var1 & 0x80)
       {
         //some code
       }
    
       if( (var1 & 0x04)||(var1 & 0x03) ) // Convert this bit?
       {                                  //
          //some code                     //
       }                                  //
    ...
    ...
    }
    If so, the only way you can do that is by making an assembler function that you call at that point.
    In that case, you will have to pass the variable as a Parameter.

    C51's parameter passing is described in the Manual

  • " If so, the only way you can do that is by making an assembler function that you call at that point.
    In that case, you will have to pass the variable as a Parameter. "

    I did the same thing what u explained above.
    But have not got any idea on how to pass a variable as a parameter?

    I have gone through the C51's parameter passing topic but I didnt get any idea.
    Since time is very less for me to complete my task ,can u please tell me the syntax for declaring that variable as extern in assembly file.

  • "But have not got any idea on how to pass a variable as a parameter?

    I have gone through the C51's parameter passing topic but I didnt get any idea."


    In that case, do as Reinhard suggested:
    Create an outline in 'C', and use the SRC directive to convert this to assembler.
    Then you can write your own assembler "body" to the function.
    You have already been given the link (twice) to the knowledgebase article that describes this.

    "can u please tell me the syntax for declaring that variable as extern in assembly file."

    You could find this for yourself in a moment in the assembler Manual but, as already explained, this will not work here!