enum value inline assembly

Technical questions regarding the XTC tools and programming with XMOS.
diltsman
Member++
Posts: 21
Joined: Sun Mar 03, 2013 11:26 pm

enum value inline assembly

Post by diltsman »

I have the following code that compiles when I call the constructor. How would I modify the code so that it will use the enum value as an immediate instead of in a register?

I know that I can use 0x0008 in place of %1, but I would rather use the enum constant if at all possible.

Code: Select all

	enum CTRL
	{
		CTRL_INUSE_OFF	= 0x0000,
		CTRL_INUSE_ON	= 0x0008
	};

	template <TIMER T>
	class timer
	{
	public:
		timer()
		{
			asm ("setc res[%0], %1"
					: /* No output */
					:"r"(T), "r"(CTRL_INUSE_ON));
		}
	};


User avatar
segher
XCore Expert
Posts: 844
Joined: Sun Jul 11, 2010 1:31 am

Post by segher »

I use

Code: Select all

static inline void setc(u32 c, u32 d)
{
        asm("setc res[%0],%1" : : "r"(c), "ri"(d));
}
This works, but isn't quite correct: the assembler instruction only
allows 16-bit unsigned immediate values, and "i" allows any integer
value. So it will blow up if you pass something else; fortunately,
no non-16-bit values are valid for setc anyway. As far as I know
the XMOS tools do not have a constraint defined for 16-bit integers.