我找到了这段代码,将堆栈指针放入EAX寄存器中(这应该是C语言中“返回”的寄存器)
#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
}
}
这次我没有与主函数的问题,但是其他函数很糟糕!!! 它无法识别__asm。 未知类型名称'mov'.... 未使用变量'eax'... 它似乎想要__asm()而不是__asm{},像正常调用函数一样。 有人可以帮我吗? PS 我有Debian 64....它可能会对64位架构有些问题?
asm
的内容。你应该使用扩展语法来传递C变量到/从汇编代码中。否则,你可能会在优化方面遇到问题。 - too honest for this site