I need to mix c code and assembler code in a C file with the IAR C Compiler. I need to do something like this (This program is only an example, I know this program is "stupid", but it is only an example of I want to do): unsigned char i; void main(void) { i; i=i+10; //ASM CODE IN C FILE push.w &i push.w R12 mov.w #25,&i } But I can not find how can I do that.In other C compilers you usually have an expresion like asm("push.w &i"), but in the IAR documentation I do not find anything like this, and the C compiler does not compile something like asm(" push.w R12") or similar. Can I do that? How? Thanks.
Mixing c and asm in IAR for MSP430.
Started by ●October 8, 2004
Reply by ●October 9, 20042004-10-09
There is an appnote that's titled "Mixing C and Assembler with the MSP430" on TI's site, (Document no: slaa140.pdf) comes with source code as well for the examples. HTH Jay --- In msp430@msp4..., "Jose Maria Lorenzo" <jmlmanzano@h...> wrote: > I need to mix c code and assembler code in a C file with the IAR C Compiler. > > I need to do something like this (This program is only an example, I know this program is "stupid", but it is only an example of I want to do): > > unsigned char i; > void main(void) > { > i; > i=i+10; > //ASM CODE IN C FILE > push.w &i > push.w R12 > mov.w #25,&i > } > > But I can not find how can I do that.In other C compilers you usually have an expresion like asm("push.w &i"), but in the IAR documentation I do not find anything like this, and the C compiler does not compile something like asm(" push.w R12") or similar. > > Can I do that? How? > > Thanks. > >
Reply by ●October 11, 20042004-10-11
> I need to mix c code and assembler code in a C
file with the IAR C
> Compiler.
>
> I need to do something like this (This program is only an example, I
> know this program is "stupid", but it is only an example of I
want
> to do):
>
> unsigned char i;
> void main(void)
> {
> i;
> i=i+10;
> //ASM CODE IN C FILE
> push.w &i
> push.w R12
> mov.w #25,&i
> }
>
> But I can not find how can I do that.In other C compilers you
> usually have an expresion like asm("push.w &i"), but in the
IAR
> documentation I do not find anything like this, and the C compiler
> does not compile something like asm(" push.w R12") or similar.
>
> Can I do that? How?
Hi Jose!
The IAR compiler, from version 2, supports the "asm" key word, that is
you can write something like:
asm("mov R4, R5")
Note that there are some limitations to this that makes it difficult
for you to use it. The main thing is that the run-time environment
must not be chnaged, that is, you can't use "push" inside the
sequence, unless you also perform the correponding pop (or add #x,
sp).
Also, you can't change the value of any normal processor register, so
if you need any you must either push and pop, or lock some registers
(R4 and R5 are available for this.)
In my experience it is almost always more efficient to write a
subroutine in real assembler and call it from your C code.
-- Anders Lindgren, IAR System
--
Disclaimer: Opinions expressed in this posting are strictly my own and
not necessarily those of my employer.