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.

Mixing C and ASM

Is there a easy way to convert asm code writen to IAR compiler V.2 so it works on IAR compiler V.5

the compiler don't like RTMODEL "__rt_version", "2", and if I edit RTMODEL to RTMODEL "__rt_version", "3"
it will compile, but I can see in my call stack that I do not return to the right place where I enter the asm code.

the asm code is placed in seperated files .s43

  • Possibly you're working with an MSP with MSP430X (20 bit) core.

    The compiler will default to large code model, generating 20 bit funciton calls (CALLA). If your ASM code uses the normal 16 bit RET instruction, this will ause problems. Using RETA instead will properly return to funcitons above 64k and also no leave surplus wors on the stack.

    Or you configure the compiler to use small code model instead.

    It's just a possible explanation, not necessarily the only one.

  • Michael Hansen said:
    Is there a easy way to convert asm code writen to IAR compiler V.2 so it works on IAR compiler V.5

    You would have to consult the compiler documentation for both version, and spot the differences...

  • c code uses the call stack to pass parameters too. And this may be different between V2 and V5.

    If you still have the V2 compiler, you can find this out. Write a simple test program in c where you use a call with a lot of parameters. Compile it with V2 and examine how the parameters are passed. Compile the same with V5 and examine how the parameters are passed. Your assembly routines have to use the same ways.

  • old_cow_yellow said:
    c code uses the call stack to pass parameters too.

    This is known as the Calling Convention - it will be described in the compiler documentation.

    old_cow_yellow said:
    And this may be different between V2 and V5.

    Indeed - hance the need to study the documentation for both versions.

    old_cow_yellow said:
    Compile it with V2 and examine how the parameters are passed.

    This is a good way to back-up what you find by studying the documentation; but, if you only do this, how will you know that you haven't just happened to stumble upon some special case...?

    Alternatively, for each assembler function that you call from 'C', write a "skeleton" in 'C', compile it, and then fill your custom assembler code into the generated assembler "skeleton"...

**Attention** This is a public forum