2014-05-21 4 views
0

eax를 2만큼 오른쪽으로 시프트하려고합니다. 현재는 0x037f이고 0x0003으로 가져 오려고합니다.프로그램 수신 신호 SIGSEGV, ASM에서 SHRD를 사용하는 세그먼트 오류

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" 
    ); 
+1

아마도 내가 잘못 생각하고 있지만, 3 가지 주장을 취하지 않을 것입니까? 네가 필요로하는 일을'쉬지 '않을까? – Joe

+0

shr은 eax를 주었을 때 그것을 좋아하지 않습니다. 내 변수 중 하나를 주려고했는데, 너무 많은 피연산자를주고 있다고 말했기 때문에 그렇게 생각하지 않습니다. –

+0

편집 : 시도 shr %% eax, 컴파일 된, 대신 0x037f 복용 및 내게 0x0003 제공, 그것은 내게 0x1bf했다. –

답변

1

나는 간단한 구문 문제였습니다.

shr $8, %%eax 

전에, eax는 0x037F였습니다. 이것은 eax 8 비트를 쉬프트 한 다음 0x0003이됩니다.