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?
http://www.keil.com/support/man/docs/c51/c51_ap_globalvars.htm You may also write a code fragment first in C and then use the SRC directive to generate an assembler template. http://www.keil.com/support/docs/1275.htm
My 'C' function will be some what like void fun(void) { data byte var1; if(var1 & 0x80) { //some code } if( (var1 & 0x04)||(var1 & 0x03) ) { //some code } ... ... } So I want to convert second if condition into assembly (for that I have created separate asm file , I am not using inline assembly concept)for that var1 is required how can I use? http://www.keil.com/support/man/docs/c51/c51_ap_globalvars.htm In the above link they have given the syntax for inline assembly concept.So here I have created a new asm file so in that how can I use var1 ?
When you made your post, there were 3 bullet points above the 'Message' window - the third of those told you what to do when posting source code. See also: http://www.keil.com/forum/tips.asp Please re-post your code, following the instructions, so that its formatting is retained. To access any symbols between multiple files in any language, the basic principles are always the same: 1. The Defining module must make the symbol "Public"; 2. The Referencing module must have a suitable "External" declaration. You should be able to take it from there...
void fun(void) { data byte var1; if(var1 & 0x80) { //some code } if( (var1 & 0x04)||(var1 & 0x03) ) { //some code } ... ... }
"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 // } // ... ... }
Did you really read the information in: http://www.keil.com/support/docs/1275.htm?
" 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!