3

下面是我用 C 和内联汇编编写的一段代码,用于将一些short值从数组加载blk到 ARMR寄存器。

...
short *blk; 
... //blk memory allocation and initialization
short tmp0, tmp1, tmp2;
asm volatile (
"ldrh %[tmp0], [%0]\n\t"
"ldrh %[tmp1], [%1]\n\t"
"ldrh %[tmp2], [%2]\n\t"
: [tmp0] "=r" (tmp0), [tmp1] "=r" (tmp1), [tmp2] "=r" (tmp2)
: "m" (blk[0])  , "m" (blk[8]), "m" (blk[8*2])
: 
);

我从 arm gcc 4.6 收到此错误消息

/tmp/ccDEBLCN.s:266: Error: ARM register expected -- `ldrh r3,[[r5,#0]]'

GCC 抱怨ldrh %[tmp2], [%2]线路,但我不明白为什么。我看了一下LDRH指令,在我看来我的指令模板是正确的。

Load memory halfword [15:0] from register address + 5-bit immediate offset
LDRH <Rd>, [<Rn>, #<immed_5> * 2]

顺便说一句,这是我用来编译它的命令:

arm-none-linux-gnueabi-gcc -O2 -march=armv7-a -mthumb 
4

2 回答 2

2
asm (
"ldrh %[tmp0], %[ref0]\n\t"
"ldrh %[tmp1], %[ref1]\n\t"
"ldrh %[tmp2], %[ref2]\n\t"
: [tmp0] "=&r" (tmp0), [tmp1] "=&r" (tmp1), [tmp2] "=r" (tmp2)
: [ref0] "m" (blk[0])  , [ref1] "m" (blk[8]), [ref2] "m" (blk[8*2])
: 
);
于 2012-07-29T02:18:24.947 回答
1

看起来编译器可能会抱怨您的代码实际上没有做任何事情。这真的是你的本意吗?

...
short *blk; 
... //blk memory allocation and initialization
short tmp0, tmp1, tmp2;
asm volatile (
"ldrh r0,[%[BLK]]\n\t"
"ldrh r1,[%[BLK], #8]\n\t"
"ldrh r2,[%[BLK], #16]\n\t"
"strh r0,[%tmp0] \n\t"
"strh r1,[%tmp1] \n\t"
"strh r2,[%tmp2] \n\t"
: [tmp0] "r" (tmp0), [tmp1] "r" (tmp1), [tmp2] "r" (tmp2), [BLK] "r" (blk)
: "r0", "r1", "r2"
: 
);
于 2012-07-29T05:24:07.523 回答