| Details | Message |
|---|
Read-Only Author shalini reddy Posted 17-May-2006 08:22 GMT Toolset C51 |  How to use a variable declared using C syntax in Assembly file shalini reddy 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? |
|
Read-Only Author Reinhard Keil Posted 17-May-2006 08:30 GMT Toolset None |  RE: How to use a variable declared using C syntax in Assembly file Reinhard Keil 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 |
|
Read-Only Author shalini reddy Posted 17-May-2006 10:11 GMT Toolset None |  RE: How to use a variable declared using C syntax in Assembly file shalini reddy 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 ? |
|
Read-Only Author A.W. Neil Posted 17-May-2006 12:08 GMT Toolset None |  Not language specific A.W. Neil 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... |
|
Read-Only Author shalini reddy Posted 17-May-2006 13:16 GMT Toolset None |  RE: Not language specific shalini reddy
void fun(void)
{
data byte var1;
if(var1 & 0x80)
{
//some code
}
if( (var1 & 0x04)||(var1 & 0x03) )
{
//some code
}
...
...
}
|
|
Read-Only Author Andy Neil Posted 17-May-2006 13:30 GMT Toolset C51 |  Insert a function call, and pass a parameter Andy Neil "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 |
|
Read-Only Author Reinhard Keil Posted 17-May-2006 14:04 GMT Toolset C51 |  RE: Insert a function call, and pass a parameter Reinhard Keil Did you really read the information in: http://www.keil.com/support/docs/1275.htm? |
|
Read-Only Author shalini reddy Posted 19-May-2006 07:21 GMT Toolset C51 |  RE: Insert a function call, and pass a parameter shalini reddy " 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. |
|
Read-Only Author Andy Neil Posted 19-May-2006 08:41 GMT Toolset C51 |  RE: Insert a function call, and pass a parameter Andy Neil "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! |
|