gpt4 book ai didi

assembly - 为什么我不能保存 rip 的值?

转载 作者:行者123 更新时间:2023-12-04 13:33:27 26 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Reading program counter directly

(7 个回答)


4年前关闭。



#include <stdint.h>
uint64_t rip;
int main()
{
asm(
"movq %%rip, %0\n" : "=m" (rip)
);

sleep(10);
}

当我编译时,我得到
cc -m64    rip.c   -o rip
/tmp/ccwNbZi1.s: Assembler messages:
/tmp/ccwNbZi1.s:12: Error: suffix or operands invalid for `movq'
make: *** [rip] Error 1

最佳答案

你看不懂(E|R)IP因为没有 x86(/64) 指令可以直接读取它。
“阅读”它的唯一方法是使用 CALL 调用电话。操作说明。它会将返回地址保存在堆栈中,并且您可以读取该地址。
更新 :在 64 位模式下,您可以利用 RIP -相对寻址,所以LEA RAX, [RIP]会在 RAX 中给你它自己的地址.另一个解决方法是 MOV RAX, $在 assembly 中。

关于assembly - 为什么我不能保存 rip 的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12397451/

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