[英]Program received signal SIGSEGV, Segmentation fault using SHRD in ASM
I'm trying to shift eax right by 2, currently it is 0x037f and I want to get it to 0x0003. 我正在尝试将eax右移2,目前是0x037f,我想将其设置为0x0003。
I'm using Cygwin, it compiles fine but when I open it with gdb, once I get to line 7 I get the title error. 我正在使用Cygwin,它可以正常编译,但是当我用gdb打开它时,一旦进入第7行,就会出现标题错误。
I've tried changing the syntax to (%eax, 2, 0) (I want to shift it left by 2 and fill with 0's) I also tried with just a 2, it has a value of 8 because I don't know if its shifting by bytes or bits. 我试过将语法更改为(%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"
);
I found the answer, it was a simple syntax problem. 我找到了答案,这是一个简单的语法问题。
shr $8, %%eax
Before, eax was 0x037F. 以前,eax是0x037F。 This shifted eax 8 bits, which then made it 0x0003. 这将eax移位了8位,然后使其变为0x0003。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.