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.

CCS/UCD3138: Can we use assembly language in UCD3138 instead of C language ?

Part Number: UCD3138

Tool/software: Code Composer Studio

Can I use assembly language in UCD3138 ? Because I want faster processing speed in logical decision instruction .

Do you have customers use assembly laguage in UCD3138 , and they use GCC or ARM of instruction ?

  • You can use assembly language if you want to. If you know a few tips, you can generally write c code which will give you logical decision type code that is just as fast as assembly. You can integrate C and assembly, but it is risky, because the optimizer will sometimes change things and make the assembly code not match anymore. The best way to do a function is assembly is to write it in C first, and then look at the assembly generated to see how any parameters are passed, and what is pushed on the stack. Generally CCS sticks to the ARM function calling conventions.

    We use the CCS assembler. Of course, you can either use ARM or Thumb mode. If you want faster code, use ARM mode. Set the processor state to 32 bit, and set the optimization for speed optimization.

    We use assembly code in our EVMs, only for things that can't be done in C, like modifying processor status registers. For efficient C code on the ARM core, we do what I described above. We normally set our interrupts for 32 bit ARM mode, which CCS 6 requires anyway. The EVMs are not consistently set for optimization, but if you want speed, set it for optimization. It's a good idea to put all functions that are frequently called by the interrupts into the same file, and make them inline, especially if they are only called once. inline means that the function is just put inline with the calling code, not actually called as a function. That way you get the efficiency of inline code with the clarity of writing functions.

    It is also very helpful to put variables into structures. Some of our codes have many of the variables used by the interrupt in a single structure. This is very useful because of the way the ARM instruction set handles addresses. There's no way to load a 32 bit address immediately with the ARM, so it takes several extra instruction cycles whenever you access a new standalone variable. But the instructions do have large address offsets with no added overhead, especially in ARM mode. So if the new variable is in a structure that is already in use, there is no need to take any extra time to load the address. It is just handled with an offset embedded in the instruction.

    The ARM is also not that efficient with bit setting and clearing. If you are writing to a bit in a peripheral register, often you actually know the state of all the other bits. It is much faster to just write to .all, rather than setting a bit.

    Other than that, when I've needed real speed-up, I've found that understanding the logic and also understanding how slow each function can be, that I can find lots more real time by changing logic and by rationing time. But that takes a long time to figure out.

    I'd suggest first studying the ARM assembly language and then looking at the assembly code that the C compiler generates. It's pretty well optimized.
  • Thank you for your answers .