- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我找到这段代码把栈指针放入EAX寄存器(应该是C中return用的寄存器)
#include <stdio.h>
unsigned long get_sp(){
unsigned long stp;
__asm{
mov
eax, esp
}
}
void main(void){
printf("\n0x%x", get_sp());
}
我用 Geany 试过了,但没用!!然后我按照编译器日志,以这种方式更改了代码:
#include <stdio.h>
unsigned long get_sp(void);
int main(void){
printf("\n0x%ld", get_sp());
return 0;
}
unsigned long get_sp(void){
unsigned long stp;
__asm{
mov eax, esp
}
}
这次我的 main 没问题,但是 other 函数就悲剧了!!!它不识别 __asm。未知类型名称“mov”....未使用的变量'eax'...它似乎需要 __asm() 而不是 __asm{},就像函数的正常调用一样。有人可以帮助我吗?聚苯乙烯我有 debian 64 ....64 架构可能有一些问题??
最佳答案
正确的 GCC 代码应该是
__attribute__((noinline,noclone))
unsigned long get_sp(void) {
unsigned long stp;
asm(
// For x86_64: "movq %%rsp, %0"
"movl %%esp, %0"
: "=r"(stp)
);
return stp;
}
关于C 和汇编 __asm 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30904654/
我知道 __asm block 可以访问在这些 block 之外声明的变量,但我想做的是找到一种方法来访问在 __asm< 中声明的变量 从这样的 block 外部 block 。我对 C 和 C++
在我的函数中我使用 __asm { mov ecx,dword ptr [0x28F1431] mov ecx,ds:[0x28F14131] } 应该产生以下字节:0x8B0
不正确的操作数类型是什么意思? 我正在尝试将一些 C++ 代码转换为汇编程序 temp_char = OChar[i] //temp_char is a character
我正在学习汇编并在我的 Digital Mars C++ 编译器中进行一些内联。我搜索了一些东西来使程序更好,并使用这些参数来调整程序: use better C++ compiler//thin
我正在使用来自 this forum topic 的代码为了获取CPU的系列信息: #include struct cpuid_type { unsigned int eax; un
我不懂汇编,所以我不确定该怎么做。 我有一个程序正在挂接到另一个程序。我已经获得函数在 Hook 程序的 .exe 中所在位置的偏移量 #define FuncToCall 0x00447E5D 那么
好吧,我想绕过我的自定义注入(inject)函数,这样代码就可以工作了 void *DetourCreate(BYTE *src, const BYTE *dst) { int len = 5
我正在使用 VC 编译器编译此 C++ 代码。我正在尝试使用 __asm 语句调用一个采用两个 WORD(又名 unsigned short)参数的函数,如下所示: __declspec(naked)
使用内联汇编指令编译代码是否需要任何标志? 我正在尝试让 g++ 编译以下代码(从 SO 上的答案克隆而来): #include using namespace std; inline unsign
我试着用谷歌搜索这个,但找不到任何足以让我理解的信息。 int i; char msg1[] = "odd"; char msg2[] = "even"; char *ptr; __asm__("
我找到这段代码把栈指针放入EAX寄存器(应该是C中return用的寄存器) #include unsigned long get_sp(){ unsigned long stp; _
当使用 Microsoft Visual C++(不是 CLI,只是标准的原生 C++)时,内联汇编是否会导致函数优化被禁用? 当我使用 IDA 检查时, block 外的一些函数代码似乎确实发生了变
简单的问题。 C 中的函数 asm 用于在您的代码中进行内联汇编。但是它返回什么?它是常规的 eax,如果不是,它返回什么? 最佳答案 __asm__ 本身不返回值。 C 标准未定义 __asm__
我正在编写一个小型 cortex M0+ 引导加载程序。我在下面有一个内联程序集,它通过从 Flash 中的应用程序位置加载堆栈指针和重置处理程序来从引导加载程序启动主应用程序。 #define FL
这个问题已经有答案了: How to get the CPU cycle count in x86_64 from C++? (5 个回答) 已关闭 4 年前。 所以我正在尝试在 Windows 的
我在 C 程序中用 asm 编写代码,我误读了 __asm{...} 是我需要的才能做到这一点。后来我发现 __asm 适用于 MSVC 编译器,而不是 GCC。 MSVC 的 __asm 关键字在
Visual Studio 2010(或 Windows 上的其他工具)是否有任何方法可以采用十六进制操作码指令,例如 EB D2 并“解码”或以其他方式将它们翻译成人类可读的 asm? 或者,有没有
char name[25]; int generated_int; for(int i = 0; i> name; int nameLen = strlen(name); __asm { pu
据我所知,__asm { ... }; 之间的唯一区别和 __asm__("...");是第一次使用mov eax, var第二个使用 movl %0, %%eax与 :"=r" (var)在末尾。还
我正在尝试移植要使用 x86_64 C++ 编译的 ARM-C 库,但出现以下错误: In file included from /usr/include/c++/5/cwchar:44:0,
我是一名优秀的程序员,十分优秀!