[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [avr-gcc-list] Using IJMP
From: |
Ben Mann |
Subject: |
RE: [avr-gcc-list] Using IJMP |
Date: |
Thu, 13 Jan 2005 11:53:49 +0800 |
Thanks guys,
Your info helped. I've never before had a need for an indirect goto, however
my current project seems to be pushing the performance envelope a little
(don't they always?). I like these embedded projects for that reason - it's
a little too easy to get away with sloppy code when writing pedestrian
applications on multi-GHz processors...
Thanks again,
Ben Mann
-----Original Message-----
From: address@hidden [mailto:address@hidden
On Behalf Of Anton Erasmus
Sent: Thursday, 13 January 2005 1:29 AM
To: address@hidden
Subject: Re: [avr-gcc-list] Using IJMP
On 12 Jan 2005 at 17:32, Ben Mann wrote:
> Hi all,
>
> as I understand it, the AVR has a cool IJMP instruction - indirect JMP
> to Z.
>
> I would like to replace some existing code:
>
> //------------
> switch( state ) {
> case A:
> state = C;
> break;
> case B:
> ...
> case N:
> ...
> }
> //------------
>
> with
>
> //------------
> //A macro with some asm to
> //load Z with state_label_address
> //and call IJMP
> IndirectJump( state_label_address );
>
> label_A:
> state_label_address = label_address_C;
> break;
> label_B:
> ...
> label_N:
> ...
> //------------
>
> The increase in speed for more than about 4 or 5 cases would be
> dramatic enough for my time-sensitive application to make it worth it.
>
> However - I don't know how to store the address of a label to my
> label_address variable in GCC. I assume this can be done with some
> inline assembler magic but I cannot seem to figure out the parameters
> to make this work. Any tips would be much appreciated.
>
Why do you want to do it in assembler if you can do it directly with a gcc C
extension ?
int foo(int state)
{
static void *labels[] = {
&&label0,
&&label1,
&&label2,
&&label3,
&&label4,
&&label5,
&&label6,
&&label7};
state&=0x07;
goto *labels[state];
label0:
return(0x0A);
label1:
return(0x0B);
label2:
return(0x0C);
label3:
return(0x0D);
label4:
return(0x0E);
label5:
return(0x0F);
label6:
return(0x10);
label7:
return(0x11);
}
Regards
Anton Erasmus
--
A J Erasmus
_______________________________________________
avr-gcc-list mailing list
address@hidden http://www.avr1.org/mailman/listinfo/avr-gcc-list