小编Tio*_*ato的帖子

“ shld”指令产生奇怪的值

我在由g ++(7.3.0)编译的内联汇编中使用“ shld”指令。它产生一些奇怪的结果。

在Ubuntu和WSL上尝试过。

   unsigned long long hi, lo;
   //some code goes here
   //...
   asm volatile (
    "shld $0x3, %1, %0;\n"
    : "=r"(hi)
    : "r"(lo)
    :
    );
   //I expect the asm produces this:
   //hi = (hi << 3) | (lo >> 61);
   //but the actual result is:
   //hi = (lo << 3) | (lo >> 61);
   //you can see the real assembly produced by gcc below.
Run Code Online (Sandbox Code Playgroud)

我希望“ hi”中的结果值为

(hi << 3) | (lo >> 61)
Run Code Online (Sandbox Code Playgroud)

但是实际结果是

(lo << 3) | …
Run Code Online (Sandbox Code Playgroud)

c c++ assembly gcc inline-assembly

1
推荐指数
1
解决办法
85
查看次数

标签 统计

assembly ×1

c ×1

c++ ×1

gcc ×1

inline-assembly ×1