2010-08-05 07:10 AM
Problem with using asm code in C
2011-05-17 05:01 AM
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.2011-05-17 05:01 AM
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.2011-05-17 05:01 AM
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' ?2011-05-17 05:01 AM
I want address of the variable instead of its value. Also i couldn't run this code. I use Ride7.
thanks for the answer.2011-05-17 05:01 AM
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 answer2011-05-17 05:01 AM
How could i do this? Can you give any example?
2011-05-17 05:01 AM
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''); }