create a function with assembly

Im having some difficulty with timing on an interrupt function on a teensy2 board I have. I have int1 configured to interrupt on falling edge and the function toggles a digital output and is done. Im seeing a 7 microsecond delay (with oscilloscope) due to overhead in the c function (pushing a ton of registers).

I need to find a way to define this function fully in assembly yet retain using the arduino libraries so that I can reduce the interrupt function overhead (5 clock cycles at mhz according to the datasheet gives about 625 nanoseconds delay.

Could you do it in hardware? A flip-flop with a inverter on the clock input?

Paul

uglyoldbob:
Im having some difficulty with timing on an interrupt function on a teensy2 board I have. I have int1 configured to interrupt on falling edge and the function toggles a digital output and is done. Im seeing a 7 microsecond delay (with oscilloscope) due to overhead in the c function (pushing a ton of registers).

I need to find a way to define this function fully in assembly yet retain using the arduino libraries so that I can reduce the interrupt function overhead (5 clock cycles at mhz according to the datasheet gives about 625 nanoseconds delay.

Within C/C++ code, you can use asm outside of a function block to put assembly code down:

// Same as int foo (void) { return 0; }

__asm__ ("\n"
                  "\t.global foo\n"
                  "\t.type   foo, @function\n"
                  "foo:\n"
                  "\tldi r24,lo8(0)\n"
                  "\tldi r25,hi8(0)\n"
                   "\tret\n"
                   "\t.size   foo, .-foo\n");

Alternatively, the IDE might recognize .s files (passed to the assembler directly) and .S files (run through the preprocessor before being passed to the assembler) in the current directory or not.

Ok, well the ide can be modified to compile .s files.

CATCH: Once you do this the teensyduino stuff won't work because it won't be there. Also the teensyduino installer won't recognize the arduino folder. Perhaps I copied the new files incorrectly?

The inline assembly does work though. Thanks for the tip.
From the main sketch.

__asm__ ("\n"
                  "\t.global pants\n"
                  "\t.type   pants, @function\n"
                  "pants:\n"
                  "\tldi r24,lo8(0)\n"
                  "\tldi r25,hi8(0)\n"
                   "\tret\n"
                   "\t.size   pants, .-pants\n");
extern "C" int pants();

//bla
void loop()
{
  pants();
}

the function toggles a digital output and is done

You don't need assembler for that.
Writing to the PIN register toggles the output bit, for example:

PINC = PINC | 0b00000100; // toggle port c, bit 2

Can't get much faster than that. I think the compiler makes it one instruction.