Shop OBEX P1 Docs P2 Docs Learn Events
dsPIC - Assembly and C? — Parallax Forums

dsPIC - Assembly and C?

John A. ZoidbergJohn A. Zoidberg Posts: 514
edited 2011-04-20 18:16 in General Discussion
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? :D

Comments

  • kwinnkwinn Posts: 8,697
    edited 2011-04-19 18:39
    For programming an old minicomputer with 16 general purpose registers we split them into groups and gave them names denoting their usage. For instance, any register starting with n had to be left unchanged by a lower level subroutine.
  • Erik FriesenErik Friesen Posts: 1,071
    edited 2011-04-20 05:06
    Your question would be better answered in the microchip c30, or dspic33/30 forums. Why assembler?
  • mindrobotsmindrobots Posts: 6,506
    edited 2011-04-20 08:30
    Assembler, the land of many choices:

    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
  • LeonLeon Posts: 7,620
    edited 2011-04-20 09:29
    I think that the C30 documentation has some recommendations for techniques when mixing C and assembler.
  • John A. ZoidbergJohn A. Zoidberg Posts: 514
    edited 2011-04-20 18:16
    Your question would be better answered in the microchip c30, or dspic33/30 forums. Why assembler?

    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.
    Leon wrote: »
    I think that the C30 documentation has some recommendations for techniques when mixing C and assembler.

    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. :D
Sign In or Register to comment.