我有一段 C++ 代码(在 GNU/Linux 环境下用 g++ 编译)加载一个函数指针(它是如何做的并不重要),用一些内联汇编将一些参数推送到堆栈上,然后调用该函数,代码是这样的:
unsigned long stack[] = { 1, 23, 33, 43 };
/* save all the registers and the stack pointer */
unsigned long esp;
asm __volatile__ ( "pusha" );
asm __volatile__ ( "mov %%esp, %0" :"=m" (esp));
for( i = 0; i < sizeof(stack); i++ ){
unsigned long val = stack[i];
asm __volatile__ ( "push %0" :: "m"(val) );
}
unsigned long ret = function_pointer();
/* restore registers and stack pointer */
asm __volatile__ ( "mov %0, %%esp" :: "m" (esp) );
asm __volatile__ ( "popa" );
我想添加一些
#ifdef _LP64
// 64bit inline assembly
#else
// 32bit version as above example
#endif
但我不知道 64 位机器的内联汇编,任何人都可以帮助我吗?
谢谢