x86-64 GNU 汇编

发布于 2025-01-07 20:30:19 字数 375 浏览 6 评论 0原文

在调查崩溃时,我遇到了以下代码片段,并立即意识到 mov 指令实际上应该是 movq 以获得正确的 64 位寄存器操作。

#elif defined(__x86_64__)
    unsigned long rbp;
    __asm__ volatile ("mov %%rbp, %0" : "=r" (rbp));
    sp = (void **) rbp;
#else

除此之外,我还发现文档声称 x86-64 的 rbp 寄存器是通用的,不包含当前帧的地址。我还发现文档声称 rbp 确实包含当前帧的地址。有人可以澄清一下吗?

While investigating a crash, I came across the following code snippet and immediately recognized that the mov instruction should actually be movq to get the correct 64-bit register operation.

#elif defined(__x86_64__)
    unsigned long rbp;
    __asm__ volatile ("mov %%rbp, %0" : "=r" (rbp));
    sp = (void **) rbp;
#else

Further to this, I also found documentation that claims that the rbp register for x86-64 is general purpose and does not contain the address of the current frame. I have also found documentation that claims that rbp does contain the address of the current frame. Can someone clarify?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

愁杀 2025-01-14 20:30:19

关于问题的第一部分(movq 而不是 mov),汇编器(在本例中)将识别出您的操作数是 64 位,并且会正确地使用movqmov 不是一条有效的指令,它是一种告诉汇编器“根据操作数使用正确的 mov 变体”的方法。

关于第二部分,它实际上是两者:它是一个通用寄存器,从某种意义上说,它可以保存任何值。它还用作堆栈帧基指针。 AMD64 应用程序编程手册的“2.4 堆栈操作”部分说:

堆栈是内存中堆栈段的一部分,用于链接
程序。软件约定通常使用以下方式定义堆栈
堆栈帧,由两个寄存器组成——堆栈帧基址
指针 (rBP) 和堆栈指针 (rSP) —

Regarding the first part of your question (movq instead of mov), the assembler (as, in this case), will recognize that your operand is 64 bits, and will correctly use movq. mov is not a valid instruction, it's a way to tell the assembler "use the right mov variant depending on the operands".

Regarding the second part, it's actually both: it's a general purpose register, in the sense that it can hold any value. It is also used as a stack-frame base pointer. The '2.4 Stack operation' section of the AMD64 Application programming manual says:

A stack is a portion of a stack segment in memory that is used to link
procedures. Software conventions typically define stacks using a
stack frame, which consists of two registers—a stack-frame base
pointer (rBP) and a stack pointer (rSP)—

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文