簡體   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