Reduction timing
Up to M32C
hello to everyone
i have to decrease the time which m32c87 has compiled the code;
i mean this code is being compiled about 30 micro second , i want it to be about 15 micro second or below the same code ,
please help ..
for(i=0;i<16;i++)
{
adcresult2008[i]=adcresultold2008[i]+(adcresult2008[i]-adcresultold2008[i])>>1;
adcresultold2008[i]=adcresult2008[i];
}
thanks in advance
Does this code have the correct result?
I think you want to calculate
adcresult2008 = adcresultold2008 + ((adcresult2008 - adcresultold2008)/2);
From the assembler code your example calculates
adcresult2008 = (adcresultold2008 + adcresult2008 - adcresultold2008)/2;
This is a little bit faster:
signed int j;
near signed int adcresult2008[16], adcresultold2008[16];
for(j=15;j>=0;j--)
{
adcresultold2008[j]=adcresultold2008[j]+((adcresult2008[j]-adcresultold2008[j])>>1);
}
My debugger said the routine took sometihng around 14µs. And this should include some overhead from the debugger. I did not check with an oscilloscope.
Are you sure you run at maximum speed with 32MHz?
hello
i am using hew for programming m32c87,
can you send the assembler code of the code at below?? pleaseeeeee
for(i=0;i<16;i++)
{
adcresult2008[i]=adcresultold2008[i]+(( adcresult2008[i]-adcresultold2008[i])>>1) ;
adcresultold2008[i]=adcresult2008[i];
}
thanks in advance very much
When do you take the new A/D reading and stuff it in the array? Is there a reason you need to do all the calculations at once?
You'd be able to eliminate the loop overhead completely, if you did the calculation each time a new value was stuffed in the array.
thank you very much, i solved , i decreased 8 mikro second...
i want to just learn the assemble code of the codes
If you want to learn assembler codes tell the compiler to include the assembler code in the list files, or tell the compiler to generate assembler sources.
i decided not to use array and loop, is there anybody who will change the codes to the assembler codes ,,
beside i want to learn as308 assemble ,, but i could not learn how i can start to main block as C,
i mean i can learn command set, but i want to learn how i will allocate ram space, how i can come to main block according to C,
for(i=0;i<16;i++)
{
adcresult2008[i]=adcresultold2008[i]+(( adcresult2008[i]-adcresultold2008[i])>>1) ;
adcresultold2008[i]=adcresult2008[i];
}
for example in C, we must write first #include files, #define ,#pragma, variables, then we can pass to main block,,
we do not need to allocate ram , place of variables...... how can we make that until main block in assebler
thanks very much
As I said, just tell the compiler to generate an assembler file of your code. You can see what it does to reserve RAM, how it writes assembler code, all these things.

