On Jul 9, 2:47 am, leo <barbosa.leona...@gmail.com> wrote:
> Hi,
>
> I'm newbie on the msp430 and I need to embed some asm in my C code.
> I'm working w/ the msp430F2418 and using the IAR Workbench as a
> developing environment.
>
> I've spent some time googling and looking at some forum discussions.
> Currently, I've already tried some ideas that i saw on the web: e.g.
> to break my code into multiples as("instr") lines, to use the #pragma
> asm #pragma endasm,.... I know there's the possibility of writing the
> entire function in assembly, but in my case i really need to mix it w/
> C language.
>
> I've also couldn't find answers in the manual (I'm pretty sure they
> might be there, but i couldn't figure out everything i've read
> though -- as i said, i'm new on this platform).
>
> I'm trying to run the following inline assembly code (in fact, i've
> got two versions, the second is a gcc-based). The IAR outputs that:
>
> for the first i got sth like this:
> Error[Og006]: Syntax error in inline assembly: "Error[0]: Invalid
> syntax"
> Error[Og006]: Syntax error in inline assembly: "Error[0]:
> Error[Og005]: Unknown symbol in inline assembly: "c"
> Error[Og005]: Unknown symbol in inline assembly: "carry"
> Error while running C/C++ compiler
>
> and for the 2nd like that:
> "Error[Pe018]: expected a ")" "
>
> __asm (
> "MOV &a,r10\n"
> "MOV &b,r11\n"
> "MOV &c,r12\n"
> "MOV @r10+,r15\n"
> "MOV @r11+,r13\n"
> "ADD r13,r15\n"
> "MOV r15,(2*0)(r12)\n"
> "MOV @r10+,r15\n"
> "MOV @r11+,r13\n"
> "ADDC r13,r15\n"
> "MOV r15,(2*1)(r12)\n"
> "MOV @r10+,r15\n"
> "MOV @r11+,r13\n"
> "ADDC r13,r15\n"
> "MOV r15,(2*2)(r12)\n"
> "MOV @r10+,r15\n"
> "MOV @r11+,r13\n"
> "ADDC r13,r15\n"
> "MOV r15,(2*3)(r12)\n"
> "MOV @r10+,r15\n"
> "MOV @r11+,r13\n"
> "ADDC r13,r15\n"
> "MOV r15,(2*4)(r12)\n"
> "MOV @r10+,r15\n"
> "MOV @r11+,r13\n"
> "ADDC r13,r15\n"
> "MOV r15,(2*5)(r12)\n"
> "MOV @r10+,r15\n"
> "MOV @r11+,r13\n"
> "ADDC r13,r15\n"
> "MOV r15,(2*6)(r12)\n"
> "MOV @r10+,r15\n"
> "MOV @r11+,r13\n"
> "ADDC r13,r15\n"
> "MOV r15,(2*7)(r12)\n"
> "MOV @r10+,r15\n"
> "MOV @r11+,r13\n"
> "ADDC r13,r15\n"
> "MOV r15,(2*8)(r12)\n"
> "MOV @r10+,r15\n"
> "MOV @r11+,r13\n"
> "ADDC r13,r15\n"
> "MOV r15,(2*9)(r12)\n"
> "CLR r15\n"
> "ADC r15\n"
> "MOV r15,&carry\n"
> );
>
> asm(
> "mov %[a],r11\n\t"
> "mov %[b],r12\n\t"
> "mov @r11+,r13\n\t"
> "mov @r12+,r14\n\t"
> "add r14,r13\n\t"
> "mov %[c],r15\n\t"
> "mov r13,2*0(r15)\n\t"
> "mov @r11+,r13\n\t"
> "mov @r12+,r14\n\t"
> "addc r14,r13\n\t"
> "mov r13,2*1(r15)\n\t"
> "mov @r11+,r13\n\t"
> "mov @r12+,r14\n\t"
> "addc r14,r13\n\t"
> "mov r13,2*2(r15)\n\t"
> "mov @r11+,r13\n\t"
> "mov @r12+,r14\n\t"
> "addc r14,r13\n\t"
> "mov r13,2*3(r15)\n\t"
> "mov @r11+,r13\n\t"
> "mov @r12+,r14\n\t"
> "addc r14,r13\n\t"
> "mov r13,2*4(r15)\n\t"
> "mov @r11+,r13\n\t"
> "mov @r12+,r14\n\t"
> "addc r14,r13\n\t"
> "mov r13,2*5(r15)\n\t"
> "mov @r11+,r13\n\t"
> "mov @r12+,r14\n\t"
> "addc r14,r13\n\t"
> "mov r13,2*6(r15)\n\t"
> "mov @r11+,r13\n\t"
> "mov @r12+,r14\n\t"
> "addc r14,r13\n\t"
> "mov r13,2*7(r15)\n\t"
> "mov @r11+,r13\n\t"
> "mov @r12+,r14\n\t"
> "addc r14,r13\n\t"
> "mov r13,2*8(r15)\n\t"
> "mov @r11+,r13\n\t"
> "mov @r12+,r14\n\t"
> "addc r14,r13\n\t"
> "mov r13,2*9(r15)\n\t"
> "clr r14\n\t"
> "adc r14\n\t"
> "mov r14,%[carry]\n\t"
> : [carry] "=m" (carry)
> : [a] "m" (a), [b] "m" (b), [c] "m" (c), "[carry]" (carry)
> :"r11","r12","r13","r14","r15"
> );
>
> In the latter, I've also tried sth like that in the end:
> "mov r14,%[carry]\n\t");
> // : [carry] "=m" (carry)
> // : [a] "m" (a), [b] "m" (b), [c] "m" (c), "[carry]" (carry)
> // :"r11","r12","r13","r14","r15"
> // );
>
> But then i've got the following:
>
> mrcomba.c
> Error[Og006]: Syntax error in inline assembly: "Error[0]:
> Error[Og006]: Syntax error in inline assembly: "Error[0]:
> Error[Og006]: Syntax error in inline assembly: "Error[0]:
> Error[Og006]: Syntax error in inline assembly: "Error[0]:
> Error while running C/C++ compiler
>
> Any help will be much appreciated
>
> Cheers
>
> Leo
As I have in 6 years never used inline assembler on the IAR EW430
tools, I can't explain the error messages other than to suggest that
you are not following the requirements for entering the assembler
source.
My comment is really why would you want to do this. From a
maintenance point of view this looks like a nightmare. You are using
a lot of registers that the compiler would normally be using for its
local variables and passed parameters. If you are using these
variables both before and after the assembler fragment then your code
will fail. There is no guarantee that the register usage within the
surrounding function body will remain the same between different
releases of the compiler, so while the register usage that you have
chosen may work now there is no guarantee in the future. With the
release of the MSP430F5x series of processors there have been two
recent releases of the toolset and I expect that there may be another
when TI release the production processor versions.
If, and this is a big if, you absolutely have to use assembler, why
don't you put this chunk of assembler into a separate file and make it
into a function. The overhead of CALLA and RETA (assuming that you
are using the 430X instruction set) is really quite small when
compared to the length of your assembler block. You should also
preserve the registers that you are using.
Ian