avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Using IJMP


From: Anton Erasmus
Subject: Re: [avr-gcc-list] Using IJMP
Date: Wed, 12 Jan 2005 19:29:26 +0200

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]