如何使用内联汇编访问堆栈基础指针(rbp)? [英] How to access stack base pointer (rbp) using inline assembly?

查看:187
本文介绍了如何使用内联汇编访问堆栈基础指针(rbp)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的要求是通过使用内联汇编偏移rbp来访问函数调用参数.但是我找不到合适的操作数约束来指定x86中的基本指针.我使用的是Intel编译器,但文档说明它支持GCC样式内联汇编.因此,基于GCC的示例就足够了.

My requirement is to access a function call parameters by offsetting rbp using inline assembly. But I couldn't find a suitable operand constraint to specify the base pointer in x86. I am using Intel compiler but it's documentation states that it supports GCC style inline assembly. So GCC based example would be sufficient.

推荐答案

您可以尝试:

#include <stdio.h>
#include <inttypes.h>

int
main(int argc, char **argv)
{
 uint64_t n;

 __asm__ __volatile__(
   "movq %%rbp, %0\n\t"
   : "=r"(n)
 );

 printf("rbp = 0x%" PRIx64 "\n", n);
 return 0;
}

这篇关于如何使用内联汇编访问堆栈基础指针(rbp)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆