Hi there,
I have a fixed assembly code that I am not allowed to touch. This code potentially utilizes the whole internal memory of my processor.
For some reasons I now have to extend this assembly code by some other code. The other code is already available, but unfortunately it is written in C. Since I am not allowed to touch the assembly code, my problem is now, that I have to adapt the C functions in a fashion that is completly neutral to the assembly code in terms of internal memory usage. Only stack is allowed!
How can I do this?
- Is it possible to tell the compiler to locate all local variables to stack? But what about the registers, accumulator, B and PSW?
- Should I alternatively force my variables to certain locations using the _at_ keyword and save/restore those locations manually to/from stack?
- Would it work if I declare my C functions as "virtual" ISRs? If so, how can I do?
- Do you have any other ideas? Please keep in mind, that the assembly code definitely cannot be changed! Everything has to be done on C side.
Thanks Jonathan
"If the assembler code must not be "touched" or "changed" that must, presumably, mean that it is fixed? Therefore, you should be able to analyse its memory usage, and use Linker directives to exclude your 'C' functions from using those areas?"
You are right and I did this analysis. But I couldn't cover the entire code and there are paths I didn't even enter. Anyway I discovered, that even in my imperfect analysis nearly the whole internal memory was utilized. That's why I would like to exclude it generally.
""Would it work if I declare my C functions as 'virtual' ISRs?". What do you mean by that?"
My idea was to declare my C functions as 'fake ISRs' so that the compiler itself cares about register saving. I also hoped that in this case he would put local variables onto stack - but you clarified this in your post.
What I did now is to define all of my C functions as "large", so they make use of the external memory (of which I fortunately have plenty of). Maybe things are slower now, but I'll give it a try.
Unfortunately even with this mechanism there still is the problem with the registers. Can I tell the compiler not to use certain registers, let's say from bank 1-3? I would then save bank 0 myself, but wouldn't have to do for the others.
... you may be better off writing an assembler equivalent from scratch
if you can't - well you are lost anyway
Erik