[Top][All Lists]

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

Re: [avr-gcc-list] Using IJMP

From: E. Weddington
Subject: Re: [avr-gcc-list] Using IJMP
Date: Wed, 12 Jan 2005 10:19:13 -0700
User-agent: Mozilla Thunderbird 0.7.3 (Windows/20040803)

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;
case B:
case N:


//A macro with some asm to //load Z with state_label_address //and call IJMP IndirectJump( state_label_address );
state_label_address = label_address_C;

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.


Take a step back for a moment.

It's generally not a good idea to mix C and inline assembly in the way that you describe; forcing the compiler to use particular assembly instructions just for optimization purposes really makes it difficult on the compiler's optimizer.

You would be better off taking either a design approach or an algorithmic approach. Since you said that your application is time-sensitive, you could do:

1. Code the parts of your application that are time-sensitive in assembly modules (*not* inline assembly) and link those in your final application.

2. Change the switch statement above. It's known that tables are the fastest form of switching on a value, with the tradeoff being it can possibly take more space (depending on size of table). It looks like that you are creating a state machine perhaps? A state machine is best implemented in a table format. For example:

newstate = table[oldstate];

If you need to do more than a simple assignment, you can even create a table of functions that get called indirectly

newstate = (*table[oldstate])();

This will get you the fastest possible execution, and has the advantages that you're still programming in C. Still to go the completely fastest route means hand-coding in assembly. Everything depends upon your application's requirements.


reply via email to

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