Martin Allard
Martin Allard

Reputation: 293

inline asm with gcc

I have this part of code that was compiling using ARMASM :

/* Software Interrupt */
/* we must save lr in case it is called from SVC mode */
#define ngARMSwi( code)   __asm { SWI code,{},{},{lr} }

example of use : ngARMSwi( 0x23);

I try to convert this to compile using gcc (code sourcery GCC-4.6.2 eabi). I found this link http://www.ethernut.de/en/documents/arm-inline-asm.html but I cannot find a way to compile this line correctly.

my best try is

#define ngARMSwi( code)  __asm__ ("SWI " (code) : : :"lr" )

but I get compile error :

error: expected ':' or ')' before '(' token

Any help is appreciated!

Upvotes: 2

Views: 717

Answers (1)

Chris Dodd
Chris Dodd

Reputation: 126518

You probably want

#define ngARMSwi(code) __asm__("SWI %0" : : "I"(code) : "lr")

Note that code is an input to the instruction, so it goes in the third section. Its place in the instuction is marked by the %0 in the string. The I is a constraint on code, indicating that it must be an 8-bit constant.

Upvotes: 1

Related Questions