AnsweredAssumed Answered

some function calls take longer to call and return

Question asked by MarcZ on Jun 9, 2013
Latest reply on Jun 12, 2013 by CraigG



We have done a test as follows:


void DummyFunction(void)


SRU(LOW,DAI_PB16_I); // Set the DAI P16

float i;          //declare an auto-variable

static float j;          //declare a static variable

register float k;     //declare a variable to be registered






SRU(HIGH,DAI_PB16_I); // Set the DAI P16



In an interrupt, we call the dummy function like this:


SRU(HIGH,DAI_PB16_I); // Set the DAI P16


SRU(LOW,DAI_PB16_I); // Set the DAI P16



When we scope port bit 16 in this case, we see two pulses where the port bit is high for 40 nanoseconds. So (ignoring the amount of time the SRU function takes to raise or lower a port bit) it means that it takes 40nS to call a function, and 40nS to return from a function.


However, when we try this same test with another, much larger function, we see that it takes 130nS to call the function and 80nS to return.


At first, we thought maybe it was because the larger function declares auto-variables, but when we tried declaring auto, static, and registered variables in our dummy function, it remains fast.


Why is it that calling and returning from the dummy function is faster than our larger function?


Thank you,