8

Could somebody tell me please how can I execute inline assembly code in C code using TI code composer studio (for ARM)?

I searched and tried but nothing worked.

For example, when I try this very simple code:

asm("push r0\n");

or this

__asm("push r0\n");

I always get:

[E0002] Illegal mnemonic specified push r0

1 Assembly Error, No Assembly Warnings

I read something says that my previous code is GCC style,and TI compiler doesn't accept it!. Then how can I execute my own inline assembly codes?

Mohammed Noureldin
  • 14,913
  • 17
  • 70
  • 99
  • inline assembly is very much compiler specific, so there is no expectation that inline assembly will port from one compiler version or brand to another. – old_timer Jul 04 '15 at 13:42

2 Answers2

8

Finally I found the solution!!

the main problem will be solved by adding a space or tab before the assembly instruction like this:

asm(" MOVS R0, #5\n");

This won't work:

asm("MOVS R0, #5\n");

And in push we have to put the register in braces {R0}

asm(" PUSH {R0}\n");

Hope that helps.

Mohammed Noureldin
  • 14,913
  • 17
  • 70
  • 99
0

I do not know an ARM Code Composer Studio. But I knew a TI Code Composer Studio and if the is meant, I could give you some hints. Use asm volatile ("...") might help. But with that method you can not access to C variables for example. It's much better to use so called intrinsic functions/methods which are functions that link C to assembler. Here is a link to a TI document: http://www.ti.com/lit/ug/spru187o/spru187o.pdf section 7.5.4. Here is the link from which I got the idea: https://e2e.ti.com/support/development_tools/code_composer_studio/f/81/t/3660

Peter Paul Kiefer
  • 2,114
  • 1
  • 11
  • 16
  • I really meant TI ccs (I edited the name). unfortunately, volatile method didn't work, I still get the same error. I am gonna read what you sent to me and tell you what I get. thanks. – Mohammed Noureldin Jul 04 '15 at 10:01
  • Perhaps it's as simple as write uppercase PUSH and use {} for the register lists. But that's only a guess. `asm ("PUSH {r0}\n")` – Peter Paul Kiefer Jul 04 '15 at 10:05
  • And I really should have read your last sentence. ;-) TI Compiler should know the ARM mneomonics but if not, then PUSH is an alias for `STMDB sp!, reglist` as you can read here http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0489e/Babefbce.html – Peter Paul Kiefer Jul 04 '15 at 10:13
  • ("PUSH {r0}\n") that didn't work :( . I am reading the links you sent to me (they are a little bit comlicated but I am trying). – Mohammed Noureldin Jul 04 '15 at 10:18
  • linked document is to their DSP compiler not arm – PeterM May 10 '16 at 20:49