dsPIC - Assembly and C?
John A. Zoidberg
Posts: 514
Hello there,
I just got a grasp of some Assembler in dsPIC, and they are much easier to use than the older PIC counterparts.
However, due to the abundance of W registers (W0-W15), there is bound to be mistakes, especially conflicts with the usage of these registers in C and the assembly.
It is because I need to use some assembler in C in the interrupts.
Any ideas to prevent the conflict?
I just got a grasp of some Assembler in dsPIC, and they are much easier to use than the older PIC counterparts.
However, due to the abundance of W registers (W0-W15), there is bound to be mistakes, especially conflicts with the usage of these registers in C and the assembly.
It is because I need to use some assembler in C in the interrupts.
Any ideas to prevent the conflict?
Comments
1) determine which registers are expected by C to remain intact across a subroutine call and
a) stay away from them in your code
b) save them away in variables when you enter your code and restore them just before you leave
c) push some/all volatile registers on the stack (if there is one) when you enter and pop them off when you leave your code
d) save ENTIRE register set in variables or stack (prefereable) when you enter restore when you leave - essentially saving teh C machine state across your ASM code
2) write it all in C and for now and assume the C compiler has better code optimization and ASM skills than you do. Once you learn more and can optimize the C code better by hand, do some of the above. By then, anything in step #1 should be second nature to you.
Things to nibble on before you byte!
Rick
I'm trying to make a DDS here - at least I can keep track of the cycles and frequency produced. If it's done at C, I do not know what is the actual frequency after the interrupt latencies.
I just referred it. I will be including the ASM inside the Interrupt routine, and I might be saving a couple of W registers for rough calculations. Will be pushing W0-W4 if it's allowable.