unsigned long start, stop;
register unsigned long sp asm ("sp");
start = sp;
这行代码声明 - 声明变量 sp
而不使用初始值设定项。
最佳答案
不同的体系结构使用不同的寄存器作为堆栈指针。下面用一个例子(linux+elf)_start函数来演示:
//unfortunately gcc has no builtin for stack pointer, so we use assembly
#ifdef __x86_64__ || defined __i386__
#define STACK_POINTER "esp"
#elif defined __aarch64__
#define STACK_POINTER "x13"
#elif defined __arm__
#define STACK_POINTER "r13"
#endif
char **environ;
void exit(int);
int main();
void _start(void){
register long *sp __asm__( STACK_POINTER );
//if you don't use argc, argv or envp/environ, you can just remove them
long argc = *sp;
char **argv = (char **)(sp + 1);
environ = (char **)(sp + argc + 1);
exit(main(argc, argv, environ) );
__builtin_unreachable(); //or for(;;); to shut up gcc
}
关于c - C语言中如何初始化寄存器unsigned long,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28424196/