我有以下内联汇编代码。但是当我试图编译它时,它抛出了代码片段后面提到的错误。
unsigned int func(void)
{
__asm__ ("mfspr r3, svr;");
}下面是错误。
{standard input}: Assembler messages:
{standard input}:3349: Error: unsupported relocation against r3
{standard input}:3349: Error: unsupported relocation against svr
{standard input}:3375: Error: unsupported relocation against r3
{standard input}:3375: Error: unsupported relocation against svr
{standard input}:3510: Error: unsupported relocation against r3
{standard input}:3510: Error: unsupported relocation against svr
{standard input}:3517: Error: unsupported relocation against r3
{standard input}:3517: Error: unsupported relocation against svr有人能帮我修好这些吗?
发布于 2015-05-15 15:45:29
显然,gas没有内置对这些寄存器的支持。为了使用它们,您应该自己定义它们,或者显式地使用它们的索引,如下所示:
mfspr 3, <some_index_here>或者,您可以包括:ppc_asm.tmpl。
如果你的核心是一个e500,那么svr索引应该是1023。
发布于 2015-05-15 15:51:36
您应该显式地指定输入和输出。正如所写的,你的ASM块可能会被优化出来!
unsigned int func(void)
{
unsigned x;
__asm__("mfspr %0, svr" : "=b"(x));
return x;
}编译器足够聪明,能够计算出寄存器应该是r3。(这是编译器的主要工作之一:分配寄存器以减少额外的移动。)
如果省略了输出规范,然后在启用优化的情况下进行编译,您可能会发现您的函数是空的,到处都找不到mfspr操作码。
发布于 2015-09-16 01:29:07
如果您将-mregnames选项传递给汇编程序,则至少会消除一些错误。(-Wa,-mregnames)。gas 2.19支持以下PPC的符号寄存器名称(来自binutils-2.19/gas/config/tc-ppc.c):
/* List of registers that are pre-defined:
Each general register has predefined names of the form:
1. r<reg_num> which has the value <reg_num>.
2. r.<reg_num> which has the value <reg_num>.
Each floating point register has predefined names of the form:
1. f<reg_num> which has the value <reg_num>.
2. f.<reg_num> which has the value <reg_num>.
Each vector unit register has predefined names of the form:
1. v<reg_num> which has the value <reg_num>.
2. v.<reg_num> which has the value <reg_num>.
Each condition register has predefined names of the form:
1. cr<reg_num> which has the value <reg_num>.
2. cr.<reg_num> which has the value <reg_num>.
There are individual registers as well:
sp or r.sp has the value 1
rtoc or r.toc has the value 2
fpscr has the value 0
xer has the value 1
lr has the value 8
ctr has the value 9
pmr has the value 0
dar has the value 19
dsisr has the value 18
dec has the value 22
sdr1 has the value 25
srr0 has the value 26
srr1 has the value 27
The table is sorted. Suitable for searching by a binary search. */https://stackoverflow.com/questions/30253742
复制相似问题