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.

MSP432P401R: Mixing C and ASM and using inline assembly

Part Number: MSP432P401R

Hello everyone,

I found out my code was slow at a certain section and wanted to write it in assembly because I have an idea how to do it and it would be faster.
The thing is, I can't find any tutorials about ASM on MSP432.

I found a tutorial about mixing ASM and C for the MSP430 but it uses a different processor architecture(RISK) and this one is ARM.
I also found the instruction set for the ARM and I generated ASM files in CCS so I could analyse the code.

These are the questions that are bothering me:
1) Where can I find good instruction how to use inline ASM? How to define input and output for inline and so on...?

2) Is there anyone or any tutorial for Mixing ASM and C. For example writing one function in ASM and calling it from C.
Could someone take a little time and make an example and make a program which adds 2 numbers and an ASM function that gets 2 numbers through parameters and returns the result?

An example like this would mean the world to me because that is all I need to start writing my own functions. I have a lot of experience with ASM but not much with mixing C and ASM.

3) In the ASM generated by CCS there are some A1-A4 registers they use and I guess they are accumulators but why can't I find anything in the file for ARM Cortex M4. I only found register r0-r12 I think.

What are A1-A4 and why can't I find them?

Thanks in advanced.

  • Hello,
    I think the best place to start is with SPNU151 (www.ti.com/.../spnu151n.pdf ).

    (1) I would recommend going to the ARM community for specific assembly examples. Today TI does not have or plan to provide assembly for the MSP432.
    (2) You can refer to the document above.
    (3) A1 though A4 are synonymous with r0-r3 (infocenter.arm.com/.../index.jsp ).

    Best Regards,
    Chris
  • The ARM infocenter page, as suggested by Chris, is IMHO the best place for core-related documentation, including the machine instructions.

    However, trying to beat a modestly modern compiler in efficiency is mostly a vain endeavour ("wild-goose chase"). Just turn on proper optimization.

  • You may want to consider making your assembly code a c-callable function, unless it is a stand-alone block of code like an interrupt service routine. Years ago, I wrote an appnote that would probably still be useful:

    www.ti.com/.../spra806.pdf
  • I'll go one by one:

    Chris Sterzik: Thanks for the info, even though you couldn't give me an example, you helped me a lot. I read all about conventions and other thing I need to know, I also found out that the __asm(); is practically useless because I can't use local variables in it. Thank you very much.

    f. m.: You are 99% right but I looked at the generated .asm files and I found a few place I could code it better. This part of the code is very important for me to be fast, so I need to optimize it even more.

    Todd Anderson78572: Oh My God. Your tutorial did it. I can't believe it was so easy. The thing is, I can code in ASM but I hate all the additional code I need to write for it to compile. And your method practically did all the work. Now I can focus on coding and not on some file conventions. I follow the function calling conventions, just mentioning this so people don't think I hate using all conventions.

    Thank you all for the great and quick answers. I work at a different time zone(when you sleep) and when I go home, you all get to work. So I see the answers during my next work day.

    Saša
  • Just some additional comments:

    There are several good ARM assembler references and tutorials around, just try your favourite search engine.

    I'm not familiar with the MSP432 intricacies, but moving time-critical routines to RAM might help. Some vendor's Flash implementations are notoriously slow (naming ST here ...), so executing routines from RAM might speed it up. If I remember correctly, it is supported by the MSP432, but I'm not sure. And for max. 48 MHz, it might not really make a difference.

    jasaleja said:
    I work at a different time zone(when you sleep) and when I go home, you all get to work.

    That's a guess of yours. I'm out-of-sync a few hours, too.

**Attention** This is a public forum