gpt4 book ai didi

c - C 内联汇编中的 RDTSC 导致段错误!

转载 作者:行者123 更新时间:2023-12-02 04:55:18 25 4
gpt4 key购买 nike

感谢你们的帮助,我的小内联汇编程序几乎就在我想要的地方。然而,现在 rdtsc 命令似乎发生了一些非常奇怪的事情;基本上,我在调用它时遇到了段错误。

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;
}

忽略 rdtsc,程序将编译并执行其应该执行的操作。但是添加 rdtsc 行会导致段错误。我在双核机器上运行这个东西并用于编译:gcc -masm=intel test.c

帮助将不胜感激!

最佳答案

rdtsc 使用滴答计数器的部分覆盖 eaxedx。由于您之前将 timings 的地址加载 (lea) 到 edx 上,rdtsc 会扰乱您的程序功能。您可以将 rdtsc 移至命令链的上层,或者使用 eaxedx 以外的寄存器来实现程序功能。

关于c - C 内联汇编中的 RDTSC 导致段错误!,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/914199/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com