This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hi all,
I've been rewriting some C functions into assembler for speed optimisation. So far it's looking almost 2x faster, but I've hit a problem.
For ease of code and speed, I've been using directly accessed variables to pass data from C to asm, however I don't know how to keep them on the same data page (so you get the code accessing the wrong location if you're not careful).
Loading the data page pointer every time a variable is accessed kills off any speed advantage of direct variables - I might as well use a structure and increment/reload the offset pointer.
If there a simple way of forcing a bank of variables to be in the same page (either in C or assembler)? Loading the DP once at the start of the function would be ideal.
Also, is there any way of declaring a structure in C and then accessing the variables directly in assembler (i.e. mov ACC,cart.apples?) The particular assembler block only ever reads one structure, so it can directly read variables as they'll never change location.
Any advice or literature suggestion are, greatly appreciated (and sorry if this has all been asked before).
John
edit: I should add, it's a C2811 Ti DSP and the variables are all declared in C and accessed by the assembler using .global tags.
John Bennett said:If there a simple way of forcing a bank of variables to be in the same page (either in C or assembler)? Loading the DP once at the start of the function would be ideal.
Create a section of appropriate size and alignment in your linker command file and put your variables into this section using #pragma DATA_SECTION.
John Bennett said:Also, is there any way of declaring a structure in C and then accessing the variables directly in assembler (i.e. mov ACC,cart.apples?) The particular assembler block only ever reads one structure, so it can directly read variables as they'll never change location.
The .cdecls assembly directive may be useful
.John Bennett said:Any advice or literature suggestion are, greatly appreciated (and sorry if this has all been asked before
spru513 and spru514 explain in detail what I mentioned above.
Regards, Johannes
Keeping data objects on one data page is called "blocking", and it is done automatically for variables declared in C. Objects which are larger than one data page will be aligned to the alignment of a data page.