Other HI-TECH Compilers & Products >> Other HI-TECH Compilers & Products

Pages: 1
Luben Hristov

*****

Reged: Oct 26 2003
Posts: 24
Loc: UK
Accessing auto variables from ASM
      #17151 - Thu May 12 2005 06:37 AM

Hello,

How I can acceess the auto variable from asm

unsigned char my_function(unsigned char data)
{
unsigned char temp; // auto variable

#asm

clr [_temp] ; // not working!!!
clr [??_my_function+1]; ; // works, but it's confusing which variable is ??_my_function+1

#endasm


return 1;

}

Well, if temp is global, then there is no problems, what about if temp is local auto variable.... Some example?

I'm concerned if I put in my code such meaningless variable names like F26, F17_main and then I change something in the code (for example add additional variable in the list, change the order of variables) , could I expect that the name is also changed?

Shell I check before every compilation do they stay on the right places (if for example F16 still pointing to my variable or it's shifted).

What is the algorythm that forms the names (F12, ??_check+3) - the sequential order, alphabetical order, calculations dependent.

What I saw is that these names do not change with changing the name of the variable, the order of the variable, calculations.... but is it true?

Is there some way to get the name of the variable (F16, ??_check+3) without opening the list file?

And I know that all this is made intentionally to protect the user from picking wrong objects in the assembler.

Thank you

Best regards
Luben

Edited by Luben Hristov (Thu May 12 2005 09:08 AM)


Post Extras: Print Post   Remind Me!   Notify Moderator  
luckyAdministrator
HI-TECH team member
*****

Reged: Oct 06 2003
Posts: 1054
Loc: Brisbane, Australia
Re: Accessing auto variables from ASM [Re: Luben Hristov]
      #17165 - Thu May 12 2005 08:20 PM

Quote:

How I can acceess the auto variable from asm




An example C program:
Code:

//file.c
unsigned char func(void)
{
    unsigned char temp;

    temp = 5;    //some C code that uses the variable
    ++temp;
    return temp;
}



//compile to assembly
htkc --chip=ht47c20-1 --opt=none -s file.c

If you look in the generated assembler file, you'll see that the compiler will refer to the local variable "temp" as something like ??_func+0, however, it also creates an equate with the more meaningful name _func_temp which you can use. It'll look something like this:

_func_temp equ ??_func+0

So you can just use this symbol. Here's an example:
Code:

unsigned char func(void)
{
    unsigned char temp;

#asm
    mov a, 5
    mov [_func_temp],a
#endasm
    ++temp;
    return temp;
}



Although, I'd recommend converting your asm code to C

--------------------
Matt Luckman
HI-TECH Software


Post Extras: Print Post   Remind Me!   Notify Moderator  
Luben Hristov

*****

Reged: Oct 26 2003
Posts: 24
Loc: UK
Re: Accessing auto variables from ASM [Re: Luben Hristov]
      #17169 - Fri May 13 2005 04:11 AM

Hello,

I think that this will work. These variables names are now meaningful.

About the assembler - I agree that is better not to use it, but unfortunately I have to do some code with fixed timing, exactly like I want. The problem is that I can't control what makes the compiler and every time I compile the project I have to go and revise the output.

The rule is - if you can avoid the assembler - avoid it.

Best regards
Luben

Edited by Luben Hristov (Fri May 13 2005 04:13 AM)


Post Extras: Print Post   Remind Me!   Notify Moderator  
Pages: 1



Extra information
0 registered and 3 anonymous users are browsing this forum.

Moderator:  ndouglas, jtemples, Dan Henry, Andrew L, mikerj, dave g, meisty, josh stevo 

Print Topic

Forum Permissions
      You cannot start new topics
      You cannot reply to topics
      HTML is enabled
      UBBCode is enabled

Rating:
Topic views: 3394

Rate this topic

Jump to

Contact Us | Privacy statement HI-TECH Software

Powered by UBB.threads™ 6.5.5