What's wrong with this statement on x86-64?

社会主义新天地 提交于 2019-12-10 21:23:40

问题


This function aims to get the start address of the stack:

unsigned long find_start(void){
        __asm__("movq %rsp, %eax");
}

When I compile it,getting an error:

Error: suffix or operands invalid for `movq'

回答1:


movq is an instruction that expects 64-bit operands. rsp is a 64-bit register, while eax is a 32-bit register.

Perhaps try rax?




回答2:


%eax is the 32-bit GP register. However you are trying to do a 64-bit move with it. It should be %rax.




回答3:


You need, as stated, to use the 64-bit register %rax.

Regarding the fact that the stack pointer is different each time, I suspect that you are seeing the results of address space layout randomization, and in real time at that...



来源:https://stackoverflow.com/questions/5691345/whats-wrong-with-this-statement-on-x86-64

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!