RDTSC in C inline assembly causes segmentation error!

Thanks to some help you guys, I got a small assembler program almost where I want it to be. However, now there seems to be something very strange with the rdtsc team; basically, i get segmentation error on call.

int timings[64*N];
int main(void)
{

    int i;

    __asm__ __volatile__ (  
       "lea edx, [timings] \n\t"  
       "rdtsc \n\t"  
       ".rept 32 \n\t"  
       "mov eax,[edx] \n\t"  
       "inc eax \n\t"  
       "mov dword ptr [edx], eax \n\t"  
       "add edx, 4 \n\t"  
       ".endr \n\t"  
    : 
    : [timings] "m" (*timings)
   );

   for(i=0; i<32; i++)
      printf("%d\n", timings[i]); 

   return 0;
}

Leaving rdtsc, the program compiles and does what it should do. But adding the rdtsc line causes a segmentation error. I run this stuff on a dual-core machine and use to compile: gcc -masm = intel test.c

Help will be appreciated!

+3
source share
2 answers

rdtsc eax edx . (lea), timings edx rdtsc . rdtsc , , eax edx .

+5

RDTSC EDX, clobber asm. GCC , , output/clobber, . GCC, :).

0

Source: https://habr.com/ru/post/1709159/


All Articles