immediate value in inline assembler

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

immediate value in inline assembler

1,259 Views
clemensreibetan
Contributor I

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))

Labels (1)
0 Kudos
2 Replies

652 Views
lunminliang
NXP Employee
NXP Employee

Hi,

I tried your code snippet in a Bareboard project wizard for P4080, in CodeWarrior 10.4, with also gcc-4.8.2-Ee500mc-eabi, the build is no problem... I put it in the above of main()...

652 Views
clemensreibetan
Contributor I

Ok I also got it to work.

I just changed optimization from -O0 to -O3.

It seems to work with all optimization levels except for O0.

Thanks for your testing.

0 Kudos