Author Topic: Calling ASM functions in C  (Read 14483 times)

0 Members and 1 Guest are viewing this topic.

Online nctnico

  • Super Contributor
  • ***
  • Posts: 28638
  • Country: nl
    • NCT Developments
Re: Calling ASM functions in C
« Reply #25 on: April 29, 2012, 04:10:23 pm »
Yeah, for my above example that will work because min/max are read out of eeprom at poweron, so the reciprocal can be calculated once at that point. Thanks

But i can't see it working in other areas of my code, such as this table X/Y interpolate function.
As the variables change in realtime

Code: [Select]
// (T,B,L,R = top/bot/left/right)
uint8_t quadinterpolate(uint8_t *quadTL, uint8_t *quadTR, uint8_t *quadBL, uint8_t *quadBR,
                        uint8_t *rowlabel1, uint8_t *rowlabel2, uint8_t *collabel1, uint8_t *collabel2,
                        uint8_t *inputrow, uint8_t *inputcol)
{
uint8_t colstep,rowstep,quadCAB,quadDAB,temp1;
div_t divout;

colstep = *collabel2-*collabel1;
rowstep = *rowlabel2-*rowlabel1;
temp1 = *inputcol - *collabel1;

divout =  div( (*quadTL-*quadTR) , colstep );
quadCAB = *quadTL - (divout.quot * temp1);

divout =  div( (*quadBL-*quadBR) , colstep );
quadDAB = *quadBL - (divout.quot * temp1);

divout =  div( (quadCAB-quadDAB) , rowstep );
return (quadCAB - (divout.quot * (*inputrow - *rowlabel1)));
}
Because this is all 8 bit you can use lookup tables. If you don't have the space you should consider moving to a faster controller. That will make these headaches go away very quickly. I doubt you can get more speed by using ASM. C compilers are very good at optimizing but on an 8 bit controller performance is very limited.
« Last Edit: April 29, 2012, 04:11:57 pm by nctnico »
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline PsiTopic starter

  • Super Contributor
  • ***
  • Posts: 10433
  • Country: nz
Re: Calling ASM functions in C
« Reply #26 on: April 30, 2012, 03:51:55 am »
Ok, I'll continue to have a play with the code.  It's not too bad at present, just slower than i would like.
The mcu isn't running at its max speed yet, so i have some other options available.

Thanks
Greek letter 'Psi' (not Pounds per Square Inch)
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf