immediate value in inline assembler

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

immediate value in inline assembler

1,390 次查看
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))

标签 (1)
0 项奖励
回复
2 回复数

783 次查看
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()...

783 次查看
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 项奖励
回复