繁体   English   中英

编程接收到的信号SIGSEGV,在ASM中使用SHRD进行分段故障

[英]Program received signal SIGSEGV, Segmentation fault using SHRD in ASM

我正在尝试将eax右移2,目前是0x037f,我想将其设置为0x0003。

我正在使用Cygwin,它可以正常编译,但是当我用gdb打开它时,一旦进入第7行,就会出现标题错误。

我试过将语法更改为(%eax,2,0)(我想将其左移2并用0填充)我也尝试过使用2,它的值为8,因为我不知道如果按字节或位移动。

     asm("   push    %%eax                           \n"
         "   push    %%ebx                           \n" 
         "   push    %[nIn]                          \n"
         "   fstcw   %[trueCWIn]                     \n"     //store FPU CW into trueCW
         "   mov     %[trueCWOut], %%eax             \n"     //store old FPU CW into tempVar
         "   mov     %%eax, %[tempVarIn]             \n"     //store old FPU CW into tempVar
         "   shrd    %%eax,8                         \n"     //shift FPU CW right to bytes
         "   add     %[roundModeOut], %%eax          \n"     //adding rounding modifier
                                                            //shift left 2 bytes
                                                            //add in restore mask (0x007F)
         "   frndint                                 \n"     //do rounding calculation
                                                            //store result into n
         "   fldcw   %[trueCWIn]                     \n"     //restoring the FPU CW to normal
         "   pop     %%ebx                           \n"
         "   pop     %%eax                           \n"

         :   [trueCWOut]     "=m"    (trueCW),
             [tempCWOut]     "=m"    (tempCW),
             [maskOut]       "=m"    (mask),
             [tempVarOut]    "=m"    (tempVar),
             [roundModeOut]  "=m"    (roundMode),
             [nOut]          "=m"    (n)

         :   [trueCWIn]      "m"     (trueCW),
             [tempCWIn]      "m"     (tempCW),
             [maskIn]        "m"     (mask),
             [tempVarIn]     "m"     (tempVar),
             [roundModeIn]   "m"     (roundMode),
             [nIn]           "m"     (n)
         :"eax", "ebx"
    );

我找到了答案,这是一个简单的语法问题。

shr $8, %%eax

以前,eax是0x037F。 这将eax移位了8位,然后使其变为0x0003。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM