cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with using asm code in C

biralti
Associate II
Posted on August 05, 2010 at 16:10

Problem with using asm code in C

7 REPLIES 7
chikos332
Associate II
Posted on May 17, 2011 at 14:01

Hi,

You can use an assembler function with one argument. The first argument is always loaded in register r0 of the core so you can directly handle this register:

example:

uint8_t __FUNCTION(uint8_t tmp)

{

  __ASM(''INSTRUCTION r0, r0'');

  __ASM(''bx lr'');

}

Cheers.

picguy2
Associate II
Posted on May 17, 2011 at 14:01

In chikos’s example the value of tmp is passed to the subroutine.  The address of tmp is what is wanted.  I.e. call with &tmp and adjust the function header to expect an address.

In IAR tools click on Help -> C/C++ development guide.  This opens up a pdf.  Search INLINE ASSEMBLER using case sensitivity.  

It seems that the only way IAR’s C/C++ inline asm(“...�?) can know about variable address is via a DCD statement.  I would suspect that local (stack allocated) variables might not work.

So I tried in EWARM v5.4 and it looks like even the example in the pdf does not work.  FWIW I also tried mov32.  It didn’t work either.

Posted on May 17, 2011 at 14:01

Why do you want to use inline assembler anyhow?

Why not create a proper assembler module, wth an assembler function that you can call from 'C' ?

biralti
Associate II
Posted on May 17, 2011 at 14:01

I want address of the variable instead of its value. Also i couldn't run this code. I use Ride7.

thanks for the answer.

biralti
Associate II
Posted on May 17, 2011 at 14:01

I use Ride7. I searched ''assembler'' in help files and i found somethings but in examples always RAM addresses was used for assign a value to variable. I couldn't send variable address to asm code. I try ''#define'' directive for obtain an address of variable but i couldn't use it in asm.

Thanks for your answer

biralti
Associate II
Posted on May 17, 2011 at 14:01

How could i do this? Can you give any example?

John F.
Senior
Posted on May 17, 2011 at 14:01

Hi,

You could pass the address of the variable as your function argument.

example:

    uint8_t temp;

    //call as ...

    FUNCTION(& temp);

    //function argument is pointer to variable (its address)

    uint8_t __FUNCTION(uint8_t * tmp)

    {

      __ASM(''INSTRUCTION r0, r0'');

      __ASM(''bx lr'');

    }