AnsweredAssumed Answered

immediate value in inline assembler

Question asked by Clemens Reibetanz on Dec 9, 2014
Latest reply on Dec 10, 2014 by Clemens Reibetanz

Hi, I have the following problem:

I am trying to set an immediate value in an inline assembler directive like this:

template <int PMC> class PerformanceMonitor { public:     inline void freezeCounter()     {         asm ("mtpmr %0, %1" : : "i" (PMLCa), "r" (1 << 31));     } private:     const int PMLCa = PMC + 128; };

 

This leads to the following:

asm operand 0 probably doesn't match constraints

 

My question is: why does this happen and how can I set PMLCa so it can be used there?

 

In the gcc-4.8.2 manual (Simple Constraints - Using the GNU Compiler Collection (GCC)) it is written that:

i
An immediate integer operand (one with constant value) is allowed. This includes symbolic constants whose values will be known only at assembly time or later. 

 

So it should be possible to use a constant as an immediate value in inline assembler or am I wrong?

 

(Note: if i replace PMLCa in line 5 with PMC it works)

 

Thanks in advance.

Regards

Clemens

 

(I'm working bare metal on a P4080DS, used compiler in CodeWarrior is "PowerPC EABI e500mc C++ Compiler" (gcc-4.8.2-Ee500mc-eabi))

Outcomes